[libcamera-devel,v2,0/5] generate and use fixed-sized Span Control types
mbox series

Message ID 20220405004215.86340-1-Rauch.Christian@gmx.de
Headers show
Series
  • generate and use fixed-sized Span Control types
Related show

Message

Christian Rauch April 5, 2022, 12:42 a.m. UTC
Hello,

This is version 2 of my fixed-sized Span patch set. The changes from version 1 include changes to the code style in "gen-controls.py" and the way how memory for default constructed fixed-sized Spans is allocated.

The default Span constructor in version 1 used a temporarily constructed "std::array<>" resulting in the Span storing a pointer to deallocated memory. Version 2 replaced this with an empty Span. In practice, this means that a Span will store its target fixed-size as the "extent" and its current storage capacity by "size_".

Best,
Christian


Christian Rauch (5):
  define Span size as shape vector
  generate fixed- and variable-sized Span Controls
  provide a default fixed-sized Span constructor
  apply clang-format style
  apply explicit fixed-sized Span type casts

 include/libcamera/base/span.h                 |  47 +++---
 include/libcamera/controls.h                  |   2 +-
 src/ipa/raspberrypi/raspberrypi.cpp           |  21 +--
 src/libcamera/control_ids.yaml                |   2 +-
 .../pipeline/raspberrypi/raspberrypi.cpp      |  36 +++--
 src/libcamera/property_ids.yaml               |   4 +-
 src/qcam/dng_writer.cpp                       | 142 +++++++++---------
 test/span.cpp                                 |   4 +-
 utils/gen-controls.py                         |  33 ++--
 9 files changed, 154 insertions(+), 137 deletions(-)

--
2.25.1

Comments

Laurent Pinchart April 5, 2022, 4:41 p.m. UTC | #1
Hi Christian,

On Tue, Apr 05, 2022 at 01:42:10AM +0100, Christian Rauch via libcamera-devel wrote:
> Hello,
> 
> This is version 2 of my fixed-sized Span patch set. The changes from
> version 1 include changes to the code style in "gen-controls.py" and
> the way how memory for default constructed fixed-sized Spans is
> allocated.
> 
> The default Span constructor in version 1 used a temporarily
> constructed "std::array<>" resulting in the Span storing a pointer to
> deallocated memory. Version 2 replaced this with an empty Span. In
> practice, this means that a Span will store its target fixed-size as
> the "extent" and its current storage capacity by "size_".

That's not how std::span<> is meant to work. Spans can have a fixed
extent or a dynamic extent, and when they have fixed extents, the number
of elements (the size) is always equal to the extent. There's no size_
member to the fixed extent span for that reason. As explained in another
e-mail in this series, I'd like to avoid departing from the std::span
API in order to be able to switch to that class in the future.

> Christian Rauch (5):
>   define Span size as shape vector
>   generate fixed- and variable-sized Span Controls
>   provide a default fixed-sized Span constructor
>   apply clang-format style
>   apply explicit fixed-sized Span type casts
> 
>  include/libcamera/base/span.h                 |  47 +++---
>  include/libcamera/controls.h                  |   2 +-
>  src/ipa/raspberrypi/raspberrypi.cpp           |  21 +--
>  src/libcamera/control_ids.yaml                |   2 +-
>  .../pipeline/raspberrypi/raspberrypi.cpp      |  36 +++--
>  src/libcamera/property_ids.yaml               |   4 +-
>  src/qcam/dng_writer.cpp                       | 142 +++++++++---------
>  test/span.cpp                                 |   4 +-
>  utils/gen-controls.py                         |  33 ++--
>  9 files changed, 154 insertions(+), 137 deletions(-)
> 
> --
> 2.25.1