summaryrefslogtreecommitdiffstatshomepage
path: root/unix/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'unix/main.c')
-rw-r--r--unix/main.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/unix/main.c b/unix/main.c
index dedee28e7f..a1c057400f 100644
--- a/unix/main.c
+++ b/unix/main.c
@@ -45,6 +45,7 @@
#include "py/gc.h"
#include "py/stackctrl.h"
#include "py/mphal.h"
+#include "py/mpthread.h"
#include "extmod/misc.h"
#include "genhdr/mpversion.h"
#include "input.h"
@@ -292,7 +293,7 @@ STATIC int usage(char **argv) {
"-v : verbose (trace various operations); can be multiple\n"
"-O[N] : apply bytecode optimizations of level N\n"
"\n"
-"Implementation specific options:\n", argv[0]
+"Implementation specific options (-X):\n", argv[0]
);
int impl_opts_cnt = 0;
printf(
@@ -302,7 +303,7 @@ STATIC int usage(char **argv) {
impl_opts_cnt++;
#if MICROPY_ENABLE_GC
printf(
-" heapsize=<n> -- set the heap size for the GC (default %ld)\n"
+" heapsize=<n>[w][K|M] -- set the heap size for the GC (default %ld)\n"
, heap_size);
impl_opts_cnt++;
#endif
@@ -350,12 +351,20 @@ STATIC void pre_process_options(int argc, char **argv) {
heap_size *= 1024;
} else if ((*end | 0x20) == 'm') {
heap_size *= 1024 * 1024;
+ } else {
+ // Compensate for ++ below
+ --end;
+ }
+ if (*++end != 0) {
+ goto invalid_arg;
}
if (word_adjust) {
heap_size = heap_size * BYTES_PER_WORD / 4;
}
#endif
} else {
+invalid_arg:
+ printf("Invalid option\n");
exit(usage(argv));
}
a++;
@@ -379,6 +388,9 @@ STATIC void set_sys_argv(char *argv[], int argc, int start_arg) {
MP_NOINLINE int main_(int argc, char **argv);
int main(int argc, char **argv) {
+ #if MICROPY_PY_THREAD
+ mp_thread_init();
+ #endif
// 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
@@ -432,10 +444,12 @@ MP_NOINLINE int main_(int argc, char **argv) {
}
if (p[0] == '~' && p[1] == '/' && home != NULL) {
// Expand standalone ~ to $HOME
- CHECKBUF(buf, PATH_MAX);
- CHECKBUF_APPEND(buf, home, strlen(home));
- CHECKBUF_APPEND(buf, p + 1, (size_t)(p1 - p - 1));
- path_items[i] = MP_OBJ_NEW_QSTR(qstr_from_strn(buf, CHECKBUF_LEN(buf)));
+ int home_l = strlen(home);
+ vstr_t vstr;
+ vstr_init(&vstr, home_l + (p1 - p - 1) + 1);
+ vstr_add_strn(&vstr, home, home_l);
+ vstr_add_strn(&vstr, p + 1, p1 - p - 1);
+ path_items[i] = mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
} else {
path_items[i] = MP_OBJ_NEW_QSTR(qstr_from_strn(p, p1 - p));
}