From patchwork Thu Sep 3 09:18:39 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 28179 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 971B7C3348 for ; Thu, 3 Sep 2026 09:18:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4E63C685EB; Thu, 3 Sep 2026 11:18:50 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="u7j/TdwD"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A9FA8685D5 for ; Thu, 3 Sep 2026 11:18:47 +0200 (CEST) Received: from pb-laptop.local (185.221.143.32.nat.pool.zt.hu [185.221.143.32]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 42C8C20EA; Thu, 3 Sep 2026 11:17:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1788427035; bh=0aPdCzPliFY+ogeG9xpvgdBmhI3cZT6mO26528Nr5Yo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u7j/TdwDzRuiai+V/IiTtsFDmKykJfVj7UsMJh8Utc8o5KFUc/Ibm5kaZWFNrk24A qwazdtYG4+5TgymQtoB6N6u/Sql5yIOVLjc6f2Gy317luc/26d2WjFhHma72dlfTuQ wiW94Hsae73ph0Ox2KNymBqiCdDSM3wklcmw4Xkc= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Jacopo Mondi , Laurent Pinchart Subject: [PATCH v3 1/5] libcamera: controls: Give name to the union containing storage Date: Thu, 3 Sep 2026 11:18:39 +0200 Message-ID: <20260903091843.85548-2-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260903091843.85548-1-barnabas.pocze@ideasonboard.com> References: <20260903091843.85548-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In order to be able to copy the storage as one unit, regardless of which member is active give a name to the union member. Also rename the union member to internal/external to clarify which is used for in-place/dynamically allocated storage. And finally drop some unnecessary `reinterpret_cast`s. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- include/libcamera/controls.h | 6 +++--- src/libcamera/controls.cpp | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 4485c228d3..da73e41848 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -246,9 +246,9 @@ private: bool isArray_; std::size_t numElements_ : 32; union { - uint64_t value_; - void *storage_; - }; + uint64_t internal; + void *external; + } storage_; void release(); void set(ControlType type, bool isArray, const void *data, diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index f5581dbb88..e9d4e7eb47 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -122,9 +122,9 @@ void ControlValue::release() { std::size_t size = numElements_ * ControlValueSize[type_]; - if (size > sizeof(value_)) { - delete[] reinterpret_cast(storage_); - storage_ = nullptr; + if (size > sizeof(storage_.internal)) { + delete[] reinterpret_cast(storage_.external); + storage_.external = nullptr; } } @@ -192,9 +192,9 @@ ControlValue &ControlValue::operator=(const ControlValue &other) std::span ControlValue::data() const { std::size_t size = numElements_ * ControlValueSize[type_]; - const uint8_t *data = size > sizeof(value_) - ? reinterpret_cast(storage_) - : reinterpret_cast(&value_); + const uint8_t *data = size > sizeof(storage_.internal) + ? reinterpret_cast(storage_.external) + : reinterpret_cast(&storage_.internal); return { data, size }; } @@ -391,8 +391,8 @@ void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen if (oldSize == newSize) return; - if (newSize > sizeof(value_)) - storage_ = reinterpret_cast(new uint8_t[newSize]); + if (newSize > sizeof(storage_.internal)) + storage_.external = new uint8_t[newSize]; } /**