Skip to content

line.set_points takes a list of points or a packed buffer on every interpreter - #44

Merged
bdbarnett merged 1 commit into
mainfrom
fix/line-points
Oct 27, 2026
Merged

bdbarnett merged 1 commit into
mainfrom
fix/line-points

Conversation

@bdbarnett

Copy link
Copy Markdown
Contributor

Fixes #37.

line.set_points(points, n) now takes the same arguments on MicroPython, CircuitPython and CPython: a list or tuple of points (point_precise_t structs or dicts), or a packed buffer.

  • CPython used to lower a const T name[] struct-array parameter to a raw pointer, so a list was refused. It now converts a list or tuple into a C array. Because LVGL keeps the pointer (lv_line_set_points never copies), the array, or the buffer you passed, is retained on the widget under a per-function key, the same way string-array arguments already are. A repeat call releases the previous one. This also applies to indev.set_button_points and to grad_init_stops's colours.
  • MicroPython and CircuitPython iterated a bytearray element by element as ints. bytes, bytearray and memoryview now pass straight through as the C array, which is what a packed buffer means.

Non-const struct arrays such as lv_obj_transform_point_array, which LVGL writes into, keep the buffer-only lowering on CPython, because a copied list would silently drop those writes.

Test

A new smoke case, test_line_points_list_and_buffer, draws the same line from a list of dicts, a list of structs, a tuple and a packed buffer. It collects garbage before layout, checks that all four give the same size, and checks that a bad item still raises.

Before this change:

  • pydevices-lvgl 9.5.52 on CPython: line.set_points rejected a list of dicts: TypeError: Cannot convert 'list' to pointer
  • MicroPython unix: line.set_points rejected a packed buffer: SyntaxError: Can't convert int to lv_point_precise_t!

After this change, built locally the way the Linux integration job builds them, the full smoke run passes on:

  • MicroPython v1.29.0 unix with lvgl-micropython at its pin
  • lvgl-python at its pin, synced from this commit on CPython 3.12, where its unit tests also pass

The generator tests (107) and regenerate_all.sh --check pass. CircuitPython is left to the integration job.

CPython lowered a const struct array to a raw pointer, so a list was
refused; it now converts a list or tuple of structs or dicts into a C
array, retained on the widget because LVGL keeps the pointer. MicroPython
iterated a bytearray as ints; bytes, bytearray and memoryview now pass
through as the C array. Fixes #37.
@bdbarnett
bdbarnett merged commit 752fb12 into main Oct 27, 2026
4 checks passed
@bdbarnett
bdbarnett deleted the fix/line-points branch October 27, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

lv.line.set_points takes different arguments on MicroPython and CPython

1 participant