diff options
| author | Andrew Leech <andrew.leech@planetinnovation.com.au> | 2025-11-05 16:35:31 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-11-22 00:06:59 +1100 |
| commit | 5f815b8a2d15a31298386d58eff5ac3c4d0fba92 (patch) | |
| tree | a9613311fa438272f5a9fe443d909f4b6e8e3ce5 /shared/runtime/pyexec.c | |
| parent | fd1ddc3f12b40e99faaf24dd099fd512fddcb62c (diff) | |
unix: Enable exit code handling for sys.exit().
Enable `MICROPY_PYEXEC_ENABLE_EXIT_CODE_HANDLING` to propagate `sys.exit()`
exit codes properly. Update `convert_pyexec_result()` to handle return
values where pyexec returns the exit code with `PYEXEC_FORCED_EXIT` flag
set for `SystemExit`. Extract the exit code from the lower 8 bits when the
flag is set, otherwise return as-is (0 for success, 1 for exception).
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Diffstat (limited to 'shared/runtime/pyexec.c')
| -rw-r--r-- | shared/runtime/pyexec.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/shared/runtime/pyexec.c b/shared/runtime/pyexec.c index d2a1403e3..428cc95b2 100644 --- a/shared/runtime/pyexec.c +++ b/shared/runtime/pyexec.c @@ -165,6 +165,7 @@ static int parse_compile_execute(const void *source, mp_parse_input_kind_t input #endif if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(((mp_obj_base_t *)nlr.ret_val)->type), MP_OBJ_FROM_PTR(&mp_type_SystemExit))) { // system exit #if MICROPY_PYEXEC_ENABLE_EXIT_CODE_HANDLING + // None is an exit value of 0; an int is its value; anything else is 1 mp_obj_t val = mp_obj_exception_get_value(MP_OBJ_FROM_PTR(nlr.ret_val)); if (val != mp_const_none) { if (mp_obj_is_int(val)) { |
