mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 19:50:30 +01:00
py/runtime: mp_stack_ctrl_init() should be called immediately on startup.
Calling it from mp_init() is too late for some ports (like Unix), and leads to incomplete stack frame being captured, with following GC issues. So, now each port should call mp_stack_ctrl_init() on its own, ASAP after startup, and taking special precautions so it really was called before stack variables get allocated (because if such variable with a pointer is missed, it may lead to over-collecting (typical symptom is segfaulting)).
This commit is contained in:
12
unix/main.c
12
unix/main.c
@@ -376,7 +376,19 @@ STATIC void set_sys_argv(char *argv[], int argc, int start_arg) {
|
||||
#define PATHLIST_SEP_CHAR ':'
|
||||
#endif
|
||||
|
||||
MP_NOINLINE int main_(int argc, char **argv);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// We should capture stack top ASAP after start, and it should be
|
||||
// captured guaranteedly before any other stack variables are allocated.
|
||||
// For this, actual main (renamed main_) should not be inlined into
|
||||
// this function. main_() itself may have other functions inlined (with
|
||||
// their own stack variables), that's why we need this main/main_ split.
|
||||
mp_stack_ctrl_init();
|
||||
return main_(argc, argv);
|
||||
}
|
||||
|
||||
MP_NOINLINE int main_(int argc, char **argv) {
|
||||
mp_stack_set_limit(40000 * (BYTES_PER_WORD / 4));
|
||||
|
||||
pre_process_options(argc, argv);
|
||||
|
||||
Reference in New Issue
Block a user