diff options
Diffstat (limited to 'unix/main.c')
-rw-r--r-- | unix/main.c | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/unix/main.c b/unix/main.c index 26736e4318..1bee639eb2 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(); @@ -149,7 +147,7 @@ STATIC char *strjoin(const char *s1, int sep_char, const char *s2) { } STATIC void do_repl(void) { - printf("Micro Python " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE "; UNIX version\n"); + printf("Micro Python " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE "; " MICROPY_PY_SYS_PLATFORM " version\n"); for (;;) { char *line = prompt(">>> "); @@ -201,8 +199,8 @@ int usage(char **argv) { impl_opts_cnt++; #if MICROPY_ENABLE_GC printf( -" heapsize=<n> -- set the heap size for the GC\n" -); +" heapsize=<n> -- set the heap size for the GC (default %ld)\n" +, heap_size); impl_opts_cnt++; #endif @@ -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,7 @@ 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_set_limit(32768); pre_process_options(argc, argv); @@ -365,7 +361,8 @@ int main(int argc, char **argv) { return usage(argv); } } else { - char *basedir = realpath(argv[a], NULL); + char *pathbuf = malloc(PATH_MAX); + char *basedir = realpath(argv[a], pathbuf); if (basedir == NULL) { fprintf(stderr, "%s: can't open file '%s': [Errno %d] ", argv[0], argv[a], errno); perror(""); @@ -377,7 +374,7 @@ int main(int argc, char **argv) { // Set base dir of the script as first entry in sys.path char *p = strrchr(basedir, '/'); path_items[0] = MP_OBJ_NEW_QSTR(qstr_from_strn(basedir, p - basedir)); - free(basedir); + free(pathbuf); for (int i = a; i < argc; i++) { mp_obj_list_append(mp_sys_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i]))); |