Skip to content

Commit d80e247

Browse files
committed
py: Disable frozenset by default, enable on unix.
Takes 416 text bytes on x86.
1 parent b181b58 commit d80e247

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

py/mpconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ typedef double mp_float_t;
237237

238238
// Whether to support frozenset object
239239
#ifndef MICROPY_ENABLE_FROZENSET
240-
#define MICROPY_ENABLE_FROZENSET (1)
240+
#define MICROPY_ENABLE_FROZENSET (0)
241241
#endif
242242

243243
// Whether to support the property object

py/objset.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,40 +51,56 @@ typedef struct _mp_obj_set_it_t {
5151
STATIC mp_obj_t set_it_iternext(mp_obj_t self_in);
5252

5353
STATIC bool is_set_or_frozenset(mp_obj_t o) {
54-
return MP_OBJ_IS_TYPE(o, &mp_type_set) || MP_OBJ_IS_TYPE(o, &mp_type_frozenset);
54+
return MP_OBJ_IS_TYPE(o, &mp_type_set)
55+
#if MICROPY_ENABLE_FROZENSET
56+
|| MP_OBJ_IS_TYPE(o, &mp_type_frozenset)
57+
#endif
58+
;
5559
}
5660

61+
#if MICROPY_ENABLE_FROZENSET
5762
STATIC void check_set_or_frozenset(mp_obj_t o) {
5863
if (!is_set_or_frozenset(o)) {
5964
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'set' object required"));
6065
}
6166
}
67+
#else
68+
#define check_set_or_frozenset(o) check_set(o)
69+
#endif
6270

6371
STATIC void check_set(mp_obj_t o) {
6472
if (!MP_OBJ_IS_TYPE(o, &mp_type_set)) {
6573
// Emulate CPython behavior
6674
// AttributeError: 'frozenset' object has no attribute 'add'
75+
#if MICROPY_ENABLE_FROZENSET
6776
if (MP_OBJ_IS_TYPE(o, &mp_type_frozenset)) {
6877
nlr_raise(mp_obj_new_exception_msg(&mp_type_AttributeError, "'frozenset' has no such attribute"));
6978
}
79+
#endif
7080
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'set' object required"));
7181
}
7282
}
7383

7484
STATIC void set_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
7585
mp_obj_set_t *self = self_in;
86+
#if MICROPY_ENABLE_FROZENSET
7687
bool is_frozen = MP_OBJ_IS_TYPE(self_in, &mp_type_frozenset);
88+
#endif
7789
if (self->set.used == 0) {
90+
#if MICROPY_ENABLE_FROZENSET
7891
if (is_frozen) {
7992
print(env, "frozen");
8093
}
94+
#endif
8195
print(env, "set()");
8296
return;
8397
}
8498
bool first = true;
99+
#if MICROPY_ENABLE_FROZENSET
85100
if (is_frozen) {
86101
print(env, "frozenset(");
87102
}
103+
#endif
88104
print(env, "{");
89105
for (int i = 0; i < self->set.alloc; i++) {
90106
if (MP_SET_SLOT_IS_FILLED(&self->set, i)) {
@@ -96,9 +112,11 @@ STATIC void set_print(void (*print)(void *env, const char *fmt, ...), void *env,
96112
}
97113
}
98114
print(env, "}");
115+
#if MICROPY_ENABLE_FROZENSET
99116
if (is_frozen) {
100117
print(env, ")");
101118
}
119+
#endif
102120
}
103121

104122

unix/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#define MICROPY_EMIT_INLINE_THUMB (0)
3232
#define MICROPY_ENABLE_GC (1)
3333
#define MICROPY_ENABLE_FINALISER (1)
34+
#define MICROPY_ENABLE_FROZENSET (1)
3435
#define MICROPY_MEM_STATS (1)
3536
#define MICROPY_DEBUG_PRINTERS (1)
3637
#define MICROPY_ENABLE_REPL_HELPERS (1)

0 commit comments

Comments
 (0)