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.
This commit is contained in:
Damien George 2019-09-26 16:24:06 +10:00
parent 7d58a197cf
commit 96f2a38075
2 changed files with 23 additions and 8 deletions

View file

@ -97,6 +97,29 @@ mp_obj_t mp_native_to_obj(mp_uint_t val, mp_uint_t type) {
#if MICROPY_EMIT_NATIVE && !MICROPY_DYNAMIC_COMPILER
#if !MICROPY_PY_BUILTINS_SET
mp_obj_t mp_obj_new_set(size_t n_args, mp_obj_t *items) {
(void)n_args;
(void)items;
mp_raise_msg(&mp_type_RuntimeError, "set unsupported");
}
void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item) {
(void)self_in;
(void)item;
mp_raise_msg(&mp_type_RuntimeError, "set unsupported");
}
#endif
#if !MICROPY_PY_BUILTINS_SLICE
mp_obj_t mp_obj_new_slice(mp_obj_t ostart, mp_obj_t ostop, mp_obj_t ostep) {
(void)ostart;
(void)ostop;
(void)ostep;
mp_raise_msg(&mp_type_RuntimeError, "slice unsupported");
}
#endif
STATIC mp_obj_dict_t *mp_native_swap_globals(mp_obj_dict_t *new_globals) {
if (new_globals == NULL) {
// 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] = {
mp_obj_new_tuple,
mp_obj_new_list,
mp_obj_new_dict,
#if MICROPY_PY_BUILTINS_SET
mp_obj_new_set,
mp_obj_set_store,
#endif
mp_obj_list_append,
mp_obj_dict_store,
mp_make_function_from_raw_code,
@ -229,9 +250,7 @@ const void *const mp_fun_table[MP_F_NUMBER_OF] = {
mp_import_name,
mp_import_from,
mp_import_all,
#if MICROPY_PY_BUILTINS_SLICE
mp_obj_new_slice,
#endif
mp_unpack_sequence,
mp_unpack_ex,
mp_delete_name,

View file

@ -173,10 +173,8 @@ typedef enum {
MP_F_BUILD_TUPLE,
MP_F_BUILD_LIST,
MP_F_BUILD_MAP,
#if MICROPY_PY_BUILTINS_SET
MP_F_BUILD_SET,
MP_F_STORE_SET,
#endif
MP_F_LIST_APPEND,
MP_F_STORE_MAP,
MP_F_MAKE_FUNCTION_FROM_RAW_CODE,
@ -191,9 +189,7 @@ typedef enum {
MP_F_IMPORT_NAME,
MP_F_IMPORT_FROM,
MP_F_IMPORT_ALL,
#if MICROPY_PY_BUILTINS_SLICE
MP_F_NEW_SLICE,
#endif
MP_F_UNPACK_SEQUENCE,
MP_F_UNPACK_EX,
MP_F_DELETE_NAME,