Show a patch.

GET /api/1.1/patches/16815/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 16815,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/16815/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/16815/",
    "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": "<20220727023816.30008-4-laurent.pinchart@ideasonboard.com>",
    "date": "2022-07-27T02:38:05",
    "name": "[libcamera-devel,v7,03/14] libcamera: yaml_parser: Preserve order of items in dictionary",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "bb85620e878bbbb6396727dfed42ae4aebfd8c54",
    "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/16815/mbox/",
    "series": [
        {
            "id": 3331,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3331/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3331",
            "date": "2022-07-27T02:38:02",
            "name": "Replace boost JSON parser with libyaml in Raspberry Pi IPA",
            "version": 7,
            "mbox": "https://patchwork.libcamera.org/series/3331/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/16815/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/16815/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 57EF6BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 27 Jul 2022 02:38:24 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DF46063319;\n\tWed, 27 Jul 2022 04:38:23 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7E22A63311\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 27 Jul 2022 04:38:21 +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 177E056D;\n\tWed, 27 Jul 2022 04:38:21 +0200 (CEST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1658889504;\n\tbh=XLxIo4t97oz8KvXoCzVK16yoYeAzn5QyoL+dbPAHQjA=;\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=NGgsizr+uVO3UQ7sC0jnM1sXN8dHajTcIiWsy4pMQwSKPZ7biSJGzBaAFC6wqp50V\n\tp1xULIdhBOikgEYJ1QIxZWpQtGXa1xwj35EoRtln/0hufUgNinemBLAh780DjUvADc\n\tq8O5GnV/Ap06jPorjqGhOKlPXh9f9fx5+wspjHsS5v5t0n+lCzRvU1nqcpbU/g6pEU\n\tub9uFmaTsN4oIdr0lVybPdEW4moAWLoEkU3A2c71AIjk9yc94v3BFhAJb5yejQ00QP\n\tOKLEDcAxhNLri+hsnU6gCwlruU+zZdZS/c4vShm4e2FZmgYgYamygw1lQUgUCQpkpZ\n\ti/oJdvKZRrZVQ==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1658889501;\n\tbh=XLxIo4t97oz8KvXoCzVK16yoYeAzn5QyoL+dbPAHQjA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=HyG/OhKZ9cVaDdHDj0Qp6ITjoZagmeNwokXplRnml1fiML/9gM7sxQ09p/tx0hdWk\n\tnS5Dt1tu62k/3VdRuYJ5Dfi4CBCohjtH9W3IUs7GmXx9Fy0UfouqyvSuKzFtfmVUYx\n\tMujdxatPhEHXcoGJo+KFs8cqnkghHt/yZI9sOItc="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"HyG/OhKZ\"; dkim-atps=neutral",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed, 27 Jul 2022 05:38:05 +0300",
        "Message-Id": "<20220727023816.30008-4-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.35.1",
        "In-Reply-To": "<20220727023816.30008-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20220727023816.30008-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v7 03/14] libcamera: yaml_parser: Preserve\n\torder of items in dictionary",
        "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 std::map container used to store dictionary items in YamlObject\ndoesn't preserve the YAML data order, as maps are ordered by key, not by\ninsertion order. While this is compliant with the YAML specification\nwhich doesn't guarantee ordering of mappings, the Raspberry Pi IPA\nrelies on elements being ordered as in the YAML data. To replace the\ndependency on boost with the YamlParser class, we thus need to guarantee\nthat the order is preserved.\n\nPreserve the order by storing items in list_ unconditionally. Turn the\nlist_ vector from storing YamlObject unique pointers to storing\nkey-value pairs, with the key being absent when the object is a list,\nnot a dictionary.\n\nThe YamlObject implementation is updated to preserve the existing API,\nwith the only difference being that YamlObject::memberNames() now\nreturns member names in the same order as in the YAML file.\n\nThe ordering is an implementation detail, so changing it doesn't violate\nthe YAML specification. The documentation is not updated to reflect\nthis, as we don't want any new user to rely on a particular ordering.\nThis commit could be reverted if desired when the Raspberry Pi IPA\nupdates to a new tuning data format and drops support for the old\nformat.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\nTested-by: Naushir Patuck <naush@raspberrypi.com>\n---\n include/libcamera/internal/yaml_parser.h | 37 +++++++++++++++---------\n src/libcamera/yaml_parser.cpp            | 35 ++++++++++++++--------\n 2 files changed, 46 insertions(+), 26 deletions(-)",
    "diff": "diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h\nindex 61f2223223a7..9c85d26a2a88 100644\n--- a/include/libcamera/internal/yaml_parser.h\n+++ b/include/libcamera/internal/yaml_parser.h\n@@ -25,12 +25,21 @@ class YamlParserContext;\n class YamlObject\n {\n private:\n-\tusing DictContainer = std::map<std::string, std::unique_ptr<YamlObject>>;\n+\tstruct Value {\n+\t\tValue(std::string &&k, std::unique_ptr<YamlObject> &&v)\n+\t\t\t: key(std::move(k)), value(std::move(v))\n+\t\t{\n+\t\t}\n+\t\tstd::string key;\n+\t\tstd::unique_ptr<YamlObject> value;\n+\t};\n+\n+\tusing Container = std::vector<Value>;\n \tusing ListContainer = std::vector<std::unique_ptr<YamlObject>>;\n \n public:\n #ifndef __DOXYGEN__\n-\ttemplate<typename Container, typename Derived>\n+\ttemplate<typename Derived>\n \tclass Iterator\n \t{\n \tpublic:\n@@ -66,10 +75,10 @@ public:\n \t\t}\n \n \tprotected:\n-\t\ttypename Container::const_iterator it_;\n+\t\tContainer::const_iterator it_;\n \t};\n \n-\ttemplate<typename Container, typename Iterator>\n+\ttemplate<typename Iterator>\n \tclass Adapter\n \t{\n \tpublic:\n@@ -92,7 +101,7 @@ public:\n \t\tconst Container &container_;\n \t};\n \n-\tclass ListIterator : public Iterator<ListContainer, ListIterator>\n+\tclass ListIterator : public Iterator<ListIterator>\n \t{\n \tpublic:\n \t\tusing value_type = const YamlObject &;\n@@ -101,16 +110,16 @@ public:\n \n \t\tvalue_type operator*() const\n \t\t{\n-\t\t\treturn *it_->get();\n+\t\t\treturn *it_->value.get();\n \t\t}\n \n \t\tpointer operator->() const\n \t\t{\n-\t\t\treturn it_->get();\n+\t\t\treturn it_->value.get();\n \t\t}\n \t};\n \n-\tclass DictIterator : public Iterator<DictContainer, DictIterator>\n+\tclass DictIterator : public Iterator<DictIterator>\n \t{\n \tpublic:\n \t\tusing value_type = std::pair<const std::string &, const YamlObject &>;\n@@ -119,17 +128,17 @@ public:\n \n \t\tvalue_type operator*() const\n \t\t{\n-\t\t\treturn { it_->first, *it_->second.get() };\n+\t\t\treturn { it_->key, *it_->value.get() };\n \t\t}\n \t};\n \n-\tclass DictAdapter : public Adapter<DictContainer, DictIterator>\n+\tclass DictAdapter : public Adapter<DictIterator>\n \t{\n \tpublic:\n \t\tusing key_type = std::string;\n \t};\n \n-\tclass ListAdapter : public Adapter<ListContainer, ListIterator>\n+\tclass ListAdapter : public Adapter<ListIterator>\n \t{\n \t};\n #endif /* __DOXYGEN__ */\n@@ -174,7 +183,7 @@ public:\n \t\treturn get<T>().value_or(defaultValue);\n \t}\n \n-\tDictAdapter asDict() const { return DictAdapter{ dictionary_ }; }\n+\tDictAdapter asDict() const { return DictAdapter{ list_ }; }\n \tListAdapter asList() const { return ListAdapter{ list_ }; }\n \n \tconst YamlObject &operator[](std::size_t index) const;\n@@ -196,8 +205,8 @@ private:\n \tType type_;\n \n \tstd::string value_;\n-\tListContainer list_;\n-\tDictContainer dictionary_;\n+\tContainer list_;\n+\tstd::map<std::string, YamlObject *> dictionary_;\n };\n \n class YamlParser final\ndiff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\nindex 4299f5abd38a..89c234fbbce5 100644\n--- a/src/libcamera/yaml_parser.cpp\n+++ b/src/libcamera/yaml_parser.cpp\n@@ -85,7 +85,6 @@ std::size_t YamlObject::size() const\n {\n \tswitch (type_) {\n \tcase Type::Dictionary:\n-\t\treturn dictionary_.size();\n \tcase Type::List:\n \t\treturn list_.size();\n \tdefault:\n@@ -280,11 +279,11 @@ std::optional<Size> YamlObject::get() const\n \tif (list_.size() != 2)\n \t\treturn {};\n \n-\tauto width = list_[0]->get<uint32_t>();\n+\tauto width = list_[0].value->get<uint32_t>();\n \tif (!width)\n \t\treturn {};\n \n-\tauto height = list_[1]->get<uint32_t>();\n+\tauto height = list_[1].value->get<uint32_t>();\n \tif (!height)\n \t\treturn {};\n \n@@ -347,7 +346,7 @@ const YamlObject &YamlObject::operator[](std::size_t index) const\n \tif (type_ != Type::List || index >= size())\n \t\treturn empty;\n \n-\treturn *list_[index];\n+\treturn *list_[index].value;\n }\n \n /**\n@@ -363,7 +362,7 @@ const YamlObject &YamlObject::operator[](std::size_t index) const\n  */\n bool YamlObject::contains(const std::string &key) const\n {\n-\tif (dictionary_.find(key) == dictionary_.end())\n+\tif (dictionary_.find(std::ref(key)) == dictionary_.end())\n \t\treturn false;\n \n \treturn true;\n@@ -635,16 +634,16 @@ int YamlParserContext::parseNextYamlObject(YamlObject &yamlObject, EventPtr even\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(new YamlObject());\n-\t\t\treturn parseNextYamlObject(*list.back(), std::move(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\t};\n \t\treturn parseDictionaryOrList(YamlObject::Type::List, handler);\n \t}\n \n \tcase YAML_MAPPING_START_EVENT: {\n \t\tyamlObject.type_ = YamlObject::Type::Dictionary;\n-\t\tauto &dictionary = yamlObject.dictionary_;\n-\t\tauto handler = [this, &dictionary](EventPtr evtKey) {\n+\t\tauto &list = yamlObject.list_;\n+\t\tauto handler = [this, &list](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@@ -662,10 +661,19 @@ int YamlParserContext::parseNextYamlObject(YamlObject &yamlObject, EventPtr even\n \t\t\tif (!evtValue)\n \t\t\t\treturn -EINVAL;\n \n-\t\t\tauto elem = dictionary.emplace(key, std::make_unique<YamlObject>());\n-\t\t\treturn parseNextYamlObject(*elem.first->second.get(), std::move(evtValue));\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};\n-\t\treturn parseDictionaryOrList(YamlObject::Type::Dictionary, handler);\n+\t\tint ret = parseDictionaryOrList(YamlObject::Type::Dictionary, 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 \tdefault:\n@@ -721,6 +729,9 @@ int YamlParserContext::parseNextYamlObject(YamlObject &yamlObject, EventPtr even\n  * The YamlParser::parse() function takes an open FILE, parses its contents, and\n  * returns a pointer to a YamlObject corresponding to the root node of the YAML\n  * document.\n+ *\n+ * The parser preserves the order of items in the YAML file, for both lists and\n+ * dictionaries.\n  */\n \n /**\n",
    "prefixes": [
        "libcamera-devel",
        "v7",
        "03/14"
    ]
}