Patch Detail
Show a patch.
GET /api/patches/16925/?format=api
{ "id": 16925, "url": "https://patchwork.libcamera.org/api/patches/16925/?format=api", "web_url": "https://patchwork.libcamera.org/patch/16925/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/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": "<20220803091502.17280-1-jacopo@jmondi.org>", "date": "2022-08-03T09:15:02", "name": "[libcamera-devel] libcamera: yaml_parser: Drop std::optional<> from getList()", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "5fce40f0f8ff8dee9a4583941755451fc040aaa2", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/16925/mbox/", "series": [ { "id": 3364, "url": "https://patchwork.libcamera.org/api/series/3364/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3364", "date": "2022-08-03T09:15:02", "name": "[libcamera-devel] libcamera: yaml_parser: Drop std::optional<> from getList()", "version": 1, "mbox": "https://patchwork.libcamera.org/series/3364/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/16925/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/16925/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 75536BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 3 Aug 2022 09:15:11 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E9F0D63315;\n\tWed, 3 Aug 2022 11:15:10 +0200 (CEST)", "from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net\n\t[217.70.183.201])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 313CD603EF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 3 Aug 2022 11:15:10 +0200 (CEST)", "(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id 04A201BF20C;\n\tWed, 3 Aug 2022 09:15:07 +0000 (UTC)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1659518110;\n\tbh=KJAK9BXM4hRThzqDTiX2ell2rwDea8AAf89/an66rYg=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:From;\n\tb=cAjxAkZniPLlrRbe2gp5zp8UoYD/wDQpZ0Btt1xQLCdEXQMlnmsd+glE3j0hU1VsH\n\tuQ7REEuJ6U2ori9fwuR6GBYy3OaH+HqH/lGhieHwyUDFkP1F1VmMTaU8HV0RzuOMyz\n\thr3mF9IypwGoKO5UYbnZAp9cwBwdSwHXUCrqbcwvpbglxu1YL/PISAP9/6MVfUcBiu\n\t52ACtQHh/MyyWtU60qUZjtztTO9rpL6rq1S6XXlgeDcb8p6PxBXpvUbjgsmdYkM5Yj\n\tsmO55aukjkzt+Ry38N5Hktjmty+NYz65qzq33X8QX0+y97ZISQhs9foZP5wDxXNOp1\n\ty+3s1v61YY1FQ==", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 3 Aug 2022 11:15:02 +0200", "Message-Id": "<20220803091502.17280-1-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.37.1", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH] libcamera: yaml_parser: Drop\n\tstd::optional<> from getList()", "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": "Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>", "Reply-To": "Jacopo Mondi <jacopo@jmondi.org>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "The YamlParser::getList<T>() function returns an\nstd::optional<std::vector<T>>.\n\nThe obvious (and only) gain in using std::optional<> is to be able to\ncheck the validity of the returned value with the dereference operator.\n\nHowever, usage of std::vector<T> as the std::optional<> template\nargument causes issues with the usage of utils::defopt with gcc8, as the\nit fails to construct a vector with defopt:\n\n/usr/include/c++/8/optional:1267:8: error: call of overloaded\n‘vector(const libcamera::utils::details::defopt_t&)’ is ambiguous\n : static_cast<_Tp>(std::forward<_Up>(__u))\n\nAs the added value of std::optional<> is debatable when used in getList(),\ndrop it and return an std::vector<T> directly. The few characters more\nthat have to be typed to check the validity of the return value\n(value.empty() in place of just !value) are compensated by the shorter\nassignment statement (value = getList<T>() in place of value =\ngetList<T>.value_or(utils::defopt))\n\nReported-by: https://buildbot.libcamera.org/#/builders/6/builds/436\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/internal/yaml_parser.h | 2 +-\n src/ipa/raspberrypi/controller/rpi/agc.cpp | 10 +++++-----\n src/ipa/rkisp1/algorithms/gsl.cpp | 8 ++++----\n src/ipa/rkisp1/algorithms/lsc.cpp | 4 ++--\n src/libcamera/yaml_parser.cpp | 18 +++++++++---------\n test/yaml-parser.cpp | 2 +-\n 6 files changed, 22 insertions(+), 22 deletions(-)\n\n--\n2.37.1", "diff": "diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h\nindex 5ba777d364fa..6d04c556f9b1 100644\n--- a/include/libcamera/internal/yaml_parser.h\n+++ b/include/libcamera/internal/yaml_parser.h\n@@ -197,7 +197,7 @@ public:\n #else\n \ttemplate<typename T>\n #endif\n-\tstd::optional<std::vector<T>> getList() const;\n+\tstd::vector<T> getList() const;\n\n \tDictAdapter asDict() const { return DictAdapter{ list_ }; }\n \tListAdapter asList() const { return ListAdapter{ list_ }; }\ndiff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp\nindex bd54a639d637..bb15d3d84186 100644\n--- a/src/ipa/raspberrypi/controller/rpi/agc.cpp\n+++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n@@ -74,16 +74,16 @@ readMeteringModes(std::map<std::string, AgcMeteringMode> &metering_modes,\n\n int AgcExposureMode::read(const libcamera::YamlObject ¶ms)\n {\n-\tauto value = params[\"shutter\"].getList<double>();\n-\tif (!value)\n+\tstd::vector<double> value = params[\"shutter\"].getList<double>();\n+\tif (value.empty())\n \t\treturn -EINVAL;\n-\tstd::transform(value->begin(), value->end(), std::back_inserter(shutter),\n+\tstd::transform(value.begin(), value.end(), std::back_inserter(shutter),\n \t\t [](double v) { return v * 1us; });\n\n \tvalue = params[\"gain\"].getList<double>();\n-\tif (!value)\n+\tif (value.empty())\n \t\treturn -EINVAL;\n-\tgain = std::move(*value);\n+\tgain = std::move(value);\n\n \tif (shutter.size() < 2 || gain.size() < 2) {\n \t\tLOG(RPiAgc, Error)\ndiff --git a/src/ipa/rkisp1/algorithms/gsl.cpp b/src/ipa/rkisp1/algorithms/gsl.cpp\nindex 2fd1a23d3a9b..0cff1b77b058 100644\n--- a/src/ipa/rkisp1/algorithms/gsl.cpp\n+++ b/src/ipa/rkisp1/algorithms/gsl.cpp\n@@ -60,7 +60,7 @@ int GammaSensorLinearization::init([[maybe_unused]] IPAContext &context,\n \t\t\t\t const YamlObject &tuningData)\n {\n \tstd::vector<uint16_t> xIntervals =\n-\t\ttuningData[\"x-intervals\"].getList<uint16_t>().value_or(utils::defopt);\n+\t\ttuningData[\"x-intervals\"].getList<uint16_t>();\n \tif (xIntervals.size() != kDegammaXIntervals) {\n \t\tLOG(RkISP1Gsl, Error)\n \t\t\t<< \"Invalid 'x' coordinates: expected \"\n@@ -84,7 +84,7 @@ int GammaSensorLinearization::init([[maybe_unused]] IPAContext &context,\n \t\treturn -EINVAL;\n \t}\n\n-\tcurveYr_ = yObject[\"red\"].getList<uint16_t>().value_or(utils::defopt);\n+\tcurveYr_ = yObject[\"red\"].getList<uint16_t>();\n \tif (curveYr_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) {\n \t\tLOG(RkISP1Gsl, Error)\n \t\t\t<< \"Invalid 'y:red' coordinates: expected \"\n@@ -93,7 +93,7 @@ int GammaSensorLinearization::init([[maybe_unused]] IPAContext &context,\n \t\treturn -EINVAL;\n \t}\n\n-\tcurveYg_ = yObject[\"green\"].getList<uint16_t>().value_or(utils::defopt);\n+\tcurveYg_ = yObject[\"green\"].getList<uint16_t>();\n \tif (curveYg_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) {\n \t\tLOG(RkISP1Gsl, Error)\n \t\t\t<< \"Invalid 'y:green' coordinates: expected \"\n@@ -102,7 +102,7 @@ int GammaSensorLinearization::init([[maybe_unused]] IPAContext &context,\n \t\treturn -EINVAL;\n \t}\n\n-\tcurveYb_ = yObject[\"blue\"].getList<uint16_t>().value_or(utils::defopt);\n+\tcurveYb_ = yObject[\"blue\"].getList<uint16_t>();\n \tif (curveYb_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) {\n \t\tLOG(RkISP1Gsl, Error)\n \t\t\t<< \"Invalid 'y:blue' coordinates: expected \"\ndiff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp\nindex 05c8c0dab5c8..d1a4332c9089 100644\n--- a/src/ipa/rkisp1/algorithms/lsc.cpp\n+++ b/src/ipa/rkisp1/algorithms/lsc.cpp\n@@ -43,7 +43,7 @@ static std::vector<double> parseSizes(const YamlObject &tuningData,\n \t\t\t\t const char *prop)\n {\n \tstd::vector<double> sizes =\n-\t\ttuningData[prop].getList<double>().value_or(utils::defopt);\n+\t\ttuningData[prop].getList<double>();\n \tif (sizes.size() != RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE) {\n \t\tLOG(RkISP1Lsc, Error)\n \t\t\t<< \"Invalid '\" << prop << \"' values: expected \"\n@@ -76,7 +76,7 @@ static std::vector<uint16_t> parseTable(const YamlObject &tuningData,\n \t\tRKISP1_CIF_ISP_LSC_SAMPLES_MAX * RKISP1_CIF_ISP_LSC_SAMPLES_MAX;\n\n \tstd::vector<uint16_t> table =\n-\t\ttuningData[prop].getList<uint16_t>().value_or(utils::defopt);\n+\t\ttuningData[prop].getList<uint16_t>();\n \tif (table.size() != kLscNumSamples) {\n \t\tLOG(RkISP1Lsc, Error)\n \t\t\t<< \"Invalid '\" << prop << \"' values: expected \"\ndiff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\nindex 84cb57d6de83..d422e0811fa7 100644\n--- a/src/libcamera/yaml_parser.cpp\n+++ b/src/libcamera/yaml_parser.cpp\n@@ -316,7 +316,7 @@ template<typename T,\n \t\t std::is_same_v<uint32_t, T> ||\n \t\t std::is_same_v<std::string, T> ||\n \t\t std::is_same_v<Size, T>> *>\n-std::optional<std::vector<T>> YamlObject::getList() const\n+std::vector<T> YamlObject::getList() const\n {\n \tif (type_ != Type::List)\n \t\treturn {};\n@@ -334,14 +334,14 @@ std::optional<std::vector<T>> YamlObject::getList() const\n \treturn values;\n }\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<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;\n-template std::optional<std::vector<uint32_t>> YamlObject::getList<uint32_t>() const;\n-template std::optional<std::vector<std::string>> YamlObject::getList<std::string>() const;\n-template std::optional<std::vector<Size>> YamlObject::getList<Size>() const;\n+template std::vector<bool> YamlObject::getList<bool>() const;\n+template std::vector<double> YamlObject::getList<double>() const;\n+template std::vector<int16_t> YamlObject::getList<int16_t>() const;\n+template std::vector<uint16_t> YamlObject::getList<uint16_t>() const;\n+template std::vector<int32_t> YamlObject::getList<int32_t>() const;\n+template std::vector<uint32_t> YamlObject::getList<uint32_t>() const;\n+template std::vector<std::string> YamlObject::getList<std::string>() const;\n+template std::vector<Size> YamlObject::getList<Size>() const;\n\n #endif /* __DOXYGEN__ */\n\ndiff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp\nindex 93ba88b8bcd5..e25944e7f6b8 100644\n--- a/test/yaml-parser.cpp\n+++ b/test/yaml-parser.cpp\n@@ -530,7 +530,7 @@ protected:\n \t\t}\n\n \t\tconst auto &values = firstElement.getList<uint16_t>();\n-\t\tif (!values || values->size() != 2 || (*values)[0] != 1 || (*values)[1] != 2) {\n+\t\tif (values.empty() || values.size() != 2 || values[0] != 1 || values[1] != 2) {\n \t\t\tcerr << \"getList() failed to return correct vector\" << std::endl;\n \t\t\treturn TestFail;\n \t\t}\n", "prefixes": [ "libcamera-devel" ] }