treewide: rework struct gpiod_line_bulk
authorBartosz Golaszewski <bgolaszewski@baylibre.com>
Tue, 20 Oct 2020 12:56:10 +0000 (12:56 +0000)
committerBartosz Golaszewski <bgolaszewski@baylibre.com>
Wed, 4 Nov 2020 15:39:09 +0000 (16:39 +0100)
commit2b02d7ae1aa6cb5165a1bcd4f90db19a2bb1beb5
tree9e0f50f0b6d933a5284ee5031679146a77f0f8f0
parentda8b32402e5221eef3b350b59c2061c78e8d7587
treewide: rework struct gpiod_line_bulk

Current implementation of struct gpiod_line_bulk uses stack memory
excessively. The structure is big: it's an array 64 pointers + 4 bytes
size. That amounts to 260 bytes on 32-bit and 516 bytes on 64-bit
architectures respectively. It's also used everywhere as all functions
dealing with single lines eventually end up calling bulk counterparts.

The rework addresses it by making the bulk structure opaque and
providing appropriate interfaces for library users while retaining a way
for internal users to allocate single line bulks on the stack.

The macro-based loop has been removed. In its place we provide a function
iterating over all lines held by a bulk and calling the provided callback
function for each line.

Since bulk operations can now fail, a bunch of test-cases has been added
to cover the relevant code.

While at it: using the word offset both when referring to line's HW
offset in a chip as well as the offset in a bulk leads to confusion.
This patch renames the bulk offset to index.

Some additional improvements to the patch by:
  Kent Gibson <warthog618@gmail.com>

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
13 files changed:
bindings/cxx/gpiod.hpp
bindings/cxx/line_bulk.cpp
bindings/python/gpiodmodule.c
include/gpiod.h
lib/core.c
lib/ctxless.c
lib/helpers.c
tests/Makefile.am
tests/gpiod-test.h
tests/tests-bulk.c [new file with mode: 0644]
tests/tests-chip.c
tests/tests-event.c
tests/tests-line.c