Patch Detail
Show a patch.
GET /api/1.1/patches/17133/?format=api
{ "id": 17133, "url": "https://patchwork.libcamera.org/api/1.1/patches/17133/?format=api", "web_url": "https://patchwork.libcamera.org/patch/17133/", "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-7-laurent.pinchart@ideasonboard.com>", "date": "2022-08-16T01:54:11", "name": "[libcamera-devel,v4,6/9] libcamera: yaml_parser: De-duplicate common code in YamlObject::get()", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "27f2897f6f31247f245817a292252af6352fc3cd", "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/17133/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/17133/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/17133/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 0D8CAC3275\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 16 Aug 2022 01:54:40 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 914CE61FD4;\n\tTue, 16 Aug 2022 03:54:39 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B676A61FBD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 16 Aug 2022 03:54:36 +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 56598496;\n\tTue, 16 Aug 2022 03:54:36 +0200 (CEST)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660614879;\n\tbh=JZ9nVNOV0g5kaaCyiDfyY+ChH3PMrrXzF4SuNMylqAc=;\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=PnUqg76Uy9mS/SuqLOiRFUiZD3RHLVdVqf7JFFc7hWJyNu7O4n2L92RTPq2GoKZaK\n\tdk6VxaNqCru+kxonmkmIJrYf1LccuCQZym9ADoJAU2AfO0938XWSnCQv564TbXFgl4\n\tRUa1fO20LvJ9MrjBH+tBew31HBmS3KB+JNdfdZYBqbWqDWXQ9UVtnBkhEnEHxhdqCF\n\tAE7hfWkQxA3oE9Iu/xRS/EuV7cjm3PEmUNUW6+khBoDfpWEAC08DarCu7AqemWsUGr\n\tBUzd9Vovpxmqct0nPIqkNIYh+SMy0lNimxS9aH8HK61ENacjLUs5epdmpqm5JWSVEb\n\tDLTV9Y899PyWQ==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1660614876;\n\tbh=JZ9nVNOV0g5kaaCyiDfyY+ChH3PMrrXzF4SuNMylqAc=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=JYA3IGPeetLW6XUKvQwvv+kgjaNiUOcZfwBLnXGEXDWhLHcF3DTKJcQhUhNAN2Feq\n\tfYnitQOEUTc7cl/W6RsK3nSWSLLZkvpYvsst+5yAg1clL9nuqPfREGHlhPy7207Klk\n\t5si4vrzvodYqz84tzlr4zlvDzpKMZqweDyEO7yQM=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"JYA3IGPe\"; dkim-atps=neutral", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 16 Aug 2022 04:54:11 +0300", "Message-Id": "<20220816015414.7462-7-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 6/9] libcamera: yaml_parser:\n\tDe-duplicate common code in YamlObject::get()", "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 specializations of the YamlObject::get() function template for\ninteger types duplicate code that doesn't directly depend on the\ntemplate type argument. Move it to separate helper functions to reduce\nthe object size.\n\nWhile at it, rephrase the comment about unsigned integer parsing.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/yaml_parser.cpp | 160 ++++++++++++++--------------------\n 1 file changed, 67 insertions(+), 93 deletions(-)", "diff": "diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\nindex 85a52c05e682..3d5efdc4419b 100644\n--- a/src/libcamera/yaml_parser.cpp\n+++ b/src/libcamera/yaml_parser.cpp\n@@ -131,23 +131,65 @@ std::optional<bool> YamlObject::get() const\n \treturn std::nullopt;\n }\n \n+namespace {\n+\n+bool parseSignedInteger(const std::string &str, int32_t min, int32_t max,\n+\t\t\tint32_t *result)\n+{\n+\tif (str == \"\")\n+\t\treturn false;\n+\n+\tchar *end;\n+\n+\terrno = 0;\n+\tlong value = std::strtol(str.c_str(), &end, 10);\n+\n+\tif ('\\0' != *end || errno == ERANGE || value < min || value > max)\n+\t\treturn false;\n+\n+\t*result = value;\n+\treturn true;\n+}\n+\n+bool parseUnsignedInteger(const std::string &str, uint32_t max, uint32_t *result)\n+{\n+\tif (str == \"\")\n+\t\treturn false;\n+\n+\t/*\n+\t * strtoul() accepts strings representing a negative number, in which\n+\t * case it negates the converted value. We don't want to silently accept\n+\t * negative values and return a large positive number, so check for a\n+\t * minus sign (after optional whitespace) and return an error.\n+\t */\n+\tstd::size_t found = str.find_first_not_of(\" \\t\");\n+\tif (found != std::string::npos && str[found] == '-')\n+\t\treturn false;\n+\n+\tchar *end;\n+\n+\terrno = 0;\n+\tunsigned long value = std::strtoul(str.c_str(), &end, 10);\n+\n+\tif ('\\0' != *end || errno == ERANGE || value > max)\n+\t\treturn false;\n+\n+\t*result = value;\n+\treturn true;\n+}\n+\n+} /* namespace */\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+\tint32_t value;\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+\tif (!parseSignedInteger(value_, std::numeric_limits<int8_t>::min(),\n+\t\t\t\tstd::numeric_limits<int8_t>::max(), &value))\n \t\treturn std::nullopt;\n \n \treturn value;\n@@ -159,28 +201,10 @@ std::optional<uint8_t> YamlObject::get() const\n \tif (type_ != Type::Value)\n \t\treturn std::nullopt;\n \n-\tif (value_ == \"\")\n-\t\treturn std::nullopt;\n+\tuint32_t value;\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+\tif (!parseUnsignedInteger(value_, std::numeric_limits<uint8_t>::max(),\n+\t\t\t\t &value))\n \t\treturn std::nullopt;\n \n \treturn value;\n@@ -192,17 +216,10 @@ std::optional<int16_t> YamlObject::get() const\n \tif (type_ != Type::Value)\n \t\treturn std::nullopt;\n \n-\tif (value_ == \"\")\n-\t\treturn std::nullopt;\n+\tint32_t value;\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<int16_t>::min() ||\n-\t value > std::numeric_limits<int16_t>::max())\n+\tif (!parseSignedInteger(value_, std::numeric_limits<int16_t>::min(),\n+\t\t\t\tstd::numeric_limits<int16_t>::max(), &value))\n \t\treturn std::nullopt;\n \n \treturn value;\n@@ -214,28 +231,10 @@ std::optional<uint16_t> YamlObject::get() const\n \tif (type_ != Type::Value)\n \t\treturn std::nullopt;\n \n-\tif (value_ == \"\")\n-\t\treturn std::nullopt;\n+\tuint32_t value;\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<uint16_t>::min() ||\n-\t value > std::numeric_limits<uint16_t>::max())\n+\tif (!parseUnsignedInteger(value_, std::numeric_limits<uint16_t>::max(),\n+\t\t\t\t &value))\n \t\treturn std::nullopt;\n \n \treturn value;\n@@ -247,17 +246,10 @@ std::optional<int32_t> YamlObject::get() const\n \tif (type_ != Type::Value)\n \t\treturn std::nullopt;\n \n-\tif (value_ == \"\")\n-\t\treturn std::nullopt;\n+\tint32_t value;\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<int32_t>::min() ||\n-\t value > std::numeric_limits<int32_t>::max())\n+\tif (!parseSignedInteger(value_, std::numeric_limits<int32_t>::min(),\n+\t\t\t\tstd::numeric_limits<int32_t>::max(), &value))\n \t\treturn std::nullopt;\n \n \treturn value;\n@@ -269,28 +261,10 @@ std::optional<uint32_t> YamlObject::get() const\n \tif (type_ != Type::Value)\n \t\treturn std::nullopt;\n \n-\tif (value_ == \"\")\n-\t\treturn std::nullopt;\n+\tuint32_t value;\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<uint32_t>::min() ||\n-\t value > std::numeric_limits<uint32_t>::max())\n+\tif (!parseUnsignedInteger(value_, std::numeric_limits<uint32_t>::max(),\n+\t\t\t\t &value))\n \t\treturn std::nullopt;\n \n \treturn value;\n", "prefixes": [ "libcamera-devel", "v4", "6/9" ] }