Show a patch.

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

{
    "id": 23191,
    "url": "https://patchwork.libcamera.org/api/patches/23191/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/23191/",
    "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": "<20250421153556.171192-2-barnabas.pocze@ideasonboard.com>",
    "date": "2025-04-21T15:35:52",
    "name": "[v2,1/5] libcamera: controls: Give name to the union containing storage",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "b02397306ec29d3816e6df0a21e98f5d8bffddb2",
    "submitter": {
        "id": 216,
        "url": "https://patchwork.libcamera.org/api/people/216/?format=api",
        "name": "Barnabás Pőcze",
        "email": "barnabas.pocze@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/23191/mbox/",
    "series": [
        {
            "id": 5135,
            "url": "https://patchwork.libcamera.org/api/series/5135/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5135",
            "date": "2025-04-21T15:35:51",
            "name": "libcamera: controls: Move constructor/assignment + swap",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/5135/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/23191/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/23191/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 C1993C327D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 21 Apr 2025 15:36:05 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8228868AC8;\n\tMon, 21 Apr 2025 17:36:03 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1B1DC68AC2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Apr 2025 17:36:00 +0200 (CEST)",
            "from pb-laptop.local (185.221.143.16.nat.pool.zt.hu\n\t[185.221.143.16])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5DADE6D6;\n\tMon, 21 Apr 2025 17:33:53 +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=\"DSMr6xEJ\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1745249633;\n\tbh=1tyum2zF6T/OXe1ZVnWsUhzpxhe5AIafayvnExR6jBg=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=DSMr6xEJEEQFUduNAP7t6faTlw6v+zntxkped7aj9n9ad+2S/FbZiQziOcxS7jNiQ\n\tGN497aoEn0tBAs7Zvet9ULJcRwijiNkL0IFy0QPw7ND2AYsdW6fycHLEBjbEpe3/99\n\tJoLMi6WAn1gQPems6UoAHhprjf5DyD2bRkn/Sjyw=",
        "From": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tJacopo Mondi <jacopo.mondi@ideasonboard.com>",
        "Subject": "[PATCH v2 1/5] libcamera: controls: Give name to the union\n\tcontaining storage",
        "Date": "Mon, 21 Apr 2025 17:35:52 +0200",
        "Message-ID": "<20250421153556.171192-2-barnabas.pocze@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.49.0",
        "In-Reply-To": "<20250421153556.171192-1-barnabas.pocze@ideasonboard.com>",
        "References": "<20250421153556.171192-1-barnabas.pocze@ideasonboard.com>",
        "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": "In order to be able to copy the storage as one unit, regardless of\nwhich member is active give a name to the union member.\n\nSigned-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\n include/libcamera/controls.h |  6 +++---\n src/libcamera/controls.cpp   | 17 ++++++++---------\n 2 files changed, 11 insertions(+), 12 deletions(-)",
    "diff": "diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\nindex 4bfe9615c..1dc6ccffa 100644\n--- a/include/libcamera/controls.h\n+++ b/include/libcamera/controls.h\n@@ -238,9 +238,9 @@ private:\n \tbool isArray_;\n \tstd::size_t numElements_ : 32;\n \tunion {\n-\t\tuint64_t value_;\n-\t\tvoid *storage_;\n-\t};\n+\t\tuint64_t internal;\n+\t\tvoid *external;\n+\t} storage_;\n \n \tvoid release();\n \tvoid set(ControlType type, bool isArray, const void *data,\ndiff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\nindex 70f6f6092..d384e1ef7 100644\n--- a/src/libcamera/controls.cpp\n+++ b/src/libcamera/controls.cpp\n@@ -10,6 +10,7 @@\n #include <sstream>\n #include <string.h>\n #include <string>\n+#include <utility>\n \n #include <libcamera/base/log.h>\n #include <libcamera/base/utils.h>\n@@ -122,10 +123,8 @@ void ControlValue::release()\n {\n \tstd::size_t size = numElements_ * ControlValueSize[type_];\n \n-\tif (size > sizeof(value_)) {\n-\t\tdelete[] reinterpret_cast<uint8_t *>(storage_);\n-\t\tstorage_ = nullptr;\n-\t}\n+\tif (size > sizeof(storage_.internal))\n+\t\tdelete[] reinterpret_cast<uint8_t *>(std::exchange(storage_.external, nullptr));\n }\n \n ControlValue::~ControlValue()\n@@ -192,9 +191,9 @@ ControlValue &ControlValue::operator=(const ControlValue &other)\n Span<const uint8_t> ControlValue::data() const\n {\n \tstd::size_t size = numElements_ * ControlValueSize[type_];\n-\tconst uint8_t *data = size > sizeof(value_)\n-\t\t\t    ? reinterpret_cast<const uint8_t *>(storage_)\n-\t\t\t    : reinterpret_cast<const uint8_t *>(&value_);\n+\tconst uint8_t *data = size > sizeof(storage_.internal)\n+\t\t\t    ? reinterpret_cast<const uint8_t *>(storage_.external)\n+\t\t\t    : reinterpret_cast<const uint8_t *>(&storage_.internal);\n \treturn { data, size };\n }\n \n@@ -391,8 +390,8 @@ void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen\n \tif (oldSize == newSize)\n \t\treturn;\n \n-\tif (newSize > sizeof(value_))\n-\t\tstorage_ = reinterpret_cast<void *>(new uint8_t[newSize]);\n+\tif (newSize > sizeof(storage_.internal))\n+\t\tstorage_.external = new uint8_t[newSize];\n }\n \n /**\n",
    "prefixes": [
        "v2",
        "1/5"
    ]
}