[libcamera-devel] [PATCH v7 0/5] generate and use fixed-sized Span Control types

Laurent Pinchart laurent.pinchart at ideasonboard.com
Sun Jun 5 00:47:46 CEST 2022


Hi Christian,

Thank you for the patches.

On Sat, Jun 04, 2022 at 10:11:43PM +0100, Christian Rauch via libcamera-devel wrote:
> Hello,
> 
> Compared to the previous version, this 1) avoids a couple of more
> "value_or" fallbacks if the validity of a control value or property
> was previously checked with "contains" and 2) avoids references to
> potential invalid control values or properties. The last point fixes
> compiler errors reported by clang.

I'm afraid I'm still seeing compilation errors :-( Here are a few:


aarch64-buildroot-linux-gnu-g++ -Isrc/android/libcamera-hal.so.p -Isrc/android -I../../src/android -I../../include/android/hardware/libhardware/include -I../../include/android/metadata -I../../include/android/system/core/include -Iinclude -I../../include -I../../subprojects/libyuv/include -Isubprojects/libyuv/__CMake_build -I../../subprojects/libyuv/__CMake_build -Isubprojects/libyuv -I../../subprojects/libyuv -Iinclude/libcamera/ipa -Iinclude/libcamera -fdiagnostics-color=always -fsanitize=address -fno-omit-frame-pointer -Wall -Winvalid-pch -Wnon-virtual-dtor -Wextra -Werror -std=c++17 -O3 -Wshadow -include config.h -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -fPIC -DLIBCAMERA_BASE_PRIVATE -MD -MQ src/android/libcamera-hal.so.p/camera_capabilities.cpp.o -MF src/android/libcamera-hal.so.p/camera_capabilities.cpp.o.d -o src/android/libcamera-hal.so.p/camera_capabilities.cpp.o -c ../../src/android/camera_capabilities.cpp
In file included from ../../include/libcamera/camera.h:20,
                 from ../../src/android/camera_capabilities.h:17,
                 from ../../src/android/camera_capabilities.cpp:8:
In member function ‘std::optional<_Tp> libcamera::ControlList::get(const libcamera::Control<T>&) const [with T = libcamera::Size]’,
    inlined from ‘int CameraCapabilities::initializeStaticMetadata()’ at ../../src/android/camera_capabilities.cpp:1053:46:
../../include/libcamera/controls.h:381:37: error: ‘*(const unsigned int*)((char*)&<unnamed> + offsetof(std::optional<libcamera::Size>,std::optional<libcamera::Size>::<unnamed>.std::_Optional_base<libcamera::Size, true, true>::<unnamed>))’ may be used uninitialized [-Werror=maybe-uninitialized]
  381 |                         return std::nullopt;
      |                                     ^~~~~~~
../../include/libcamera/controls.h: In member function ‘int CameraCapabilities::initializeStaticMetadata()’:
../../include/libcamera/controls.h:381:37: note: ‘<anonymous>’ declared here
  381 |                         return std::nullopt;
      |                                     ^~~~~~~
In member function ‘std::optional<_Tp> libcamera::ControlList::get(const libcamera::Control<T>&) const [with T = libcamera::Size]’,
    inlined from ‘int CameraCapabilities::initializeStaticMetadata()’ at ../../src/android/camera_capabilities.cpp:1053:46:
../../include/libcamera/controls.h:381:37: error: ‘((const unsigned int*)((char*)&<unnamed> + offsetof(std::optional<libcamera::Size>,std::optional<libcamera::Size>::<unnamed>.std::_Optional_base<libcamera::Size, true, true>::_M_payload.std::_Optional_payload<libcamera::Size, true, true, true>::<unnamed>.std::_Optional_payload_base<libcamera::Size>::_M_payload)))[1]’ may be used uninitialized [-Werror=maybe-uninitialized]
  381 |                         return std::nullopt;
      |                                     ^~~~~~~
../../include/libcamera/controls.h: In member function ‘int CameraCapabilities::initializeStaticMetadata()’:
../../include/libcamera/controls.h:381:37: note: ‘<anonymous>’ declared here
  381 |                         return std::nullopt;
      |                                     ^~~~~~~


g++-10.3.1 -Isrc/android/libcamera-hal.so.p -Isrc/android -I../../src/android -I../../include/android/hardware/libhardware/include -I../../include/android/metadata -I../../include/android/system/core/include -Iinclude -I../../include -I../../subprojects/libyuv/include -Isubprojects/libyuv/__CMake_build -I../../subprojects/libyuv/__CMake_build -Isubprojects/libyuv -I../../subprojects/libyuv -Iinclude/libcamera/ipa -Iinclude/libcamera -I/usr/include/libexif -fdiagnostics-color=always -fsanitize=address -fno-omit-frame-pointer -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -Wextra -Werror -std=c++17 -O3 -Wshadow -include config.h -fPIC -DLIBCAMERA_BASE_PRIVATE -MD -MQ src/android/libcamera-hal.so.p/camera_capabilities.cpp.o -MF src/android/libcamera-hal.so.p/camera_capabilities.cpp.o.d -o src/android/libcamera-hal.so.p/camera_capabilities.cpp.o -c ../../src/android/camera_capabilities.cpp
In file included from ../../include/libcamera/camera.h:20,
                 from ../../src/android/camera_capabilities.h:17,
                 from ../../src/android/camera_capabilities.cpp:8:
../../include/libcamera/controls.h: In member function ‘int CameraCapabilities::initializeStaticMetadata()’:
../../include/libcamera/controls.h:381:16: error: ‘<anonymous>’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  381 |    return std::nullopt;
      |                ^~~~~~~
../../include/libcamera/controls.h:381:16: error: ‘*((void*)&<anonymous> +4)’ may be used uninitialized in this function [-Werror=maybe-uninitialized]


g++-8.4.0 -Isrc/ipa/raspberrypi/ipa_rpi.so.p -Isrc/ipa/raspberrypi -I../../src/ipa/raspberrypi -Iinclude -I../../include -Isrc/ipa -I../../src/ipa -I../../src/ipa/raspberrypi/controller -Iinclude/libcamera/ipa -Iinclude/libcamera -I/usr/include -fdiagnostics-color=always -fsanitize=address -fno-omit-frame-pointer -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -Wextra -Werror -std=c++17 -O3 -Wl,--start-group -lstdc++fs -Wl,--end-group -Wshadow -include config.h -fPIC -DBOOST_ALL_NO_LIB -DLIBCAMERA_BASE_PRIVATE -MD -MQ src/ipa/raspberrypi/ipa_rpi.so.p/raspberrypi.cpp.o -MF src/ipa/raspberrypi/ipa_rpi.so.p/raspberrypi.cpp.o.d -o src/ipa/raspberrypi/ipa_rpi.so.p/raspberrypi.cpp.o -c ../../src/ipa/raspberrypi/raspberrypi.cpp
../../src/ipa/raspberrypi/raspberrypi.cpp: In member function ‘void libcamera::ipa::RPi::IPARPi::reportMetadata()’:
../../src/ipa/raspberrypi/raspberrypi.cpp:520:42: error: no matching function for call to ‘libcamera::Span<const int, 4>::Span(<brace-enclosed initializer list>)’
         blackLevelStatus->black_level_b }));
                                          ^
In file included from ../../src/ipa/raspberrypi/raspberrypi.cpp:20:
../../include/libcamera/base/span.h:189:12: note: candidate: ‘constexpr libcamera::Span<T, Extent>::Span(const libcamera::Span<T, Extent>&) [with T = const int; long unsigned int Extent = 4]’
  constexpr Span(const Span &other) noexcept = default;
            ^~~~
../../include/libcamera/base/span.h:189:12: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const libcamera::Span<const int, 4>&’
../../include/libcamera/base/span.h:181:21: note: candidate: ‘template<class U, long unsigned int N> constexpr libcamera::Span<T, Extent>::Span(const libcamera::Span<U, N>&, std::enable_if_t<(std::is_convertible<_Up (*)[], _Tp (*)[]>::value && (N == Extent)), std::nullptr_t>)’
  explicit constexpr Span(const Span<U, N> &s,
                     ^~~~
../../include/libcamera/base/span.h:181:21: note:   template argument deduction/substitution failed:
../../src/ipa/raspberrypi/raspberrypi.cpp:520:42: note:   couldn't deduce template parameter ‘U’
         blackLevelStatus->black_level_b }));
                                          ^
In file included from ../../src/ipa/raspberrypi/raspberrypi.cpp:20:
../../include/libcamera/base/span.h:168:21: note: candidate: ‘template<class Container> constexpr libcamera::Span<T, Extent>::Span(const Container&, std::enable_if_t<((((! libcamera::details::is_span<Container>::value) && (! libcamera::details::is_array<Container>::value)) && (! std::is_array<_Up>::value)) && std::is_convertible<typename std::remove_pointer<decltype (libcamera::utils::data(cont))>::type (*)[], T (*)[]>::value), std::nullptr_t>)’
  explicit constexpr Span(const Container &cont,
                     ^~~~
../../include/libcamera/base/span.h:168:21: note:   template argument deduction/substitution failed:
../../src/ipa/raspberrypi/raspberrypi.cpp:520:42: note:   couldn't deduce template parameter ‘Container’
         blackLevelStatus->black_level_b }));
                                          ^
In file included from ../../src/ipa/raspberrypi/raspberrypi.cpp:20:
../../include/libcamera/base/span.h:156:21: note: candidate: ‘template<class Container> constexpr libcamera::Span<T, Extent>::Span(Container&, std::enable_if_t<((((! libcamera::details::is_span<Container>::value) && (! libcamera::details::is_array<Container>::value)) && (! std::is_array<_Up>::value)) && std::is_convertible<typename std::remove_pointer<decltype (libcamera::utils::data(cont))>::type (*)[], T (*)[]>::value), std::nullptr_t>)’
  explicit constexpr Span(Container &cont,
                     ^~~~
../../include/libcamera/base/span.h:156:21: note:   template argument deduction/substitution failed:
../../src/ipa/raspberrypi/raspberrypi.cpp:520:42: note:   couldn't deduce template parameter ‘Container’
         blackLevelStatus->black_level_b }));
                                          ^
In file included from ../../src/ipa/raspberrypi/raspberrypi.cpp:20:
../../include/libcamera/base/span.h:146:12: note: candidate: ‘template<long unsigned int N> constexpr libcamera::Span<T, Extent>::Span(const std::array<typename std::remove_cv< <template-parameter-1-1> >::type, N>&, std::enable_if_t<(std::is_convertible<typename std::remove_pointer<decltype (libcamera::utils::data(arr))>::type (*)[], T (*)[]>::value && (N == Extent)), std::nullptr_t>)’
  constexpr Span(const std::array<value_type, N> &arr,
            ^~~~
../../include/libcamera/base/span.h:146:12: note:   template argument deduction/substitution failed:
../../src/ipa/raspberrypi/raspberrypi.cpp:520:42: note:   couldn't deduce template parameter ‘N’
         blackLevelStatus->black_level_b }));
                                          ^
In file included from ../../src/ipa/raspberrypi/raspberrypi.cpp:20:
../../include/libcamera/base/span.h:136:12: note: candidate: ‘template<long unsigned int N> constexpr libcamera::Span<T, Extent>::Span(std::array<typename std::remove_cv< <template-parameter-1-1> >::type, N>&, std::enable_if_t<(std::is_convertible<typename std::remove_pointer<decltype (libcamera::utils::data(arr))>::type (*)[], T (*)[]>::value && (N == Extent)), std::nullptr_t>)’
  constexpr Span(std::array<value_type, N> &arr,
            ^~~~
../../include/libcamera/base/span.h:136:12: note:   template argument deduction/substitution failed:
../../src/ipa/raspberrypi/raspberrypi.cpp:520:42: note:   couldn't deduce template parameter ‘N’
         blackLevelStatus->black_level_b }));
                                          ^
In file included from ../../src/ipa/raspberrypi/raspberrypi.cpp:20:
../../include/libcamera/base/span.h:126:12: note: candidate: ‘template<long unsigned int N> constexpr libcamera::Span<T, Extent>::Span(libcamera::Span<T, Extent>::element_type (&)[N], std::enable_if_t<(std::is_convertible<typename std::remove_pointer<decltype (libcamera::utils::data(arr))>::type (*)[], T (*)[]>::value && (N == Extent)), std::nullptr_t>)’
  constexpr Span(element_type (&arr)[N],
            ^~~~
../../include/libcamera/base/span.h:126:12: note:   template argument deduction/substitution failed:
../../src/ipa/raspberrypi/raspberrypi.cpp:520:42: note:   mismatched types ‘int’ and ‘short unsigned int’
         blackLevelStatus->black_level_b }));
                                          ^
In file included from ../../src/ipa/raspberrypi/raspberrypi.cpp:20:
../../include/libcamera/base/span.h:120:21: note: candidate: ‘constexpr libcamera::Span<T, Extent>::Span(libcamera::Span<T, Extent>::pointer, libcamera::Span<T, Extent>::pointer) [with T = const int; long unsigned int Extent = 4; libcamera::Span<T, Extent>::pointer = const int*]’
  explicit constexpr Span(pointer first, [[maybe_unused]] pointer last)
                     ^~~~
../../include/libcamera/base/span.h:120:21: note:   candidate expects 2 arguments, 1 provided
../../include/libcamera/base/span.h:115:21: note: candidate: ‘constexpr libcamera::Span<T, Extent>::Span(libcamera::Span<T, Extent>::pointer, libcamera::Span<T, Extent>::size_type) [with T = const int; long unsigned int Extent = 4; libcamera::Span<T, Extent>::pointer = const int*; libcamera::Span<T, Extent>::size_type = long unsigned int]’
  explicit constexpr Span(pointer ptr, [[maybe_unused]] size_type count)
                     ^~~~
../../include/libcamera/base/span.h:115:21: note:   candidate expects 2 arguments, 1 provided
../../include/libcamera/base/span.h:110:12: note: candidate: ‘template<bool Dependent, class> constexpr libcamera::Span<T, Extent>::Span()’
  constexpr Span() noexcept
            ^~~~
../../include/libcamera/base/span.h:110:12: note:   template argument deduction/substitution failed:
../../src/ipa/raspberrypi/raspberrypi.cpp:520:42: note:   candidate expects 0 arguments, 1 provided
         blackLevelStatus->black_level_b }));
                                          ^

> Christian Rauch (5):
>   libcamera: controls: Use std::optional to handle invalid control
>     values
>   libcamera: ipu3: Fix rogue whitespace
>   libcamera: controls: Define size of array controls as a shape vector
>   libcamera: controls: Generate fixed- and variable-sized Span Controls
>   libcamera: controls: Apply explicit fixed-sized Span type casts
> 
>  include/libcamera/controls.h                  |  7 ++--
>  src/android/camera_capabilities.cpp           | 12 +++----
>  src/android/camera_device.cpp                 | 21 ++++++------
>  src/android/camera_hal_manager.cpp            |  2 +-
>  src/cam/main.cpp                              |  4 +--
>  src/ipa/raspberrypi/raspberrypi.cpp           | 21 ++++++------
>  src/libcamera/control_ids.yaml                |  4 +--
>  src/libcamera/pipeline/ipu3/ipu3.cpp          | 11 +++----
>  .../pipeline/raspberrypi/raspberrypi.cpp      |  9 +++---
>  src/libcamera/property_ids.yaml               |  4 +--
>  src/qcam/dng_writer.cpp                       | 22 ++++++-------
>  utils/gen-controls.py                         | 32 +++++++++++++------
>  12 files changed, 81 insertions(+), 68 deletions(-)

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list