Skip to content

Commit 3ebd4d0

Browse files
committed
py: Add option to disable set() object (enabled by default).
1 parent fb510b3 commit 3ebd4d0

6 files changed

Lines changed: 17 additions & 0 deletions

File tree

py/builtintables.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ STATIC const mp_map_elem_t mp_builtin_object_table[] = {
6464
{ MP_OBJ_NEW_QSTR(MP_QSTR_property), (mp_obj_t)&mp_type_property },
6565
#endif
6666
{ MP_OBJ_NEW_QSTR(MP_QSTR_range), (mp_obj_t)&mp_type_range },
67+
#if MICROPY_PY_BUILTINS_SET
6768
{ MP_OBJ_NEW_QSTR(MP_QSTR_set), (mp_obj_t)&mp_type_set },
69+
#endif
6870
{ MP_OBJ_NEW_QSTR(MP_QSTR_str), (mp_obj_t)&mp_type_str },
6971
{ MP_OBJ_NEW_QSTR(MP_QSTR_super), (mp_obj_t)&mp_type_super },
7072
{ MP_OBJ_NEW_QSTR(MP_QSTR_tuple), (mp_obj_t)&mp_type_tuple },

py/mpconfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ typedef double mp_float_t;
239239
/*****************************************************************************/
240240
/* Fine control over Python builtins, classes, modules, etc */
241241

242+
// Whether to support set object
243+
#ifndef MICROPY_PY_BUILTINS_SET
244+
#define MICROPY_PY_BUILTINS_SET (1)
245+
#endif
246+
242247
// Whether to support slice subscript operators and slice object
243248
#ifndef MICROPY_PY_BUILTINS_SLICE
244249
#define MICROPY_PY_BUILTINS_SLICE (1)

py/objset.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#include "runtime0.h"
3838
#include "builtin.h"
3939

40+
#if MICROPY_PY_BUILTINS_SET
41+
4042
typedef struct _mp_obj_set_t {
4143
mp_obj_base_t base;
4244
mp_set_t set;
@@ -584,3 +586,5 @@ void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item) {
584586
mp_obj_set_t *self = self_in;
585587
mp_set_lookup(&self->set, item, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND);
586588
}
589+
590+
#endif // MICROPY_PY_BUILTINS_SET

py/runtime.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,8 +1173,10 @@ void *const mp_fun_table[MP_F_NUMBER_OF] = {
11731173
mp_obj_list_append,
11741174
mp_obj_new_dict,
11751175
mp_obj_dict_store,
1176+
#if MICROPY_PY_BUILTINS_SET
11761177
mp_obj_new_set,
11771178
mp_obj_set_store,
1179+
#endif
11781180
mp_make_function_from_raw_code,
11791181
mp_call_function_n_kw_for_native,
11801182
mp_call_method_n_kw,

py/runtime0.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ typedef enum {
115115
MP_F_LIST_APPEND,
116116
MP_F_BUILD_MAP,
117117
MP_F_STORE_MAP,
118+
#if MICROPY_PY_BUILTINS_SET
118119
MP_F_BUILD_SET,
119120
MP_F_STORE_SET,
121+
#endif
120122
MP_F_MAKE_FUNCTION_FROM_RAW_CODE,
121123
MP_F_CALL_FUNCTION_N_KW_FOR_NATIVE,
122124
MP_F_CALL_METHOD_N_KW,

py/vm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ mp_vm_return_kind_t mp_execute_bytecode2(mp_code_state *code_state, volatile mp_
772772
sp -= 2;
773773
DISPATCH();
774774

775+
#if MICROPY_PY_BUILTINS_SET
775776
ENTRY(MP_BC_BUILD_SET):
776777
DECODE_UINT;
777778
sp -= unum - 1;
@@ -784,6 +785,7 @@ mp_vm_return_kind_t mp_execute_bytecode2(mp_code_state *code_state, volatile mp_
784785
mp_obj_set_store(sp[-unum], sp[0]);
785786
sp--;
786787
DISPATCH();
788+
#endif
787789

788790
#if MICROPY_PY_BUILTINS_SLICE
789791
ENTRY(MP_BC_BUILD_SLICE):

0 commit comments

Comments
 (0)