[{"id":26634,"web_url":"https://patchwork.libcamera.org/comment/26634/","msgid":"<20230312151305.GT2545@pendragon.ideasonboard.com>","date":"2023-03-12T15:13:05","subject":"Re: [libcamera-devel] [PATCH v4 14/15] py: Improve stub type\n\tgeneration for PyCameraEvent","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Tomi,\n\nThank you for the patch.\n\nOn Thu, Mar 09, 2023 at 04:26:00PM +0200, Tomi Valkeinen via libcamera-devel wrote:\n> We store the camera, request and fb fields in PyCameraEvent as\n> py::objects, so that we keep the refs and keep-alives. When we\n> return py::objects to the Python side, they, obviously, show up\n> as \"objects\" when the stub generation is looking at the fields.\n> \n> Fix this by manually casting the py::objects to the correct C++\n> counterparts, which causes pybind11 to assign the correct types for the\n> properties, helpind stubgen to generate correct types.\n\ns/helpind/helping/\n\n> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  src/py/libcamera/py_main.cpp | 14 +++++++++++---\n>  1 file changed, 11 insertions(+), 3 deletions(-)\n> \n> diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp\n> index 1585b14a..cb7088b1 100644\n> --- a/src/py/libcamera/py_main.cpp\n> +++ b/src/py/libcamera/py_main.cpp\n> @@ -100,11 +100,19 @@ PYBIND11_MODULE(_libcamera, m)\n>  \t\t.value(\"RequestCompleted\", CameraEventType::RequestCompleted)\n>  \t\t.value(\"BufferCompleted\", CameraEventType::BufferCompleted);\n>  \n> +\t/*\n> +\t * For camera, request and fb fields, manually typecast to the C++ type,\n> +\t * so that pybind11 assigns the actual type for the return value. This\n> +\t * makes the stubs generated by pybind11-stubgen contain the correct type,\n> +\t * instead of \"object\".\n> +\t *\n> +\t * Maybe there's a better way to do this...\n> +\t */\n>  \tpyEvent\n>  \t\t.def_readonly(\"type\", &PyCameraEvent::type_)\n> -\t\t.def_readonly(\"camera\", &PyCameraEvent::camera_)\n> -\t\t.def_readonly(\"request\", &PyCameraEvent::request_)\n> -\t\t.def_readonly(\"fb\", &PyCameraEvent::fb_);\n> +\t\t.def_property_readonly(\"camera\", [](PyCameraEvent &self) { return self.camera_.cast<Camera *>(); })\n> +\t\t.def_property_readonly(\"request\", [](PyCameraEvent &self) { return self.request_.cast<Request *>(); })\n> +\t\t.def_property_readonly(\"fb\", [](PyCameraEvent &self) { return self.fb_.cast<FrameBuffer *>(); });\n>  \n>  \tpyCameraManager\n>  \t\t.def_static(\"singleton\", []() {","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 3698DBE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 12 Mar 2023 15:13:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8DEDE62707;\n\tSun, 12 Mar 2023 16:13:13 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 67C3662705\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 12 Mar 2023 16:13:12 +0100 (CET)","from pendragon.ideasonboard.com (85-76-21-162-nat.elisa-mobile.fi\n\t[85.76.21.162])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DA118814;\n\tSun, 12 Mar 2023 16:13:06 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1678633993;\n\tbh=tIbEKJUDmhVmdvCnQdDWhUrd9QwqFPDbTT4ahoZ+I0g=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=w/yq5W56aSaWQ76sCfoleTeWhO45EajKFL5CSBW3y7kSd23NCSnW7wJjKGYgy185x\n\tIiDy9AQI3kjkpgTGrST63XFtn0YGuglxmTaEcCm23mRRzCevtGamXr0ECD8UvHO2Xt\n\tyNcPpkOGlvZ7zzXobg5VVpidiJUbrnrsA4E6Qb9ggr94GMIbR16cp3yAAet9Jv8Fnz\n\tzYp5u4opDYVI1KMz2Hbm8sz+r/0+Grg4iuHT04pR4q3lfv6gxwO9JX54aTqN/XmI2x\n\tsiWn+AJkBoY7yidsfZh5ziTgiQ6fZqPmGlAWeNVjDyZ+SQ+GqeTgtWJadkTRlDwfA5\n\tat7f9M95Fa/eA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1678633992;\n\tbh=tIbEKJUDmhVmdvCnQdDWhUrd9QwqFPDbTT4ahoZ+I0g=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=bTMjzcZ1eRJl3zBFJLGing2xBhgFlJhMk3QbpuSb0QToZgoEXUfhacKFCTSwy1Hwg\n\ttSgblnBAG+gb7D4gTX6bJ0GistjxpEDxIVi5bOBAjYv5TEZb23Tsd5bPNSIYnqBVW8\n\tuem/IGC30FaxFKswOO1C+SjdDFU9IR6fU7N17gc4="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"bTMjzcZ1\"; dkim-atps=neutral","Date":"Sun, 12 Mar 2023 17:13:05 +0200","To":"Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>","Message-ID":"<20230312151305.GT2545@pendragon.ideasonboard.com>","References":"<20230309142601.70556-1-tomi.valkeinen@ideasonboard.com>\n\t<20230309142601.70556-15-tomi.valkeinen@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20230309142601.70556-15-tomi.valkeinen@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v4 14/15] py: Improve stub type\n\tgeneration for PyCameraEvent","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]