{"id":23184,"url":"https://patchwork.libcamera.org/api/1.1/patches/23184/?format=json","web_url":"https://patchwork.libcamera.org/patch/23184/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20250417113539.1137936-1-barnabas.pocze@ideasonboard.com>","date":"2025-04-17T11:35:37","name":"[v1,1/3] libcamera: controls: Give name to the union containing storage","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"b02397306ec29d3816e6df0a21e98f5d8bffddb2","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/1.1/people/216/?format=json","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/23184/mbox/","series":[{"id":5131,"url":"https://patchwork.libcamera.org/api/1.1/series/5131/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5131","date":"2025-04-17T11:35:37","name":"[v1,1/3] libcamera: controls: Give name to the union containing storage","version":1,"mbox":"https://patchwork.libcamera.org/series/5131/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/23184/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/23184/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 B2E6CC3213\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 17 Apr 2025 11:35:46 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D071268AC0;\n\tThu, 17 Apr 2025 13:35:45 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 776DE617E8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 17 Apr 2025 13:35:43 +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 B6CD56A2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 17 Apr 2025 13:33:39 +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=\"b4mdfVLh\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1744889619;\n\tbh=N5HOeHDcCvRz+tweAkZi65QD0yX0Kgq8ZQ3yK34x4v8=;\n\th=From:To:Subject:Date:From;\n\tb=b4mdfVLhT6TktPwBNiCJ+8m3lGx181ackKV7XIfmX4/V5pOTP+2smk/xXUmFlEA3D\n\tp6xQnxSXtlW9LZNoUQ0vPjkQPrpuZVYUcKvy0gf+r+IE1y48uIrjZq/Q46kz9yZOHn\n\tNY+a0d7ottTrtkRjKeMsivM3Wxb/i9AK3xXH9nng=","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"[PATCH v1 1/3] libcamera: controls: Give name to the union\n\tcontaining storage","Date":"Thu, 17 Apr 2025 13:35:37 +0200","Message-ID":"<20250417113539.1137936-1-barnabas.pocze@ideasonboard.com>","X-Mailer":"git-send-email 2.49.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":"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>\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":["v1","1/3"]}