summaryrefslogtreecommitdiff
path: root/py/objarray.c
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2025-07-22 13:06:28 +1000
committerDamien George <damien@micropython.org>2025-07-24 14:55:34 +1000
commit3185bb5827acd6a1f27a9299abee52640dd495f2 (patch)
tree4a8bf7ebbe175188b22fdfc8578afee80320459f /py/objarray.c
parent45aa65b67d075fa8b2e71d57f1a94566f51207bb (diff)
py/obj: Add new type flag to indicate subscr accepts slice-on-stack.
The recently merged 5e9189d6d1c00c92694888bf9c74276779c40716 now allows temporary slices to be allocated on the C stack, which is much better than allocating them on the GC heap. Unfortunately there are cases where the C-allocated slice can escape and be retained as an object, which leads to crashes (because that object points to the C stack which now has other values on it). The fix here is to add a new `MP_TYPE_FLAG_SUBSCR_ALLOWS_STACK_SLICE`. Native types should set this flag if their subscr method is guaranteed not to hold on to a reference of the slice object. Fixes issue #17733 (see also #17723). Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py/objarray.c')
-rw-r--r--py/objarray.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/py/objarray.c b/py/objarray.c
index 1fd026939..ac4e343d0 100644
--- a/py/objarray.c
+++ b/py/objarray.c
@@ -626,7 +626,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
MP_DEFINE_CONST_OBJ_TYPE(
mp_type_bytearray,
MP_QSTR_bytearray,
- MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE | MP_TYPE_FLAG_ITER_IS_GETITER,
+ MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE | MP_TYPE_FLAG_ITER_IS_GETITER | MP_TYPE_FLAG_SUBSCR_ALLOWS_STACK_SLICE,
make_new, bytearray_make_new,
print, array_print,
iter, array_iterator_new,
@@ -654,7 +654,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
MP_DEFINE_CONST_OBJ_TYPE(
mp_type_memoryview,
MP_QSTR_memoryview,
- MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE | MP_TYPE_FLAG_ITER_IS_GETITER,
+ MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE | MP_TYPE_FLAG_ITER_IS_GETITER | MP_TYPE_FLAG_SUBSCR_ALLOWS_STACK_SLICE,
make_new, memoryview_make_new,
iter, array_iterator_new,
unary_op, array_unary_op,