[{"id":32948,"web_url":"https://patchwork.libcamera.org/comment/32948/","msgid":"<kah362b4nhv5xejl5xjgyfjphhs332cj4uddscpj57vnmlzaqh@ghd7lcpdzqu5>","date":"2025-01-07T16:47:35","subject":"Re: [RFC PATCH v1 06/12] apps: lc-compliance: Use `std::vector` for\n\targument array","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Barnabás\n\nOn Fri, Dec 20, 2024 at 03:08:29PM +0000, Barnabás Pőcze wrote:\n> Just use an `std::vector` to store the arguments passed to\n> `InitGoogleTest()`. This removes the need for the map and\n> the separate `argc` variable used for size-keeping.\n>\n> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n\nNice, that really seemed like a lot of not required complications\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\nThanks\n  j\n\n> ---\n>  src/apps/lc-compliance/main.cpp | 36 +++++++++------------------------\n>  1 file changed, 9 insertions(+), 27 deletions(-)\n>\n> diff --git a/src/apps/lc-compliance/main.cpp b/src/apps/lc-compliance/main.cpp\n> index cdd0bd515..3d9c51fc3 100644\n> --- a/src/apps/lc-compliance/main.cpp\n> +++ b/src/apps/lc-compliance/main.cpp\n> @@ -80,45 +80,27 @@ static int initCamera(CameraManager *cm, OptionsParser::Options options)\n>\n>  static int initGtestParameters(char *arg0, OptionsParser::Options options)\n>  {\n> -\tconst std::map<std::string, std::string> gtestFlags = { { \"list\", \"--gtest_list_tests\" },\n> -\t\t\t\t\t\t\t\t{ \"filter\", \"--gtest_filter\" } };\n> -\n> -\tint argc = 0;\n> +\tstd::vector<char *> argv;\n>  \tstd::string filterParam;\n>\n> -\t/*\n> -\t * +2 to have space for both the 0th argument that is needed but not\n> -\t * used and the null at the end.\n> -\t */\n> -\tchar **argv = new char *[(gtestFlags.size() + 2)];\n> -\tif (!argv)\n> -\t\treturn -ENOMEM;\n> -\n> -\targv[0] = arg0;\n> -\targc++;\n> +\targv.push_back(arg0);\n>\n> -\tif (options.isSet(OptList)) {\n> -\t\targv[argc] = const_cast<char *>(gtestFlags.at(\"list\").c_str());\n> -\t\targc++;\n> -\t}\n> +\tif (options.isSet(OptList))\n> +\t\targv.push_back(const_cast<char *>(\"--gtest_list_tests\"));\n>\n>  \tif (options.isSet(OptFilter)) {\n>  \t\t/*\n>  \t\t * The filter flag needs to be passed as a single parameter, in\n>  \t\t * the format --gtest_filter=filterStr\n>  \t\t */\n> -\t\tfilterParam = gtestFlags.at(\"filter\") + \"=\" +\n> -\t\t\t      static_cast<const std::string &>(options[OptFilter]);\n> -\n> -\t\targv[argc] = const_cast<char *>(filterParam.c_str());\n> -\t\targc++;\n> +\t\tfilterParam = \"--gtest_filter=\" + options[OptFilter].toString();\n> +\t\targv.push_back(const_cast<char *>(filterParam.c_str()));\n>  \t}\n>\n> -\targv[argc] = nullptr;\n> -\n> -\t::testing::InitGoogleTest(&argc, argv);\n> +\targv.push_back(nullptr);\n>\n> -\tdelete[] argv;\n> +\tint argc = argv.size();\n> +\t::testing::InitGoogleTest(&argc, argv.data());\n>\n>  \treturn 0;\n>  }\n> --\n> 2.47.1\n>\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 10A3BC32DC\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  7 Jan 2025 16:47:42 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3EC52684E2;\n\tTue,  7 Jan 2025 17:47:41 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 896A2684CD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Jan 2025 17:47:39 +0100 (CET)","from ideasonboard.com (mob-5-90-140-128.net.vodafone.it\n\t[5.90.140.128])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 205A1675;\n\tTue,  7 Jan 2025 17:46:47 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"wDnP0qiF\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1736268407;\n\tbh=NK6xcPj8nfmzVJftvEjKbqkVEXSmXwV5htN0Yo0y6Vw=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=wDnP0qiFmmdzu0S/Y+wvxExFX3OBcGaNzTALrI0KHLKlZV1vRTsLKV5wqw9mh6Tat\n\t5Nr41DcfmN52lwfxrSx+jXsWk/nbsZ1I4/bcKg/L8Sd1yyKpcxsYnW1vkykHJRPuW2\n\txKvSo4s370YWOxRGfZ62R+aqJI89sr15vk6MF/iI=","Date":"Tue, 7 Jan 2025 17:47:35 +0100","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [RFC PATCH v1 06/12] apps: lc-compliance: Use `std::vector` for\n\targument array","Message-ID":"<kah362b4nhv5xejl5xjgyfjphhs332cj4uddscpj57vnmlzaqh@ghd7lcpdzqu5>","References":"<20241220150759.709756-1-pobrn@protonmail.com>\n\t<20241220150759.709756-7-pobrn@protonmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20241220150759.709756-7-pobrn@protonmail.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":32997,"web_url":"https://patchwork.libcamera.org/comment/32997/","msgid":"<Z4BK4Uy65tX0RtNI@pyrite.rasen.tech>","date":"2025-01-09T22:17:05","subject":"Re: [RFC PATCH v1 06/12] apps: lc-compliance: Use `std::vector` for\n\targument array","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"On Fri, Dec 20, 2024 at 03:08:29PM +0000, Barnabás Pőcze wrote:\n> Just use an `std::vector` to store the arguments passed to\n> `InitGoogleTest()`. This removes the need for the map and\n> the separate `argc` variable used for size-keeping.\n> \n> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  src/apps/lc-compliance/main.cpp | 36 +++++++++------------------------\n>  1 file changed, 9 insertions(+), 27 deletions(-)\n> \n> diff --git a/src/apps/lc-compliance/main.cpp b/src/apps/lc-compliance/main.cpp\n> index cdd0bd515..3d9c51fc3 100644\n> --- a/src/apps/lc-compliance/main.cpp\n> +++ b/src/apps/lc-compliance/main.cpp\n> @@ -80,45 +80,27 @@ static int initCamera(CameraManager *cm, OptionsParser::Options options)\n>  \n>  static int initGtestParameters(char *arg0, OptionsParser::Options options)\n>  {\n> -\tconst std::map<std::string, std::string> gtestFlags = { { \"list\", \"--gtest_list_tests\" },\n> -\t\t\t\t\t\t\t\t{ \"filter\", \"--gtest_filter\" } };\n> -\n> -\tint argc = 0;\n> +\tstd::vector<char *> argv;\n>  \tstd::string filterParam;\n>  \n> -\t/*\n> -\t * +2 to have space for both the 0th argument that is needed but not\n> -\t * used and the null at the end.\n> -\t */\n> -\tchar **argv = new char *[(gtestFlags.size() + 2)];\n> -\tif (!argv)\n> -\t\treturn -ENOMEM;\n> -\n> -\targv[0] = arg0;\n> -\targc++;\n> +\targv.push_back(arg0);\n>  \n> -\tif (options.isSet(OptList)) {\n> -\t\targv[argc] = const_cast<char *>(gtestFlags.at(\"list\").c_str());\n> -\t\targc++;\n> -\t}\n> +\tif (options.isSet(OptList))\n> +\t\targv.push_back(const_cast<char *>(\"--gtest_list_tests\"));\n>  \n>  \tif (options.isSet(OptFilter)) {\n>  \t\t/*\n>  \t\t * The filter flag needs to be passed as a single parameter, in\n>  \t\t * the format --gtest_filter=filterStr\n>  \t\t */\n> -\t\tfilterParam = gtestFlags.at(\"filter\") + \"=\" +\n> -\t\t\t      static_cast<const std::string &>(options[OptFilter]);\n> -\n> -\t\targv[argc] = const_cast<char *>(filterParam.c_str());\n> -\t\targc++;\n> +\t\tfilterParam = \"--gtest_filter=\" + options[OptFilter].toString();\n> +\t\targv.push_back(const_cast<char *>(filterParam.c_str()));\n>  \t}\n>  \n> -\targv[argc] = nullptr;\n> -\n> -\t::testing::InitGoogleTest(&argc, argv);\n> +\targv.push_back(nullptr);\n>  \n> -\tdelete[] argv;\n> +\tint argc = argv.size();\n> +\t::testing::InitGoogleTest(&argc, argv.data());\n>  \n>  \treturn 0;\n>  }\n> -- \n> 2.47.1\n> \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 D2DADC32EA\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  9 Jan 2025 22:17:12 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8867A68500;\n\tThu,  9 Jan 2025 23:17:12 +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 B88AB61884\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  9 Jan 2025 23:17:11 +0100 (CET)","from pyrite.rasen.tech (h175-177-049-030.catv02.itscom.jp\n\t[175.177.49.30])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0D512D01;\n\tThu,  9 Jan 2025 23:16:16 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"RjNWnizG\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1736460978;\n\tbh=4qiOttPpHlrp0MWoW5RpPE73geMTSc4dbKKra8uykxE=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=RjNWnizG1w7fJz2VYjtV51pQrEStms1419p6EeiL7M98osTji4n2Nrlho90aqYCGn\n\tevR7rs62DoiYYE9kXrA6Sys/HAxazGioUTAsXIZjpqgM2kSNT8zaihKlLUIGsnfblZ\n\tZXHirpJC/Bp/1qV60Zmsn8ZXJ0qEa4DAnA859VjY=","Date":"Fri, 10 Jan 2025 07:17:05 +0900","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [RFC PATCH v1 06/12] apps: lc-compliance: Use `std::vector` for\n\targument array","Message-ID":"<Z4BK4Uy65tX0RtNI@pyrite.rasen.tech>","References":"<20241220150759.709756-1-pobrn@protonmail.com>\n\t<20241220150759.709756-7-pobrn@protonmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20241220150759.709756-7-pobrn@protonmail.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":33003,"web_url":"https://patchwork.libcamera.org/comment/33003/","msgid":"<20250110002131.GK6159@pendragon.ideasonboard.com>","date":"2025-01-10T00:21:31","subject":"Re: [RFC PATCH v1 06/12] apps: lc-compliance: Use `std::vector` for\n\targument array","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 Fri, Dec 20, 2024 at 03:08:29PM +0000, Barnabás Pőcze wrote:\n> Just use an `std::vector` to store the arguments passed to\n> `InitGoogleTest()`. This removes the need for the map and\n> the separate `argc` variable used for size-keeping.\n> \n> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n> ---\n>  src/apps/lc-compliance/main.cpp | 36 +++++++++------------------------\n>  1 file changed, 9 insertions(+), 27 deletions(-)\n> \n> diff --git a/src/apps/lc-compliance/main.cpp b/src/apps/lc-compliance/main.cpp\n> index cdd0bd515..3d9c51fc3 100644\n> --- a/src/apps/lc-compliance/main.cpp\n> +++ b/src/apps/lc-compliance/main.cpp\n> @@ -80,45 +80,27 @@ static int initCamera(CameraManager *cm, OptionsParser::Options options)\n>  \n>  static int initGtestParameters(char *arg0, OptionsParser::Options options)\n>  {\n> -\tconst std::map<std::string, std::string> gtestFlags = { { \"list\", \"--gtest_list_tests\" },\n> -\t\t\t\t\t\t\t\t{ \"filter\", \"--gtest_filter\" } };\n> -\n> -\tint argc = 0;\n> +\tstd::vector<char *> argv;\n>  \tstd::string filterParam;\n>  \n> -\t/*\n> -\t * +2 to have space for both the 0th argument that is needed but not\n> -\t * used and the null at the end.\n> -\t */\n> -\tchar **argv = new char *[(gtestFlags.size() + 2)];\n> -\tif (!argv)\n> -\t\treturn -ENOMEM;\n> -\n> -\targv[0] = arg0;\n> -\targc++;\n> +\targv.push_back(arg0);\n>  \n> -\tif (options.isSet(OptList)) {\n> -\t\targv[argc] = const_cast<char *>(gtestFlags.at(\"list\").c_str());\n> -\t\targc++;\n> -\t}\n> +\tif (options.isSet(OptList))\n> +\t\targv.push_back(const_cast<char *>(\"--gtest_list_tests\"));\n\nFunctions that take a char ** when they never modify the contents of the\nstrings are annoying :-/\n\nWould it be better to drop the const_char here and below, and add a\nsingle one when calling ::testing::InitGoogleTest() with\n\n\t::testing::InitGoogleTest(&argc, const_cast<char **>(argv.data()));\n\n?\n\nEither way,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  \n>  \tif (options.isSet(OptFilter)) {\n>  \t\t/*\n>  \t\t * The filter flag needs to be passed as a single parameter, in\n>  \t\t * the format --gtest_filter=filterStr\n>  \t\t */\n> -\t\tfilterParam = gtestFlags.at(\"filter\") + \"=\" +\n> -\t\t\t      static_cast<const std::string &>(options[OptFilter]);\n> -\n> -\t\targv[argc] = const_cast<char *>(filterParam.c_str());\n> -\t\targc++;\n> +\t\tfilterParam = \"--gtest_filter=\" + options[OptFilter].toString();\n> +\t\targv.push_back(const_cast<char *>(filterParam.c_str()));\n>  \t}\n>  \n> -\targv[argc] = nullptr;\n> -\n> -\t::testing::InitGoogleTest(&argc, argv);\n> +\targv.push_back(nullptr);\n>  \n> -\tdelete[] argv;\n> +\tint argc = argv.size();\n> +\t::testing::InitGoogleTest(&argc, argv.data());\n>  \n>  \treturn 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 ABBC2C32EA\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 10 Jan 2025 00:21:36 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CEF39684F3;\n\tFri, 10 Jan 2025 01:21:35 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 76EBE684E0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 10 Jan 2025 01:21:34 +0100 (CET)","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 64C0378C;\n\tFri, 10 Jan 2025 01:20:40 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"j38rvgxV\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1736468440;\n\tbh=xucDtlP0RsnsTpkB7DZKL1Vh8al+onHOnmSbbQ5PRJ4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=j38rvgxVnrMxW6vVKO72ZsczaISU0xGku+lc//L876v4ypwfDaC91Dk0KmRugmh3a\n\tNydz+gv0ZNRqU8wyMBNC1ZjNhTth12BBaP0XUxl1FwNOGiInBUAJ24FppH65uoLs7m\n\tNXZjVkNbcuuvhYASWEyiSp2+MckShyQSpBAf0EsA=","Date":"Fri, 10 Jan 2025 02:21:31 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [RFC PATCH v1 06/12] apps: lc-compliance: Use `std::vector` for\n\targument array","Message-ID":"<20250110002131.GK6159@pendragon.ideasonboard.com>","References":"<20241220150759.709756-1-pobrn@protonmail.com>\n\t<20241220150759.709756-7-pobrn@protonmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20241220150759.709756-7-pobrn@protonmail.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":33011,"web_url":"https://patchwork.libcamera.org/comment/33011/","msgid":"<xsBkGJr5-ekO-TLoJ2EYw_Zm2AlO3ks-7HHUZI0ZHPyB8CkWDiyWH-BXrv3nKwQ8iGnajqVH5hpVG06phWiowpKi2dhqWoUq6I58VH_Fp-A=@protonmail.com>","date":"2025-01-10T09:37:57","subject":"Re: [RFC PATCH v1 06/12] apps: lc-compliance: Use `std::vector` for\n\targument array","submitter":{"id":133,"url":"https://patchwork.libcamera.org/api/people/133/","name":"Pőcze Barnabás","email":"pobrn@protonmail.com"},"content":"Hi\n\n\n2025. január 10., péntek 1:21 keltezéssel, Laurent Pinchart <laurent.pinchart@ideasonboard.com> írta:\n\n> Hi Barnabás,\n> \n> Thank you for the patch.\n> \n> On Fri, Dec 20, 2024 at 03:08:29PM +0000, Barnabás Pőcze wrote:\n> > Just use an `std::vector` to store the arguments passed to\n> > `InitGoogleTest()`. This removes the need for the map and\n> > the separate `argc` variable used for size-keeping.\n> >\n> > Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n> > ---\n> >  src/apps/lc-compliance/main.cpp | 36 +++++++++------------------------\n> >  1 file changed, 9 insertions(+), 27 deletions(-)\n> >\n> > diff --git a/src/apps/lc-compliance/main.cpp b/src/apps/lc-compliance/main.cpp\n> > index cdd0bd515..3d9c51fc3 100644\n> > --- a/src/apps/lc-compliance/main.cpp\n> > +++ b/src/apps/lc-compliance/main.cpp\n> > @@ -80,45 +80,27 @@ static int initCamera(CameraManager *cm, OptionsParser::Options options)\n> >\n> >  static int initGtestParameters(char *arg0, OptionsParser::Options options)\n> >  {\n> > -\tconst std::map<std::string, std::string> gtestFlags = { { \"list\", \"--gtest_list_tests\" },\n> > -\t\t\t\t\t\t\t\t{ \"filter\", \"--gtest_filter\" } };\n> > -\n> > -\tint argc = 0;\n> > +\tstd::vector<char *> argv;\n> >  \tstd::string filterParam;\n> >\n> > -\t/*\n> > -\t * +2 to have space for both the 0th argument that is needed but not\n> > -\t * used and the null at the end.\n> > -\t */\n> > -\tchar **argv = new char *[(gtestFlags.size() + 2)];\n> > -\tif (!argv)\n> > -\t\treturn -ENOMEM;\n> > -\n> > -\targv[0] = arg0;\n> > -\targc++;\n> > +\targv.push_back(arg0);\n> >\n> > -\tif (options.isSet(OptList)) {\n> > -\t\targv[argc] = const_cast<char *>(gtestFlags.at(\"list\").c_str());\n> > -\t\targc++;\n> > -\t}\n> > +\tif (options.isSet(OptList))\n> > +\t\targv.push_back(const_cast<char *>(\"--gtest_list_tests\"));\n> \n> Functions that take a char ** when they never modify the contents of the\n> strings are annoying :-/\n> \n> Would it be better to drop the const_char here and below, and add a\n> single one when calling ::testing::InitGoogleTest() with\n> \n> \t::testing::InitGoogleTest(&argc, const_cast<char **>(argv.data()));\n> \n> ?\n\nYes, that works, so I'll move the `const_cast` into the `InitGoogleTest()` invocation.\n\n\nRegards,\nBarnabás Pőcze\n\n\n> \n> Either way,\n> \n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> >\n> >  \tif (options.isSet(OptFilter)) {\n> >  \t\t/*\n> >  \t\t * The filter flag needs to be passed as a single parameter, in\n> >  \t\t * the format --gtest_filter=filterStr\n> >  \t\t */\n> > -\t\tfilterParam = gtestFlags.at(\"filter\") + \"=\" +\n> > -\t\t\t      static_cast<const std::string &>(options[OptFilter]);\n> > -\n> > -\t\targv[argc] = const_cast<char *>(filterParam.c_str());\n> > -\t\targc++;\n> > +\t\tfilterParam = \"--gtest_filter=\" + options[OptFilter].toString();\n> > +\t\targv.push_back(const_cast<char *>(filterParam.c_str()));\n> >  \t}\n> >\n> > -\targv[argc] = nullptr;\n> > -\n> > -\t::testing::InitGoogleTest(&argc, argv);\n> > +\targv.push_back(nullptr);\n> >\n> > -\tdelete[] argv;\n> > +\tint argc = argv.size();\n> > +\t::testing::InitGoogleTest(&argc, argv.data());\n> >\n> >  \treturn 0;\n> >  }\n> \n> --\n> Regards,\n> \n> Laurent Pinchart\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 BEFA4C32EF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 10 Jan 2025 09:38:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 67BBA684F3;\n\tFri, 10 Jan 2025 10:38:07 +0100 (CET)","from mail-10631.protonmail.ch (mail-10631.protonmail.ch\n\t[79.135.106.31])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CFCD5684E1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 10 Jan 2025 10:38:04 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=protonmail.com header.i=@protonmail.com\n\theader.b=\"pgDIjvXC\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;\n\ts=protonmail3; t=1736501883; x=1736761083;\n\tbh=kOTE/H/3OA8gOv7krgl6xp3xkzq6c7zMU3zWKph9eEk=;\n\th=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References:\n\tFeedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID:\n\tMessage-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post;\n\tb=pgDIjvXCKjqyTIJc+0K35BVJQ3zpUHDdo/u3Di0/nqd+JBg5pHaxaLz3HX3DNfR3w\n\tVezZmxJgW/+QLVPrlyBG6B3iqkVfZLpuPGZIFcfd6rPjvmUlApcWnuYLIDLk4JefB5\n\t/GMkJc6aQ93N73TzMU4c/FjOZFErH7mE7MqdnVcLDY/ceoat395DR2ZNTv8yhwsaBO\n\ttv4OwcA0UP04GxcjnDIswIzvhY0Td0+wnkmrMv6IZD+bxyxIQPQMjEE19wiKrONuWn\n\tPtNjNJOZocv8cROI6BLSpeyXDYtBj2skxza8m+SUmWqa8Ng9TLoThB5K0XwKA99e/B\n\tPlEHQXHttvmSw==","Date":"Fri, 10 Jan 2025 09:37:57 +0000","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [RFC PATCH v1 06/12] apps: lc-compliance: Use `std::vector` for\n\targument array","Message-ID":"<xsBkGJr5-ekO-TLoJ2EYw_Zm2AlO3ks-7HHUZI0ZHPyB8CkWDiyWH-BXrv3nKwQ8iGnajqVH5hpVG06phWiowpKi2dhqWoUq6I58VH_Fp-A=@protonmail.com>","In-Reply-To":"<20250110002131.GK6159@pendragon.ideasonboard.com>","References":"<20241220150759.709756-1-pobrn@protonmail.com>\n\t<20241220150759.709756-7-pobrn@protonmail.com>\n\t<20250110002131.GK6159@pendragon.ideasonboard.com>","Feedback-ID":"20568564:user:proton","X-Pm-Message-ID":"3247461139020b9691edc5af479de56aab1a31c7","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"quoted-printable","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>"}}]