Skip to content

Commit 5377502

Browse files
committed
Merge branch 'master' of github.com:micropython/micropython
2 parents fd6925b + efc36f0 commit 5377502

4 files changed

Lines changed: 30 additions & 10 deletions

File tree

py/objarray.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,27 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
139139
return MP_OBJ_NOT_SUPPORTED;
140140
} else {
141141
mp_obj_array_t *o = self_in;
142-
uint index = mp_get_index(o->base.type, o->len, index_in, false);
143-
if (value == MP_OBJ_SENTINEL) {
144-
// load
145-
return mp_binary_get_val_array(o->typecode, o->items, index);
142+
if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) {
143+
machine_uint_t start, stop;
144+
if (!m_seq_get_fast_slice_indexes(o->len, index_in, &start, &stop)) {
145+
assert(0);
146+
}
147+
mp_obj_array_t *res = array_new(o->typecode, stop - start);
148+
int sz = mp_binary_get_size('@', o->typecode, NULL);
149+
assert(sz > 0);
150+
byte *p = o->items;
151+
memcpy(res->items, p + start * sz, (stop - start) * sz);
152+
return res;
146153
} else {
147-
// store
148-
mp_binary_set_val_array(o->typecode, o->items, index, value);
149-
return mp_const_none;
154+
uint index = mp_get_index(o->base.type, o->len, index_in, false);
155+
if (value == MP_OBJ_SENTINEL) {
156+
// load
157+
return mp_binary_get_val_array(o->typecode, o->items, index);
158+
} else {
159+
// store
160+
mp_binary_set_val_array(o->typecode, o->items, index, value);
161+
return mp_const_none;
162+
}
150163
}
151164
}
152165
}

tests/basics/bytearray1.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@
1313
for i in a:
1414
s += i
1515
print(s)
16+
17+
print(a[1:])
18+
print(a[:-1])
19+
print(a[2:3])

tests/basics/class-super.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
class Base:
22

3+
def __init__(self):
4+
self.a = 1
5+
36
def meth(self):
4-
print("in Base meth")
7+
print("in Base meth", self.a)
58

69
class Sub(Base):
710

unix/modffi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ STATIC mp_obj_t ffimod_func(uint n_args, const mp_obj_t *args) {
141141
mp_obj_t iterable = mp_getiter(args[3]);
142142
mp_obj_t item;
143143
int i = 0;
144-
while ((item = mp_iternext(iterable)) != MP_OBJ_NULL) {
144+
while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
145145
o->params[i++] = get_ffi_type(item);
146146
}
147147

@@ -178,7 +178,7 @@ STATIC mp_obj_t mod_ffi_callback(mp_obj_t rettype_in, mp_obj_t func_in, mp_obj_t
178178
mp_obj_t iterable = mp_getiter(paramtypes_in);
179179
mp_obj_t item;
180180
int i = 0;
181-
while ((item = mp_iternext(iterable)) != MP_OBJ_NULL) {
181+
while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
182182
o->params[i++] = get_ffi_type(item);
183183
}
184184

0 commit comments

Comments
 (0)