QUERY · ISSUE
Binary operations on undefined variables crash the native emitter.
bug
Port, board and/or hardware
unix
MicroPython version
MicroPython v1.24.0-preview.206.ge9814e987.dirty on 2024-08-16; linux [GCC 14.2.1] version
Reproduction
Run the following code:
@micropython.native
def f():
a += 0 # Or anything else, really
f()
Expected behaviour
A NameError exception should be raised. (CPython raises NameError: name 'a' is not defined)
Observed behaviour
This is the backtrace of the crash when running the interpreter under GDB:
Program received signal SIGSEGV, Segmentation fault.
mp_obj_get_type (o_in=o_in@entry=0x0) at ../../py/obj.c:61
61 return o->type;
(gdb) bt
#0 mp_obj_get_type (o_in=o_in@entry=0x0) at ../../py/obj.c:61
#1 0x0000555555591333 in mp_binary_op (op=MP_BINARY_OP_INPLACE_ADD, lhs=0x0, rhs=0x1) at ../../py/runtime.c:630
#2 0x00007ffff7fc0053 in ?? ()
#3 0x00007ffff7a06440 in ?? ()
#4 0x00007ffff7fc006d in ?? ()
#5 0x00007fffffff9610 in ?? ()
#6 0x0000000000000003 in ?? ()
#7 0x00007fffffff9760 in ?? ()
#8 0x0000000000000000 in ?? ()
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree
CANDIDATE · ISSUE
mpy-cross: Assertion failed when compiling tests/basics/exception_chain.py.
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
- Build mpy-cross with no special flags (
make -C mpy-cross clean && make -C mpy-cross) - Compile
tests/basics/exception_chain.pyinto native code (arch does not matter) withmpy-cross -X emit=native -march=debug tests/basics/exception_chain.py mpy-crosswill 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