diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-07-09 01:48:07 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-07-09 01:48:07 +0300 |
commit | 520f35632d78e1b73f647d993205aade0de8b1ce (patch) | |
tree | 5a8c11a0cf293ffb15c2fe1af7f7746c0022eeca /unix | |
parent | 649b69a1dbc91c7df8809c4a20c6287b23ac7f52 (diff) | |
download | micropython-520f35632d78e1b73f647d993205aade0de8b1ce.tar.gz micropython-520f35632d78e1b73f647d993205aade0de8b1ce.zip |
unix/main: When preparing sys.path, allocate exact strings on uPy heap.
Due to the way modern compilers work (allocating space for stack vars once
at tha start of function, and deallocating once on exit from), using
intermediate stack buffer of big size caused blockage of 4K (PATH_MAX)
on stack for the entire duration of MicroPython execution.
Diffstat (limited to 'unix')
-rw-r--r-- | unix/main.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/unix/main.c b/unix/main.c index aa109d41c6..a1c057400f 100644 --- a/unix/main.c +++ b/unix/main.c @@ -444,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)); } |