Skip to content
This repository was archived by the owner on Oct 28, 2023. It is now read-only.

Commit 520f356

Browse files
committed
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.
1 parent 649b69a commit 520f356

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

unix/main.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,12 @@ MP_NOINLINE int main_(int argc, char **argv) {
444444
}
445445
if (p[0] == '~' && p[1] == '/' && home != NULL) {
446446
// Expand standalone ~ to $HOME
447-
CHECKBUF(buf, PATH_MAX);
448-
CHECKBUF_APPEND(buf, home, strlen(home));
449-
CHECKBUF_APPEND(buf, p + 1, (size_t)(p1 - p - 1));
450-
path_items[i] = MP_OBJ_NEW_QSTR(qstr_from_strn(buf, CHECKBUF_LEN(buf)));
447+
int home_l = strlen(home);
448+
vstr_t vstr;
449+
vstr_init(&vstr, home_l + (p1 - p - 1) + 1);
450+
vstr_add_strn(&vstr, home, home_l);
451+
vstr_add_strn(&vstr, p + 1, p1 - p - 1);
452+
path_items[i] = mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
451453
} else {
452454
path_items[i] = MP_OBJ_NEW_QSTR(qstr_from_strn(p, p1 - p));
453455
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy