summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2018-01-23 20:54:02 -0500
committerDan Halbert <halbert@halwitz.org>2018-01-23 20:54:02 -0500
commit4b1e9d8f92aa948f8ecccf364edcb911a135f2c8 (patch)
tree9eeae0c057397a27784e93fe3b58ae2102c10d38 /py
parentfe851fc15e2f02734133c9a2874bf3b407332f65 (diff)
alloca seems buggy on M4
Diffstat (limited to 'py')
-rw-r--r--py/builtinimport.c2
-rw-r--r--py/runtime.c5
2 files changed, 4 insertions, 3 deletions
diff --git a/py/builtinimport.c b/py/builtinimport.c
index b76ea00bd..0caba74f4 100644
--- a/py/builtinimport.c
+++ b/py/builtinimport.c
@@ -330,7 +330,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
}
uint new_mod_l = (mod_len == 0 ? (size_t)(p - this_name) : (size_t)(p - this_name) + 1 + mod_len);
- char *new_mod = alloca(new_mod_l);
+ char new_mod[new_mod_l];
memcpy(new_mod, this_name, p - this_name);
if (mod_len != 0) {
new_mod[p - this_name] = '.';
diff --git a/py/runtime.c b/py/runtime.c
index cbec82f17..7a16e4a1b 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -1428,9 +1428,10 @@ import_error:
mp_load_method_maybe(module, MP_QSTR___name__, dest);
size_t pkg_name_len;
const char *pkg_name = mp_obj_str_get_data(dest[0], &pkg_name_len);
-
const uint dot_name_len = pkg_name_len + 1 + qstr_len(name);
- char *dot_name = alloca(dot_name_len);
+ // Previously dot_name was created using alloca(), but that caused run-time crashes on M4 due to
+ // stack corruption (compiler bug, it appears), so use an array instead.
+ char dot_name[dot_name_len];
memcpy(dot_name, pkg_name, pkg_name_len);
dot_name[pkg_name_len] = '.';
memcpy(dot_name + pkg_name_len + 1, qstr_str(name), qstr_len(name));