[{"id":14238,"web_url":"https://patchwork.libcamera.org/comment/14238/","msgid":"<20201214033711.GD2095@pyrite.rasen.tech>","date":"2020-12-14T03:37:11","subject":"Re: [libcamera-devel] [PATCH] libcamera: Replace ARRAY_SIZE() with\n\tstd::size()","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Hi Laurent,\n\nOn Sat, Dec 12, 2020 at 01:23:19AM +0200, Laurent Pinchart wrote:\n> C++17 has a std::size() function that returns the size of a C-style\n> array. Use it instead of the custom ARRAY_SIZE macro.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  include/libcamera/internal/utils.h  | 2 --\n>  src/ipa/raspberrypi/raspberrypi.cpp | 4 ++--\n>  src/libcamera/camera.cpp            | 8 ++++----\n>  src/libcamera/log.cpp               | 7 ++++---\n>  src/libcamera/utils.cpp             | 5 -----\n>  src/libcamera/v4l2_videodevice.cpp  | 6 +++---\n>  test/ipc/unixsocket.cpp             | 6 +++---\n>  7 files changed, 16 insertions(+), 22 deletions(-)\n> \n> diff --git a/include/libcamera/internal/utils.h b/include/libcamera/internal/utils.h\n> index ebb2c4038e19..f08134afb5ba 100644\n> --- a/include/libcamera/internal/utils.h\n> +++ b/include/libcamera/internal/utils.h\n> @@ -17,8 +17,6 @@\n>  #include <sys/time.h>\n>  #include <vector>\n>  \n> -#define ARRAY_SIZE(a)\t(sizeof(a) / sizeof(a[0]))\n> -\n>  #ifndef __DOXYGEN__\n>  \n>  /* uClibc and uClibc-ng don't provide O_TMPFILE */\n> diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\n> index 801400214c3a..a7439badb7dc 100644\n> --- a/src/ipa/raspberrypi/raspberrypi.cpp\n> +++ b/src/ipa/raspberrypi/raspberrypi.cpp\n> @@ -6,6 +6,7 @@\n>   */\n>  \n>  #include <algorithm>\n> +#include <array>\n>  #include <fcntl.h>\n>  #include <math.h>\n>  #include <stdint.h>\n> @@ -27,7 +28,6 @@\n>  #include \"libcamera/internal/buffer.h\"\n>  #include \"libcamera/internal/camera_sensor.h\"\n>  #include \"libcamera/internal/log.h\"\n> -#include \"libcamera/internal/utils.h\"\n>  \n>  #include <linux/bcm2835-isp.h>\n>  \n> @@ -1092,7 +1092,7 @@ void IPARPi::applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls)\n>  \t * Choose smallest cell size that won't exceed 63x48 cells.\n>  \t */\n>  \tconst int cellSizes[] = { 16, 32, 64, 128, 256 };\n> -\tunsigned int numCells = ARRAY_SIZE(cellSizes);\n> +\tunsigned int numCells = std::size(cellSizes);\n>  \tunsigned int i, w, h, cellSize;\n>  \tfor (i = 0; i < numCells; i++) {\n>  \t\tcellSize = cellSizes[i];\n> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\n> index 3579ba96b6ea..c1de1fee701a 100644\n> --- a/src/libcamera/camera.cpp\n> +++ b/src/libcamera/camera.cpp\n> @@ -7,6 +7,7 @@\n>  \n>  #include <libcamera/camera.h>\n>  \n> +#include <array>\n>  #include <atomic>\n>  #include <iomanip>\n>  \n> @@ -17,7 +18,6 @@\n>  #include \"libcamera/internal/log.h\"\n>  #include \"libcamera/internal/pipeline_handler.h\"\n>  #include \"libcamera/internal/thread.h\"\n> -#include \"libcamera/internal/utils.h\"\n>  \n>  /**\n>   * \\file camera.h\n> @@ -393,7 +393,7 @@ int Camera::Private::isAccessAllowed(State state, bool allowDisconnected) const\n>  \tif (currentState == state)\n>  \t\treturn 0;\n>  \n> -\tASSERT(static_cast<unsigned int>(state) < ARRAY_SIZE(camera_state_names));\n> +\tASSERT(static_cast<unsigned int>(state) < std::size(camera_state_names));\n>  \n>  \tLOG(Camera, Debug) << \"Camera in \" << camera_state_names[currentState]\n>  \t\t\t   << \" state trying operation requiring state \"\n> @@ -412,8 +412,8 @@ int Camera::Private::isAccessAllowed(State low, State high,\n>  \tif (currentState >= low && currentState <= high)\n>  \t\treturn 0;\n>  \n> -\tASSERT(static_cast<unsigned int>(low) < ARRAY_SIZE(camera_state_names) &&\n> -\t       static_cast<unsigned int>(high) < ARRAY_SIZE(camera_state_names));\n> +\tASSERT(static_cast<unsigned int>(low) < std::size(camera_state_names) &&\n> +\t       static_cast<unsigned int>(high) < std::size(camera_state_names));\n>  \n>  \tLOG(Camera, Debug) << \"Camera in \" << camera_state_names[currentState]\n>  \t\t\t   << \" state trying operation requiring state between \"\n> diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp\n> index 180eb97ba664..45c7c2d24652 100644\n> --- a/src/libcamera/log.cpp\n> +++ b/src/libcamera/log.cpp\n> @@ -7,6 +7,7 @@\n>  \n>  #include \"libcamera/internal/log.h\"\n>  \n> +#include <array>\n>  #if HAVE_BACKTRACE\n>  #include <execinfo.h>\n>  #endif\n> @@ -91,7 +92,7 @@ static const char *log_severity_name(LogSeverity severity)\n>  \t\t\"FATAL\",\n>  \t};\n>  \n> -\tif (static_cast<unsigned int>(severity) < ARRAY_SIZE(names))\n> +\tif (static_cast<unsigned int>(severity) < std::size(names))\n>  \t\treturn names[severity];\n>  \telse\n>  \t\treturn \"UNKWN\";\n> @@ -406,7 +407,7 @@ void Logger::backtrace()\n>  \t\treturn;\n>  \n>  \tvoid *buffer[32];\n> -\tint num_entries = ::backtrace(buffer, ARRAY_SIZE(buffer));\n> +\tint num_entries = ::backtrace(buffer, std::size(buffer));\n>  \tchar **strings = backtrace_symbols(buffer, num_entries);\n>  \tif (!strings)\n>  \t\treturn;\n> @@ -620,7 +621,7 @@ LogSeverity Logger::parseLogLevel(const std::string &level)\n>  \t\t\tseverity = LogInvalid;\n>  \t} else {\n>  \t\tseverity = LogInvalid;\n> -\t\tfor (unsigned int i = 0; i < ARRAY_SIZE(names); ++i) {\n> +\t\tfor (unsigned int i = 0; i < std::size(names); ++i) {\n>  \t\t\tif (names[i] == level) {\n>  \t\t\t\tseverity = i;\n>  \t\t\t\tbreak;\n> diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\n> index da85c9c24340..e90375ae115c 100644\n> --- a/src/libcamera/utils.cpp\n> +++ b/src/libcamera/utils.cpp\n> @@ -31,11 +31,6 @@ namespace libcamera {\n>  \n>  namespace utils {\n>  \n> -/**\n> - * \\def ARRAY_SIZE(array)\n> - * \\brief Determine the number of elements in the static array.\n> - */\n> -\n>  /**\n>   * \\brief Strip the directory prefix from the path\n>   * \\param[in] path The path to process\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index e2b582842a9b..baf683d6d985 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -7,6 +7,7 @@\n>  \n>  #include \"libcamera/internal/v4l2_videodevice.h\"\n>  \n> +#include <array>\n>  #include <fcntl.h>\n>  #include <iomanip>\n>  #include <sstream>\n> @@ -26,7 +27,6 @@\n>  #include \"libcamera/internal/log.h\"\n>  #include \"libcamera/internal/media_device.h\"\n>  #include \"libcamera/internal/media_object.h\"\n> -#include \"libcamera/internal/utils.h\"\n>  \n>  /**\n>   * \\file v4l2_videodevice.h\n> @@ -860,7 +860,7 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set)\n>  \tpix->num_planes = format->planesCount;\n>  \tpix->field = V4L2_FIELD_NONE;\n>  \n> -\tASSERT(pix->num_planes <= ARRAY_SIZE(pix->plane_fmt));\n> +\tASSERT(pix->num_planes <= std::size(pix->plane_fmt));\n>  \n>  \tfor (unsigned int i = 0; i < pix->num_planes; ++i) {\n>  \t\tpix->plane_fmt[i].bytesperline = format->planes[i].bpl;\n> @@ -1255,7 +1255,7 @@ std::unique_ptr<FrameBuffer> V4L2VideoDevice::createBuffer(unsigned int index)\n>  \tbuf.index = index;\n>  \tbuf.type = bufferType_;\n>  \tbuf.memory = V4L2_MEMORY_MMAP;\n> -\tbuf.length = ARRAY_SIZE(v4l2Planes);\n> +\tbuf.length = std::size(v4l2Planes);\n>  \tbuf.m.planes = v4l2Planes;\n>  \n>  \tint ret = ioctl(VIDIOC_QUERYBUF, &buf);\n> diff --git a/test/ipc/unixsocket.cpp b/test/ipc/unixsocket.cpp\n> index 19a1d7dd8a2d..80157b342795 100644\n> --- a/test/ipc/unixsocket.cpp\n> +++ b/test/ipc/unixsocket.cpp\n> @@ -6,6 +6,7 @@\n>   */\n>  \n>  #include <algorithm>\n> +#include <array>\n>  #include <fcntl.h>\n>  #include <iostream>\n>  #include <stdlib.h>\n> @@ -19,7 +20,6 @@\n>  #include \"libcamera/internal/ipc_unixsocket.h\"\n>  #include \"libcamera/internal/thread.h\"\n>  #include \"libcamera/internal/timer.h\"\n> -#include \"libcamera/internal/utils.h\"\n>  \n>  #include \"test.h\"\n>  \n> @@ -311,7 +311,7 @@ protected:\n>  \t\t};\n>  \t\tint fds[2];\n>  \n> -\t\tfor (unsigned int i = 0; i < ARRAY_SIZE(strings); i++) {\n> +\t\tfor (unsigned int i = 0; i < std::size(strings); i++) {\n>  \t\t\tunsigned int len = strlen(strings[i]);\n>  \n>  \t\t\tfds[i] = open(\"/tmp\", O_TMPFILE | O_RDWR,\n> @@ -333,7 +333,7 @@ protected:\n>  \t\tif (ret)\n>  \t\t\treturn ret;\n>  \n> -\t\tfor (unsigned int i = 0; i < ARRAY_SIZE(strings); i++) {\n> +\t\tfor (unsigned int i = 0; i < std::size(strings); i++) {\n>  \t\t\tunsigned int len = strlen(strings[i]);\n>  \t\t\tchar buf[len];\n>  \n> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","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 4CDEFBD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 14 Dec 2020 03:37:21 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D22636158F;\n\tMon, 14 Dec 2020 04:37:20 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AC818600EB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 14 Dec 2020 04:37:19 +0100 (CET)","from pyrite.rasen.tech (unknown\n\t[IPv6:2400:4051:61:600:2c71:1b79:d06d:5032])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CE6CC96;\n\tMon, 14 Dec 2020 04:37:17 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"F+bVd8Tj\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1607917039;\n\tbh=eFMnEhzoKGt/94XdLcyf2jWp7LgBj7yZLJBlcWbY2BM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=F+bVd8TjTNwuON7kNH7h8UpxDMSaP5QXc43IvfIqDtnMpk8fq7ToXNN1uBl0KZm67\n\tisl7FZNq7vIZKiUWzJaFFKNXVJyShXPC2FhuLYHisywFYu0FxShwOJXsLXcAmlGnwI\n\tyuFwsBKVu6Qtp7RzCvb9VMP4+d4igTshsa7UQZXg=","Date":"Mon, 14 Dec 2020 12:37:11 +0900","From":"paul.elder@ideasonboard.com","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20201214033711.GD2095@pyrite.rasen.tech>","References":"<20201211232319.32088-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20201211232319.32088-1-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH] libcamera: Replace ARRAY_SIZE() with\n\tstd::size()","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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":14239,"web_url":"https://patchwork.libcamera.org/comment/14239/","msgid":"<dd83be82-38fe-fd5e-5e87-3fea086b8e1f@uajain.com>","date":"2020-12-14T04:59:11","subject":"Re: [libcamera-devel] [PATCH] libcamera: Replace ARRAY_SIZE() with\n\tstd::size()","submitter":{"id":1,"url":"https://patchwork.libcamera.org/api/people/1/","name":"Umang Jain","email":"email@uajain.com"},"content":"Hi Laurent,\n\nOn 12/12/20 4:53 AM, Laurent Pinchart wrote:\n> C++17 has a std::size() function that returns the size of a C-style\n> array. Use it instead of the custom ARRAY_SIZE macro.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Umang Jain <email@uajain.com>\n> ---\n>   include/libcamera/internal/utils.h  | 2 --\n>   src/ipa/raspberrypi/raspberrypi.cpp | 4 ++--\n>   src/libcamera/camera.cpp            | 8 ++++----\n>   src/libcamera/log.cpp               | 7 ++++---\n>   src/libcamera/utils.cpp             | 5 -----\n>   src/libcamera/v4l2_videodevice.cpp  | 6 +++---\n>   test/ipc/unixsocket.cpp             | 6 +++---\n>   7 files changed, 16 insertions(+), 22 deletions(-)\n>\n> diff --git a/include/libcamera/internal/utils.h b/include/libcamera/internal/utils.h\n> index ebb2c4038e19..f08134afb5ba 100644\n> --- a/include/libcamera/internal/utils.h\n> +++ b/include/libcamera/internal/utils.h\n> @@ -17,8 +17,6 @@\n>   #include <sys/time.h>\n>   #include <vector>\n>   \n> -#define ARRAY_SIZE(a)\t(sizeof(a) / sizeof(a[0]))\n> -\n>   #ifndef __DOXYGEN__\n>   \n>   /* uClibc and uClibc-ng don't provide O_TMPFILE */\n> diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\n> index 801400214c3a..a7439badb7dc 100644\n> --- a/src/ipa/raspberrypi/raspberrypi.cpp\n> +++ b/src/ipa/raspberrypi/raspberrypi.cpp\n> @@ -6,6 +6,7 @@\n>    */\n>   \n>   #include <algorithm>\n> +#include <array>\n>   #include <fcntl.h>\n>   #include <math.h>\n>   #include <stdint.h>\n> @@ -27,7 +28,6 @@\n>   #include \"libcamera/internal/buffer.h\"\n>   #include \"libcamera/internal/camera_sensor.h\"\n>   #include \"libcamera/internal/log.h\"\n> -#include \"libcamera/internal/utils.h\"\n>   \n>   #include <linux/bcm2835-isp.h>\n>   \n> @@ -1092,7 +1092,7 @@ void IPARPi::applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls)\n>   \t * Choose smallest cell size that won't exceed 63x48 cells.\n>   \t */\n>   \tconst int cellSizes[] = { 16, 32, 64, 128, 256 };\n> -\tunsigned int numCells = ARRAY_SIZE(cellSizes);\n> +\tunsigned int numCells = std::size(cellSizes);\n>   \tunsigned int i, w, h, cellSize;\n>   \tfor (i = 0; i < numCells; i++) {\n>   \t\tcellSize = cellSizes[i];\n> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\n> index 3579ba96b6ea..c1de1fee701a 100644\n> --- a/src/libcamera/camera.cpp\n> +++ b/src/libcamera/camera.cpp\n> @@ -7,6 +7,7 @@\n>   \n>   #include <libcamera/camera.h>\n>   \n> +#include <array>\n>   #include <atomic>\n>   #include <iomanip>\n>   \n> @@ -17,7 +18,6 @@\n>   #include \"libcamera/internal/log.h\"\n>   #include \"libcamera/internal/pipeline_handler.h\"\n>   #include \"libcamera/internal/thread.h\"\n> -#include \"libcamera/internal/utils.h\"\n>   \n>   /**\n>    * \\file camera.h\n> @@ -393,7 +393,7 @@ int Camera::Private::isAccessAllowed(State state, bool allowDisconnected) const\n>   \tif (currentState == state)\n>   \t\treturn 0;\n>   \n> -\tASSERT(static_cast<unsigned int>(state) < ARRAY_SIZE(camera_state_names));\n> +\tASSERT(static_cast<unsigned int>(state) < std::size(camera_state_names));\n>   \n>   \tLOG(Camera, Debug) << \"Camera in \" << camera_state_names[currentState]\n>   \t\t\t   << \" state trying operation requiring state \"\n> @@ -412,8 +412,8 @@ int Camera::Private::isAccessAllowed(State low, State high,\n>   \tif (currentState >= low && currentState <= high)\n>   \t\treturn 0;\n>   \n> -\tASSERT(static_cast<unsigned int>(low) < ARRAY_SIZE(camera_state_names) &&\n> -\t       static_cast<unsigned int>(high) < ARRAY_SIZE(camera_state_names));\n> +\tASSERT(static_cast<unsigned int>(low) < std::size(camera_state_names) &&\n> +\t       static_cast<unsigned int>(high) < std::size(camera_state_names));\n>   \n>   \tLOG(Camera, Debug) << \"Camera in \" << camera_state_names[currentState]\n>   \t\t\t   << \" state trying operation requiring state between \"\n> diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp\n> index 180eb97ba664..45c7c2d24652 100644\n> --- a/src/libcamera/log.cpp\n> +++ b/src/libcamera/log.cpp\n> @@ -7,6 +7,7 @@\n>   \n>   #include \"libcamera/internal/log.h\"\n>   \n> +#include <array>\n>   #if HAVE_BACKTRACE\n>   #include <execinfo.h>\n>   #endif\n> @@ -91,7 +92,7 @@ static const char *log_severity_name(LogSeverity severity)\n>   \t\t\"FATAL\",\n>   \t};\n>   \n> -\tif (static_cast<unsigned int>(severity) < ARRAY_SIZE(names))\n> +\tif (static_cast<unsigned int>(severity) < std::size(names))\n>   \t\treturn names[severity];\n>   \telse\n>   \t\treturn \"UNKWN\";\n> @@ -406,7 +407,7 @@ void Logger::backtrace()\n>   \t\treturn;\n>   \n>   \tvoid *buffer[32];\n> -\tint num_entries = ::backtrace(buffer, ARRAY_SIZE(buffer));\n> +\tint num_entries = ::backtrace(buffer, std::size(buffer));\n>   \tchar **strings = backtrace_symbols(buffer, num_entries);\n>   \tif (!strings)\n>   \t\treturn;\n> @@ -620,7 +621,7 @@ LogSeverity Logger::parseLogLevel(const std::string &level)\n>   \t\t\tseverity = LogInvalid;\n>   \t} else {\n>   \t\tseverity = LogInvalid;\n> -\t\tfor (unsigned int i = 0; i < ARRAY_SIZE(names); ++i) {\n> +\t\tfor (unsigned int i = 0; i < std::size(names); ++i) {\n>   \t\t\tif (names[i] == level) {\n>   \t\t\t\tseverity = i;\n>   \t\t\t\tbreak;\n> diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\n> index da85c9c24340..e90375ae115c 100644\n> --- a/src/libcamera/utils.cpp\n> +++ b/src/libcamera/utils.cpp\n> @@ -31,11 +31,6 @@ namespace libcamera {\n>   \n>   namespace utils {\n>   \n> -/**\n> - * \\def ARRAY_SIZE(array)\n> - * \\brief Determine the number of elements in the static array.\n> - */\n> -\n>   /**\n>    * \\brief Strip the directory prefix from the path\n>    * \\param[in] path The path to process\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index e2b582842a9b..baf683d6d985 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -7,6 +7,7 @@\n>   \n>   #include \"libcamera/internal/v4l2_videodevice.h\"\n>   \n> +#include <array>\n>   #include <fcntl.h>\n>   #include <iomanip>\n>   #include <sstream>\n> @@ -26,7 +27,6 @@\n>   #include \"libcamera/internal/log.h\"\n>   #include \"libcamera/internal/media_device.h\"\n>   #include \"libcamera/internal/media_object.h\"\n> -#include \"libcamera/internal/utils.h\"\n>   \n>   /**\n>    * \\file v4l2_videodevice.h\n> @@ -860,7 +860,7 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set)\n>   \tpix->num_planes = format->planesCount;\n>   \tpix->field = V4L2_FIELD_NONE;\n>   \n> -\tASSERT(pix->num_planes <= ARRAY_SIZE(pix->plane_fmt));\n> +\tASSERT(pix->num_planes <= std::size(pix->plane_fmt));\n>   \n>   \tfor (unsigned int i = 0; i < pix->num_planes; ++i) {\n>   \t\tpix->plane_fmt[i].bytesperline = format->planes[i].bpl;\n> @@ -1255,7 +1255,7 @@ std::unique_ptr<FrameBuffer> V4L2VideoDevice::createBuffer(unsigned int index)\n>   \tbuf.index = index;\n>   \tbuf.type = bufferType_;\n>   \tbuf.memory = V4L2_MEMORY_MMAP;\n> -\tbuf.length = ARRAY_SIZE(v4l2Planes);\n> +\tbuf.length = std::size(v4l2Planes);\n>   \tbuf.m.planes = v4l2Planes;\n>   \n>   \tint ret = ioctl(VIDIOC_QUERYBUF, &buf);\n> diff --git a/test/ipc/unixsocket.cpp b/test/ipc/unixsocket.cpp\n> index 19a1d7dd8a2d..80157b342795 100644\n> --- a/test/ipc/unixsocket.cpp\n> +++ b/test/ipc/unixsocket.cpp\n> @@ -6,6 +6,7 @@\n>    */\n>   \n>   #include <algorithm>\n> +#include <array>\n>   #include <fcntl.h>\n>   #include <iostream>\n>   #include <stdlib.h>\n> @@ -19,7 +20,6 @@\n>   #include \"libcamera/internal/ipc_unixsocket.h\"\n>   #include \"libcamera/internal/thread.h\"\n>   #include \"libcamera/internal/timer.h\"\n> -#include \"libcamera/internal/utils.h\"\n>   \n>   #include \"test.h\"\n>   \n> @@ -311,7 +311,7 @@ protected:\n>   \t\t};\n>   \t\tint fds[2];\n>   \n> -\t\tfor (unsigned int i = 0; i < ARRAY_SIZE(strings); i++) {\n> +\t\tfor (unsigned int i = 0; i < std::size(strings); i++) {\n>   \t\t\tunsigned int len = strlen(strings[i]);\n>   \n>   \t\t\tfds[i] = open(\"/tmp\", O_TMPFILE | O_RDWR,\n> @@ -333,7 +333,7 @@ protected:\n>   \t\tif (ret)\n>   \t\t\treturn ret;\n>   \n> -\t\tfor (unsigned int i = 0; i < ARRAY_SIZE(strings); i++) {\n> +\t\tfor (unsigned int i = 0; i < std::size(strings); i++) {\n>   \t\t\tunsigned int len = strlen(strings[i]);\n>   \t\t\tchar buf[len];\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 A63C6C0F1A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 14 Dec 2020 04:59:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1F78A61590;\n\tMon, 14 Dec 2020 05:59:19 +0100 (CET)","from mail.uajain.com (static.126.159.217.95.clients.your-server.de\n\t[95.217.159.126])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B3403600EB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 14 Dec 2020 05:59:16 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=uajain.com header.i=@uajain.com\n\theader.b=\"Q9QFJ8uv\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=uajain.com; s=mail;\n\tt=1607921955; bh=E+1Stv5cI3LJc3ynMJM90VrBJbTBAdvriw6jvJjbxc4=;\n\th=Subject:To:References:From:In-Reply-To;\n\tb=Q9QFJ8uvQJGNoxgNMUjQ7pzqjnanQfLF2cMxyhWHaDbA4h2LHvXD8tas9USdjhNpG\n\txIos1ydaFPvmxj6jopueXVctrqACstaUuOOo1One7c3xvIyGpW7oSHUTH4PtLfj7KC\n\tgJ0VdoegjCTZMJ188b2xEUfy+J2AOECk1PZabXQXxL7jp+cXxIk73oet8DapHs2Tb8\n\t3VKsiVTibrpB5viHnCbILpA6NiCCcyBaKppFgrJAFIRlsdsqTDkwtvF9SFjkA3fQAB\n\tpZZAQuxRFnfvGpDC2WSeomspbJfrtaTT8Hi2N7Iip98bie/itmElI+7X4gZ9m1zXmp\n\tIovdM/Zgr2aJQ==","To":"libcamera-devel@lists.libcamera.org","References":"<20201211232319.32088-1-laurent.pinchart@ideasonboard.com>","From":"Umang Jain <email@uajain.com>","Message-ID":"<dd83be82-38fe-fd5e-5e87-3fea086b8e1f@uajain.com>","Date":"Mon, 14 Dec 2020 10:29:11 +0530","Mime-Version":"1.0","In-Reply-To":"<20201211232319.32088-1-laurent.pinchart@ideasonboard.com>","Content-Language":"en-US","Subject":"Re: [libcamera-devel] [PATCH] libcamera: Replace ARRAY_SIZE() with\n\tstd::size()","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>","Content-Transfer-Encoding":"7bit","Content-Type":"text/plain; charset=\"us-ascii\"; Format=\"flowed\"","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":14241,"web_url":"https://patchwork.libcamera.org/comment/14241/","msgid":"<20201214075038.clw6jmezbco7i3gy@uno.localdomain>","date":"2020-12-14T07:50:38","subject":"Re: [libcamera-devel] [PATCH] libcamera: Replace ARRAY_SIZE() with\n\tstd::size()","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent\n\nOn Sat, Dec 12, 2020 at 01:23:19AM +0200, Laurent Pinchart wrote:\n> C++17 has a std::size() function that returns the size of a C-style\n> array. Use it instead of the custom ARRAY_SIZE macro.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  include/libcamera/internal/utils.h  | 2 --\n>  src/ipa/raspberrypi/raspberrypi.cpp | 4 ++--\n>  src/libcamera/camera.cpp            | 8 ++++----\n>  src/libcamera/log.cpp               | 7 ++++---\n>  src/libcamera/utils.cpp             | 5 -----\n>  src/libcamera/v4l2_videodevice.cpp  | 6 +++---\n>  test/ipc/unixsocket.cpp             | 6 +++---\n>  7 files changed, 16 insertions(+), 22 deletions(-)\n>\n> diff --git a/include/libcamera/internal/utils.h b/include/libcamera/internal/utils.h\n> index ebb2c4038e19..f08134afb5ba 100644\n> --- a/include/libcamera/internal/utils.h\n> +++ b/include/libcamera/internal/utils.h\n> @@ -17,8 +17,6 @@\n>  #include <sys/time.h>\n>  #include <vector>\n>\n> -#define ARRAY_SIZE(a)\t(sizeof(a) / sizeof(a[0]))\n> -\n>  #ifndef __DOXYGEN__\n>\n>  /* uClibc and uClibc-ng don't provide O_TMPFILE */\n> diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\n> index 801400214c3a..a7439badb7dc 100644\n> --- a/src/ipa/raspberrypi/raspberrypi.cpp\n> +++ b/src/ipa/raspberrypi/raspberrypi.cpp\n> @@ -6,6 +6,7 @@\n>   */\n>\n>  #include <algorithm>\n> +#include <array>\n>  #include <fcntl.h>\n>  #include <math.h>\n>  #include <stdint.h>\n> @@ -27,7 +28,6 @@\n>  #include \"libcamera/internal/buffer.h\"\n>  #include \"libcamera/internal/camera_sensor.h\"\n>  #include \"libcamera/internal/log.h\"\n> -#include \"libcamera/internal/utils.h\"\n>\n>  #include <linux/bcm2835-isp.h>\n>\n> @@ -1092,7 +1092,7 @@ void IPARPi::applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls)\n>  \t * Choose smallest cell size that won't exceed 63x48 cells.\n>  \t */\n>  \tconst int cellSizes[] = { 16, 32, 64, 128, 256 };\n> -\tunsigned int numCells = ARRAY_SIZE(cellSizes);\n> +\tunsigned int numCells = std::size(cellSizes);\n\nI wonder if replacing cellSizes[] with a const std::array and use\nstd::array::size() wouldn't be more C++-ish.\n\nThe change itself is fine though\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n  j\n>  \tunsigned int i, w, h, cellSize;\n>  \tfor (i = 0; i < numCells; i++) {\n>  \t\tcellSize = cellSizes[i];\n> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\n> index 3579ba96b6ea..c1de1fee701a 100644\n> --- a/src/libcamera/camera.cpp\n> +++ b/src/libcamera/camera.cpp\n> @@ -7,6 +7,7 @@\n>\n>  #include <libcamera/camera.h>\n>\n> +#include <array>\n>  #include <atomic>\n>  #include <iomanip>\n>\n> @@ -17,7 +18,6 @@\n>  #include \"libcamera/internal/log.h\"\n>  #include \"libcamera/internal/pipeline_handler.h\"\n>  #include \"libcamera/internal/thread.h\"\n> -#include \"libcamera/internal/utils.h\"\n>\n>  /**\n>   * \\file camera.h\n> @@ -393,7 +393,7 @@ int Camera::Private::isAccessAllowed(State state, bool allowDisconnected) const\n>  \tif (currentState == state)\n>  \t\treturn 0;\n>\n> -\tASSERT(static_cast<unsigned int>(state) < ARRAY_SIZE(camera_state_names));\n> +\tASSERT(static_cast<unsigned int>(state) < std::size(camera_state_names));\n>\n>  \tLOG(Camera, Debug) << \"Camera in \" << camera_state_names[currentState]\n>  \t\t\t   << \" state trying operation requiring state \"\n> @@ -412,8 +412,8 @@ int Camera::Private::isAccessAllowed(State low, State high,\n>  \tif (currentState >= low && currentState <= high)\n>  \t\treturn 0;\n>\n> -\tASSERT(static_cast<unsigned int>(low) < ARRAY_SIZE(camera_state_names) &&\n> -\t       static_cast<unsigned int>(high) < ARRAY_SIZE(camera_state_names));\n> +\tASSERT(static_cast<unsigned int>(low) < std::size(camera_state_names) &&\n> +\t       static_cast<unsigned int>(high) < std::size(camera_state_names));\n>\n>  \tLOG(Camera, Debug) << \"Camera in \" << camera_state_names[currentState]\n>  \t\t\t   << \" state trying operation requiring state between \"\n> diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp\n> index 180eb97ba664..45c7c2d24652 100644\n> --- a/src/libcamera/log.cpp\n> +++ b/src/libcamera/log.cpp\n> @@ -7,6 +7,7 @@\n>\n>  #include \"libcamera/internal/log.h\"\n>\n> +#include <array>\n>  #if HAVE_BACKTRACE\n>  #include <execinfo.h>\n>  #endif\n> @@ -91,7 +92,7 @@ static const char *log_severity_name(LogSeverity severity)\n>  \t\t\"FATAL\",\n>  \t};\n>\n> -\tif (static_cast<unsigned int>(severity) < ARRAY_SIZE(names))\n> +\tif (static_cast<unsigned int>(severity) < std::size(names))\n>  \t\treturn names[severity];\n>  \telse\n>  \t\treturn \"UNKWN\";\n> @@ -406,7 +407,7 @@ void Logger::backtrace()\n>  \t\treturn;\n>\n>  \tvoid *buffer[32];\n> -\tint num_entries = ::backtrace(buffer, ARRAY_SIZE(buffer));\n> +\tint num_entries = ::backtrace(buffer, std::size(buffer));\n>  \tchar **strings = backtrace_symbols(buffer, num_entries);\n>  \tif (!strings)\n>  \t\treturn;\n> @@ -620,7 +621,7 @@ LogSeverity Logger::parseLogLevel(const std::string &level)\n>  \t\t\tseverity = LogInvalid;\n>  \t} else {\n>  \t\tseverity = LogInvalid;\n> -\t\tfor (unsigned int i = 0; i < ARRAY_SIZE(names); ++i) {\n> +\t\tfor (unsigned int i = 0; i < std::size(names); ++i) {\n>  \t\t\tif (names[i] == level) {\n>  \t\t\t\tseverity = i;\n>  \t\t\t\tbreak;\n> diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\n> index da85c9c24340..e90375ae115c 100644\n> --- a/src/libcamera/utils.cpp\n> +++ b/src/libcamera/utils.cpp\n> @@ -31,11 +31,6 @@ namespace libcamera {\n>\n>  namespace utils {\n>\n> -/**\n> - * \\def ARRAY_SIZE(array)\n> - * \\brief Determine the number of elements in the static array.\n> - */\n> -\n>  /**\n>   * \\brief Strip the directory prefix from the path\n>   * \\param[in] path The path to process\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index e2b582842a9b..baf683d6d985 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -7,6 +7,7 @@\n>\n>  #include \"libcamera/internal/v4l2_videodevice.h\"\n>\n> +#include <array>\n>  #include <fcntl.h>\n>  #include <iomanip>\n>  #include <sstream>\n> @@ -26,7 +27,6 @@\n>  #include \"libcamera/internal/log.h\"\n>  #include \"libcamera/internal/media_device.h\"\n>  #include \"libcamera/internal/media_object.h\"\n> -#include \"libcamera/internal/utils.h\"\n>\n>  /**\n>   * \\file v4l2_videodevice.h\n> @@ -860,7 +860,7 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set)\n>  \tpix->num_planes = format->planesCount;\n>  \tpix->field = V4L2_FIELD_NONE;\n>\n> -\tASSERT(pix->num_planes <= ARRAY_SIZE(pix->plane_fmt));\n> +\tASSERT(pix->num_planes <= std::size(pix->plane_fmt));\n>\n>  \tfor (unsigned int i = 0; i < pix->num_planes; ++i) {\n>  \t\tpix->plane_fmt[i].bytesperline = format->planes[i].bpl;\n> @@ -1255,7 +1255,7 @@ std::unique_ptr<FrameBuffer> V4L2VideoDevice::createBuffer(unsigned int index)\n>  \tbuf.index = index;\n>  \tbuf.type = bufferType_;\n>  \tbuf.memory = V4L2_MEMORY_MMAP;\n> -\tbuf.length = ARRAY_SIZE(v4l2Planes);\n> +\tbuf.length = std::size(v4l2Planes);\n>  \tbuf.m.planes = v4l2Planes;\n>\n>  \tint ret = ioctl(VIDIOC_QUERYBUF, &buf);\n> diff --git a/test/ipc/unixsocket.cpp b/test/ipc/unixsocket.cpp\n> index 19a1d7dd8a2d..80157b342795 100644\n> --- a/test/ipc/unixsocket.cpp\n> +++ b/test/ipc/unixsocket.cpp\n> @@ -6,6 +6,7 @@\n>   */\n>\n>  #include <algorithm>\n> +#include <array>\n>  #include <fcntl.h>\n>  #include <iostream>\n>  #include <stdlib.h>\n> @@ -19,7 +20,6 @@\n>  #include \"libcamera/internal/ipc_unixsocket.h\"\n>  #include \"libcamera/internal/thread.h\"\n>  #include \"libcamera/internal/timer.h\"\n> -#include \"libcamera/internal/utils.h\"\n>\n>  #include \"test.h\"\n>\n> @@ -311,7 +311,7 @@ protected:\n>  \t\t};\n>  \t\tint fds[2];\n>\n> -\t\tfor (unsigned int i = 0; i < ARRAY_SIZE(strings); i++) {\n> +\t\tfor (unsigned int i = 0; i < std::size(strings); i++) {\n>  \t\t\tunsigned int len = strlen(strings[i]);\n>\n>  \t\t\tfds[i] = open(\"/tmp\", O_TMPFILE | O_RDWR,\n> @@ -333,7 +333,7 @@ protected:\n>  \t\tif (ret)\n>  \t\t\treturn ret;\n>\n> -\t\tfor (unsigned int i = 0; i < ARRAY_SIZE(strings); i++) {\n> +\t\tfor (unsigned int i = 0; i < std::size(strings); i++) {\n>  \t\t\tunsigned int len = strlen(strings[i]);\n>  \t\t\tchar buf[len];\n>\n> --\n> Regards,\n>\n> Laurent Pinchart\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","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 03C3DC0F1A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 14 Dec 2020 07:50:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 906096158D;\n\tMon, 14 Dec 2020 08:50:30 +0100 (CET)","from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net\n\t[217.70.183.196])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C4964600EB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 14 Dec 2020 08:50:29 +0100 (CET)","from uno.localdomain (host-95-245-192-76.retail.telecomitalia.it\n\t[95.245.192.76]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay4-d.mail.gandi.net (Postfix) with ESMTPSA id C1139E0004;\n\tMon, 14 Dec 2020 07:50:28 +0000 (UTC)"],"X-Originating-IP":"95.245.192.76","Date":"Mon, 14 Dec 2020 08:50:38 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20201214075038.clw6jmezbco7i3gy@uno.localdomain>","References":"<20201211232319.32088-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20201211232319.32088-1-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH] libcamera: Replace ARRAY_SIZE() with\n\tstd::size()","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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":14244,"web_url":"https://patchwork.libcamera.org/comment/14244/","msgid":"<X9dr5zryNkN6Z62y@pendragon.ideasonboard.com>","date":"2020-12-14T13:43:03","subject":"Re: [libcamera-devel] [PATCH] libcamera: Replace ARRAY_SIZE() with\n\tstd::size()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn Mon, Dec 14, 2020 at 08:50:38AM +0100, Jacopo Mondi wrote:\n> On Sat, Dec 12, 2020 at 01:23:19AM +0200, Laurent Pinchart wrote:\n> > C++17 has a std::size() function that returns the size of a C-style\n> > array. Use it instead of the custom ARRAY_SIZE macro.\n> >\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  include/libcamera/internal/utils.h  | 2 --\n> >  src/ipa/raspberrypi/raspberrypi.cpp | 4 ++--\n> >  src/libcamera/camera.cpp            | 8 ++++----\n> >  src/libcamera/log.cpp               | 7 ++++---\n> >  src/libcamera/utils.cpp             | 5 -----\n> >  src/libcamera/v4l2_videodevice.cpp  | 6 +++---\n> >  test/ipc/unixsocket.cpp             | 6 +++---\n> >  7 files changed, 16 insertions(+), 22 deletions(-)\n> >\n> > diff --git a/include/libcamera/internal/utils.h b/include/libcamera/internal/utils.h\n> > index ebb2c4038e19..f08134afb5ba 100644\n> > --- a/include/libcamera/internal/utils.h\n> > +++ b/include/libcamera/internal/utils.h\n> > @@ -17,8 +17,6 @@\n> >  #include <sys/time.h>\n> >  #include <vector>\n> >\n> > -#define ARRAY_SIZE(a)\t(sizeof(a) / sizeof(a[0]))\n> > -\n> >  #ifndef __DOXYGEN__\n> >\n> >  /* uClibc and uClibc-ng don't provide O_TMPFILE */\n> > diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\n> > index 801400214c3a..a7439badb7dc 100644\n> > --- a/src/ipa/raspberrypi/raspberrypi.cpp\n> > +++ b/src/ipa/raspberrypi/raspberrypi.cpp\n> > @@ -6,6 +6,7 @@\n> >   */\n> >\n> >  #include <algorithm>\n> > +#include <array>\n> >  #include <fcntl.h>\n> >  #include <math.h>\n> >  #include <stdint.h>\n> > @@ -27,7 +28,6 @@\n> >  #include \"libcamera/internal/buffer.h\"\n> >  #include \"libcamera/internal/camera_sensor.h\"\n> >  #include \"libcamera/internal/log.h\"\n> > -#include \"libcamera/internal/utils.h\"\n> >\n> >  #include <linux/bcm2835-isp.h>\n> >\n> > @@ -1092,7 +1092,7 @@ void IPARPi::applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls)\n> >  \t * Choose smallest cell size that won't exceed 63x48 cells.\n> >  \t */\n> >  \tconst int cellSizes[] = { 16, 32, 64, 128, 256 };\n> > -\tunsigned int numCells = ARRAY_SIZE(cellSizes);\n> > +\tunsigned int numCells = std::size(cellSizes);\n> \n> I wonder if replacing cellSizes[] with a const std::array and use\n> std::array::size() wouldn't be more C++-ish.\n\nThe trouble with std::array() is that you need to declare the array size\nexplicitly. This would become\n\n \tconst std::array<int, 5> cellSizes{ 16, 32, 64, 128, 256 };\n\nAn experimental std::make_array() has been proposed (see\nhttps://en.cppreference.com/w/cpp/experimental/make_array) to overcome\nthat limitation. It has been dropped in favour of std::to_array() (see\nhttps://en.cppreference.com/w/cpp/container/array/to_array) that has\nbeen merged in C++20. The code would then become\n\n\tconst auto cellSizes = std::to_array<int>({ 16, 32, 64, 128, 256 });\n\nWe could possibly implement this function in the utils namespace (that\nwould need to be double-checked though, as it may depend template\ndeduction rules that have been updated in C++20). I'm not sure if the\nend result is better though.\n\n> The change itself is fine though\n> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n> \n> >  \tunsigned int i, w, h, cellSize;\n> >  \tfor (i = 0; i < numCells; i++) {\n> >  \t\tcellSize = cellSizes[i];\n> > diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\n> > index 3579ba96b6ea..c1de1fee701a 100644\n> > --- a/src/libcamera/camera.cpp\n> > +++ b/src/libcamera/camera.cpp\n> > @@ -7,6 +7,7 @@\n> >\n> >  #include <libcamera/camera.h>\n> >\n> > +#include <array>\n> >  #include <atomic>\n> >  #include <iomanip>\n> >\n> > @@ -17,7 +18,6 @@\n> >  #include \"libcamera/internal/log.h\"\n> >  #include \"libcamera/internal/pipeline_handler.h\"\n> >  #include \"libcamera/internal/thread.h\"\n> > -#include \"libcamera/internal/utils.h\"\n> >\n> >  /**\n> >   * \\file camera.h\n> > @@ -393,7 +393,7 @@ int Camera::Private::isAccessAllowed(State state, bool allowDisconnected) const\n> >  \tif (currentState == state)\n> >  \t\treturn 0;\n> >\n> > -\tASSERT(static_cast<unsigned int>(state) < ARRAY_SIZE(camera_state_names));\n> > +\tASSERT(static_cast<unsigned int>(state) < std::size(camera_state_names));\n> >\n> >  \tLOG(Camera, Debug) << \"Camera in \" << camera_state_names[currentState]\n> >  \t\t\t   << \" state trying operation requiring state \"\n> > @@ -412,8 +412,8 @@ int Camera::Private::isAccessAllowed(State low, State high,\n> >  \tif (currentState >= low && currentState <= high)\n> >  \t\treturn 0;\n> >\n> > -\tASSERT(static_cast<unsigned int>(low) < ARRAY_SIZE(camera_state_names) &&\n> > -\t       static_cast<unsigned int>(high) < ARRAY_SIZE(camera_state_names));\n> > +\tASSERT(static_cast<unsigned int>(low) < std::size(camera_state_names) &&\n> > +\t       static_cast<unsigned int>(high) < std::size(camera_state_names));\n> >\n> >  \tLOG(Camera, Debug) << \"Camera in \" << camera_state_names[currentState]\n> >  \t\t\t   << \" state trying operation requiring state between \"\n> > diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp\n> > index 180eb97ba664..45c7c2d24652 100644\n> > --- a/src/libcamera/log.cpp\n> > +++ b/src/libcamera/log.cpp\n> > @@ -7,6 +7,7 @@\n> >\n> >  #include \"libcamera/internal/log.h\"\n> >\n> > +#include <array>\n> >  #if HAVE_BACKTRACE\n> >  #include <execinfo.h>\n> >  #endif\n> > @@ -91,7 +92,7 @@ static const char *log_severity_name(LogSeverity severity)\n> >  \t\t\"FATAL\",\n> >  \t};\n> >\n> > -\tif (static_cast<unsigned int>(severity) < ARRAY_SIZE(names))\n> > +\tif (static_cast<unsigned int>(severity) < std::size(names))\n> >  \t\treturn names[severity];\n> >  \telse\n> >  \t\treturn \"UNKWN\";\n> > @@ -406,7 +407,7 @@ void Logger::backtrace()\n> >  \t\treturn;\n> >\n> >  \tvoid *buffer[32];\n> > -\tint num_entries = ::backtrace(buffer, ARRAY_SIZE(buffer));\n> > +\tint num_entries = ::backtrace(buffer, std::size(buffer));\n> >  \tchar **strings = backtrace_symbols(buffer, num_entries);\n> >  \tif (!strings)\n> >  \t\treturn;\n> > @@ -620,7 +621,7 @@ LogSeverity Logger::parseLogLevel(const std::string &level)\n> >  \t\t\tseverity = LogInvalid;\n> >  \t} else {\n> >  \t\tseverity = LogInvalid;\n> > -\t\tfor (unsigned int i = 0; i < ARRAY_SIZE(names); ++i) {\n> > +\t\tfor (unsigned int i = 0; i < std::size(names); ++i) {\n> >  \t\t\tif (names[i] == level) {\n> >  \t\t\t\tseverity = i;\n> >  \t\t\t\tbreak;\n> > diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\n> > index da85c9c24340..e90375ae115c 100644\n> > --- a/src/libcamera/utils.cpp\n> > +++ b/src/libcamera/utils.cpp\n> > @@ -31,11 +31,6 @@ namespace libcamera {\n> >\n> >  namespace utils {\n> >\n> > -/**\n> > - * \\def ARRAY_SIZE(array)\n> > - * \\brief Determine the number of elements in the static array.\n> > - */\n> > -\n> >  /**\n> >   * \\brief Strip the directory prefix from the path\n> >   * \\param[in] path The path to process\n> > diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> > index e2b582842a9b..baf683d6d985 100644\n> > --- a/src/libcamera/v4l2_videodevice.cpp\n> > +++ b/src/libcamera/v4l2_videodevice.cpp\n> > @@ -7,6 +7,7 @@\n> >\n> >  #include \"libcamera/internal/v4l2_videodevice.h\"\n> >\n> > +#include <array>\n> >  #include <fcntl.h>\n> >  #include <iomanip>\n> >  #include <sstream>\n> > @@ -26,7 +27,6 @@\n> >  #include \"libcamera/internal/log.h\"\n> >  #include \"libcamera/internal/media_device.h\"\n> >  #include \"libcamera/internal/media_object.h\"\n> > -#include \"libcamera/internal/utils.h\"\n> >\n> >  /**\n> >   * \\file v4l2_videodevice.h\n> > @@ -860,7 +860,7 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set)\n> >  \tpix->num_planes = format->planesCount;\n> >  \tpix->field = V4L2_FIELD_NONE;\n> >\n> > -\tASSERT(pix->num_planes <= ARRAY_SIZE(pix->plane_fmt));\n> > +\tASSERT(pix->num_planes <= std::size(pix->plane_fmt));\n> >\n> >  \tfor (unsigned int i = 0; i < pix->num_planes; ++i) {\n> >  \t\tpix->plane_fmt[i].bytesperline = format->planes[i].bpl;\n> > @@ -1255,7 +1255,7 @@ std::unique_ptr<FrameBuffer> V4L2VideoDevice::createBuffer(unsigned int index)\n> >  \tbuf.index = index;\n> >  \tbuf.type = bufferType_;\n> >  \tbuf.memory = V4L2_MEMORY_MMAP;\n> > -\tbuf.length = ARRAY_SIZE(v4l2Planes);\n> > +\tbuf.length = std::size(v4l2Planes);\n> >  \tbuf.m.planes = v4l2Planes;\n> >\n> >  \tint ret = ioctl(VIDIOC_QUERYBUF, &buf);\n> > diff --git a/test/ipc/unixsocket.cpp b/test/ipc/unixsocket.cpp\n> > index 19a1d7dd8a2d..80157b342795 100644\n> > --- a/test/ipc/unixsocket.cpp\n> > +++ b/test/ipc/unixsocket.cpp\n> > @@ -6,6 +6,7 @@\n> >   */\n> >\n> >  #include <algorithm>\n> > +#include <array>\n> >  #include <fcntl.h>\n> >  #include <iostream>\n> >  #include <stdlib.h>\n> > @@ -19,7 +20,6 @@\n> >  #include \"libcamera/internal/ipc_unixsocket.h\"\n> >  #include \"libcamera/internal/thread.h\"\n> >  #include \"libcamera/internal/timer.h\"\n> > -#include \"libcamera/internal/utils.h\"\n> >\n> >  #include \"test.h\"\n> >\n> > @@ -311,7 +311,7 @@ protected:\n> >  \t\t};\n> >  \t\tint fds[2];\n> >\n> > -\t\tfor (unsigned int i = 0; i < ARRAY_SIZE(strings); i++) {\n> > +\t\tfor (unsigned int i = 0; i < std::size(strings); i++) {\n> >  \t\t\tunsigned int len = strlen(strings[i]);\n> >\n> >  \t\t\tfds[i] = open(\"/tmp\", O_TMPFILE | O_RDWR,\n> > @@ -333,7 +333,7 @@ protected:\n> >  \t\tif (ret)\n> >  \t\t\treturn ret;\n> >\n> > -\t\tfor (unsigned int i = 0; i < ARRAY_SIZE(strings); i++) {\n> > +\t\tfor (unsigned int i = 0; i < std::size(strings); i++) {\n> >  \t\t\tunsigned int len = strlen(strings[i]);\n> >  \t\t\tchar buf[len];\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 EDD2DC0F1A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 14 Dec 2020 13:43:11 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 737636158C;\n\tMon, 14 Dec 2020 14:43:11 +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 25EE360321\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 14 Dec 2020 14:43:10 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8F78C96;\n\tMon, 14 Dec 2020 14:43:09 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"sEQSUATh\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1607953389;\n\tbh=BqvsBHA5/r/7JySAOuy4ZTNX9qSPS27HnFPQde5Wa3g=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=sEQSUATh1ink9uvpVvR3nvNSO1N31M1YdKorpVjOUyUaaRRSX2JQ5B8wdpZUrToh2\n\tJN+jkOQArmPVsUTMtFlixhr9OsLcHTmOsn7cP9u3OQ2VsujfslhJ+Q78z5vTHvcLd1\n\tWsk4hCNXNk7NewFuR220Mw4pk+o6HE9IfGhQwZA0=","Date":"Mon, 14 Dec 2020 15:43:03 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<X9dr5zryNkN6Z62y@pendragon.ideasonboard.com>","References":"<20201211232319.32088-1-laurent.pinchart@ideasonboard.com>\n\t<20201214075038.clw6jmezbco7i3gy@uno.localdomain>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20201214075038.clw6jmezbco7i3gy@uno.localdomain>","Subject":"Re: [libcamera-devel] [PATCH] libcamera: Replace ARRAY_SIZE() with\n\tstd::size()","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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]