Skip to content

Commit 96f2a38

Browse files
committed
py/nativeglue: Make mp_fun_table fixed size regardless of config.
So that mpy files with native code will always work correctly, and raise an exception if a feature is used that is not supported by the runtime.
1 parent 7d58a19 commit 96f2a38

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

py/nativeglue.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,29 @@ mp_obj_t mp_native_to_obj(mp_uint_t val, mp_uint_t type) {
9797

9898
#if MICROPY_EMIT_NATIVE && !MICROPY_DYNAMIC_COMPILER
9999

100+
#if !MICROPY_PY_BUILTINS_SET
101+
mp_obj_t mp_obj_new_set(size_t n_args, mp_obj_t *items) {
102+
(void)n_args;
103+
(void)items;
104+
mp_raise_msg(&mp_type_RuntimeError, "set unsupported");
105+
}
106+
107+
void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item) {
108+
(void)self_in;
109+
(void)item;
110+
mp_raise_msg(&mp_type_RuntimeError, "set unsupported");
111+
}
112+
#endif
113+
114+
#if !MICROPY_PY_BUILTINS_SLICE
115+
mp_obj_t mp_obj_new_slice(mp_obj_t ostart, mp_obj_t ostop, mp_obj_t ostep) {
116+
(void)ostart;
117+
(void)ostop;
118+
(void)ostep;
119+
mp_raise_msg(&mp_type_RuntimeError, "slice unsupported");
120+
}
121+
#endif
122+
100123
STATIC mp_obj_dict_t *mp_native_swap_globals(mp_obj_dict_t *new_globals) {
101124
if (new_globals == NULL) {
102125
// Globals were the originally the same so don't restore them
@@ -211,10 +234,8 @@ const void *const mp_fun_table[MP_F_NUMBER_OF] = {
211234
mp_obj_new_tuple,
212235
mp_obj_new_list,
213236
mp_obj_new_dict,
214-
#if MICROPY_PY_BUILTINS_SET
215237
mp_obj_new_set,
216238
mp_obj_set_store,
217-
#endif
218239
mp_obj_list_append,
219240
mp_obj_dict_store,
220241
mp_make_function_from_raw_code,
@@ -229,9 +250,7 @@ const void *const mp_fun_table[MP_F_NUMBER_OF] = {
229250
mp_import_name,
230251
mp_import_from,
231252
mp_import_all,
232-
#if MICROPY_PY_BUILTINS_SLICE
233253
mp_obj_new_slice,
234-
#endif
235254
mp_unpack_sequence,
236255
mp_unpack_ex,
237256
mp_delete_name,

py/runtime0.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,8 @@ typedef enum {
173173
MP_F_BUILD_TUPLE,
174174
MP_F_BUILD_LIST,
175175
MP_F_BUILD_MAP,
176-
#if MICROPY_PY_BUILTINS_SET
177176
MP_F_BUILD_SET,
178177
MP_F_STORE_SET,
179-
#endif
180178
MP_F_LIST_APPEND,
181179
MP_F_STORE_MAP,
182180
MP_F_MAKE_FUNCTION_FROM_RAW_CODE,
@@ -191,9 +189,7 @@ typedef enum {
191189
MP_F_IMPORT_NAME,
192190
MP_F_IMPORT_FROM,
193191
MP_F_IMPORT_ALL,
194-
#if MICROPY_PY_BUILTINS_SLICE
195192
MP_F_NEW_SLICE,
196-
#endif
197193
MP_F_UNPACK_SEQUENCE,
198194
MP_F_UNPACK_EX,
199195
MP_F_DELETE_NAME,

0 commit comments

Comments
 (0)