{"id":26454,"url":"https://patchwork.libcamera.org/api/patches/26454/?format=json","web_url":"https://patchwork.libcamera.org/patch/26454/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260407153427.1825999-15-laurent.pinchart@ideasonboard.com>","date":"2026-04-07T15:33:59","name":"[v2,14/42] libcamera: yaml_parser: Un-friend YamlParserContext from YamlObject","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"59a2fc943fdcce6d7f2ca219f5a9850fc577f009","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/26454/mbox/","series":[{"id":5873,"url":"https://patchwork.libcamera.org/api/series/5873/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5873","date":"2026-04-07T15:33:45","name":"libcamera: Global configuration file improvements","version":2,"mbox":"https://patchwork.libcamera.org/series/5873/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/26454/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/26454/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 40708C32FE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  7 Apr 2026 15:34:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D288662DCB;\n\tTue,  7 Apr 2026 17:34:50 +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 588EB62DD7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Apr 2026 17:34:47 +0200 (CEST)","from killaraus.ideasonboard.com\n\t(2001-14ba-703d-e500--2a1.rev.dnainternet.fi\n\t[IPv6:2001:14ba:703d:e500::2a1])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id C8DE998A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Apr 2026 17:33:19 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"GCjb/DxV\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1775575999;\n\tbh=xSPIi+oHJsO/IDbh+rOdR9WCgBicw9wEP2PnCgzOQu4=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=GCjb/DxVO3zrNL5syJY1ohs14qwjz/Q2p7UHZbGkhHnbmWvUv+8tK1YO4cOjV9nsT\n\tiY8eHtQ313QRq+JeT4+3fCmRC5NUCi7QGAAC8YqawCrGxuu6u2tDC2IBKvEQTvcTXH\n\tlpTeJXO3M972bgYuMqpw6ZWxNghC48sAAh0gzpWM=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"[PATCH v2 14/42] libcamera: yaml_parser: Un-friend YamlParserContext\n\tfrom YamlObject","Date":"Tue,  7 Apr 2026 18:33:59 +0300","Message-ID":"<20260407153427.1825999-15-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.52.0","In-Reply-To":"<20260407153427.1825999-1-laurent.pinchart@ideasonboard.com>","References":"<20260407153427.1825999-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"YamlParserContext is a friend of the YamlObject class to access private\nmember variables. Now that YamlObject exposes functions to set a value\nand add children, this is not needed anymore. Decouple the two classes.\n\nThe YamlParserContext::readValue() function now takes a const reference\nto the EventPtr as the YamlParserContext::parseNextYamlObject() function\nneeds to access it in the error handler.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\nChanges since v1:\n\n- Add error checking for add() failures\n- Pass const reference to readValue() function\n---\n include/libcamera/internal/yaml_parser.h |  1 -\n src/libcamera/yaml_parser.cpp            | 63 +++++++++++-------------\n 2 files changed, 28 insertions(+), 36 deletions(-)","diff":"diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h\nindex 3be61c503c88..c41397df67ab 100644\n--- a/include/libcamera/internal/yaml_parser.h\n+++ b/include/libcamera/internal/yaml_parser.h\n@@ -205,7 +205,6 @@ private:\n \n \ttemplate<typename T>\n \tfriend struct Accessor;\n-\tfriend class YamlParserContext;\n \n \tenum class Type {\n \t\tDictionary,\ndiff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\nindex 61088c7aed4f..6caacc3111c4 100644\n--- a/src/libcamera/yaml_parser.cpp\n+++ b/src/libcamera/yaml_parser.cpp\n@@ -517,8 +517,8 @@ private:\n \n \tEventPtr nextEvent();\n \n-\tvoid readValue(std::string &value, EventPtr event);\n-\tint parseDictionaryOrList(YamlObject::Type type,\n+\tstd::string readValue(const EventPtr &event);\n+\tint parseDictionaryOrList(yaml_event_type_t endEventType,\n \t\t\t\t  const std::function<int(EventPtr event)> &parseItem);\n \tint parseNextYamlObject(YamlObject &yamlObject, EventPtr event);\n \n@@ -660,22 +660,22 @@ int YamlParserContext::parseContent(YamlObject &yamlObject)\n /**\n  * \\fn YamlParserContext::readValue()\n  * \\brief Parse event scalar and fill its content into a string\n- * \\param[in] value The string reference to fill value\n  *\n  * A helper function to parse a scalar event as string. The caller needs to\n- * guarantee the event is of scaler type.\n+ * guarantee the event is of scalar type.\n+ *\n+ * \\return The scalar event value as a string\n  */\n-void YamlParserContext::readValue(std::string &value, EventPtr event)\n+std::string YamlParserContext::readValue(const EventPtr &event)\n {\n-\tvalue.assign(reinterpret_cast<char *>(event->data.scalar.value),\n-\t\t     event->data.scalar.length);\n+\treturn std::string{ reinterpret_cast<const char *>(event->data.scalar.value),\n+\t\t\t    event->data.scalar.length };\n }\n \n /**\n  * \\fn YamlParserContext::parseDictionaryOrList()\n  * \\brief A helper function to abstract the common part of parsing dictionary or list\n- *\n- * \\param[in] isDictionary True for parsing a dictionary, and false for a list\n+ * \\param[in] endEventType The YAML end event type (sequence or mapping)\n  * \\param[in] parseItem The callback to handle an item\n  *\n  * A helper function to abstract parsing an item from a dictionary or a list.\n@@ -690,13 +690,9 @@ void YamlParserContext::readValue(std::string &value, EventPtr event)\n  * \\return 0 on success or a negative error code otherwise\n  * \\retval -EINVAL The parser is failed to initialize\n  */\n-int YamlParserContext::parseDictionaryOrList(YamlObject::Type type,\n+int YamlParserContext::parseDictionaryOrList(yaml_event_type_t endEventType,\n \t\t\t\t\t     const std::function<int(EventPtr event)> &parseItem)\n {\n-\tyaml_event_type_t endEventType = YAML_SEQUENCE_END_EVENT;\n-\tif (type == YamlObject::Type::Dictionary)\n-\t\tendEventType = YAML_MAPPING_END_EVENT;\n-\n \t/*\n \t * Add a safety counter to make sure we don't loop indefinitely in case\n \t * the YAML file is malformed.\n@@ -738,24 +734,19 @@ int YamlParserContext::parseNextYamlObject(YamlObject &yamlObject, EventPtr even\n \n \tswitch (event->type) {\n \tcase YAML_SCALAR_EVENT:\n-\t\tyamlObject.type_ = YamlObject::Type::Value;\n-\t\treadValue(yamlObject.value_, std::move(event));\n+\t\tyamlObject.set(readValue(event));\n \t\treturn 0;\n \n \tcase YAML_SEQUENCE_START_EVENT: {\n-\t\tyamlObject.type_ = YamlObject::Type::List;\n-\t\tauto &list = yamlObject.list_;\n-\t\tauto handler = [this, &list](EventPtr evt) {\n-\t\t\tlist.emplace_back(std::string{}, std::make_unique<YamlObject>());\n-\t\t\treturn parseNextYamlObject(*list.back().value, std::move(evt));\n+\t\tauto handler = [this, &yamlObject](EventPtr evt) {\n+\t\t\tYamlObject *child = yamlObject.add(std::make_unique<YamlObject>());\n+\t\t\treturn parseNextYamlObject(*child, std::move(evt));\n \t\t};\n-\t\treturn parseDictionaryOrList(YamlObject::Type::List, handler);\n+\t\treturn parseDictionaryOrList(YAML_SEQUENCE_END_EVENT, handler);\n \t}\n \n \tcase YAML_MAPPING_START_EVENT: {\n-\t\tyamlObject.type_ = YamlObject::Type::Dictionary;\n-\t\tauto &list = yamlObject.list_;\n-\t\tauto handler = [this, &list](EventPtr evtKey) {\n+\t\tauto handler = [this, &yamlObject](EventPtr evtKey) {\n \t\t\t/* Parse key */\n \t\t\tif (evtKey->type != YAML_SCALAR_EVENT) {\n \t\t\t\tLOG(YamlParser, Error) << \"Expect key at line: \"\n@@ -765,26 +756,28 @@ int YamlParserContext::parseNextYamlObject(YamlObject &yamlObject, EventPtr even\n \t\t\t\treturn -EINVAL;\n \t\t\t}\n \n-\t\t\tstd::string key;\n-\t\t\treadValue(key, std::move(evtKey));\n+\t\t\tstd::string key = readValue(evtKey);\n \n \t\t\t/* Parse value */\n \t\t\tEventPtr evtValue = nextEvent();\n \t\t\tif (!evtValue)\n \t\t\t\treturn -EINVAL;\n \n-\t\t\tauto &elem = list.emplace_back(std::move(key),\n-\t\t\t\t\t\t       std::make_unique<YamlObject>());\n-\t\t\treturn parseNextYamlObject(*elem.value, std::move(evtValue));\n+\t\t\tYamlObject *child = yamlObject.add(std::move(key),\n+\t\t\t\t\t\t\t   std::make_unique<YamlObject>());\n+\t\t\tif (!child) {\n+\t\t\t\tLOG(YamlParser, Error)\n+\t\t\t\t\t<< \"Duplicated key at line \"\n+\t\t\t\t\t<< evtKey->start_mark.line;\n+\t\t\t\treturn -EINVAL;\n+\t\t\t}\n+\n+\t\t\treturn parseNextYamlObject(*child, std::move(evtValue));\n \t\t};\n-\t\tint ret = parseDictionaryOrList(YamlObject::Type::Dictionary, handler);\n+\t\tint ret = parseDictionaryOrList(YAML_MAPPING_END_EVENT, handler);\n \t\tif (ret)\n \t\t\treturn ret;\n \n-\t\tauto &dictionary = yamlObject.dictionary_;\n-\t\tfor (const auto &elem : list)\n-\t\t\tdictionary.emplace(elem.key, elem.value.get());\n-\n \t\treturn 0;\n \t}\n \n","prefixes":["v2","14/42"]}