File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -190,6 +190,10 @@ int main(int argc, char **argv) {
190
190
init_flash_fs ();
191
191
192
192
int stack_dummy ;
193
+ // Store the location of stack_dummy as an approximation for the top of the
194
+ // stack so the GC can account for objects that may be referenced by the
195
+ // stack between here and where gc_collect is called.
196
+ stack_top = (char * )& stack_dummy ;
193
197
reset_mp ();
194
198
195
199
// Main script is finished, so now go into REPL mode.
@@ -203,7 +207,6 @@ int main(int argc, char **argv) {
203
207
}
204
208
if (exit_code == PYEXEC_FORCED_EXIT ) {
205
209
mp_hal_stdout_tx_str ("soft reboot\r\n" );
206
- stack_top = (char * )& stack_dummy ;
207
210
reset_mp ();
208
211
} else if (exit_code != 0 ) {
209
212
break ;
@@ -218,6 +221,8 @@ void gc_collect(void) {
218
221
// pointers from CPU registers, and thus may function incorrectly.
219
222
void * dummy ;
220
223
gc_collect_start ();
224
+ // This naively collects all object references from an approximate stack
225
+ // range.
221
226
gc_collect_root (& dummy , ((mp_uint_t )stack_top - (mp_uint_t )& dummy ) / sizeof (mp_uint_t ));
222
227
gc_collect_end ();
223
228
gc_dump_info ();
You can’t perform that action at this time.
0 commit comments