Skip to content

Commit c49ddb9

Browse files
committed
py: Fix configurability of builtin slice.
1 parent 3ebd4d0 commit c49ddb9

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
lines changed

py/obj.h

+2
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,9 @@ typedef struct {
568568
} mp_bound_slice_t;
569569

570570
void mp_seq_multiply(const void *items, uint item_sz, uint len, uint times, void *dest);
571+
#if MICROPY_PY_BUILTINS_SLICE
571572
bool mp_seq_get_fast_slice_indexes(machine_uint_t len, mp_obj_t slice, mp_bound_slice_t *indexes);
573+
#endif
572574
#define mp_seq_copy(dest, src, len, item_t) memcpy(dest, src, len * sizeof(item_t))
573575
#define mp_seq_cat(dest, src1, len1, src2, len2, item_t) { memcpy(dest, src1, (len1) * sizeof(item_t)); memcpy(dest + (len1), src2, (len2) * sizeof(item_t)); }
574576
bool mp_seq_cmp_bytes(int op, const byte *data1, uint len1, const byte *data2, uint len2);

py/objarray.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
169169
return MP_OBJ_NULL; // op not supported
170170
} else {
171171
mp_obj_array_t *o = self_in;
172-
if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) {
172+
if (0) {
173+
#if MICROPY_PY_BUILTINS_SLICE
174+
} else if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) {
173175
if (value != MP_OBJ_SENTINEL) {
174176
// Only getting a slice is suported so far, not assignment
175177
// TODO: confirmed that both bytearray and array.array support
@@ -187,6 +189,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
187189
byte *p = o->items;
188190
memcpy(res->items, p + slice.start * sz, (slice.stop - slice.start) * sz);
189191
return res;
192+
#endif
190193
} else {
191194
uint index = mp_get_index(o->base.type, o->len, index_in, false);
192195
if (value == MP_OBJ_SENTINEL) {

py/runtime.c

+2
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,9 @@ void *const mp_fun_table[MP_F_NUMBER_OF] = {
11851185
mp_import_name,
11861186
mp_import_from,
11871187
mp_import_all,
1188+
#if MICROPY_PY_BUILTINS_SLICE
11881189
mp_obj_new_slice,
1190+
#endif
11891191
mp_unpack_sequence,
11901192
mp_unpack_ex,
11911193
};

py/runtime0.h

+2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ typedef enum {
127127
MP_F_IMPORT_NAME,
128128
MP_F_IMPORT_FROM,
129129
MP_F_IMPORT_ALL,
130+
#if MICROPY_PY_BUILTINS_SLICE
130131
MP_F_NEW_SLICE,
132+
#endif
131133
MP_F_UNPACK_SEQUENCE,
132134
MP_F_UNPACK_EX,
133135
MP_F_NUMBER_OF,

py/sequence.c

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ void mp_seq_multiply(const void *items, uint item_sz, uint len, uint times, void
5151
}
5252
}
5353

54+
#if MICROPY_PY_BUILTINS_SLICE
55+
5456
bool mp_seq_get_fast_slice_indexes(machine_uint_t len, mp_obj_t slice, mp_bound_slice_t *indexes) {
5557
mp_obj_t ostart, ostop, ostep;
5658
machine_int_t start, stop;
@@ -102,6 +104,8 @@ bool mp_seq_get_fast_slice_indexes(machine_uint_t len, mp_obj_t slice, mp_bound_
102104
return true;
103105
}
104106

107+
#endif
108+
105109
mp_obj_t mp_seq_extract_slice(uint len, const mp_obj_t *seq, mp_bound_slice_t *indexes) {
106110
machine_int_t start = indexes->start, stop = indexes->stop;
107111
machine_int_t step = indexes->step;

0 commit comments

Comments
 (0)