diff --git a/py/objarray.c b/py/objarray.c index cf8b1ed4eb2d2e4be2bea23c6a039e9c12b73816..b7a84ba4cf6e215f683c0c6f6610f1e08b7a16f8 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -139,14 +139,27 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value return MP_OBJ_NOT_SUPPORTED; } else { mp_obj_array_t *o = self_in; - uint index = mp_get_index(o->base.type, o->len, index_in, false); - if (value == MP_OBJ_SENTINEL) { - // load - return mp_binary_get_val_array(o->typecode, o->items, index); + if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) { + machine_uint_t start, stop; + if (!m_seq_get_fast_slice_indexes(o->len, index_in, &start, &stop)) { + assert(0); + } + mp_obj_array_t *res = array_new(o->typecode, stop - start); + int sz = mp_binary_get_size('@', o->typecode, NULL); + assert(sz > 0); + byte *p = o->items; + memcpy(res->items, p + start * sz, (stop - start) * sz); + return res; } else { - // store - mp_binary_set_val_array(o->typecode, o->items, index, value); - return mp_const_none; + uint index = mp_get_index(o->base.type, o->len, index_in, false); + if (value == MP_OBJ_SENTINEL) { + // load + return mp_binary_get_val_array(o->typecode, o->items, index); + } else { + // store + mp_binary_set_val_array(o->typecode, o->items, index, value); + return mp_const_none; + } } } } diff --git a/tests/basics/bytearray1.py b/tests/basics/bytearray1.py index e564165b9f5c17d9fc9da5744c884dbe509eaab3..02066cafc34ff2799bfde7fe1e09f8de547b1a1b 100644 --- a/tests/basics/bytearray1.py +++ b/tests/basics/bytearray1.py @@ -13,3 +13,7 @@ s = 0 for i in a: s += i print(s) + +print(a[1:]) +print(a[:-1]) +print(a[2:3]) diff --git a/tests/basics/class-super.py b/tests/basics/class-super.py index 6a87b2fd00c817af2924ff7e056f1ce7aab3b18f..0f2852a47933dc3baadef930b881661c7030b440 100644 --- a/tests/basics/class-super.py +++ b/tests/basics/class-super.py @@ -1,7 +1,10 @@ class Base: + def __init__(self): + self.a = 1 + def meth(self): - print("in Base meth") + print("in Base meth", self.a) class Sub(Base): diff --git a/unix/modffi.c b/unix/modffi.c index bdaa3b2b4325a2a2b9cb20fca3a81f5f84e803c3..83bc2c5454e842cc9ab10800496ac065b0cc8fca 100644 --- a/unix/modffi.c +++ b/unix/modffi.c @@ -141,7 +141,7 @@ STATIC mp_obj_t ffimod_func(uint n_args, const mp_obj_t *args) { mp_obj_t iterable = mp_getiter(args[3]); mp_obj_t item; int i = 0; - while ((item = mp_iternext(iterable)) != MP_OBJ_NULL) { + while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { o->params[i++] = get_ffi_type(item); } @@ -178,7 +178,7 @@ STATIC mp_obj_t mod_ffi_callback(mp_obj_t rettype_in, mp_obj_t func_in, mp_obj_t mp_obj_t iterable = mp_getiter(paramtypes_in); mp_obj_t item; int i = 0; - while ((item = mp_iternext(iterable)) != MP_OBJ_NULL) { + while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { o->params[i++] = get_ffi_type(item); }