diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-02-27 22:16:05 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-02-27 22:17:15 +0200 |
commit | cefcbb22b2befac1baa9953c477fcee4031635d3 (patch) | |
tree | 34a4c43587350c4f57b5ffd0a54360b4a075493f /py/objlist.c | |
parent | 0bb971370bef272aea369f0f8699dd0523b6a977 (diff) | |
download | micropython-cefcbb22b2befac1baa9953c477fcee4031635d3.tar.gz micropython-cefcbb22b2befac1baa9953c477fcee4031635d3.zip |
objarray: Implement array slice assignment.
This is rarely used feature which takes enough code to implement, so is
controlled by MICROPY_PY_ARRAY_SLICE_ASSIGN config setting, default off.
But otherwise it may be useful, as allows to update arbitrary-sized data
buffers in-place.
Slice is yet to implement, and actually, slice assignment implemented in
such a way that RHS of assignment should be array of the exact same item
typecode as LHS. CPython has it more relaxed, where RHS can be any sequence
of compatible types (e.g. it's possible to assign list of int's to a
bytearray slice).
Overall, when all "slice write" features are implemented, it may cost ~1KB
of code.
Diffstat (limited to 'py/objlist.c')
-rw-r--r-- | py/objlist.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/py/objlist.c b/py/objlist.c index e0c8953755..03e3dda033 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -165,7 +165,7 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { mp_int_t len_adj = slice.start - slice.stop; //printf("Len adj: %d\n", len_adj); assert(len_adj <= 0); - mp_seq_replace_slice_no_grow(self->items, self->len, slice.start, slice.stop, self->items/*NULL*/, 0, mp_obj_t); + mp_seq_replace_slice_no_grow(self->items, self->len, slice.start, slice.stop, self->items/*NULL*/, 0, sizeof(*self->items)); // Clear "freed" elements at the end of list mp_seq_clear(self->items, self->len + len_adj, self->len, sizeof(*self->items)); self->len += len_adj; @@ -211,10 +211,10 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { self->alloc = self->len + len_adj; } mp_seq_replace_slice_grow_inplace(self->items, self->len, - slice_out.start, slice_out.stop, slice->items, slice->len, len_adj, mp_obj_t); + slice_out.start, slice_out.stop, slice->items, slice->len, len_adj, sizeof(*self->items)); } else { mp_seq_replace_slice_no_grow(self->items, self->len, - slice_out.start, slice_out.stop, slice->items, slice->len, mp_obj_t); + slice_out.start, slice_out.stop, slice->items, slice->len, sizeof(*self->items)); // Clear "freed" elements at the end of list mp_seq_clear(self->items, self->len + len_adj, self->len, sizeof(*self->items)); // TODO: apply allocation policy re: alloc_size |