From c49ddb9315b8a3839439727d5a3df1f4226777e1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 1 Jun 2014 13:49:35 +0100 Subject: [PATCH] py: Fix configurability of builtin slice. --- py/obj.h | 2 ++ py/objarray.c | 5 ++++- py/runtime.c | 2 ++ py/runtime0.h | 2 ++ py/sequence.c | 4 ++++ 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/py/obj.h b/py/obj.h index e7c044df0f..7c83715111 100644 --- a/py/obj.h +++ b/py/obj.h @@ -568,7 +568,9 @@ typedef struct { } mp_bound_slice_t; void mp_seq_multiply(const void *items, uint item_sz, uint len, uint times, void *dest); +#if MICROPY_PY_BUILTINS_SLICE bool mp_seq_get_fast_slice_indexes(machine_uint_t len, mp_obj_t slice, mp_bound_slice_t *indexes); +#endif #define mp_seq_copy(dest, src, len, item_t) memcpy(dest, src, len * sizeof(item_t)) #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)); } bool mp_seq_cmp_bytes(int op, const byte *data1, uint len1, const byte *data2, uint len2); diff --git a/py/objarray.c b/py/objarray.c index 91fcec624a..44fbf2f998 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -169,7 +169,9 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value return MP_OBJ_NULL; // op not supported } else { mp_obj_array_t *o = self_in; - if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) { + if (0) { +#if MICROPY_PY_BUILTINS_SLICE + } else if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) { if (value != MP_OBJ_SENTINEL) { // Only getting a slice is suported so far, not assignment // 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 byte *p = o->items; memcpy(res->items, p + slice.start * sz, (slice.stop - slice.start) * sz); return res; +#endif } else { uint index = mp_get_index(o->base.type, o->len, index_in, false); if (value == MP_OBJ_SENTINEL) { diff --git a/py/runtime.c b/py/runtime.c index cb4d16be18..ecaf40deb4 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1185,7 +1185,9 @@ 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, }; diff --git a/py/runtime0.h b/py/runtime0.h index 1d1f9d77c4..eea578237a 100644 --- a/py/runtime0.h +++ b/py/runtime0.h @@ -127,7 +127,9 @@ 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_NUMBER_OF, diff --git a/py/sequence.c b/py/sequence.c index c940d9f69f..c73f3baba1 100644 --- a/py/sequence.c +++ b/py/sequence.c @@ -51,6 +51,8 @@ void mp_seq_multiply(const void *items, uint item_sz, uint len, uint times, void } } +#if MICROPY_PY_BUILTINS_SLICE + bool mp_seq_get_fast_slice_indexes(machine_uint_t len, mp_obj_t slice, mp_bound_slice_t *indexes) { mp_obj_t ostart, ostop, ostep; 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_ return true; } +#endif + mp_obj_t mp_seq_extract_slice(uint len, const mp_obj_t *seq, mp_bound_slice_t *indexes) { machine_int_t start = indexes->start, stop = indexes->stop; machine_int_t step = indexes->step;