Skip to content

fix(gen): support MicroPython's renamed mp_obj_int_to_bytes() API - #411

Open
andrewleech wants to merge 1 commit into
lvgl:masterfrom
andrewleech:fix/mp-obj-int-to-bytes
Open

fix(gen): support MicroPython's renamed mp_obj_int_to_bytes() API#411
andrewleech wants to merge 1 commit into
lvgl:masterfrom
andrewleech:fix/mp-obj-int-to-bytes

Conversation

@andrewleech

@andrewleech andrewleech commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

MicroPython commit e00daa3a ("py/binary,objint: Add overflow checks and int.to_bytes(signed=True)") renamed mp_obj_int_to_bytes_impl() to mp_obj_int_to_bytes() and changed its signature, adding is_signed and overflow_check parameters. The generated binding calls this helper in mp_obj_get_ull(), so building against MicroPython 1.29 or later fails to link with undefined reference to 'mp_obj_int_to_bytes_impl'.

This guards the call on MICROPY_VERSION >= MICROPY_MAKE_VERSION(1, 29, 0), calling the new API on 1.29+ and the old one on earlier versions. The reverse helper mp_obj_int_from_bytes_impl() was not renamed and is unchanged.

lv_micropython merges the upstream MicroPython master that carries the rename, so it needs the same fix: lvgl/lv_micropython#106.

Testing

Built the binding into a MicroPython firmware for an i.MX RT1176 board (mimxrt port, arm-none-eabi) against a 1.29 MicroPython: it links, and mp_obj_get_ull() compiles the mp_obj_int_to_bytes() call. The pre-1.29 branch of the guard was checked by preprocessing against a 1.24 header, which selects the old call.

I did not test the unix port.

Generative AI

I used generative AI tools when creating this PR, but a human has checked the code and is responsible for the code and the description above.

MicroPython commit e00daa3a ("py/binary,objint: Add overflow checks and
int.to_bytes(signed=True)") renamed mp_obj_int_to_bytes_impl() to
mp_obj_int_to_bytes() with a new signature (adding is_signed and
overflow_check parameters), for the 1.29 release. The generated binding
called the old name unconditionally in mp_obj_get_ull(), so building against
1.29 or later failed to link with an undefined reference to
mp_obj_int_to_bytes_impl.

Guard the call on MICROPY_VERSION so the binding builds against both APIs.
@andrewleech
andrewleech force-pushed the fix/mp-obj-int-to-bytes branch from 9a4d2d1 to 5309970 Compare July 20, 2026 03:14
@o-murphy

Copy link
Copy Markdown

Confirming independent testing on the unix port (you noted you hadn't tried it): rebuilt ports/unix against current MicroPython master (5aaa6d17) via USER_C_MODULES with this exact fix applied - builds clean, import lvgl works, and a smoke test creating obj/button/label with add_event_cb/send_event runs correctly end to end. The #if MICROPY_VERSION >= MICROPY_MAKE_VERSION(1, 29, 0) guard is the right call - I'd independently landed on the same mp_obj_int_to_bytes(obj, sizeof(val), (byte*)&val, big_endian, false, false) replacement call but without the backward-compat guard, so this version is the better fix.

Side note: this is very likely also why the tests/api CI jobs (basic.py, basic_indev.py, basic_slider.py) have been failing on master since run 28447459670 (2026-06-30, six days after the breaking MicroPython commit) - same root cause, worth a rebase/rerun once this merges to confirm.

@o-murphy

Copy link
Copy Markdown

@andrewleech @pi-anl

Confirming this also fixes the unix port, since the description notes it wasn't tested there.

Applied the same guard to gen/gen_mpy.py and gen/lv_mpy_example.c and built ports/unix as a USER_C_MODULES usermod against a current MicroPython checkout (sys.implementation.version == (1, 29, 0, 'preview')), which is right at the MICROPY_VERSION >= MICROPY_MAKE_VERSION(1, 29, 0) boundary this PR adds, so the new mp_obj_int_to_bytes() branch is the one actually compiled and exercised, not the old one.

Built and ran it repeatedly (dozens of rebuilds over the last day), including live LVGL UI code -- buttons, labels, style colors, indev state -- that routes through mp_obj_get_ull() in the generated binding. No link errors, no runtime issues.

So: confirmed working on unix in addition to the mimxrt testing already in the description.

@o-murphy

Copy link
Copy Markdown

Confirming this also fixes the unix port (the description notes it wasn't tested there): built ports/unix as a USER_C_MODULES usermod against a current MicroPython checkout (sys.implementation.version == (1, 29, 0, 'preview')), right at the MICROPY_VERSION >= MICROPY_MAKE_VERSION(1, 29, 0) boundary this PR adds, so the new mp_obj_int_to_bytes() branch is the one actually compiled and exercised. Built and ran it repeatedly over the last few days, including real LVGL UI code (buttons, labels, style colors, indev state) that routes through mp_obj_get_ull() in the generated binding - no link errors, no runtime issues.

Worth calling out how live this bug currently is: CI on master is failing this exact way on all four ports right now - run 30154151496, 4 days ago, unix/stm32/rp2/esp32 all hit implicit declaration of function 'mp_obj_int_to_bytes'; did you mean 'mp_obj_int_to_bytes_impl'?. That run was even built against 7ee268e ("fix: update mp_obj_int_to_bytes implementation for correct byte conversion"), a different attempt at this same problem - it doesn't actually resolve it, same error either way. None of this shows up as red because the workflow sets continue-on-error: true per job.

We've got a follow-up PR (#413) building on top of this one - adds LVGL's native Wayland driver, and separately fixes a regression that's kept every desktop window driver (SDL included) out of the Python bindings since May. Rebasing that once this lands.

@andrewleech
andrewleech marked this pull request as ready for review July 29, 2026 20:32

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants