uUR: build on MicroPython 1.27 while keeping pre-1.19 (MaixPy) support#3
Merged
Merged
Conversation
The uUR binding uses the pre-v1.19 MicroPython C API, so it does not compile on MicroPython >= 1.19 (e.g. 1.27). Support both the modern and the pre-1.19 (MaixPy-era, used by Krux) API in a single file. MicroPython's v1.19 "type slots" refactor changed three things the binding uses: type definitions (flat struct -> MP_DEFINE_CONST_OBJ_TYPE), finaliser allocation (m_new_obj_with_finaliser -> mp_obj_malloc_with_finaliser), and MP_REGISTER_MODULE arity (3 args -> 2). uUR.c: - MP_ERROR_TEXT: #ifndef fallback to the raw string on builds that predate it. - Finaliser: define mp_obj_malloc_with_finaliser in terms of the legacy m_new_obj_with_finaliser when absent, so the call sites use one spelling. - Type definitions and MP_REGISTER_MODULE: #if defined(MP_DEFINE_CONST_OBJ_TYPE) selects modern vs legacy; the legacy branch is the existing code verbatim. - The unused result / expected_part_count / processed_parts_count method objects (these values are exposed as attributes) compile only on the legacy path; newer toolchains reject them under -Werror=unused-const-variable. CMakeLists.txt (ESP-IDF component): - Add src/types/bip39.c, which uUR.c references but was missing from SRCS. - REQUIRES mbedtls only; mbedtls_compat is absent on ESP-IDF 5.5.x, and tests/esp-idf-smoke already requires only mbedtls. The legacy (< v1.19) path is unchanged from the current code. Verified building on MicroPython 1.27 / ESP-IDF 5.5.x (ESP32-P4); uUR.URDecoder decodes a multi-part crypto-psbt UR to the expected CBOR on-device. Co-Authored-By: kdmukai <934746+kdmukai@users.noreply.github.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The uUR binding uses the pre-v1.19 MicroPython C API, so it does not compile on
MicroPython >= 1.19 (e.g. 1.27). This makes it build on both the modern and the
pre-1.19 (MaixPy-era, used by Krux) API in a single file.
MicroPython's v1.19 "type slots" refactor changed three things the binding uses:
type definitions (flat struct ->
MP_DEFINE_CONST_OBJ_TYPE), finaliserallocation (
m_new_obj_with_finaliser->mp_obj_malloc_with_finaliser), andMP_REGISTER_MODULEarity (3 args -> 2).uUR.c:
MP_ERROR_TEXT:#ifndeffallback to the raw string on builds that predate it.mp_obj_malloc_with_finaliserin terms of the legacym_new_obj_with_finaliserwhen absent, so the call sites use one spelling.MP_REGISTER_MODULE:#if defined(MP_DEFINE_CONST_OBJ_TYPE)selects modern vs legacy; the legacy branch is the existing code verbatim.
result/expected_part_count/processed_parts_countmethodobjects (these values are exposed as attributes) compile only on the legacy
path; newer toolchains reject them under
-Werror=unused-const-variable.CMakeLists.txt (ESP-IDF component):
src/types/bip39.c, which uUR.c references but was missing from SRCS.mbedtlsonly.mbedtls_compatis absent on ESP-IDF 5.5.x, andtests/esp-idf-smokealready requires onlymbedtls.The legacy (< v1.19) path is unchanged from the current code, so existing
consumers are unaffected.
Tested: builds on MicroPython 1.27 with ESP-IDF 5.5.x (ESP32-P4);
uUR.URDecoderdecodes a multi-part crypto-psbt UR to the expected CBOR on-device. Not built
against a pre-v1.19 MicroPython — cUR's CI does not build uUR.c today (it is
clang-format checked only; the
pcandesp-idfjobs build the C library). Ajob compiling uUR.c as a USER_C_MODULE against a modern and a pre-v1.19
MicroPython would cover both paths.