Skip to content

Commit 4b1e9d8

Browse files
committed
alloca seems buggy on M4
1 parent fe851fc commit 4b1e9d8

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

extmod/modure.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ STATIC mp_obj_t re_split(size_t n_args, const mp_obj_t *args) {
144144
}
145145

146146
mp_obj_t retval = mp_obj_new_list(0, NULL);
147-
const char **caps = alloca(caps_num * sizeof(char*));
147+
const char* caps[caps_num];
148148
while (true) {
149149
// cast is a workaround for a bug in msvc: it treats const char** as a const pointer instead of a pointer to pointer to const char
150150
memset((char**)caps, 0, caps_num * sizeof(char*));

py/builtinimport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
330330
}
331331

332332
uint new_mod_l = (mod_len == 0 ? (size_t)(p - this_name) : (size_t)(p - this_name) + 1 + mod_len);
333-
char *new_mod = alloca(new_mod_l);
333+
char new_mod[new_mod_l];
334334
memcpy(new_mod, this_name, p - this_name);
335335
if (mod_len != 0) {
336336
new_mod[p - this_name] = '.';

py/runtime.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,9 +1428,10 @@ mp_obj_t mp_import_from(mp_obj_t module, qstr name) {
14281428
mp_load_method_maybe(module, MP_QSTR___name__, dest);
14291429
size_t pkg_name_len;
14301430
const char *pkg_name = mp_obj_str_get_data(dest[0], &pkg_name_len);
1431-
14321431
const uint dot_name_len = pkg_name_len + 1 + qstr_len(name);
1433-
char *dot_name = alloca(dot_name_len);
1432+
// Previously dot_name was created using alloca(), but that caused run-time crashes on M4 due to
1433+
// stack corruption (compiler bug, it appears), so use an array instead.
1434+
char dot_name[dot_name_len];
14341435
memcpy(dot_name, pkg_name, pkg_name_len);
14351436
dot_name[pkg_name_len] = '.';
14361437
memcpy(dot_name + pkg_name_len + 1, qstr_str(name), qstr_len(name));

0 commit comments

Comments
 (0)