diff options
| author | Dan Halbert <halbert@halwitz.org> | 2019-04-17 20:25:12 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-17 20:25:12 -0400 |
| commit | fcfafe6ced4067c97c90b65b4027025e7a2f9da4 (patch) | |
| tree | 77cdaf39504ce0bf458f8325c4a99ce47d715d6a | |
| parent | 5b94b7727d952f7ad3419b497eceb80fd7313615 (diff) | |
| parent | 92ba5c26b03cbb3da8c663e222b76bbff66b547a (diff) | |
Merge pull request #1809 from tannewt/board_i2c_crash_v2
Unify VM cleanup code
| -rwxr-xr-x | main.c | 45 |
1 files changed, 19 insertions, 26 deletions
@@ -176,6 +176,22 @@ bool maybe_run_list(const char ** filenames, pyexec_result_t* exec_result) { return true; } +void cleanup_after_vm(supervisor_allocation* heap) { + // Turn off the display and flush the fileystem before the heap disappears. + #if CIRCUITPY_DISPLAYIO + reset_displays(); + #endif + filesystem_flush(); + stop_mp(); + free_memory(heap); + supervisor_move_memory(); + + reset_port(); + reset_board_busses(); + reset_board(); + reset_status_led(); +} + bool run_code_py(safe_mode_t safe_mode) { bool serial_connected_at_start = serial_connected(); #ifdef CIRCUITPY_AUTORELOAD_DELAY_MS @@ -219,19 +235,7 @@ bool run_code_py(safe_mode_t safe_mode) { serial_write_compressed(translate("WARNING: Your code filename has two extensions\n")); } } - // Turn off the display and flush the fileystem before the heap disappears. - #if CIRCUITPY_DISPLAYIO - reset_displays(); - #endif - filesystem_flush(); - stop_mp(); - free_memory(heap); - supervisor_move_memory(); - - reset_port(); - reset_board_busses(); - reset_board(); - reset_status_led(); + cleanup_after_vm(heap); if (result.return_code & PYEXEC_FORCED_EXIT) { return reload_requested; @@ -359,13 +363,7 @@ void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { boot_output_file = NULL; #endif - // Reset to remove any state that boot.py setup. It should only be used to - // change internal state that's not in the heap. - reset_port(); - reset_board(); - stop_mp(); - free_memory(heap); - supervisor_move_memory(); + cleanup_after_vm(heap); } } @@ -382,12 +380,7 @@ int run_repl(void) { } else { exit_code = pyexec_friendly_repl(); } - filesystem_flush(); - reset_port(); - reset_board(); - stop_mp(); - free_memory(heap); - supervisor_move_memory(); + cleanup_after_vm(heap); autoreload_resume(); return exit_code; } |
