[{"id":34549,"web_url":"https://patchwork.libcamera.org/comment/34549/","msgid":"<20250618160539.GB13334@pendragon.ideasonboard.com>","date":"2025-06-18T16:05:39","subject":"Re: [PATCH v1] libcamera: base: bound_method: Move return value","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Barnabás,\n\nThank you for the patch.\n\nOn Wed, Jun 18, 2025 at 04:45:36PM +0200, Barnabás Pőcze wrote:\n> Instead of copying, just move the returned value when the call is made\n> through an argument pack. This enables, e.g. `Object::invokeMethod()`\n> to be usable with functions returning types, such as`std::unique_ptr`,\n> that have no copy ctor/assignment. Since there are no other users of\n> the argument pack object, this is safe to do. Reference return types\n> are not supported, so a simple `std::move()` is sufficient.\n> \n> Link: https://bugs.libcamera.org/show_bug.cgi?id=273#c1\n\nWe usually use Bug:.\n\n> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n> ---\n>  include/libcamera/base/bound_method.h | 17 ++++++-----------\n>  test/object-invoke.cpp                | 16 ++++++++++++++++\n>  2 files changed, 22 insertions(+), 11 deletions(-)\n> \n> diff --git a/include/libcamera/base/bound_method.h b/include/libcamera/base/bound_method.h\n> index 507c320d3..8b433a0da 100644\n> --- a/include/libcamera/base/bound_method.h\n> +++ b/include/libcamera/base/bound_method.h\n> @@ -38,11 +38,6 @@ public:\n>  \t{\n>  \t}\n>  \n> -\tR returnValue()\n> -\t{\n> -\t\treturn ret_;\n> -\t}\n> -\n>  \tstd::tuple<typename std::remove_reference_t<Args>...> args_;\n>  \tR ret_;\n>  };\n> @@ -56,10 +51,6 @@ public:\n>  \t{\n>  \t}\n>  \n> -\tvoid returnValue()\n> -\t{\n> -\t}\n> -\n>  \tstd::tuple<typename std::remove_reference_t<Args>...> args_;\n>  };\n>  \n> @@ -141,7 +132,9 @@ public:\n>  \n>  \t\tauto pack = std::make_shared<PackType>(args...);\n>  \t\tbool sync = BoundMethodBase::activatePack(pack, deleteMethod);\n> -\t\treturn sync ? pack->returnValue() : R();\n> +\n> +\t\tif constexpr (!std::is_void_v<R>)\n> +\t\t\treturn sync ? std::move(pack->ret_) : R();\n>  \t}\n>  \n>  \tR invoke(Args... args) override\n> @@ -176,7 +169,9 @@ public:\n>  \n>  \t\tauto pack = std::make_shared<PackType>(args...);\n>  \t\tbool sync = BoundMethodBase::activatePack(pack, deleteMethod);\n> -\t\treturn sync ? pack->returnValue() : R();\n> +\n> +\t\tif constexpr (!std::is_void_v<R>)\n> +\t\t\treturn sync ? std::move(pack->ret_) : R();\n>  \t}\n>  \n>  \tR invoke(Args... args) override\n> diff --git a/test/object-invoke.cpp b/test/object-invoke.cpp\n> index def1e61e4..d309cff15 100644\n> --- a/test/object-invoke.cpp\n> +++ b/test/object-invoke.cpp\n> @@ -58,6 +58,19 @@ public:\n>  \t\treturn 42;\n>  \t}\n>  \n> +\tstruct MoveOnly {\n> +\t\tMoveOnly() = default;\n> +\t\tMoveOnly(const MoveOnly &) = delete;\n> +\t\tMoveOnly &operator=(const MoveOnly &) = delete;\n> +\t\tMoveOnly(MoveOnly &&) = default;\n> +\t\tMoveOnly &operator=(MoveOnly &&) = default;\n> +\t};\n> +\n> +\tMoveOnly methodWithReturnMoveOnly()\n> +\t{\n> +\t\treturn {};\n> +\t}\n> +\n>  private:\n>  \tStatus status_;\n>  \tint value_;\n> @@ -186,6 +199,9 @@ protected:\n>  \t\t\treturn TestFail;\n>  \t\t}\n>  \n> +\t\t/* Test invoking a method that returns type with no copy ctor/assignment. */\n> +\t\tobject_.invokeMethod(&InvokedObject::methodWithReturnMoveOnly, ConnectionTypeBlocking);\n\nYou can wrap this line.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\n>  \t\treturn TestPass;\n>  \t}\n>","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 0FB06C3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 18 Jun 2025 16:06:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3DE9668DC1;\n\tWed, 18 Jun 2025 18:05:59 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2AC4C68DC1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 18 Jun 2025 18:05:58 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CBC9B752;\n\tWed, 18 Jun 2025 18:05:44 +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=\"uapXuKqx\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1750262745;\n\tbh=mbPcZhOFBVbBcPgOR+X1Fxx+GY2nmcnFSEyG3Qman5g=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=uapXuKqxQ0C4OCK+53v32PA6URko3ygEYEeJFqmdlMAH2aeWBKp097K4tv/j07Zju\n\t48wt1bg9pBd5lJevs38wgan+L+4w2iWNRaEmJKMeglkBrODa0a0C48rPoG9SYf1Ob1\n\tvgpx+wZuedXS+KqMKI/ClijgRMO0jo8HcytVl1tQ=","Date":"Wed, 18 Jun 2025 19:05:39 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v1] libcamera: base: bound_method: Move return value","Message-ID":"<20250618160539.GB13334@pendragon.ideasonboard.com>","References":"<20250618144536.443175-1-barnabas.pocze@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20250618144536.443175-1-barnabas.pocze@ideasonboard.com>","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>"}}]