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

This commit is contained in:
Damien George 2014-01-18 23:42:49 +00:00
parent 8fce5b42a2
commit 932bf1c48f
2 changed files with 5 additions and 3 deletions

View File

@ -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)));

View File

@ -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;