Patch Detail
Show a patch.
GET /api/patches/26613/?format=api
{ "id": 26613, "url": "https://patchwork.libcamera.org/api/patches/26613/?format=api", "web_url": "https://patchwork.libcamera.org/patch/26613/", "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": "<20260504140646.1455101-1-laurent.pinchart@ideasonboard.com>", "date": "2026-05-04T14:06:45", "name": "[v2,1/2] libcamera: base: Restore defopt", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "a5e4ff44537db9d4787d3f09d1237301250ac620", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/26613/mbox/", "series": [ { "id": 5902, "url": "https://patchwork.libcamera.org/api/series/5902/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5902", "date": "2026-05-04T14:06:45", "name": "[v2,1/2] libcamera: base: Restore defopt", "version": 2, "mbox": "https://patchwork.libcamera.org/series/5902/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/26613/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/26613/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 14599BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 4 May 2026 14:06:51 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 03E0E6301E;\n\tMon, 4 May 2026 16:06:50 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7942C62FE1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 4 May 2026 16:06:48 +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 ESMTPSA id 61CC69C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 4 May 2026 16:06:46 +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=\"d0w7nFsQ\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1777903606;\n\tbh=SkItsZtMvz7VeKwdXrsX2EfAExmQuiHqekk1gRj3phI=;\n\th=From:To:Subject:Date:From;\n\tb=d0w7nFsQABXENa+ead1q3huSpEp5lhElNOBSIUvQEbiclT3jelN9rUZmkMYlHMNih\n\tA0V109KqC61YJ4xrHSf689fYCgy4ncgnEvyfd9Vnl+jSPCuRJEAvI7DHdLj0TksuIF\n\tu8HBJPQDEBsXRc2JJWJbQzQSOb8PbC3syaiKHuio=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Subject": "[PATCH v2 1/2] libcamera: base: Restore defopt", "Date": "Mon, 4 May 2026 17:06:45 +0300", "Message-ID": "<20260504140646.1455101-1-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.53.0", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "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": "utils::defopt was removed due to compilation errors with gcc 8 that were\ndeemed impossible to work around. Now that libcamera has dropped support\nfor gcc 8, restore the utility.\n\nThis reverts commit e0e54965df015b954d75ebe945221372f2dffb80, with a few\nextra changes on top:\n\n- Make defopt_t::operator T() constexpr\n- Rework the documentation to drop rationale invalidated by\n https://cplusplus.github.io/LWG/issue3886\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\nChanges since v1:\n\n- Update commit message\n- Make defopt_t::operator T() constexpr\n- Rework the documentation to drop rationale invalidated by\n https://cplusplus.github.io/LWG/issue3886\n---\n include/libcamera/base/utils.h | 15 ++++++++++\n src/libcamera/base/utils.cpp | 17 +++++++++++\n test/utils.cpp | 53 ++++++++++++++++++++++++++++++++++\n 3 files changed, 85 insertions(+)\n\n\nbase-commit: 183e37362f57ff3ce7493abf0bc6f1b57b931f55", "diff": "diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h\nindex b33a4c644a87..9835fd7980dc 100644\n--- a/include/libcamera/base/utils.h\n+++ b/include/libcamera/base/utils.h\n@@ -430,6 +430,21 @@ scope_exit(EF) -> scope_exit<EF>;\n \n #endif /* __DOXYGEN__ */\n \n+namespace details {\n+\n+struct defopt_t {\n+\ttemplate<typename T>\n+\tconstexpr operator T() const\n+\t{\n+\t\tstatic_assert(std::is_default_constructible_v<T>);\n+\t\treturn T{};\n+\t}\n+};\n+\n+} /* namespace details */\n+\n+constexpr details::defopt_t defopt;\n+\n #ifndef __DOXYGEN__\n std::ostream &operator<<(std::ostream &os, const Duration &d);\n #endif\ndiff --git a/src/libcamera/base/utils.cpp b/src/libcamera/base/utils.cpp\nindex 4ab2bd863e11..eca3efddb2e3 100644\n--- a/src/libcamera/base/utils.cpp\n+++ b/src/libcamera/base/utils.cpp\n@@ -685,6 +685,23 @@ void ScopeExitActions::release()\n \tactions_.clear();\n }\n \n+/**\n+ * \\var defopt\n+ * \\brief Constant used with std::optional::value_or() to create a\n+ * default-constructed object\n+ *\n+ * The std::optional<T>::value_or(U &&default_value) function returns the\n+ * contained value if available, or \\a default_value if the std::optional has no\n+ * value. If the desired default value is a default-constructed T, the obvious\n+ * option is to call std::optional<T>::value_or(T{}). This approach however\n+ * constructs the \\a default_value T{} even if the std::optional instance has a\n+ * value, which impacts efficiency.\n+ *\n+ * The defopt variable solves this issue by providing a value that can be passed\n+ * to std::optional<T>::value_or() and get implicitly converted to a\n+ * default-constructed T.\n+ */\n+\n #ifndef __DOXYGEN__\n std::ostream &operator<<(std::ostream &os, const Duration &d)\n {\ndiff --git a/test/utils.cpp b/test/utils.cpp\nindex b5ce94e5e912..eba3ed9fbf43 100644\n--- a/test/utils.cpp\n+++ b/test/utils.cpp\n@@ -178,6 +178,55 @@ protected:\n \t\treturn TestPass;\n \t}\n \n+\tint testDefopt()\n+\t{\n+\t\tstatic bool defaultConstructed = false;\n+\n+\t\tstruct ValueType {\n+\t\t\tValueType()\n+\t\t\t\t: value_(-1)\n+\t\t\t{\n+\t\t\t\tdefaultConstructed = true;\n+\t\t\t}\n+\n+\t\t\tValueType(int value)\n+\t\t\t\t: value_(value)\n+\t\t\t{\n+\t\t\t}\n+\n+\t\t\tint value_;\n+\t\t};\n+\n+\t\t/*\n+\t\t * Test that utils::defopt doesn't cause default-construction\n+\t\t * of a ValueType instance when value_or(utils::defopt) is\n+\t\t * called on a std::optional that has a value.\n+\t\t */\n+\t\tstd::optional<ValueType> opt = ValueType(0);\n+\t\tValueType value = opt.value_or(utils::defopt);\n+\n+\t\tif (defaultConstructed || value.value_ != 0) {\n+\t\t\tstd::cerr << \"utils::defopt didn't prevent default construction\"\n+\t\t\t\t << std::endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Then test that the ValueType is correctly default-constructed\n+\t\t * when the std::optional has no value.\n+\t\t */\n+\t\topt = std::nullopt;\n+\t\tvalue = opt.value_or(utils::defopt);\n+\n+\t\tif (!defaultConstructed || value.value_ != -1) {\n+\t\t\tstd::cerr << \"utils::defopt didn't cause default construction\"\n+\t\t\t\t << std::endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\treturn TestPass;\n+\t}\n+\n \tint run()\n \t{\n \t\t/* utils::hex() test. */\n@@ -332,6 +381,10 @@ protected:\n \t\tif (testDuration() != TestPass)\n \t\t\treturn TestFail;\n \n+\t\t/* utils::defopt test. */\n+\t\tif (testDefopt() != TestPass)\n+\t\t\treturn TestFail;\n+\n \t\treturn TestPass;\n \t}\n };\n", "prefixes": [ "v2", "1/2" ] }