From patchwork Thu Jan 2 23:53:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2483 Return-Path: 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 51AEF60467 for ; Fri, 3 Jan 2020 00:53:25 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C1B3B516 for ; Fri, 3 Jan 2020 00:53:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1578009204; bh=uNqQmLSHAXsMLPj8HA5Fa4lkEHdR6JU16IO6QksnNaM=; h=From:To:Subject:Date:From; b=lANtWYa+HgJ3q/38gbRU2ffk8wyb3D6LWoiYy6e9j58oEh21KXFsIB6Y8oRKgmOub EQKOwd/ZD7xM5bYKKCd1/292evT+jefU4lWo++0O2LMnys3WYUzzpjXvFeYEznkW1e OO+0nTHbwBSErukDvWC42gxqQnfFMgto1BOF4iDo= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Jan 2020 01:53:10 +0200 Message-Id: <20200102235311.12009-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] test: object-invoke: Test invocation of method taking a reference argument 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: , X-List-Received-Date: Thu, 02 Jan 2020 23:53:25 -0000 Object::invokeMethod() fails with a compilation error when the invoked method takes a reference argument. Add a test case for this issue. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder --- test/object-invoke.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/object-invoke.cpp b/test/object-invoke.cpp index 560adee14e3a..f9a8bea9dce2 100644 --- a/test/object-invoke.cpp +++ b/test/object-invoke.cpp @@ -49,6 +49,10 @@ public: value_ = value; } + void methodWithReference(const int &value) + { + } + private: Status status_; int value_; @@ -119,6 +123,14 @@ protected: return TestFail; } + /* + * Test invoking a method that takes reference arguments. This + * targets compilation, there's no need to check runtime + * results. + */ + object_.invokeMethod(&InvokedObject::methodWithReference, + ConnectionTypeBlocking, 42); + return TestPass; } From patchwork Thu Jan 2 23:53:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2484 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7EAB660469 for ; Fri, 3 Jan 2020 00:53:25 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1AA7E9A5 for ; Fri, 3 Jan 2020 00:53:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1578009205; bh=XvyIQc2YGGrvrBKw69hPk6jZi/Ge2LUwEmcv43pmvL4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=pLrAluxUBFYmhAX6ELIpHnnPQmbZDTWyLtOC4+vfTcAlEgLri/m6WuQ8EyN0fTrdl WOrf9M6Pgb+5kYfeYGHTvOYFaj/RbfOTqwcwIQIzujtsCEDv8YW2fdwm33tIC8yl2B IPPintOO7B5gMX2+3xeMHKDbCO2bKsrwAudn7wzw= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Jan 2020 01:53:11 +0200 Message-Id: <20200102235311.12009-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102235311.12009-1-laurent.pinchart@ideasonboard.com> References: <20200102235311.12009-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] libcamera: object: Support reference arguments in invokeMethod() 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: , X-List-Received-Date: Thu, 02 Jan 2020 23:53:25 -0000 Invoking a method that takes a reference argument with Object::invokeMethod() results in a compilation error: ../test/object-invoke.cpp:131:11: error: no matching member function for call to 'invokeMethod' object_.invokeMethod(&InvokedObject::methodWithReference, ~~~~~~~~^~~~~~~~~~~~ ../include/libcamera/object.h:33:7: note: candidate template ignored: deduced conflicting types for parameter 'Args' ( vs. ) void invokeMethod(void (T::*func)(Args...), ConnectionType type, Args... args) This is due to the fact that implicit type conversions (from value to reference in this case) takes place after template argument type deduction, during overload resolution. A similar issue would occur if T::func took a long argument and invokeMethod() was called with an in argument. Fix this by specifying to sets of argument types in the invokeMethod() template, one for the arguments to the invoked method, and one for the arguments to invokeMethod() itself. The compiler can then first perform type deduction separately, and implicit conversion in a second step. Reported-by: Paul Elder Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Jacopo Mondi --- include/libcamera/object.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/libcamera/object.h b/include/libcamera/object.h index 86e0f7265865..21b70460b516 100644 --- a/include/libcamera/object.h +++ b/include/libcamera/object.h @@ -29,13 +29,15 @@ public: void postMessage(std::unique_ptr msg); - template::value>::type * = nullptr> - void invokeMethod(void (T::*func)(Args...), ConnectionType type, Args... args) + template::value>::type * = nullptr> + void invokeMethod(void (T::*func)(FuncArgs...), ConnectionType type, + Args... args) { T *obj = static_cast(this); BoundMethodBase *method = - new BoundMemberMethod(obj, this, func, type); - void *pack = new typename BoundMemberMethod::PackType{ args... }; + new BoundMemberMethod(obj, this, func, type); + void *pack = new typename BoundMemberMethod::PackType{ args... }; method->activatePack(pack, true); }