Skip to content

Commit fb36eab

Browse files
pi-anlandrewleech
authored andcommitted
ports/all: Run atexit during soft-reset.
Signed-off-by: Andrew Leech <andrew@alelec.net>
1 parent a952fe1 commit fb36eab

File tree

11 files changed

+48
-4
lines changed

11 files changed

+48
-4
lines changed

ports/esp32/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "py/repl.h"
5050
#include "py/gc.h"
5151
#include "py/mphal.h"
52+
#include "py/objmodule.h"
5253
#include "shared/readline/readline.h"
5354
#include "shared/runtime/pyexec.h"
5455
#include "shared/timeutils/timeutils.h"
@@ -182,6 +183,10 @@ void mp_task(void *pvParameter) {
182183
mp_thread_deinit();
183184
#endif
184185

186+
#if MICROPY_PY_SYS_ATEXIT
187+
mp_sys_atexit_execute();
188+
#endif
189+
185190
gc_sweep_all();
186191

187192
// Free any native code pointers that point to iRAM.

ports/esp8266/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "py/mperrno.h"
3636
#include "py/mphal.h"
3737
#include "py/gc.h"
38+
#include "py/objmodule.h"
3839

3940
#include "extmod/misc.h"
4041
#include "extmod/modmachine.h"
@@ -88,6 +89,9 @@ static void mp_reset(void) {
8889
}
8990

9091
void soft_reset(void) {
92+
#if MICROPY_PY_SYS_ATEXIT
93+
mp_sys_atexit_execute();
94+
#endif
9195
gc_sweep_all();
9296
mp_hal_stdout_tx_str("MPY: soft reboot\r\n");
9397
mp_hal_delay_us(10000); // allow UART to flush output

ports/mimxrt/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "py/gc.h"
3131
#include "py/mperrno.h"
3232
#include "py/stackctrl.h"
33+
#include "py/objmodule.h"
3334
#include "shared/readline/readline.h"
3435
#include "shared/runtime/gchelper.h"
3536
#include "shared/runtime/pyexec.h"
@@ -159,6 +160,9 @@ int main(void) {
159160
machine_uart_deinit_all();
160161
machine_pwm_deinit_all();
161162
soft_timer_deinit();
163+
#if MICROPY_PY_SYS_ATEXIT
164+
mp_sys_atexit_execute();
165+
#endif
162166
gc_sweep_all();
163167
mp_deinit();
164168
}

ports/nrf/main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "py/lexer.h"
3636
#include "py/parse.h"
3737
#include "py/obj.h"
38+
#include "py/objmodule.h"
3839
#include "py/runtime.h"
3940
#include "py/stackctrl.h"
4041
#include "py/gc.h"
@@ -292,6 +293,11 @@ void NORETURN _start(void) {
292293
pwm_deinit_all();
293294
#endif
294295

296+
#if MICROPY_PY_SYS_ATEXIT
297+
mp_sys_atexit_execute();
298+
#endif
299+
300+
gc_sweep_all();
295301
mp_deinit();
296302

297303
printf("MPY: soft reboot\n");

ports/qemu/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "py/stackctrl.h"
3232
#include "py/gc.h"
3333
#include "py/mperrno.h"
34+
#include "py/objmodule.h"
3435
#include "shared/runtime/gchelper.h"
3536
#include "shared/runtime/pyexec.h"
3637

@@ -60,6 +61,9 @@ int main(int argc, char **argv) {
6061

6162
mp_printf(&mp_plat_print, "MPY: soft reboot\n");
6263

64+
#if MICROPY_PY_SYS_ATEXIT
65+
mp_sys_atexit_execute();
66+
#endif
6367
gc_sweep_all();
6468
mp_deinit();
6569
}

ports/renesas-ra/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "py/gc.h"
3434
#include "py/mperrno.h"
3535
#include "py/mphal.h"
36+
#include "py/objmodule.h"
3637
#include "shared/readline/readline.h"
3738
#include "shared/runtime/pyexec.h"
3839
#include "shared/runtime/softtimer.h"
@@ -435,6 +436,10 @@ int main(void) {
435436
pyb_thread_deinit();
436437
#endif
437438

439+
#if MICROPY_PY_SYS_ATEXIT
440+
mp_sys_atexit_execute();
441+
#endif
442+
438443
MICROPY_BOARD_END_SOFT_RESET(&state);
439444

440445
gc_sweep_all();

ports/rp2/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "py/gc.h"
3333
#include "py/mperrno.h"
3434
#include "py/mphal.h"
35+
#include "py/objmodule.h"
3536
#include "extmod/modbluetooth.h"
3637
#include "extmod/modnetwork.h"
3738
#include "shared/readline/readline.h"
@@ -241,6 +242,9 @@ int main(int argc, char **argv) {
241242
#if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
242243
mp_usbd_deinit();
243244
#endif
245+
#if MICROPY_PY_SYS_ATEXIT
246+
mp_sys_atexit_execute();
247+
#endif
244248

245249
// Hook for resetting anything right at the end of a soft reset command.
246250
MICROPY_BOARD_END_SOFT_RESET();

ports/samd/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "py/gc.h"
3030
#include "py/mperrno.h"
3131
#include "py/stackctrl.h"
32+
#include "py/objmodule.h"
3233
#include "shared/readline/readline.h"
3334
#include "shared/runtime/gchelper.h"
3435
#include "shared/runtime/pyexec.h"
@@ -98,6 +99,9 @@ void samd_main(void) {
9899
#if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
99100
mp_usbd_deinit();
100101
#endif
102+
#if MICROPY_PY_SYS_ATEXIT
103+
mp_sys_atexit_execute();
104+
#endif
101105
gc_sweep_all();
102106
#if MICROPY_PY_MACHINE_I2C || MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_UART
103107
sercom_deinit_all();

ports/stm32/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "py/gc.h"
3333
#include "py/mperrno.h"
3434
#include "py/mphal.h"
35+
#include "py/objmodule.h"
3536
#include "shared/readline/readline.h"
3637
#include "shared/runtime/pyexec.h"
3738
#include "shared/runtime/softtimer.h"
@@ -698,6 +699,10 @@ void stm32_main(uint32_t reset_mode) {
698699
MP_STATE_PORT(pyb_stdio_uart) = NULL;
699700
#endif
700701

702+
#if MICROPY_PY_SYS_ATEXIT
703+
mp_sys_atexit_execute();
704+
#endif
705+
701706
MICROPY_BOARD_END_SOFT_RESET(&state);
702707

703708
gc_sweep_all();

ports/unix/main.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "py/builtin.h"
4444
#include "py/repl.h"
4545
#include "py/gc.h"
46+
#include "py/objmodule.h"
4647
#include "py/objstr.h"
4748
#include "py/cstack.h"
4849
#include "py/mphal.h"
@@ -753,10 +754,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
753754
#endif
754755

755756
#if MICROPY_PY_SYS_ATEXIT
756-
// Beware, the sys.settrace callback should be disabled before running sys.atexit.
757-
if (mp_obj_is_callable(MP_STATE_VM(sys_exitfunc))) {
758-
mp_call_function_0(MP_STATE_VM(sys_exitfunc));
759-
}
757+
mp_sys_atexit_execute();
760758
#endif
761759

762760
#if MICROPY_PY_MICROPYTHON_MEM_INFO

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