Skip to content

Commit 3fb1c8b

Browse files
committed
ports/all: deinit builtin modules on soft-reset.
Signed-off-by: Andrew Leech <[email protected]>
1 parent f66ea31 commit 3fb1c8b

File tree

11 files changed

+52
-0
lines changed

11 files changed

+52
-0
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_MODULE_BUILTIN_INIT
187+
mp_module_builtin_deinit();
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_MODULE_BUILTIN_INIT
93+
mp_module_builtin_deinit();
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_MODULE_BUILTIN_INIT
164+
mp_module_builtin_deinit();
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_MODULE_BUILTIN_INIT
297+
mp_module_builtin_deinit();
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_MODULE_BUILTIN_INIT
65+
mp_module_builtin_deinit();
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_MODULE_BUILTIN_INIT
440+
mp_module_builtin_deinit();
441+
#endif
442+
438443
MICROPY_BOARD_END_SOFT_RESET(&state);
439444

440445
gc_sweep_all();

ports/rp2/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 "extmod/modbluetooth.h"
3637
#include "extmod/modnetwork.h"
3738
#include "shared/readline/readline.h"
@@ -242,6 +243,10 @@ int main(int argc, char **argv) {
242243
mp_usbd_deinit();
243244
#endif
244245

246+
#if MICROPY_MODULE_BUILTIN_INIT
247+
mp_module_builtin_deinit();
248+
#endif
249+
245250
// Hook for resetting anything right at the end of a soft reset command.
246251
MICROPY_BOARD_END_SOFT_RESET();
247252

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_MODULE_BUILTIN_INIT
103+
mp_module_builtin_deinit();
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_MODULE_BUILTIN_INIT
703+
mp_module_builtin_deinit();
704+
#endif
705+
701706
MICROPY_BOARD_END_SOFT_RESET(&state);
702707

703708
gc_sweep_all();

ports/unix/main.c

Lines changed: 5 additions & 0 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"
@@ -774,6 +775,10 @@ MP_NOINLINE int main_(int argc, char **argv) {
774775
mp_thread_deinit();
775776
#endif
776777

778+
#if MICROPY_MODULE_BUILTIN_INIT
779+
mp_module_builtin_deinit();
780+
#endif
781+
777782
#if defined(MICROPY_UNIX_COVERAGE)
778783
gc_sweep_all();
779784
#endif

0 commit comments

Comments
 (0)