[{"id":33989,"web_url":"https://patchwork.libcamera.org/comment/33989/","msgid":"<aAd0PhM5NoMxKXwg@pyrite.rasen.tech>","date":"2025-04-22T10:49:34","subject":"Re: [RFC PATCH v1] utils: ipc: Do not define variables in signal\n\thandler upfront","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Hi Barnabás,\n\nThanks for the patch.\n\nOn Wed, Mar 26, 2025 at 11:13:24AM +0100, Barnabás Pőcze wrote:\n> Defining the variables at the beginning of the function forces the types\n> to be default constructible, which may not be desirable; furthermore, it\n> also forces the move/copy assignment operator to be used when the\n> deserialized value is retrieved.\n\nAh, I see. Nice catch.\n\n> \n> Having `T val = f()` has the advantage of benefitting from potential RVO\n> as well as not requiring `T` to be default constructible, so generate\n> code in that form by calling `deserialize_call()` with `declare=true`.\n> \n> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  .../generators/libcamera_templates/module_ipa_proxy.cpp.tmpl | 5 +----\n>  1 file changed, 1 insertion(+), 4 deletions(-)\n> \n> diff --git a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n> index ce3cc5ab6..07165821e 100644\n> --- a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n> +++ b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n> @@ -239,10 +239,7 @@ void {{proxy_name}}::{{method.mojom_name}}IPC(\n>  \t[[maybe_unused]] size_t dataSize,\n>  \t[[maybe_unused]] const std::vector<SharedFD> &fds)\n>  {\n> -{%- for param in method.parameters %}\n> -\t{{param|name}} {{param.mojom_name}};\n> -{%- endfor %}\n> -{{proxy_funcs.deserialize_call(method.parameters, 'data', 'fds', false, false, true, 'dataSize')}}\n> +{{proxy_funcs.deserialize_call(method.parameters, 'data', 'fds', false, true, true, 'dataSize')}}\n>  \t{{method.mojom_name}}.emit({{method.parameters|params_comma_sep}});\n>  }\n>  {% endfor %}\n> -- \n> 2.49.0\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 E6C52C327D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 22 Apr 2025 10:49:50 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3383F68ACB;\n\tTue, 22 Apr 2025 12:49:50 +0200 (CEST)","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 338D8617E3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 22 Apr 2025 12:49:49 +0200 (CEST)","from pyrite.rasen.tech (unknown\n\t[IPv6:2404:7a81:160:2100:bedf:5f9a:c968:1149])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3484E250;\n\tTue, 22 Apr 2025 12:47:39 +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=\"T0KPfSvd\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1745318861;\n\tbh=3exLsZ7mJvuXJjhhlLYHHiEagJ8pPwdDvKIjEROQBIc=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=T0KPfSvdfjxnX8tX3LSFzqM/BJ2JHbd7h6uFy5W7QSXCiEDcWH+b9VnPfc2JUz6KS\n\trZjUsl7uh/XDuxXslpuQFe6H1viqh/r7pn1JSbBRvaAOMkKIl86t3KySU8GrGH0r1p\n\t1t1ue78vFPdYOgz3iIVzorsUQTk4WMiZ/VPAa/wE=","Date":"Tue, 22 Apr 2025 19:49:34 +0900","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [RFC PATCH v1] utils: ipc: Do not define variables in signal\n\thandler upfront","Message-ID":"<aAd0PhM5NoMxKXwg@pyrite.rasen.tech>","References":"<20250326101324.1514654-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":"<20250326101324.1514654-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>"}},{"id":33998,"web_url":"https://patchwork.libcamera.org/comment/33998/","msgid":"<20250422174908.GI17813@pendragon.ideasonboard.com>","date":"2025-04-22T17:49:08","subject":"Re: [RFC PATCH v1] utils: ipc: Do not define variables in signal\n\thandler upfront","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, Mar 26, 2025 at 11:13:24AM +0100, Barnabás Pőcze wrote:\n> Defining the variables at the beginning of the function forces the types\n> to be default constructible, which may not be desirable; furthermore, it\n> also forces the move/copy assignment operator to be used when the\n> deserialized value is retrieved.\n> \n> Having `T val = f()` has the advantage of benefitting from potential RVO\n> as well as not requiring `T` to be default constructible, so generate\n> code in that form by calling `deserialize_call()` with `declare=true`.\n\nI looked at the diff in generated files:\n\ndiff -Nur a/src/libcamera/proxy/ipu3_ipa_proxy.cpp b/src/libcamera/proxy/ipu3_ipa_proxy.cpp\n--- a/src/libcamera/proxy/ipu3_ipa_proxy.cpp\t2025-03-20 17:00:30.998772793 +0200\n+++ b/src/libcamera/proxy/ipu3_ipa_proxy.cpp\t2025-04-22 18:26:58.982280071 +0300\n@@ -609,9 +609,6 @@\n \t[[maybe_unused]] size_t dataSize,\n \t[[maybe_unused]] const std::vector<SharedFD> &fds)\n {\n-\tuint32_t frame;\n-\tControlList sensorControls;\n-\tControlList lensControls;\n \n \t[[maybe_unused]] const size_t frameBufSize = readPOD<uint32_t>(data, 0, data + dataSize);\n \t[[maybe_unused]] const size_t sensorControlsBufSize = readPOD<uint32_t>(data, 4, data + dataSize);\n@@ -622,18 +619,18 @@\n \tconst size_t lensControlsStart = sensorControlsStart + sensorControlsBufSize;\n \n \n-\tframe =\n+\tuint32_t frame =\n         IPADataSerializer<uint32_t>::deserialize(\n         \tdata + frameStart,\n         \tdata + frameStart + frameBufSize);\n \n-\tsensorControls =\n+\tControlList sensorControls =\n         IPADataSerializer<ControlList>::deserialize(\n         \tdata + sensorControlsStart,\n         \tdata + sensorControlsStart + sensorControlsBufSize,\n         \t&controlSerializer_);\n \n-\tlensControls =\n+\tControlList lensControls =\n         IPADataSerializer<ControlList>::deserialize(\n         \tdata + lensControlsStart,\n         \tdata + lensControlsStart + lensControlsBufSize,\n@@ -654,13 +651,12 @@\n \t[[maybe_unused]] size_t dataSize,\n \t[[maybe_unused]] const std::vector<SharedFD> &fds)\n {\n-\tuint32_t frame;\n \n \n \tconst size_t frameStart = 0;\n \n \n-\tframe =\n+\tuint32_t frame =\n         IPADataSerializer<uint32_t>::deserialize(\n         \tdata + frameStart,\n         \tdata + dataSize);\n@@ -681,8 +677,6 @@\n \t[[maybe_unused]] size_t dataSize,\n \t[[maybe_unused]] const std::vector<SharedFD> &fds)\n {\n-\tuint32_t frame;\n-\tControlList metadata;\n \n \t[[maybe_unused]] const size_t frameBufSize = readPOD<uint32_t>(data, 0, data + dataSize);\n \t[[maybe_unused]] const size_t metadataBufSize = readPOD<uint32_t>(data, 4, data + dataSize);\n@@ -691,12 +685,12 @@\n \tconst size_t metadataStart = frameStart + frameBufSize;\n \n \n-\tframe =\n+\tuint32_t frame =\n         IPADataSerializer<uint32_t>::deserialize(\n         \tdata + frameStart,\n         \tdata + frameStart + frameBufSize);\n \n-\tmetadata =\n+\tControlList metadata =\n         IPADataSerializer<ControlList>::deserialize(\n         \tdata + metadataStart,\n         \tdata + metadataStart + metadataBufSize,\n\nThis looks right.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n> ---\n>  .../generators/libcamera_templates/module_ipa_proxy.cpp.tmpl | 5 +----\n>  1 file changed, 1 insertion(+), 4 deletions(-)\n> \n> diff --git a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n> index ce3cc5ab6..07165821e 100644\n> --- a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n> +++ b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n> @@ -239,10 +239,7 @@ void {{proxy_name}}::{{method.mojom_name}}IPC(\n>  \t[[maybe_unused]] size_t dataSize,\n>  \t[[maybe_unused]] const std::vector<SharedFD> &fds)\n>  {\n> -{%- for param in method.parameters %}\n> -\t{{param|name}} {{param.mojom_name}};\n> -{%- endfor %}\n> -{{proxy_funcs.deserialize_call(method.parameters, 'data', 'fds', false, false, true, 'dataSize')}}\n> +{{proxy_funcs.deserialize_call(method.parameters, 'data', 'fds', false, true, true, 'dataSize')}}\n>  \t{{method.mojom_name}}.emit({{method.parameters|params_comma_sep}});\n>  }\n>  {% endfor %}","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 86F33C327D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 22 Apr 2025 17:49:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A61C368ACA;\n\tTue, 22 Apr 2025 19:49:12 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 674E3617E3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 22 Apr 2025 19:49:11 +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 6971F2AC;\n\tTue, 22 Apr 2025 19:49:10 +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=\"UWdMiO/t\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1745344150;\n\tbh=eY4bE+3m5FK0HQW+FcoCXRDPeaZGZOZNS0WkcN3sOJ0=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=UWdMiO/tUkSD18HG/4JyHRccTCCeI5WhdpG7Mokb4XAzrfJJRRjy+2HmylVTPu/IR\n\t58Ryo7sh+lerWKyEY68UUFVBb5zv8zQpGguEoc/DIkZS0yccdH55+zg7/9BFkdax+5\n\tMxQCO2vXRni/sa+XF9sppiJSDtegrQ26L2HJcDEU=","Date":"Tue, 22 Apr 2025 20:49:08 +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: [RFC PATCH v1] utils: ipc: Do not define variables in signal\n\thandler upfront","Message-ID":"<20250422174908.GI17813@pendragon.ideasonboard.com>","References":"<20250326101324.1514654-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":"<20250326101324.1514654-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>"}}]