From 3ebd4d0cae58241c963cabd3cbd02fc9ca261a2f Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 1 Jun 2014 13:46:47 +0100 Subject: [PATCH] py: Add option to disable set() object (enabled by default). --- py/builtintables.c | 2 ++ py/mpconfig.h | 5 +++++ py/objset.c | 4 ++++ py/runtime.c | 2 ++ py/runtime0.h | 2 ++ py/vm.c | 2 ++ 6 files changed, 17 insertions(+) diff --git a/py/builtintables.c b/py/builtintables.c index 05fefb64ce..628514da1c 100644 --- a/py/builtintables.c +++ b/py/builtintables.c @@ -64,7 +64,9 @@ STATIC const mp_map_elem_t mp_builtin_object_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_property), (mp_obj_t)&mp_type_property }, #endif { MP_OBJ_NEW_QSTR(MP_QSTR_range), (mp_obj_t)&mp_type_range }, +#if MICROPY_PY_BUILTINS_SET { MP_OBJ_NEW_QSTR(MP_QSTR_set), (mp_obj_t)&mp_type_set }, +#endif { MP_OBJ_NEW_QSTR(MP_QSTR_str), (mp_obj_t)&mp_type_str }, { MP_OBJ_NEW_QSTR(MP_QSTR_super), (mp_obj_t)&mp_type_super }, { MP_OBJ_NEW_QSTR(MP_QSTR_tuple), (mp_obj_t)&mp_type_tuple }, diff --git a/py/mpconfig.h b/py/mpconfig.h index a72d5c260e..77b76bf13d 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -239,6 +239,11 @@ typedef double mp_float_t; /*****************************************************************************/ /* Fine control over Python builtins, classes, modules, etc */ +// Whether to support set object +#ifndef MICROPY_PY_BUILTINS_SET +#define MICROPY_PY_BUILTINS_SET (1) +#endif + // Whether to support slice subscript operators and slice object #ifndef MICROPY_PY_BUILTINS_SLICE #define MICROPY_PY_BUILTINS_SLICE (1) diff --git a/py/objset.c b/py/objset.c index 5cde712061..ab76b57642 100644 --- a/py/objset.c +++ b/py/objset.c @@ -37,6 +37,8 @@ #include "runtime0.h" #include "builtin.h" +#if MICROPY_PY_BUILTINS_SET + typedef struct _mp_obj_set_t { mp_obj_base_t base; mp_set_t set; @@ -584,3 +586,5 @@ void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item) { mp_obj_set_t *self = self_in; mp_set_lookup(&self->set, item, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND); } + +#endif // MICROPY_PY_BUILTINS_SET diff --git a/py/runtime.c b/py/runtime.c index d2219175d1..cb4d16be18 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1173,8 +1173,10 @@ void *const mp_fun_table[MP_F_NUMBER_OF] = { mp_obj_list_append, mp_obj_new_dict, mp_obj_dict_store, +#if MICROPY_PY_BUILTINS_SET mp_obj_new_set, mp_obj_set_store, +#endif mp_make_function_from_raw_code, mp_call_function_n_kw_for_native, mp_call_method_n_kw, diff --git a/py/runtime0.h b/py/runtime0.h index 542edf4a62..1d1f9d77c4 100644 --- a/py/runtime0.h +++ b/py/runtime0.h @@ -115,8 +115,10 @@ typedef enum { MP_F_LIST_APPEND, MP_F_BUILD_MAP, MP_F_STORE_MAP, +#if MICROPY_PY_BUILTINS_SET MP_F_BUILD_SET, MP_F_STORE_SET, +#endif MP_F_MAKE_FUNCTION_FROM_RAW_CODE, MP_F_CALL_FUNCTION_N_KW_FOR_NATIVE, MP_F_CALL_METHOD_N_KW, diff --git a/py/vm.c b/py/vm.c index d739dfe804..cfb390bae7 100644 --- a/py/vm.c +++ b/py/vm.c @@ -772,6 +772,7 @@ unwind_jump: sp -= 2; DISPATCH(); +#if MICROPY_PY_BUILTINS_SET ENTRY(MP_BC_BUILD_SET): DECODE_UINT; sp -= unum - 1; @@ -784,6 +785,7 @@ unwind_jump: mp_obj_set_store(sp[-unum], sp[0]); sp--; DISPATCH(); +#endif #if MICROPY_PY_BUILTINS_SLICE ENTRY(MP_BC_BUILD_SLICE):