@@ -425,7 +425,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
425425 };
426426 #endif
427427
428- supervisor_allocation * pystack = ( supervisor_allocation * ) 1 ;
428+ supervisor_allocation * pystack = NULL ;
429429 #if MICROPY_ENABLE_PYSTACK
430430 pystack = allocate_pystack ();
431431 #endif
@@ -767,8 +767,12 @@ STATIC void __attribute__ ((noinline)) run_safemode_py(safe_mode_t safe_mode) {
767767 return ;
768768 }
769769
770+ supervisor_allocation * pystack = NULL ;
771+ #if MICROPY_ENABLE_PYSTACK
772+ pystack = allocate_pystack ();
773+ #endif
770774 supervisor_allocation * heap = allocate_remaining_memory ();
771- start_mp (heap );
775+ start_mp (heap , pystack );
772776
773777 static const char * const safemode_py_filenames [] = {"safemode.py" , "safemode.txt" };
774778 maybe_run_list (safemode_py_filenames , MP_ARRAY_SIZE (safemode_py_filenames ));
@@ -779,7 +783,7 @@ STATIC void __attribute__ ((noinline)) run_safemode_py(safe_mode_t safe_mode) {
779783 set_safe_mode (SAFE_MODE_SAFEMODE_PY_ERROR );
780784 }
781785
782- cleanup_after_vm (heap , _exec_result .exception );
786+ cleanup_after_vm (heap , pystack , _exec_result .exception );
783787 _exec_result .exception = NULL ;
784788}
785789#endif
@@ -800,7 +804,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
800804
801805 // Do USB setup even if boot.py is not run.
802806
803- supervisor_allocation * pystack = ( supervisor_allocation * ) 1 ;
807+ supervisor_allocation * pystack = NULL ;
804808 #if MICROPY_ENABLE_PYSTACK
805809 pystack = allocate_pystack ();
806810 #endif
@@ -906,7 +910,7 @@ STATIC int run_repl(void) {
906910 int exit_code = PYEXEC_FORCED_EXIT ;
907911 stack_resize ();
908912 filesystem_flush ();
909- supervisor_allocation * pystack = ( supervisor_allocation * ) 1 ;
913+ supervisor_allocation * pystack = NULL ;
910914 #if MICROPY_ENABLE_PYSTACK
911915 pystack = allocate_pystack ();
912916 #endif
0 commit comments