diff options
| author | Damien George <damien@micropython.org> | 2024-07-18 13:20:31 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2024-07-20 12:13:14 +1000 |
| commit | 69c25ea8653566ec97690b5121bd10b753c89426 (patch) | |
| tree | f7994c218eebafb78ecd2e0e05a8c7e341523068 /ports/unix/modmachine.c | |
| parent | a734ee9057a760b0316eca110d71db1524142fec (diff) | |
shared/runtime/pyexec: Make a raised SystemExit always do a forced exit.
The current situation with SystemExit and soft reset is the following:
- `sys.exit()` follows CPython and just raises `SystemExit`.
- On the unix port, raising `SystemExit` quits the application/MicroPython,
whether at the REPL or in code (this follows CPython behaviour).
- On bare-metal ports, raising `SystemExit` at the REPL does nothing,
raising it in code will stop the code and drop into the REPL.
- `machine.soft_reset()` raises `SystemExit` but with a special flag set,
and bare-metal targets check this flag when it propagates to the
top-level and do a soft reset when they receive it.
The original idea here was that a bare-metal target can't "quit" like the
unix port can, and so dropping to the REPL was considered the same as
"quit". But this bare-metal behaviour is arguably inconsistent with unix,
and "quit" should mean terminate everything, including REPL access.
This commit changes the behaviour to the following, which is more
consistent:
- Raising `SystemExit` on a bare-metal port will do a soft reset (unless
the exception is caught by the application).
- `machine.soft_reset()` is now equivalent to `sys.exit()`.
- unix port behaviour remains unchanged.
Tested running the test suite on an stm32 board and everything still
passes, in particular tests that skip by raising `SystemExit` still
correctly skip.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'ports/unix/modmachine.c')
| -rw-r--r-- | ports/unix/modmachine.c | 3 |
1 files changed, 0 insertions, 3 deletions
diff --git a/ports/unix/modmachine.c b/ports/unix/modmachine.c index 6f3ab8094..d1cdbe861 100644 --- a/ports/unix/modmachine.c +++ b/ports/unix/modmachine.c @@ -36,9 +36,6 @@ #define MICROPY_PAGE_MASK (MICROPY_PAGE_SIZE - 1) #endif -// This variable is needed for machine.soft_reset(), but the variable is otherwise unused. -int pyexec_system_exit = 0; - uintptr_t mod_machine_mem_get_addr(mp_obj_t addr_o, uint align) { uintptr_t addr = mp_obj_get_int_truncated(addr_o); if ((addr & (align - 1)) != 0) { |
