Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
932bf1c4
Commit
932bf1c4
authored
Jan 18, 2014
by
Damien George
Browse files
py: Fix VM/runtime unpack sequence bug, Issue #193.
parent
8fce5b42
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/runtime.c
View file @
932bf1c4
...
@@ -761,7 +761,7 @@ mp_obj_t rt_store_set(mp_obj_t set, mp_obj_t item) {
...
@@ -761,7 +761,7 @@ mp_obj_t rt_store_set(mp_obj_t set, mp_obj_t item) {
return
set
;
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
)
{
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
))
{
if
(
MP_OBJ_IS_TYPE
(
seq_in
,
&
tuple_type
)
||
MP_OBJ_IS_TYPE
(
seq_in
,
&
list_type
))
{
uint
seq_len
;
uint
seq_len
;
...
@@ -776,7 +776,9 @@ void rt_unpack_sequence(mp_obj_t seq_in, uint num, mp_obj_t *items) {
...
@@ -776,7 +776,9 @@ void rt_unpack_sequence(mp_obj_t seq_in, uint num, mp_obj_t *items) {
}
else
if
(
seq_len
>
num
)
{
}
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
));
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
{
}
else
{
// TODO call rt_getiter and extract via rt_iternext
// 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
)));
nlr_jump
(
mp_obj_new_exception_msg_varg
(
MP_QSTR_TypeError
,
"'%s' object is not iterable"
,
mp_obj_get_type_str
(
seq_in
)));
...
...
py/vm.c
View file @
932bf1c4
...
@@ -450,7 +450,7 @@ bool mp_execute_byte_code_2(const byte *code_info, const byte **ip_in_out, mp_ob
...
@@ -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
:
case
MP_BC_UNPACK_SEQUENCE
:
DECODE_UINT
;
DECODE_UINT
;
rt_unpack_sequence
(
sp
[
0
],
unum
,
sp
+
unum
-
1
);
rt_unpack_sequence
(
sp
[
0
],
unum
,
sp
);
sp
+=
unum
-
1
;
sp
+=
unum
-
1
;
break
;
break
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment