From b2fa1b50edaea43007d692d24391c6f3aa4d15ca Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 31 May 2018 23:11:08 +1000 Subject: [PATCH] ports: Call gc_sweep_all() when doing a soft reset. This calls finalisers of things like files and sockets to cleanly close them. --- ports/esp32/main.c | 2 ++ ports/esp8266/main.c | 1 + ports/stm32/main.c | 2 ++ ports/unix/main.c | 4 ++++ 4 files changed, 9 insertions(+) diff --git a/ports/esp32/main.c b/ports/esp32/main.c index e7290c7eb8..acbbfdccce 100644 --- a/ports/esp32/main.c +++ b/ports/esp32/main.c @@ -116,6 +116,8 @@ soft_reset: mp_thread_deinit(); #endif + gc_sweep_all(); + mp_hal_stdout_tx_str("PYB: soft reboot\r\n"); // deinitialise peripherals diff --git a/ports/esp8266/main.c b/ports/esp8266/main.c index 975262fd16..7e5034b04a 100644 --- a/ports/esp8266/main.c +++ b/ports/esp8266/main.c @@ -88,6 +88,7 @@ STATIC void mp_reset(void) { } void soft_reset(void) { + gc_sweep_all(); mp_hal_stdout_tx_str("PYB: soft reboot\r\n"); mp_hal_delay_us(10000); // allow UART to flush output mp_reset(); diff --git a/ports/stm32/main.c b/ports/stm32/main.c index 19c77453f9..c018d2de2a 100644 --- a/ports/stm32/main.c +++ b/ports/stm32/main.c @@ -756,5 +756,7 @@ soft_reset_exit: pyb_thread_deinit(); #endif + gc_sweep_all(); + goto soft_reset; } diff --git a/ports/unix/main.c b/ports/unix/main.c index b68fe92797..1cf237a2b2 100644 --- a/ports/unix/main.c +++ b/ports/unix/main.c @@ -647,6 +647,10 @@ MP_NOINLINE int main_(int argc, char **argv) { } #endif + #if defined(MICROPY_UNIX_COVERAGE) + gc_sweep_all(); + #endif + mp_deinit(); #if MICROPY_ENABLE_GC && !defined(NDEBUG)