diff options
author | Damien George <damien.p.george@gmail.com> | 2014-01-18 23:42:49 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-01-18 23:42:49 +0000 |
commit | 932bf1c48f5ccbb82b7693af4ba05fb48508afbf (patch) | |
tree | c6186134c1bbf9cd9c9b3073e121eb58b765df87 | |
parent | 8fce5b42a282d2878004b6a6b53927c7ebeede3f (diff) | |
download | micropython-932bf1c48f5ccbb82b7693af4ba05fb48508afbf.tar.gz micropython-932bf1c48f5ccbb82b7693af4ba05fb48508afbf.zip |
py: Fix VM/runtime unpack sequence bug, Issue #193.
-rw-r--r-- | py/runtime.c | 6 | ||||
-rw-r--r-- | py/vm.c | 2 |
2 files changed, 5 insertions, 3 deletions
diff --git a/py/runtime.c b/py/runtime.c index 0931538991..fbcc983ab7 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -761,7 +761,7 @@ mp_obj_t rt_store_set(mp_obj_t set, mp_obj_t item) { return set; } -// unpacked items are stored in order into the array pointed to by items +// unpacked items are stored in reverse order into the array pointed to by items void rt_unpack_sequence(mp_obj_t seq_in, uint num, mp_obj_t *items) { if (MP_OBJ_IS_TYPE(seq_in, &tuple_type) || MP_OBJ_IS_TYPE(seq_in, &list_type)) { uint seq_len; @@ -776,7 +776,9 @@ void rt_unpack_sequence(mp_obj_t seq_in, uint num, mp_obj_t *items) { } else if (seq_len > num) { nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_ValueError, "too many values to unpack (expected %d)", (void*)(machine_uint_t)num)); } - memcpy(items, seq_items, num * sizeof(mp_obj_t)); + for (uint i = 0; i < num; i++) { + items[i] = seq_items[num - 1 - i]; + } } else { // TODO call rt_getiter and extract via rt_iternext nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "'%s' object is not iterable", mp_obj_get_type_str(seq_in))); @@ -450,7 +450,7 @@ bool mp_execute_byte_code_2(const byte *code_info, const byte **ip_in_out, mp_ob case MP_BC_UNPACK_SEQUENCE: DECODE_UINT; - rt_unpack_sequence(sp[0], unum, sp + unum - 1); + rt_unpack_sequence(sp[0], unum, sp); sp += unum - 1; break; |