From patchwork Thu Jun 19 09:32:18 2025 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: 23600 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 02189BDE6B for ; Thu, 19 Jun 2025 09:32:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DBFCE68DE0; Thu, 19 Jun 2025 11:32:23 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Fl8mATnS"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5DDAC614E1 for ; Thu, 19 Jun 2025 11:32:22 +0200 (CEST) Received: from pb-laptop.local (185.221.143.107.nat.pool.zt.hu [185.221.143.107]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 604479CA; Thu, 19 Jun 2025 11:32:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1750325528; bh=Ia1V0WxJcG2yOGR4T7Q+apof+nDricln3xlWkIqAiVI=; h=From:To:Cc:Subject:Date:From; b=Fl8mATnSXuwQY4PmOnnRLPF/FM3TcpHgpwYqHxpn2hVFeOHuiVkvD/FDc/Ep553UC Tr2dlusL7le8LnI4SHVCN/KOII8DvVaaqR2si697aW+xG57wqLW/EzkerGby0e1t97 rRTdUNdWq+bUfCr800yIJ0vYtVxSgWuCkZINw1zI= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Laurent Pinchart Subject: [PATCH v2] libcamera: base: bound_method: Move return value Date: Thu, 19 Jun 2025 11:32:18 +0200 Message-ID: <20250619093218.1335931-1-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.50.0 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" Instead of copying, just move the returned value when the call is made through an argument pack. This enables, e.g. `Object::invokeMethod()` to be usable with functions returning types, such as`std::unique_ptr`, that have no copy ctor/assignment. Since there are no other users of the argument pack object, this is safe to do. Reference return types are not supported, so a simple `std::move()` is sufficient. Bug: https://bugs.libcamera.org/show_bug.cgi?id=273#c1 Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart --- changes in v2: * add `[[maybe_unused]]` for gcc 9 * review comments v1: https://patchwork.libcamera.org/patch/23598/ --- include/libcamera/base/bound_method.h | 21 ++++++++------------- test/object-invoke.cpp | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 13 deletions(-) -- 2.50.0 diff --git a/include/libcamera/base/bound_method.h b/include/libcamera/base/bound_method.h index 507c320d3..e14614bc4 100644 --- a/include/libcamera/base/bound_method.h +++ b/include/libcamera/base/bound_method.h @@ -38,11 +38,6 @@ public: { } - R returnValue() - { - return ret_; - } - std::tuple...> args_; R ret_; }; @@ -56,10 +51,6 @@ public: { } - void returnValue() - { - } - std::tuple...> args_; }; @@ -140,8 +131,10 @@ public: return func_(args...); auto pack = std::make_shared(args...); - bool sync = BoundMethodBase::activatePack(pack, deleteMethod); - return sync ? pack->returnValue() : R(); + [[maybe_unused]] bool sync = BoundMethodBase::activatePack(pack, deleteMethod); + + if constexpr (!std::is_void_v) + return sync ? std::move(pack->ret_) : R(); } R invoke(Args... args) override @@ -175,8 +168,10 @@ public: } auto pack = std::make_shared(args...); - bool sync = BoundMethodBase::activatePack(pack, deleteMethod); - return sync ? pack->returnValue() : R(); + [[maybe_unused]] bool sync = BoundMethodBase::activatePack(pack, deleteMethod); + + if constexpr (!std::is_void_v) + return sync ? std::move(pack->ret_) : R(); } R invoke(Args... args) override diff --git a/test/object-invoke.cpp b/test/object-invoke.cpp index def1e61e4..ab4a15751 100644 --- a/test/object-invoke.cpp +++ b/test/object-invoke.cpp @@ -58,6 +58,19 @@ public: return 42; } + struct MoveOnly { + MoveOnly() = default; + MoveOnly(const MoveOnly &) = delete; + MoveOnly &operator=(const MoveOnly &) = delete; + MoveOnly(MoveOnly &&) = default; + MoveOnly &operator=(MoveOnly &&) = default; + }; + + MoveOnly methodWithReturnMoveOnly() + { + return {}; + } + private: Status status_; int value_; @@ -186,6 +199,10 @@ protected: return TestFail; } + /* Test invoking a method that returns type with no copy ctor/assignment. */ + object_.invokeMethod(&InvokedObject::methodWithReturnMoveOnly, + ConnectionTypeBlocking); + return TestPass; }