Skip to content

Commit 1d95f35

Browse files
committed
extmod/modmachine: Use sys.exit as implementation of machine.soft_reset.
It does the same thing, raising `SystemExit`. Signed-off-by: Damien George <damien@micropython.org>
1 parent 8528d83 commit 1d95f35

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

extmod/modmachine.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* THE SOFTWARE.
2525
*/
2626

27+
#include "py/builtin.h"
2728
#include "py/runtime.h"
2829

2930
#if MICROPY_PY_MACHINE
@@ -35,6 +36,10 @@
3536
#include "drivers/dht/dht.h"
3637
#endif
3738

39+
#if !MICROPY_PY_SYS_EXIT
40+
#error MICROPY_PY_MACHINE requires MICROPY_PY_SYS_EXIT
41+
#endif
42+
3843
// The port must provide implementations of these low-level machine functions.
3944

4045
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);
6166
#include MICROPY_PY_MACHINE_INCLUDEFILE
6267
#endif
6368

64-
static mp_obj_t machine_soft_reset(void) {
65-
mp_raise_type(&mp_type_SystemExit);
66-
}
67-
static MP_DEFINE_CONST_FUN_OBJ_0(machine_soft_reset_obj, machine_soft_reset);
68-
6969
#if MICROPY_PY_MACHINE_BOOTLOADER
7070
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
7171
mp_machine_bootloader(n_args, args);
@@ -156,7 +156,7 @@ static const mp_rom_map_elem_t machine_module_globals_table[] = {
156156
#endif
157157

158158
// Reset related functions.
159-
{ MP_ROM_QSTR(MP_QSTR_soft_reset), MP_ROM_PTR(&machine_soft_reset_obj) },
159+
{ MP_ROM_QSTR(MP_QSTR_soft_reset), MP_ROM_PTR(&mp_sys_exit_obj) },
160160
#if MICROPY_PY_MACHINE_BOOTLOADER
161161
{ MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&machine_bootloader_obj) },
162162
#endif

py/builtin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ MP_DECLARE_CONST_FUN_OBJ_2(mp_op_getitem_obj);
126126
MP_DECLARE_CONST_FUN_OBJ_3(mp_op_setitem_obj);
127127
MP_DECLARE_CONST_FUN_OBJ_2(mp_op_delitem_obj);
128128

129+
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_exit_obj);
130+
129131
// Modules needed by the runtime.
130132
extern const mp_obj_dict_t mp_module_builtins_globals;
131133
extern const mp_obj_module_t mp_module___main__;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy