diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-06-25 03:03:34 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-06-27 00:03:55 +0300 |
commit | 23668698cba9bf861c697e65e3d07f9433396b8b (patch) | |
tree | 7b87345f47610c70e7b5a3559b387e822936573e /unix | |
parent | 91b576d1472b481f02a9f9f20dd263ef606a186a (diff) | |
download | micropython-23668698cba9bf861c697e65e3d07f9433396b8b.tar.gz micropython-23668698cba9bf861c697e65e3d07f9433396b8b.zip |
py: Add portable framework to query/check C stack usage.
Such mechanism is important to get stable Python functioning, because Python
function calling is handled with C stack. The idea is to sprinkle
STACK_CHECK() calls in places where there can be C recursion.
TODO: Add more STACK_CHECK()'s.
Diffstat (limited to 'unix')
-rw-r--r-- | unix/main.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/unix/main.c b/unix/main.c index 552df9b804..a08661339c 100644 --- a/unix/main.c +++ b/unix/main.c @@ -51,6 +51,7 @@ #include "gc.h" #include "genhdr/py-version.h" #include "input.h" +#include "stackctrl.h" // Command line options, with their defaults bool compile_only = false; @@ -63,9 +64,6 @@ uint mp_verbose_flag; long heap_size = 128*1024 * (sizeof(machine_uint_t) / 4); #endif -// Stack top at the start of program -char *stack_top; - void microsocket_init(); void time_init(); void ffi_init(); @@ -214,10 +212,9 @@ int usage(char **argv) { } mp_obj_t mem_info(void) { - volatile int stack_dummy; printf("mem: total=%d, current=%d, peak=%d\n", m_get_total_bytes_allocated(), m_get_current_bytes_allocated(), m_get_peak_bytes_allocated()); - printf("stack: " INT_FMT "\n", stack_top - (char*)&stack_dummy); + printf("stack: %u\n", stack_usage()); #if MICROPY_ENABLE_GC gc_dump_info(); #endif @@ -268,8 +265,8 @@ void pre_process_options(int argc, char **argv) { #endif int main(int argc, char **argv) { - volatile int stack_dummy; - stack_top = (char*)&stack_dummy; + stack_ctrl_init(); + stack_set_limit(32768); pre_process_options(argc, argv); |