← index #17547Issue #17415
Related · medium · value 2.130
QUERY · ISSUE

mpy-cross: Assertion failed when compiling tests/basics/exception_chain.py.

openby agattiopened 2025-06-22updated 2025-12-23
bug

Port, board and/or hardware

Unix on Linux/amd64

MicroPython version

MicroPython v1.26.0-preview.261.gbcc8d4ee1.dirty on 2025-06-22; linux [GCC 15.1.1] version

Reproduction

  1. Build mpy-cross with no special flags (make -C mpy-cross clean && make -C mpy-cross)
  2. Compile tests/basics/exception_chain.py into native code (arch does not matter) with mpy-cross -X emit=native -march=debug tests/basics/exception_chain.py
  3. mpy-cross will crash.

Expected behaviour

Compiling tests/basics/exception_chain.py should not crash mpy-cross.

Observed behaviour

mpy-cross crashes with:

mpy-cross: ../py/emitnative.c:2947: emit_native_raise_varargs: Assertion `n_args == 1' failed.`

Additional Information

If having a multi-arg exception is not supported for native code compilation, then an error message should be printed rather than crashing the compiler.

Code of Conduct

Yes, I agree

CANDIDATE · ISSUE

Native & viper failures with setjmp exception handling

openby jepleropened 2025-06-02updated 2025-06-04
bug

Port, board and/or hardware

unix

MicroPython version

MicroPython v1.26.0-preview.169.g429478dcfc.dirty on 2025-06-02; linux [GCC 12.2.0] version
(modified from v1.26.0-preview-166-gc0111e63b3)

Reproduction

  1. grab my branch at https://github.com/jepler/circuitpython/tree/coverage-setjmp
  2. in ports/unix make VARIANT=coverage_setjmp test

Expected behaviour

Expected all tests to pass

Observed behaviour

The native_gen.py test fails with a segfault. This is the minimized version of the crashing code:

# catching an exception from .throw()
@micropython.native
def gen3():
    try:
        yield 1
    except Exception as er:
        print("caught", repr(er))


g = gen3()
print(g.throw(ValueError(42)))

Additional Information

The branch above has 3 changes:

  • introduce a unix variant that uses setjmp for exception handling
  • fix a build error in mp_native_yield_from
  • turns on N_NLR_SETJMP in emitnative whenever MICROPY_NLR_SETJMP is enabled and N_NLR_SETJMP is not otherwise used (note: this fixes other errors in make test that occur with MICROPY_NLR_SETJMP enabled)

It is vaguely possible that my change in mp_native_yield_from is wrong and I considered whether it might contribute to the crash, but in my reduced testcase a gdb breakpoint on that function isn't hit so I don't think that's it.

Code of Conduct

Yes, I agree

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied