Skip to content
This repository was archived by the owner on Oct 30, 2026. It is now read-only.

Struct array fields read as live views and check assignments - #45

Merged
bdbarnett merged 3 commits into
mainfrom
fix/struct-arrays
Oct 27, 2026
Merged

bdbarnett merged 3 commits into
mainfrom
fix/struct-arrays

Conversation

@bdbarnett

Copy link
Copy Markdown
Contributor

Fixes #38.

Fixed-size struct arrays inside a struct now read as a live view, on both runtimes. Examples are draw_triangle_dsc_t.p, grad_dsc_t.stops, inv_areas and recognizers. Before, MicroPython handed back a copy, so item writes were lost. CPython handed back an opaque Blob with no length.

You can index the view, take its len(), iterate over it, and write an element by attribute, by struct or by dict. You can also assign the whole field from a list of exactly N items, or from a buffer of exactly the field's size. A wrong length or a bad item raises, and the field is left unchanged. An index past the end raises IndexError. A view keeps its owner alive across gc.collect().

The new smoke test test_struct_array_fields failed on main before this change:

  • MicroPython: struct array item writes were lost: [(0.0,0.0)...]
  • CPython: object of type 'lvgl.Blob' has no len()

With this change it passes on MicroPython and CPython locally, and lvgl-python's unittests pass. pytest (107) passes and regenerate_all.sh --check matches.

draw_triangle_dsc_t.p, grad_dsc_t.stops and the other struct-array
fields now index, write through and take len() on every interpreter.
MicroPython returned a list of copies, so writes were lost; CPython
returned a Blob, and assigning a list memcpy'd from NULL. Whole-array
assignment takes exactly N structs or dicts, or a buffer of the array's
size, and otherwise raises and leaves the field unchanged. Fixes #38.
@bdbarnett
bdbarnett merged commit 3f4fdf3 into main Oct 27, 2026
4 checks passed
@bdbarnett
bdbarnett deleted the fix/struct-arrays branch October 27, 2026 16:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Fixed-size struct arrays (draw_triangle_dsc_t.p, grad_dsc_t.stops) can't be indexed; list assignment segfaults CPython

1 participant