Commit 932bf1c4 authored by Damien George's avatar Damien George
Browse files

py: Fix VM/runtime unpack sequence bug, Issue #193.

parent 8fce5b42
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment