From 5f3ecc29f8f0d69d15710ded3278fe055f532517 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 18 Jul 2024 13:24:27 +1000 Subject: [PATCH] extmod/modmachine: Use sys.exit as implementation of machine.soft_reset. It does the same thing, raising `SystemExit`. Signed-off-by: Damien George --- extmod/modmachine.c | 12 ++++++------ py/builtin.h | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/extmod/modmachine.c b/extmod/modmachine.c index a423d8067c..5906835949 100644 --- a/extmod/modmachine.c +++ b/extmod/modmachine.c @@ -24,6 +24,7 @@ * THE SOFTWARE. */ +#include "py/builtin.h" #include "py/runtime.h" #if MICROPY_PY_MACHINE @@ -35,6 +36,10 @@ #include "drivers/dht/dht.h" #endif +#if !MICROPY_PY_SYS_EXIT +#error MICROPY_PY_MACHINE requires MICROPY_PY_SYS_EXIT +#endif + // The port must provide implementations of these low-level machine functions. static void mp_machine_idle(void); @@ -61,11 +66,6 @@ NORETURN static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args); #include MICROPY_PY_MACHINE_INCLUDEFILE #endif -static mp_obj_t machine_soft_reset(void) { - mp_raise_type(&mp_type_SystemExit); -} -static MP_DEFINE_CONST_FUN_OBJ_0(machine_soft_reset_obj, machine_soft_reset); - #if MICROPY_PY_MACHINE_BOOTLOADER NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) { mp_machine_bootloader(n_args, args); @@ -156,7 +156,7 @@ static const mp_rom_map_elem_t machine_module_globals_table[] = { #endif // Reset related functions. - { MP_ROM_QSTR(MP_QSTR_soft_reset), MP_ROM_PTR(&machine_soft_reset_obj) }, + { MP_ROM_QSTR(MP_QSTR_soft_reset), MP_ROM_PTR(&mp_sys_exit_obj) }, #if MICROPY_PY_MACHINE_BOOTLOADER { MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&machine_bootloader_obj) }, #endif diff --git a/py/builtin.h b/py/builtin.h index 81d0789802..6efe3e8fac 100644 --- a/py/builtin.h +++ b/py/builtin.h @@ -126,6 +126,8 @@ MP_DECLARE_CONST_FUN_OBJ_2(mp_op_getitem_obj); MP_DECLARE_CONST_FUN_OBJ_3(mp_op_setitem_obj); MP_DECLARE_CONST_FUN_OBJ_2(mp_op_delitem_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_exit_obj); + // Modules needed by the runtime. extern const mp_obj_dict_t mp_module_builtins_globals; extern const mp_obj_module_t mp_module___main__;