[{"id":24331,"web_url":"https://patchwork.libcamera.org/comment/24331/","msgid":"<20220803111041.GC311202@pyrite.rasen.tech>","date":"2022-08-03T11:10:41","subject":"Re: [libcamera-devel] [PATCH] libcamera: yaml_parser: Return\n\tnullopt on error","submitter":{"id":97,"url":"https://patchwork.libcamera.org/api/people/97/","name":"Nicolas Dufresne via libcamera-devel","email":"libcamera-devel@lists.libcamera.org"},"content":"On Wed, Aug 03, 2022 at 01:03:24PM +0200, Jacopo Mondi via libcamera-devel wrote:\n> The YamlParser::getList<>() function returns an std::optional<> to allow\n> callers to identify cases where parsing the .yaml file failed from cases\n> where the parsed list is just empty.\n> \n> The current implementation however returns an empty list in case of\n> errors, making it impossible for the caller to detect parsing failures.\n> \n> Fix this by returning std::nullopt in case of errors.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  src/libcamera/yaml_parser.cpp | 4 ++--\n>  1 file changed, 2 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\n> index 84cb57d6de83..c96e99e1317c 100644\n> --- a/src/libcamera/yaml_parser.cpp\n> +++ b/src/libcamera/yaml_parser.cpp\n> @@ -319,7 +319,7 @@ template<typename T,\n>  std::optional<std::vector<T>> YamlObject::getList() const\n>  {\n>  \tif (type_ != Type::List)\n> -\t\treturn {};\n> +\t\treturn std::nullopt;\n>  \n>  \tstd::vector<T> values;\n>  \tvalues.reserve(list_.size());\n> @@ -327,7 +327,7 @@ std::optional<std::vector<T>> YamlObject::getList() const\n>  \tfor (const YamlObject &entry : asList()) {\n>  \t\tconst auto value = entry.get<T>();\n>  \t\tif (!value)\n> -\t\t\treturn {};\n> +\t\t\treturn std::nullopt;\n>  \t\tvalues.emplace_back(*value);\n>  \t}\n>  \n> -- \n> 2.37.1\n>","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 6CD4CBE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  3 Aug 2022 11:10:50 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D674B63310;\n\tWed,  3 Aug 2022 13:10:49 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 20104603E6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Aug 2022 13:10:49 +0200 (CEST)","from pyrite.rasen.tech (h175-177-042-159.catv02.itscom.jp\n\t[175.177.42.159])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CC2E68B;\n\tWed,  3 Aug 2022 13:10:47 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1659525049;\n\tbh=neyRJCuRAXpfRYnGhPcCj5mlgDn2M1ycLvqi2uhKiRs=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=1sz8J/x5JJJijh5FXZ54NhNC2M08+fT71EzBOEnDGWykDMw3eyVnoYyJQigBR+zxF\n\tXyC25XPecqD/2E2FiTBeGHq5c7RyTZ+YtXIQbUJpdzFL2u2V44KRam3JD9vNXKMQdW\n\t1Kq1ycOsN973DxgqDYsYfku1Gbfb3xzI/0bnXBo+TRGHikcv7E9R3PQCr7jM5lzXwV\n\tk6l2U8c/hbfppIkMJ6NhmeDIKRugDuhbcbX7fAqMkYAulh4ECmfWqy0z5QysdAhKxx\n\tZy2Y7Topsp3N4Hg7c3IR/QWT++Rma1d34OpzuW1Lyq00LnN36EECGCEMe4ZfVOO/Zj\n\taHXQogEVC7FtA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1659525048;\n\tbh=neyRJCuRAXpfRYnGhPcCj5mlgDn2M1ycLvqi2uhKiRs=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=BMNxP9izgBw4fQGgRE5jpS5tptQwQa8Q444sJ3bvH4ldOBkUa8N93O3jHjUWI+vPF\n\t2DQX/GCgW5ju0KKvboIecAJVSD8hUjYaZM37lYxXb4B8IN6PI1e3XV4dW/+8W9+XAK\n\tfhBmKeO4BMTsSkvcgqxLhEmIhSWoOsknPS5qXBBE="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"BMNxP9iz\"; dkim-atps=neutral","Date":"Wed, 3 Aug 2022 20:10:41 +0900","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<20220803111041.GC311202@pyrite.rasen.tech>","References":"<20220803110324.28539-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20220803110324.28539-1-jacopo@jmondi.org>","Subject":"Re: [libcamera-devel] [PATCH] libcamera: yaml_parser: Return\n\tnullopt on error","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":"Paul Elder via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"paul.elder@ideasonboard.com","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":24332,"web_url":"https://patchwork.libcamera.org/comment/24332/","msgid":"<YupZHT3BDZBJB9Vn@pendragon.ideasonboard.com>","date":"2022-08-03T11:16:45","subject":"Re: [libcamera-devel] [PATCH] libcamera: yaml_parser: Return\n\tnullopt on error","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Wed, Aug 03, 2022 at 01:03:24PM +0200, Jacopo Mondi via libcamera-devel wrote:\n> The YamlParser::getList<>() function returns an std::optional<> to allow\n> callers to identify cases where parsing the .yaml file failed from cases\n> where the parsed list is just empty.\n> \n> The current implementation however returns an empty list in case of\n> errors, making it impossible for the caller to detect parsing failures.\n\nThat's actually not true:\n\n--------\n#include <iostream>\n#include <optional>\n#include <vector>\n\nstatic std::optional<std::vector<int>> foo(bool null)\n{\n\tif (null)\n\t\treturn std::nullopt;\n\telse\n\t\treturn {};\n}\n\nint main()\n{\n\tstd::optional<std::vector<int>> opt;\n\n\topt = foo(true);\n\tstd::cout << \"- opt \" << (opt == std::nullopt ? \"==\" : \"!=\") << \" std::nullopt\" << std::endl;\n\n\topt = foo(false);\n\tstd::cout << \"- opt \" << (opt == std::nullopt ? \"==\" : \"!=\") << \" std::nullopt\" << std::endl;\n\n\treturn 0;\n}\n--------\n\nprints\n\n--------\n- opt == std::nullopt\n- opt == std::nullopt\n--------\n\n{} means a default-constructed object, whose type is inferred from the\nreturn type of the function here, so std::optional<std::vector<int>>()\nin this case, which is equal to std::nullopt.\n\nHowever, I agree that std::nullopt is more explicit, so I like the\nchange, but the commit message should be reworded.\n\n> Fix this by returning std::nullopt in case of errors.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/libcamera/yaml_parser.cpp | 4 ++--\n>  1 file changed, 2 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\n> index 84cb57d6de83..c96e99e1317c 100644\n> --- a/src/libcamera/yaml_parser.cpp\n> +++ b/src/libcamera/yaml_parser.cpp\n> @@ -319,7 +319,7 @@ template<typename T,\n>  std::optional<std::vector<T>> YamlObject::getList() const\n>  {\n>  \tif (type_ != Type::List)\n> -\t\treturn {};\n> +\t\treturn std::nullopt;\n>  \n>  \tstd::vector<T> values;\n>  \tvalues.reserve(list_.size());\n> @@ -327,7 +327,7 @@ std::optional<std::vector<T>> YamlObject::getList() const\n>  \tfor (const YamlObject &entry : asList()) {\n>  \t\tconst auto value = entry.get<T>();\n>  \t\tif (!value)\n> -\t\t\treturn {};\n> +\t\t\treturn std::nullopt;\n>  \t\tvalues.emplace_back(*value);\n>  \t}\n>","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 AD3BAC3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  3 Aug 2022 11:16:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 07472603E6;\n\tWed,  3 Aug 2022 13:16:54 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0FDF6603E6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Aug 2022 13:16:52 +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 6A5D48B;\n\tWed,  3 Aug 2022 13:16:51 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1659525414;\n\tbh=4v2SX32F22qlww/JNuU/DtZsc+Gl2GtZGgcPBqr1zQU=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=zQCpo1d4XQfdr9bkWwlv6cbTHGkhAKmzwBd0jWSmbjq9KN/yHTvDwk2r1pbwGvXjU\n\tjDWQGyCeuBK7bYbFsyvj49NgN2lIsUS3CPVUPxE3nJ3dFwaoTdqzLW3kPk9XamJphZ\n\temo9kwjZU31rDQOv1th+1j0htJvnY5Ogo74pVo6xH4f0P7XJCCwkMt9NTrRGzhHJMk\n\tb+MCIfCzAwrbIfTRW0Y9oXcMiLAinz2JfPZNPMMWbjwLn/aJkXKA/jy7dILq6kIDgV\n\tMCmz8ppYMpdibGTMq2XSyPTEyxkQzy5EAQLpteCOHF0+HgsBTn7/z5mI6RgAu57OpI\n\tniKe0hD9TrV4A==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1659525411;\n\tbh=4v2SX32F22qlww/JNuU/DtZsc+Gl2GtZGgcPBqr1zQU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=FrNmfHfDhXrEcb4A42UUFRy3MVpw48yuOe8y8vZ4gSILFf9l6oU/dkwZ8ZixKCgqm\n\tZrFbBLyqBN/Jn/Bkm96kZqwfcwxpP/uQsP3HMIc1VQiOvhs0d7Ul9UhvhgK30VnGTy\n\tDJxzxynevrziUU/7kYM7k1sRxRPi2E8tTQ9TYzF8="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"FrNmfHfD\"; dkim-atps=neutral","Date":"Wed, 3 Aug 2022 14:16:45 +0300","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<YupZHT3BDZBJB9Vn@pendragon.ideasonboard.com>","References":"<20220803110324.28539-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220803110324.28539-1-jacopo@jmondi.org>","Subject":"Re: [libcamera-devel] [PATCH] libcamera: yaml_parser: Return\n\tnullopt on error","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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]