[{"id":33705,"web_url":"https://patchwork.libcamera.org/comment/33705/","msgid":"<174293028131.2136573.7845605037038505646@ping.linuxembedded.co.uk>","date":"2025-03-25T19:18:01","subject":"Re: [RFC PATCH v3 6/9] libcamera: process: Use span instead of\n\tvector","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Barnabás Pőcze (2025-03-25 18:08:18)\n> Use `libcamera::Span` whenever applicable.\n> \n> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n> ---\n>  include/libcamera/internal/process.h  | 8 ++++----\n>  src/libcamera/ipc_pipe_unixsocket.cpp | 9 +++------\n\nIf you're in here, it might be worth reviewing another of Julien's\npatches here too:\n\n- https://patchwork.libcamera.org/patch/22425/\n\nBut I think this patch seems ok to me.\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n>  src/libcamera/process.cpp             | 8 ++++----\n>  test/process/process_test.cpp         | 5 ++---\n>  4 files changed, 13 insertions(+), 17 deletions(-)\n> \n> diff --git a/include/libcamera/internal/process.h b/include/libcamera/internal/process.h\n> index 030a1e66e..e4f5bb979 100644\n> --- a/include/libcamera/internal/process.h\n> +++ b/include/libcamera/internal/process.h\n> @@ -9,9 +9,9 @@\n>  \n>  #include <signal.h>\n>  #include <string>\n> -#include <vector>\n>  \n>  #include <libcamera/base/signal.h>\n> +#include <libcamera/base/span.h>\n>  #include <libcamera/base/unique_fd.h>\n>  \n>  namespace libcamera {\n> @@ -31,8 +31,8 @@ public:\n>         ~Process();\n>  \n>         int start(const std::string &path,\n> -                 const std::vector<std::string> &args = std::vector<std::string>(),\n> -                 const std::vector<int> &fds = std::vector<int>());\n> +                 Span<const std::string> args = {},\n> +                 Span<const int> fds = {});\n>  \n>         ExitStatus exitStatus() const { return exitStatus_; }\n>         int exitCode() const { return exitCode_; }\n> @@ -44,7 +44,7 @@ public:\n>  private:\n>         LIBCAMERA_DISABLE_COPY_AND_MOVE(Process)\n>  \n> -       void closeAllFdsExcept(const std::vector<int> &fds);\n> +       void closeAllFdsExcept(Span<const int> fds);\n>         int isolate();\n>         void died(int wstatus);\n>  \n> diff --git a/src/libcamera/ipc_pipe_unixsocket.cpp b/src/libcamera/ipc_pipe_unixsocket.cpp\n> index 668ec73b9..7ee7cac79 100644\n> --- a/src/libcamera/ipc_pipe_unixsocket.cpp\n> +++ b/src/libcamera/ipc_pipe_unixsocket.cpp\n> @@ -28,10 +28,6 @@ IPCPipeUnixSocket::IPCPipeUnixSocket(const char *ipaModulePath,\n>                                      const char *ipaProxyWorkerPath)\n>         : IPCPipe()\n>  {\n> -       std::vector<int> fds;\n> -       std::vector<std::string> args;\n> -       args.push_back(ipaModulePath);\n> -\n>         socket_ = std::make_unique<IPCUnixSocket>();\n>         UniqueFD fd = socket_->create();\n>         if (!fd.isValid()) {\n> @@ -39,8 +35,9 @@ IPCPipeUnixSocket::IPCPipeUnixSocket(const char *ipaModulePath,\n>                 return;\n>         }\n>         socket_->readyRead.connect(this, &IPCPipeUnixSocket::readyRead);\n> -       args.push_back(std::to_string(fd.get()));\n> -       fds.push_back(fd.get());\n> +\n> +       std::array args{ std::string(ipaModulePath), std::to_string(fd.get()) };\n> +       std::array fds{ fd.get() };\n>  \n>         proc_ = std::make_unique<Process>();\n>         int ret = proc_->start(ipaProxyWorkerPath, args, fds);\n> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp\n> index 62e63255b..5603dc903 100644\n> --- a/src/libcamera/process.cpp\n> +++ b/src/libcamera/process.cpp\n> @@ -235,8 +235,8 @@ Process::~Process()\n>   * or a negative error code otherwise\n>   */\n>  int Process::start(const std::string &path,\n> -                  const std::vector<std::string> &args,\n> -                  const std::vector<int> &fds)\n> +                  Span<const std::string> args,\n> +                  Span<const int> fds)\n>  {\n>         int ret;\n>  \n> @@ -282,9 +282,9 @@ int Process::start(const std::string &path,\n>         }\n>  }\n>  \n> -void Process::closeAllFdsExcept(const std::vector<int> &fds)\n> +void Process::closeAllFdsExcept(Span<const int> fds)\n>  {\n> -       std::vector<int> v(fds);\n> +       std::vector<int> v(fds.begin(), fds.end());\n>         sort(v.begin(), v.end());\n>  \n>         ASSERT(v.empty() || v.front() >= 0);\n> diff --git a/test/process/process_test.cpp b/test/process/process_test.cpp\n> index e9f5e7e9b..a88d8fef1 100644\n> --- a/test/process/process_test.cpp\n> +++ b/test/process/process_test.cpp\n> @@ -5,9 +5,9 @@\n>   * Process test\n>   */\n>  \n> +#include <array>\n>  #include <iostream>\n>  #include <unistd.h>\n> -#include <vector>\n>  \n>  #include <libcamera/base/event_dispatcher.h>\n>  #include <libcamera/base/thread.h>\n> @@ -48,8 +48,7 @@ protected:\n>                 Timer timeout;\n>  \n>                 int exitCode = 42;\n> -               vector<std::string> args;\n> -               args.push_back(to_string(exitCode));\n> +               std::array args{ to_string(exitCode) };\n>                 proc_.finished.connect(this, &ProcessTest::procFinished);\n>  \n>                 /* Test that kill() on an unstarted process is safe. */\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 D182FC323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 25 Mar 2025 19:18:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 13F43600EB;\n\tTue, 25 Mar 2025 20:18:06 +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 6B85D600EB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 25 Mar 2025 20:18:04 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0B515353;\n\tTue, 25 Mar 2025 20:16:17 +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=\"iPr430p8\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1742930177;\n\tbh=l4jrJMLgC4LTuvnoxjIOkWW2ST/Nq6mUBiokiphMTYg=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=iPr430p8+7mbRSixYBZ9zUc2111AfmkE3yxjbsHyTeoVhyzNPt7v8VMBniSmFEhCt\n\tVwMUGhrB2AFM2J5fGPlhuouN3uqfcsvoLp+5/p1mUqGsM48mDeDsbPQgdsQ+KnNoV7\n\tG15z992aINQ1N1Gu3HqJ7Jg+9/QTHdljTWY7JWaE=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250325180821.1456154-7-barnabas.pocze@ideasonboard.com>","References":"<20250325180821.1456154-1-barnabas.pocze@ideasonboard.com>\n\t<20250325180821.1456154-7-barnabas.pocze@ideasonboard.com>","Subject":"Re: [RFC PATCH v3 6/9] libcamera: process: Use span instead of\n\tvector","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Tue, 25 Mar 2025 19:18:01 +0000","Message-ID":"<174293028131.2136573.7845605037038505646@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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":33725,"web_url":"https://patchwork.libcamera.org/comment/33725/","msgid":"<20250326140855.GF8303@pendragon.ideasonboard.com>","date":"2025-03-26T14:08:55","subject":"Re: [RFC PATCH v3 6/9] libcamera: process: Use span instead of\n\tvector","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 Tue, Mar 25, 2025 at 07:08:18PM +0100, Barnabás Pőcze wrote:\n> Use `libcamera::Span` whenever applicable.\n> \n> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  include/libcamera/internal/process.h  | 8 ++++----\n>  src/libcamera/ipc_pipe_unixsocket.cpp | 9 +++------\n>  src/libcamera/process.cpp             | 8 ++++----\n>  test/process/process_test.cpp         | 5 ++---\n>  4 files changed, 13 insertions(+), 17 deletions(-)\n> \n> diff --git a/include/libcamera/internal/process.h b/include/libcamera/internal/process.h\n> index 030a1e66e..e4f5bb979 100644\n> --- a/include/libcamera/internal/process.h\n> +++ b/include/libcamera/internal/process.h\n> @@ -9,9 +9,9 @@\n>  \n>  #include <signal.h>\n>  #include <string>\n> -#include <vector>\n>  \n>  #include <libcamera/base/signal.h>\n> +#include <libcamera/base/span.h>\n>  #include <libcamera/base/unique_fd.h>\n>  \n>  namespace libcamera {\n> @@ -31,8 +31,8 @@ public:\n>  \t~Process();\n>  \n>  \tint start(const std::string &path,\n> -\t\t  const std::vector<std::string> &args = std::vector<std::string>(),\n> -\t\t  const std::vector<int> &fds = std::vector<int>());\n> +\t\t  Span<const std::string> args = {},\n> +\t\t  Span<const int> fds = {});\n>  \n>  \tExitStatus exitStatus() const { return exitStatus_; }\n>  \tint exitCode() const { return exitCode_; }\n> @@ -44,7 +44,7 @@ public:\n>  private:\n>  \tLIBCAMERA_DISABLE_COPY_AND_MOVE(Process)\n>  \n> -\tvoid closeAllFdsExcept(const std::vector<int> &fds);\n> +\tvoid closeAllFdsExcept(Span<const int> fds);\n>  \tint isolate();\n>  \tvoid died(int wstatus);\n>  \n> diff --git a/src/libcamera/ipc_pipe_unixsocket.cpp b/src/libcamera/ipc_pipe_unixsocket.cpp\n> index 668ec73b9..7ee7cac79 100644\n> --- a/src/libcamera/ipc_pipe_unixsocket.cpp\n> +++ b/src/libcamera/ipc_pipe_unixsocket.cpp\n> @@ -28,10 +28,6 @@ IPCPipeUnixSocket::IPCPipeUnixSocket(const char *ipaModulePath,\n>  \t\t\t\t     const char *ipaProxyWorkerPath)\n>  \t: IPCPipe()\n>  {\n> -\tstd::vector<int> fds;\n> -\tstd::vector<std::string> args;\n> -\targs.push_back(ipaModulePath);\n> -\n>  \tsocket_ = std::make_unique<IPCUnixSocket>();\n>  \tUniqueFD fd = socket_->create();\n>  \tif (!fd.isValid()) {\n> @@ -39,8 +35,9 @@ IPCPipeUnixSocket::IPCPipeUnixSocket(const char *ipaModulePath,\n>  \t\treturn;\n>  \t}\n>  \tsocket_->readyRead.connect(this, &IPCPipeUnixSocket::readyRead);\n> -\targs.push_back(std::to_string(fd.get()));\n> -\tfds.push_back(fd.get());\n> +\n> +\tstd::array args{ std::string(ipaModulePath), std::to_string(fd.get()) };\n> +\tstd::array fds{ fd.get() };\n>  \n>  \tproc_ = std::make_unique<Process>();\n>  \tint ret = proc_->start(ipaProxyWorkerPath, args, fds);\n> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp\n> index 62e63255b..5603dc903 100644\n> --- a/src/libcamera/process.cpp\n> +++ b/src/libcamera/process.cpp\n> @@ -235,8 +235,8 @@ Process::~Process()\n>   * or a negative error code otherwise\n>   */\n>  int Process::start(const std::string &path,\n> -\t\t   const std::vector<std::string> &args,\n> -\t\t   const std::vector<int> &fds)\n> +\t\t   Span<const std::string> args,\n> +\t\t   Span<const int> fds)\n>  {\n>  \tint ret;\n>  \n> @@ -282,9 +282,9 @@ int Process::start(const std::string &path,\n>  \t}\n>  }\n>  \n> -void Process::closeAllFdsExcept(const std::vector<int> &fds)\n> +void Process::closeAllFdsExcept(Span<const int> fds)\n>  {\n> -\tstd::vector<int> v(fds);\n> +\tstd::vector<int> v(fds.begin(), fds.end());\n>  \tsort(v.begin(), v.end());\n>  \n>  \tASSERT(v.empty() || v.front() >= 0);\n> diff --git a/test/process/process_test.cpp b/test/process/process_test.cpp\n> index e9f5e7e9b..a88d8fef1 100644\n> --- a/test/process/process_test.cpp\n> +++ b/test/process/process_test.cpp\n> @@ -5,9 +5,9 @@\n>   * Process test\n>   */\n>  \n> +#include <array>\n>  #include <iostream>\n>  #include <unistd.h>\n> -#include <vector>\n>  \n>  #include <libcamera/base/event_dispatcher.h>\n>  #include <libcamera/base/thread.h>\n> @@ -48,8 +48,7 @@ protected:\n>  \t\tTimer timeout;\n>  \n>  \t\tint exitCode = 42;\n> -\t\tvector<std::string> args;\n> -\t\targs.push_back(to_string(exitCode));\n> +\t\tstd::array args{ to_string(exitCode) };\n>  \t\tproc_.finished.connect(this, &ProcessTest::procFinished);\n>  \n>  \t\t/* Test that kill() on an unstarted process is safe. */","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 4CF25C3213\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 26 Mar 2025 14:09:21 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5E43268969;\n\tWed, 26 Mar 2025 15:09:20 +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 3DA1868950\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 26 Mar 2025 15:09:19 +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 09944475;\n\tWed, 26 Mar 2025 15:07:30 +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=\"rbxXYVB/\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1742998051;\n\tbh=rPP1eo4bj7jOWIwfPpoZrT2B2n/pF93xA8+PWAeQHSo=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=rbxXYVB/P0BsdSXMFqnS+LBwnfc0UH0riVW3jjrc8pPfvl1KTvPwoqXCVDOvMHqy9\n\t7IVmuv8u6Ib5UgZWUNxlN+NA9mY/zC8/wT57eI460oWJIS+qDl7nRCA3vfWbz/jyqk\n\toju/WvXistA6Ahyg9wbN26GdpGy13/jMizTnO/jM=","Date":"Wed, 26 Mar 2025 16:08:55 +0200","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 v3 6/9] libcamera: process: Use span instead of\n\tvector","Message-ID":"<20250326140855.GF8303@pendragon.ideasonboard.com>","References":"<20250325180821.1456154-1-barnabas.pocze@ideasonboard.com>\n\t<20250325180821.1456154-7-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":"<20250325180821.1456154-7-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>"}}]