diff options
| author | Paul Sokolovsky | 2016-01-29 01:05:53 +0200 |
|---|---|---|
| committer | Paul Sokolovsky | 2016-01-29 02:13:42 +0200 |
| commit | d3b1f0b627ccc6705d9fe958549badb87a74ded1 (patch) | |
| tree | ccc7d03e2f5cd00bb022f70093ca99915715ba42 /unix | |
| parent | 850212203a97754bdaf1844b71c8fe8ee905236f (diff) | |
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)).
Diffstat (limited to 'unix')
| -rw-r--r-- | unix/main.c | 12 | ||||
| -rw-r--r-- | unix/mpconfigport.h | 4 |
2 files changed, 16 insertions, 0 deletions
diff --git a/unix/main.c b/unix/main.c index 03902a3e9..4ba68dcb9 100644 --- a/unix/main.c +++ b/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); diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index 2f992fdf0..f7fdeec07 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -214,6 +214,10 @@ void mp_unix_mark_exec(void); #define MP_PLAT_ALLOC_EXEC(min_size, ptr, size) mp_unix_alloc_exec(min_size, ptr, size) #define MP_PLAT_FREE_EXEC(ptr, size) mp_unix_free_exec(ptr, size) +#ifndef MP_NOINLINE +#define MP_NOINLINE __attribute__((noinline)) +#endif + #if MICROPY_PY_OS_DUPTERM #define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len) #else |
