From patchwork Mon Jan 20 17:38:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2713 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1B11F6081F for ; Mon, 20 Jan 2020 18:38:21 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id ADE3610D6 for ; Mon, 20 Jan 2020 18:38:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1579541900; bh=PNjzR3WxiO+vO/1ZND9WK69/l54MBwae0rrQ0g3uCKA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Wwx2ObC2g9hPxoZM5YP75ohtDiPc3aBqzIE8l6VH1yHwyW6zjY+Bcb25OJqBcd6Iq 89u5ipoNkQFJbs3SdkcclfgAB3Az2u5GvB72FFgqZiieTVoCFFhjeVjftuNfUH12Dn Kd5cvLNr0LLJk+B6m92XWTm5e2yf7QqrQAGhdk9o= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jan 2020 19:38:14 +0200 Message-Id: <20200120173816.31829-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200120173816.31829-1-laurent.pinchart@ideasonboard.com> References: <20200120173816.31829-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/3] libcamera: utils: Add a new make_array() function X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Jan 2020 17:38:21 -0000 Add a custom implementation of std::make_array() as defined by the library fundamentals TS v2 ([1]). The function is useful to initialize static arrays without requiring manually specifying the number of elements, which could lead to bugs when the specified size is larger than the number of initializers. This is an experimental feature in the C++ standard, and while available in in stdlibc++ from g++-6 onwards, it is not provided by libc++. [1] https://en.cppreference.com/w/cpp/experimental/make_array Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- Documentation/Doxyfile.in | 1 + src/libcamera/include/utils.h | 42 +++++++++++++++++++++++++++++++++++ src/libcamera/utils.cpp | 14 ++++++++++++ 3 files changed, 57 insertions(+) diff --git a/Documentation/Doxyfile.in b/Documentation/Doxyfile.in index 8e6fbdbb92b6..6de59d407e7b 100644 --- a/Documentation/Doxyfile.in +++ b/Documentation/Doxyfile.in @@ -877,6 +877,7 @@ EXCLUDE_SYMBOLS = libcamera::BoundMethodArgs \ libcamera::BoundMethodPackBase \ libcamera::BoundMethodStatic \ libcamera::SignalBase \ + *::details::* \ std::* # The EXAMPLE_PATH tag can be used to specify one or more files or directories diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h index e467eb21c518..6e9b9259456a 100644 --- a/src/libcamera/include/utils.h +++ b/src/libcamera/include/utils.h @@ -8,12 +8,15 @@ #define __LIBCAMERA_UTILS_H__ #include +#include #include +#include #include #include #include #include #include +#include #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) @@ -108,6 +111,45 @@ inline _hex hex(uint64_t value, unsigned int width) size_t strlcpy(char *dst, const char *src, size_t size); +namespace details { + +namespace make_array { + + template + struct negation : std::integral_constant {}; + + template struct conjunction : std::true_type {}; + template struct conjunction : B1 {}; + template + struct conjunction + : std::conditional_t, B1> {}; + + template struct is_ref_wrapper : std::false_type {}; + template struct is_ref_wrapper> : std::true_type {}; + + template + struct return_type_helper { + using type = D; + }; + template + struct return_type_helper : std::common_type { + static_assert(conjunction>>...>::value, + "Types cannot contain reference_wrappers when D is void"); + }; + + template + using return_type = std::array::type, + sizeof...(Types)>; +} /* namespace make_array */ + +} /* namespace details */ + +template +constexpr details::make_array::return_type make_array(Types&&... t) +{ + return {std::forward(t)... }; +} + } /* namespace utils */ } /* namespace libcamera */ diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp index 4beffdab5eb6..b639cfa83d0c 100644 --- a/src/libcamera/utils.cpp +++ b/src/libcamera/utils.cpp @@ -199,6 +199,20 @@ size_t strlcpy(char *dst, const char *src, size_t size) return strlen(src); } +/** + * \fn template libcamera::utils::make_array(Types&&... t) + * \brief Create a std::array with automatic deduction of element type and count + * \param[in] t The initialization values for the array elements + * + * This function creates and returns an instance of std::array whose size is + * equal to the number of arguments. If the template argument \a D is void, the + * array element type is deduced from the elements through + * std::common_types_t. Otherwise it is set to D. The elements are + * initialized from the corresponding arguments. + * + * \return A std::array initialized from the arguments + */ + } /* namespace utils */ } /* namespace libcamera */ From patchwork Mon Jan 20 17:38:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2714 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 71AAD6081F for ; Mon, 20 Jan 2020 18:38:21 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 10A9AA62 for ; Mon, 20 Jan 2020 18:38:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1579541901; bh=QHcWgmH1eF1E9Lh3ogOsxezv1As9vkLrBYBDWKNCfIQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=AAD1omRS//KM3wvDeJAq2gUo4TkPmPrQVBXQ+6c8gJ+E7jIDOaF2S4jlRjt7ns6K3 jb6O1y81AnKs40izADVUkR5aP9ypl8J2rn549gwmLsH4j6n3PPHab35bl78YCfcZbC h9qlCspMWCUYD2GkOyPTt/VDBV5SG9j4jfLRVyiY= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jan 2020 19:38:15 +0200 Message-Id: <20200120173816.31829-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200120173816.31829-1-laurent.pinchart@ideasonboard.com> References: <20200120173816.31829-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/3] libcamera: Use utils::make_array() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Jan 2020 17:38:21 -0000 Replace manual static array initialization with utils::make_array() to avoid manually specifying the number of elements. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 6 ++--- src/libcamera/pipeline/vimc.cpp | 6 ++--- src/libcamera/stream.cpp | 6 ++--- src/v4l2/v4l2_camera_proxy.cpp | 30 ++++++++++++------------ 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 0b3dd9759387..911f665720b3 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -433,16 +433,16 @@ RkISP1CameraConfiguration::RkISP1CameraConfiguration(Camera *camera, CameraConfiguration::Status RkISP1CameraConfiguration::validate() { - static const std::array formats{ + static const auto formats = utils::make_array( DRM_FORMAT_YUYV, DRM_FORMAT_YVYU, DRM_FORMAT_VYUY, DRM_FORMAT_NV16, DRM_FORMAT_NV61, DRM_FORMAT_NV21, - DRM_FORMAT_NV12, + DRM_FORMAT_NV12 /* \todo Add support for 8-bit greyscale to DRM formats */ - }; + ); const CameraSensor *sensor = data_->sensor_; Status status = Valid; diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp index b1054d307ea2..7df21f2b7a6f 100644 --- a/src/libcamera/pipeline/vimc.cpp +++ b/src/libcamera/pipeline/vimc.cpp @@ -106,11 +106,11 @@ private: namespace { -constexpr std::array pixelformats{ +constexpr auto pixelformats = utils::make_array( DRM_FORMAT_RGB888, DRM_FORMAT_BGR888, - DRM_FORMAT_BGRA8888, -}; + DRM_FORMAT_BGRA8888 +); } /* namespace */ diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp index 13789e9eb344..943f044b7b7a 100644 --- a/src/libcamera/stream.cpp +++ b/src/libcamera/stream.cpp @@ -135,7 +135,7 @@ std::vector StreamFormats::sizes(PixelFormat pixelformat) const * from v4l2 documentation and source code as well as lists of * common frame sizes. */ - static const std::array rangeDiscreteSizes = { + static const auto rangeDiscreteSizes = utils::make_array( Size(160, 120), Size(240, 160), Size(320, 240), @@ -188,8 +188,8 @@ std::vector StreamFormats::sizes(PixelFormat pixelformat) const Size(4096, 2160), Size(5120, 2160), Size(5120, 2880), - Size(7680, 4320), - }; + Size(7680, 4320) + ); std::vector sizes; /* Make sure pixel format exists. */ diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index e58fd6a0d8b5..3b0a4bcb830f 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -546,24 +546,24 @@ struct PixelFormatInfo { namespace { -constexpr std::array pixelFormatInfo = {{ +constexpr auto pixelFormatInfo = utils::make_array( /* RGB formats. */ - { DRM_FORMAT_RGB888, V4L2_PIX_FMT_BGR24, 1, {{ { 24, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, - { DRM_FORMAT_BGR888, V4L2_PIX_FMT_RGB24, 1, {{ { 24, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, - { DRM_FORMAT_BGRA8888, V4L2_PIX_FMT_ARGB32, 1, {{ { 32, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, + PixelFormatInfo{ DRM_FORMAT_RGB888, V4L2_PIX_FMT_BGR24, 1, {{ { 24, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, + PixelFormatInfo{ DRM_FORMAT_BGR888, V4L2_PIX_FMT_RGB24, 1, {{ { 24, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, + PixelFormatInfo{ DRM_FORMAT_BGRA8888, V4L2_PIX_FMT_ARGB32, 1, {{ { 32, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, /* YUV packed formats. */ - { DRM_FORMAT_UYVY, V4L2_PIX_FMT_UYVY, 1, {{ { 16, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, - { DRM_FORMAT_VYUY, V4L2_PIX_FMT_VYUY, 1, {{ { 16, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, - { DRM_FORMAT_YUYV, V4L2_PIX_FMT_YUYV, 1, {{ { 16, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, - { DRM_FORMAT_YVYU, V4L2_PIX_FMT_YVYU, 1, {{ { 16, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, + PixelFormatInfo{ DRM_FORMAT_UYVY, V4L2_PIX_FMT_UYVY, 1, {{ { 16, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, + PixelFormatInfo{ DRM_FORMAT_VYUY, V4L2_PIX_FMT_VYUY, 1, {{ { 16, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, + PixelFormatInfo{ DRM_FORMAT_YUYV, V4L2_PIX_FMT_YUYV, 1, {{ { 16, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, + PixelFormatInfo{ DRM_FORMAT_YVYU, V4L2_PIX_FMT_YVYU, 1, {{ { 16, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, /* YUY planar formats. */ - { DRM_FORMAT_NV12, V4L2_PIX_FMT_NV12, 2, {{ { 8, 1, 1 }, { 16, 2, 2 }, { 0, 0, 0 } }} }, - { DRM_FORMAT_NV21, V4L2_PIX_FMT_NV21, 2, {{ { 8, 1, 1 }, { 16, 2, 2 }, { 0, 0, 0 } }} }, - { DRM_FORMAT_NV16, V4L2_PIX_FMT_NV16, 2, {{ { 8, 1, 1 }, { 16, 2, 1 }, { 0, 0, 0 } }} }, - { DRM_FORMAT_NV61, V4L2_PIX_FMT_NV61, 2, {{ { 8, 1, 1 }, { 16, 2, 1 }, { 0, 0, 0 } }} }, - { DRM_FORMAT_NV24, V4L2_PIX_FMT_NV24, 2, {{ { 8, 1, 1 }, { 16, 2, 1 }, { 0, 0, 0 } }} }, - { DRM_FORMAT_NV42, V4L2_PIX_FMT_NV42, 2, {{ { 8, 1, 1 }, { 16, 1, 1 }, { 0, 0, 0 } }} }, -}}; + PixelFormatInfo{ DRM_FORMAT_NV12, V4L2_PIX_FMT_NV12, 2, {{ { 8, 1, 1 }, { 16, 2, 2 }, { 0, 0, 0 } }} }, + PixelFormatInfo{ DRM_FORMAT_NV21, V4L2_PIX_FMT_NV21, 2, {{ { 8, 1, 1 }, { 16, 2, 2 }, { 0, 0, 0 } }} }, + PixelFormatInfo{ DRM_FORMAT_NV16, V4L2_PIX_FMT_NV16, 2, {{ { 8, 1, 1 }, { 16, 2, 1 }, { 0, 0, 0 } }} }, + PixelFormatInfo{ DRM_FORMAT_NV61, V4L2_PIX_FMT_NV61, 2, {{ { 8, 1, 1 }, { 16, 2, 1 }, { 0, 0, 0 } }} }, + PixelFormatInfo{ DRM_FORMAT_NV24, V4L2_PIX_FMT_NV24, 2, {{ { 8, 1, 1 }, { 16, 2, 1 }, { 0, 0, 0 } }} }, + PixelFormatInfo{ DRM_FORMAT_NV42, V4L2_PIX_FMT_NV42, 2, {{ { 8, 1, 1 }, { 16, 1, 1 }, { 0, 0, 0 } }} } +); } /* namespace */ From patchwork Mon Jan 20 17:38:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2715 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C04EF6081F for ; Mon, 20 Jan 2020 18:38:21 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 62C5410D6 for ; Mon, 20 Jan 2020 18:38:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1579541901; bh=WWLXvwTHQaiX6BmRPdeYbn5mDIBJ2XbviXSOEyuI/gw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=okGHnI15CtEfz0NWpH9DR4e/O5ZqWXkyMqnLLS3Ay3ykG3Rvkx5sp/K63CUAfbZOt xugc9cCWFsesCkZhX3hNJHs/q4EJdSpAY61okj3pegtzBpY8FT5DNgSzH0OfWasVvJ iOrLxO0/Ixy55qnqALUI5JeH7KFCD9o5K7uawOu8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jan 2020 19:38:16 +0200 Message-Id: <20200120173816.31829-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200120173816.31829-1-laurent.pinchart@ideasonboard.com> References: <20200120173816.31829-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/3] libcamera: Replace ARRAY_SIZE with std::array X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Jan 2020 17:38:21 -0000 Replace the C-style arrays with std::array wherever the ARRAY_SIZE macro is used, removing the need for the macro completely. std::array combines the performance and accessibility of C-style arrays with the benefits of a standard container, which is shown here through the ability to carry its size. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/camera.cpp | 13 +++++++------ src/libcamera/include/utils.h | 2 -- src/libcamera/ipa_module.cpp | 11 ++++++----- src/libcamera/log.cpp | 23 ++++++++++++----------- src/libcamera/utils.cpp | 5 ----- src/libcamera/v4l2_videodevice.cpp | 7 ++++--- test/ipc/unixsocket.cpp | 8 ++++---- 7 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 79a5f994f9bb..769f16c9ceab 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -7,6 +7,7 @@ #include +#include #include #include @@ -404,20 +405,20 @@ Camera::~Camera() LOG(Camera, Error) << "Removing camera while still in use"; } -static const char *const camera_state_names[] = { +static constexpr auto camera_state_names = utils::make_array( "Available", "Acquired", "Configured", - "Running", -}; + "Running" +); bool Camera::stateBetween(State low, State high) const { if (state_ >= low && state_ <= high) return true; - ASSERT(static_cast(low) < ARRAY_SIZE(camera_state_names) && - static_cast(high) < ARRAY_SIZE(camera_state_names)); + ASSERT(static_cast(low) < camera_state_names.size() && + static_cast(high) < camera_state_names.size()); LOG(Camera, Debug) << "Camera in " << camera_state_names[state_] << " state trying operation requiring state between " @@ -432,7 +433,7 @@ bool Camera::stateIs(State state) const if (state_ == state) return true; - ASSERT(static_cast(state) < ARRAY_SIZE(camera_state_names)); + ASSERT(static_cast(state) < camera_state_names.size()); LOG(Camera, Debug) << "Camera in " << camera_state_names[state_] << " state trying operation requiring state " diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h index 6e9b9259456a..9057f8b0de84 100644 --- a/src/libcamera/include/utils.h +++ b/src/libcamera/include/utils.h @@ -18,8 +18,6 @@ #include #include -#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) - #ifndef __DOXYGEN__ /* uClibc and uClibc-ng don't provide O_TMPFILE */ diff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp index 2c355ea8b5e5..6d9ff77d5bd4 100644 --- a/src/libcamera/ipa_module.cpp +++ b/src/libcamera/ipa_module.cpp @@ -480,7 +480,7 @@ bool IPAModule::match(PipelineHandler *pipe, */ bool IPAModule::isOpenSource() const { - static const char *osLicenses[] = { + static constexpr auto osLicenses = utils::make_array( "GPL-2.0-only", "GPL-2.0-or-later", "GPL-3.0-only", @@ -488,12 +488,13 @@ bool IPAModule::isOpenSource() const "LGPL-2.1-only", "LGPL-2.1-or-later", "LGPL-3.0-only", - "LGPL-3.0-or-later", - }; + "LGPL-3.0-or-later" + ); - for (unsigned int i = 0; i < ARRAY_SIZE(osLicenses); i++) - if (!strcmp(osLicenses[i], info_.license)) + for (const char *license : osLicenses) { + if (!strcmp(license, info_.license)) return true; + } return false; } diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp index 1c82dc68fb0f..fec48c9e7175 100644 --- a/src/libcamera/log.cpp +++ b/src/libcamera/log.cpp @@ -7,6 +7,7 @@ #include "log.h" +#include #if HAVE_BACKTRACE #include #endif @@ -83,15 +84,15 @@ static int log_severity_to_syslog(LogSeverity severity) static const char *log_severity_name(LogSeverity severity) { - static const char *const names[] = { + static constexpr auto names = utils::make_array( " DBG", " INFO", " WARN", " ERR", - "FATAL", - }; + "FATAL" + ); - if (static_cast(severity) < ARRAY_SIZE(names)) + if (static_cast(severity) < names.size()) return names[severity]; else return "UNKWN"; @@ -405,9 +406,9 @@ void Logger::backtrace() if (!output) return; - void *buffer[32]; - int num_entries = ::backtrace(buffer, ARRAY_SIZE(buffer)); - char **strings = backtrace_symbols(buffer, num_entries); + std::array buffer; + int num_entries = ::backtrace(buffer.data(), buffer.size()); + char **strings = backtrace_symbols(buffer.data(), num_entries); if (!strings) return; @@ -603,13 +604,13 @@ void Logger::parseLogLevels() */ LogSeverity Logger::parseLogLevel(const std::string &level) { - static const char *const names[] = { + static constexpr auto names = utils::make_array( "DEBUG", "INFO", "WARN", "ERROR", - "FATAL", - }; + "FATAL" + ); int severity; @@ -620,7 +621,7 @@ LogSeverity Logger::parseLogLevel(const std::string &level) severity = LogInvalid; } else { severity = LogInvalid; - for (unsigned int i = 0; i < ARRAY_SIZE(names); ++i) { + for (unsigned int i = 0; i < names.size(); ++i) { if (names[i] == level) { severity = i; break; diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp index b639cfa83d0c..dfd140ca464a 100644 --- a/src/libcamera/utils.cpp +++ b/src/libcamera/utils.cpp @@ -22,11 +22,6 @@ namespace libcamera { namespace utils { -/** - * \def ARRAY_SIZE(array) - * \brief Determine the number of elements in the static array. - */ - /** * \brief Strip the directory prefix from the path * \param[in] path The path to process diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 82267730289d..234d8123c7b4 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -7,6 +7,7 @@ #include "v4l2_videodevice.h" +#include #include #include #include @@ -992,13 +993,13 @@ int V4L2VideoDevice::exportBuffers(unsigned int count, for (unsigned i = 0; i < count; ++i) { struct v4l2_buffer buf = {}; - struct v4l2_plane planes[VIDEO_MAX_PLANES] = {}; + std::array planes = {}; buf.index = i; buf.type = bufferType_; buf.memory = memoryType_; - buf.length = ARRAY_SIZE(planes); - buf.m.planes = planes; + buf.length = planes.size(); + buf.m.planes = planes.data(); ret = ioctl(VIDIOC_QUERYBUF, &buf); if (ret < 0) { diff --git a/test/ipc/unixsocket.cpp b/test/ipc/unixsocket.cpp index f53042b88720..5bf543c197fa 100644 --- a/test/ipc/unixsocket.cpp +++ b/test/ipc/unixsocket.cpp @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -21,7 +22,6 @@ #include "ipc_unixsocket.h" #include "test.h" #include "thread.h" -#include "utils.h" #define CMD_CLOSE 0 #define CMD_REVERSE 1 @@ -303,13 +303,13 @@ protected: IPCUnixSocket::Payload message, response; int ret; - static const char *strings[2] = { + static constexpr std::array strings = { "Foo", "Bar", }; int fds[2]; - for (unsigned int i = 0; i < ARRAY_SIZE(strings); i++) { + for (unsigned int i = 0; i < strings.size(); i++) { unsigned int len = strlen(strings[i]); fds[i] = open("/tmp", O_TMPFILE | O_RDWR, @@ -331,7 +331,7 @@ protected: if (ret) return ret; - for (unsigned int i = 0; i < ARRAY_SIZE(strings); i++) { + for (unsigned int i = 0; i < strings.size(); i++) { unsigned int len = strlen(strings[i]); char buf[len];