Patch Detail
Show a patch.
GET /api/1.1/patches/17132/?format=api
{ "id": 17132, "url": "https://patchwork.libcamera.org/api/1.1/patches/17132/?format=api", "web_url": "https://patchwork.libcamera.org/patch/17132/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20220816015414.7462-6-laurent.pinchart@ideasonboard.com>", "date": "2022-08-16T01:54:10", "name": "[libcamera-devel,v4,5/9] libcamera: yaml_parser: Enable YamlObject::get() for int8_t and uint8_t", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "c70c67b3eba0a3e6a000a6dabaaafce912b94a36", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/17132/mbox/", "series": [ { "id": 3418, "url": "https://patchwork.libcamera.org/api/1.1/series/3418/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3418", "date": "2022-08-16T01:54:05", "name": "Add DPF tuning support for RkISP1", "version": 4, "mbox": "https://patchwork.libcamera.org/series/3418/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/17132/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/17132/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 2CA35C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 16 Aug 2022 01:54:39 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EBC2E61FD2;\n\tTue, 16 Aug 2022 03:54:38 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5DB0E61FC4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 16 Aug 2022 03:54:35 +0200 (CEST)", "from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F1CB9496;\n\tTue, 16 Aug 2022 03:54:34 +0200 (CEST)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660614878;\n\tbh=MnNYIntuyymR7unE1fXXD+PG9BX+3m1CqgAiFujFWp0=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=g0ih25sGKpz4xFlkF3LOVhhS0jkd6xcx+h1CYmEc9gD8I2ZW3XYbhfJHM9cOwD2wg\n\tIdR+j5OTybHnYRgc9D0P7adwoKRTornTir8xxa5UwRj7Gfea9UfyijI9xF5P7FsmXu\n\t83szzY1uo7cTnNkpdtXtf89GLkw3DSipv0u9c1deLK1cMKv+ZPqmR0l3ITONgF0Uyz\n\tMHVjHjalaH8o31abRYflLJZi2+Oh9MCjWXcSNnI7BmWY/kRZVP2iveczbX6418fi4I\n\toOGvH38YkbvvWqTcJh3g/C8Micqe5fNlTWBucYfSe5lUtZlzKftXfyfFOvj4GVY7q7\n\t/bhhjYcfyGOCw==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1660614875;\n\tbh=MnNYIntuyymR7unE1fXXD+PG9BX+3m1CqgAiFujFWp0=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=S1OJDx29WJsjxCN2rDZIsbL2yFxiuNzGFaJXfRZDbWFIRp39+Fzq5UPFzNI4ZSHk0\n\tE1v9xmfpYUIs1/+vAwrH2NAPY8iAprMxyBGu9HM4CYahD44bPzOarHSXVw03UMXMpw\n\tadTPAEHQXd9swXQYdwqAsZDh9hXmnppRtb0lYLVQ=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"S1OJDx29\"; dkim-atps=neutral", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 16 Aug 2022 04:54:10 +0300", "Message-Id": "<20220816015414.7462-6-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.35.1", "In-Reply-To": "<20220816015414.7462-1-laurent.pinchart@ideasonboard.com>", "References": "<20220816015414.7462-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v4 5/9] libcamera: yaml_parser: Enable\n\tYamlObject::get() for int8_t and uint8_t", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "From": "Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>", "Reply-To": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "The YamlObject::get() function template is implemented for 16-bit and\n32-bit integers. Add an 8-bit specialization that will be used in the\nrkisp1 IPA module, and extend the unit tests accordingly.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/internal/yaml_parser.h | 4 ++\n src/libcamera/yaml_parser.cpp | 59 ++++++++++++++++\n test/yaml-parser.cpp | 86 ++++++++++++++++++++----\n 3 files changed, 137 insertions(+), 12 deletions(-)", "diff": "diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h\nindex 5ba777d364fa..8ca71df867ab 100644\n--- a/include/libcamera/internal/yaml_parser.h\n+++ b/include/libcamera/internal/yaml_parser.h\n@@ -166,6 +166,8 @@ public:\n \t\t std::enable_if_t<\n \t\t\t std::is_same_v<bool, T> ||\n \t\t\t std::is_same_v<double, T> ||\n+\t\t\t std::is_same_v<int8_t, T> ||\n+\t\t\t std::is_same_v<uint8_t, T> ||\n \t\t\t std::is_same_v<int16_t, T> ||\n \t\t\t std::is_same_v<uint16_t, T> ||\n \t\t\t std::is_same_v<int32_t, T> ||\n@@ -188,6 +190,8 @@ public:\n \t\t std::enable_if_t<\n \t\t\t std::is_same_v<bool, T> ||\n \t\t\t std::is_same_v<double, T> ||\n+\t\t\t std::is_same_v<int8_t, T> ||\n+\t\t\t std::is_same_v<uint8_t, T> ||\n \t\t\t std::is_same_v<int16_t, T> ||\n \t\t\t std::is_same_v<uint16_t, T> ||\n \t\t\t std::is_same_v<int32_t, T> ||\ndiff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\nindex f928b7238a19..85a52c05e682 100644\n--- a/src/libcamera/yaml_parser.cpp\n+++ b/src/libcamera/yaml_parser.cpp\n@@ -131,6 +131,61 @@ std::optional<bool> YamlObject::get() const\n \treturn std::nullopt;\n }\n \n+template<>\n+std::optional<int8_t> YamlObject::get() const\n+{\n+\tif (type_ != Type::Value)\n+\t\treturn std::nullopt;\n+\n+\tif (value_ == \"\")\n+\t\treturn std::nullopt;\n+\n+\tchar *end;\n+\n+\terrno = 0;\n+\tlong value = std::strtol(value_.c_str(), &end, 10);\n+\n+\tif ('\\0' != *end || errno == ERANGE ||\n+\t value < std::numeric_limits<int8_t>::min() ||\n+\t value > std::numeric_limits<int8_t>::max())\n+\t\treturn std::nullopt;\n+\n+\treturn value;\n+}\n+\n+template<>\n+std::optional<uint8_t> YamlObject::get() const\n+{\n+\tif (type_ != Type::Value)\n+\t\treturn std::nullopt;\n+\n+\tif (value_ == \"\")\n+\t\treturn std::nullopt;\n+\n+\t/*\n+\t * libyaml parses all scalar values as strings. When a string has\n+\t * leading spaces before a minus sign, for example \" -10\", strtoul\n+\t * skips leading spaces, accepts the leading minus sign, and the\n+\t * calculated digits are negated as if by unary minus. Rule it out in\n+\t * case the user gets a large number when the value is negative.\n+\t */\n+\tstd::size_t found = value_.find_first_not_of(\" \\t\");\n+\tif (found != std::string::npos && value_[found] == '-')\n+\t\treturn std::nullopt;\n+\n+\tchar *end;\n+\n+\terrno = 0;\n+\tunsigned long value = std::strtoul(value_.c_str(), &end, 10);\n+\n+\tif ('\\0' != *end || errno == ERANGE ||\n+\t value < std::numeric_limits<uint8_t>::min() ||\n+\t value > std::numeric_limits<uint8_t>::max())\n+\t\treturn std::nullopt;\n+\n+\treturn value;\n+}\n+\n template<>\n std::optional<int16_t> YamlObject::get() const\n {\n@@ -310,6 +365,8 @@ template<typename T,\n \t std::enable_if_t<\n \t\t std::is_same_v<bool, T> ||\n \t\t std::is_same_v<double, T> ||\n+\t\t std::is_same_v<int8_t, T> ||\n+\t\t std::is_same_v<uint8_t, T> ||\n \t\t std::is_same_v<int16_t, T> ||\n \t\t std::is_same_v<uint16_t, T> ||\n \t\t std::is_same_v<int32_t, T> ||\n@@ -336,6 +393,8 @@ std::optional<std::vector<T>> YamlObject::getList() const\n \n template std::optional<std::vector<bool>> YamlObject::getList<bool>() const;\n template std::optional<std::vector<double>> YamlObject::getList<double>() const;\n+template std::optional<std::vector<int8_t>> YamlObject::getList<int8_t>() const;\n+template std::optional<std::vector<uint8_t>> YamlObject::getList<uint8_t>() const;\n template std::optional<std::vector<int16_t>> YamlObject::getList<int16_t>() const;\n template std::optional<std::vector<uint16_t>> YamlObject::getList<uint16_t>() const;\n template std::optional<std::vector<int32_t>> YamlObject::getList<int32_t>() const;\ndiff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp\nindex 28f8cc8822b3..2d92463aed98 100644\n--- a/test/yaml-parser.cpp\n+++ b/test/yaml-parser.cpp\n@@ -24,6 +24,8 @@ using namespace std;\n static const string testYaml =\n \t\"string: libcamera\\n\"\n \t\"double: 3.14159\\n\"\n+\t\"int8_t: -100\\n\"\n+\t\"uint8_t: 100\\n\"\n \t\"int16_t: -1000\\n\"\n \t\"uint16_t: 1000\\n\"\n \t\"int32_t: -100000\\n\"\n@@ -76,6 +78,8 @@ protected:\n \n \tenum class Type {\n \t\tString,\n+\t\tInt8,\n+\t\tUInt8,\n \t\tInt16,\n \t\tUInt16,\n \t\tInt32,\n@@ -90,10 +94,13 @@ protected:\n \t{\n \t\tbool isList = type == Type::List || type == Type::Size;\n \t\tbool isScalar = !isList && type != Type::Dictionary;\n+\t\tbool isInteger8 = type == Type::Int8 || type == Type::UInt8;\n \t\tbool isInteger16 = type == Type::Int16 || type == Type::UInt16;\n \t\tbool isInteger32 = type == Type::Int32 || type == Type::UInt32;\n-\t\tbool isInteger = isInteger16 || isInteger32;\n-\t\tbool isSigned = type == Type::Int16 || type == Type::Int32;\n+\t\tbool isIntegerUpTo16 = isInteger8 || isInteger16;\n+\t\tbool isIntegerUpTo32 = isIntegerUpTo16 || isInteger32;\n+\t\tbool isSigned = type == Type::Int8 || type == Type::Int16 ||\n+\t\t\t type == Type::Int32;\n \n \t\tif ((isScalar && !obj.isValue()) || (!isScalar && obj.isValue())) {\n \t\t\tstd::cerr\n@@ -124,35 +131,49 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tif (!isInteger16 && obj.get<int16_t>()) {\n+\t\tif (!isInteger8 && obj.get<int8_t>()) {\n+\t\t\tstd::cerr\n+\t\t\t\t<< \"Object \" << name << \" didn't fail to parse as \"\n+\t\t\t\t<< \"int8_t\" << std::endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif ((!isInteger8 || isSigned) && obj.get<uint8_t>()) {\n+\t\t\tstd::cerr\n+\t\t\t\t<< \"Object \" << name << \" didn't fail to parse as \"\n+\t\t\t\t<< \"uint8_t\" << std::endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (!isIntegerUpTo16 && obj.get<int16_t>()) {\n \t\t\tstd::cerr\n \t\t\t\t<< \"Object \" << name << \" didn't fail to parse as \"\n \t\t\t\t<< \"int16_t\" << std::endl;\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tif ((!isInteger16 || isSigned) && obj.get<uint16_t>()) {\n+\t\tif ((!isIntegerUpTo16 || isSigned) && obj.get<uint16_t>()) {\n \t\t\tstd::cerr\n \t\t\t\t<< \"Object \" << name << \" didn't fail to parse as \"\n \t\t\t\t<< \"uint16_t\" << std::endl;\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tif (!isInteger && obj.get<int32_t>()) {\n+\t\tif (!isIntegerUpTo32 && obj.get<int32_t>()) {\n \t\t\tstd::cerr\n \t\t\t\t<< \"Object \" << name << \" didn't fail to parse as \"\n \t\t\t\t<< \"int32_t\" << std::endl;\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tif ((!isInteger || isSigned) && obj.get<uint32_t>()) {\n+\t\tif ((!isIntegerUpTo32 || isSigned) && obj.get<uint32_t>()) {\n \t\t\tstd::cerr\n \t\t\t\t<< \"Object \" << name << \" didn't fail to parse as \"\n \t\t\t\t<< \"uint32_t\" << std::endl;\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tif (!isInteger && type != Type::Double && obj.get<double>()) {\n+\t\tif (!isIntegerUpTo32 && type != Type::Double && obj.get<double>()) {\n \t\t\tstd::cerr\n \t\t\t\t<< \"Object \" << name << \" didn't fail to parse as \"\n \t\t\t\t<< \"double\" << std::endl;\n@@ -174,8 +195,10 @@ protected:\n \t{\n \t\tuint64_t unsignedValue = static_cast<uint64_t>(value);\n \t\tstd::string strValue = std::to_string(value);\n+\t\tbool isInteger8 = type == Type::Int8 || type == Type::UInt8;\n \t\tbool isInteger16 = type == Type::Int16 || type == Type::UInt16;\n-\t\tbool isSigned = type == Type::Int16 || type == Type::Int32;\n+\t\tbool isSigned = type == Type::Int8 || type == Type::Int16 ||\n+\t\t\t\ttype == Type::Int32;\n \n \t\t/* All integers can be parsed as strings or double. */\n \n@@ -195,7 +218,27 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tif (isInteger16) {\n+\t\tif (isInteger8) {\n+\t\t\tif (obj.get<int8_t>().value_or(0) != value ||\n+\t\t\t obj.get<int8_t>(0) != value) {\n+\t\t\t\tstd::cerr\n+\t\t\t\t\t<< \"Object \" << name << \" failed to parse as \"\n+\t\t\t\t\t<< \"int8_t\" << std::endl;\n+\t\t\t\treturn TestFail;\n+\t\t\t}\n+\t\t}\n+\n+\t\tif (isInteger8 && !isSigned) {\n+\t\t\tif (obj.get<uint8_t>().value_or(0) != unsignedValue ||\n+\t\t\t obj.get<uint8_t>(0) != unsignedValue) {\n+\t\t\t\tstd::cerr\n+\t\t\t\t\t<< \"Object \" << name << \" failed to parse as \"\n+\t\t\t\t\t<< \"uint8_t\" << std::endl;\n+\t\t\t\treturn TestFail;\n+\t\t\t}\n+\t\t}\n+\n+\t\tif (isInteger8 || isInteger16) {\n \t\t\tif (obj.get<int16_t>().value_or(0) != value ||\n \t\t\t obj.get<int16_t>(0) != value) {\n \t\t\t\tstd::cerr\n@@ -205,7 +248,7 @@ protected:\n \t\t\t}\n \t\t}\n \n-\t\tif (isInteger16 && !isSigned) {\n+\t\tif ((isInteger8 || isInteger16) && !isSigned) {\n \t\t\tif (obj.get<uint16_t>().value_or(0) != unsignedValue ||\n \t\t\t obj.get<uint16_t>(0) != unsignedValue) {\n \t\t\t\tstd::cerr\n@@ -272,8 +315,9 @@ protected:\n \t\t}\n \n \t\tstd::vector<const char *> rootElemNames = {\n-\t\t\t\"string\", \"double\", \"int16_t\", \"uint16_t\", \"int32_t\",\n-\t\t\t\"uint32_t\", \"size\", \"list\", \"dictionary\", \"level1\",\n+\t\t\t\"string\", \"double\", \"int8_t\", \"uint8_t\", \"int16_t\",\n+\t\t\t\"uint16_t\", \"int32_t\", \"uint32_t\", \"size\", \"list\",\n+\t\t\t\"dictionary\", \"level1\",\n \t\t};\n \n \t\tfor (const char *name : rootElemNames) {\n@@ -296,6 +340,24 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n+\t\t/* Test int8_t object */\n+\t\tauto &int8Obj = (*root)[\"int8_t\"];\n+\n+\t\tif (testObjectType(int8Obj, \"int8_t\", Type::Int8) != TestPass)\n+\t\t\treturn TestFail;\n+\n+\t\tif (testIntegerObject(int8Obj, \"int8_t\", Type::Int8, -100) != TestPass)\n+\t\t\treturn TestFail;\n+\n+\t\t/* Test uint8_t object */\n+\t\tauto &uint8Obj = (*root)[\"uint8_t\"];\n+\n+\t\tif (testObjectType(uint8Obj, \"uint8_t\", Type::UInt8) != TestPass)\n+\t\t\treturn TestFail;\n+\n+\t\tif (testIntegerObject(uint8Obj, \"uint8_t\", Type::UInt8, 100) != TestPass)\n+\t\t\treturn TestFail;\n+\n \t\t/* Test int16_t object */\n \t\tauto &int16Obj = (*root)[\"int16_t\"];\n \n", "prefixes": [ "libcamera-devel", "v4", "5/9" ] }