Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
c0dc7c3d
Commit
c0dc7c3d
authored
Apr 24, 2014
by
Damien George
Browse files
py, vm: Fix recent bug where state is freed too early.
parent
d5e8482c
Changes
1
Hide whitespace changes
Inline
Side-by-side
py/vm.c
View file @
c0dc7c3d
...
...
@@ -151,30 +151,38 @@ mp_vm_return_kind_t mp_execute_byte_code(const byte *code, const mp_obj_t *args,
}
#endif
// get possible exception object before we free the state
*
ret
=
state
[
n_state
-
1
];
mp_vm_return_kind_t
ret_kind
;
switch
(
vm_return_kind
)
{
case
MP_VM_RETURN_NORMAL
:
// return value is in *sp
*
ret
=
*
sp
;
ret_kind
=
MP_VM_RETURN_NORMAL
;
break
;
case
MP_VM_RETURN_EXCEPTION
:
// return value is in state[n_state - 1]
*
ret
=
state
[
n_state
-
1
];
ret_kind
=
MP_VM_RETURN_EXCEPTION
;
break
;
case
MP_VM_RETURN_YIELD
:
// byte-code shouldn't yield
default:
assert
(
0
);
*
ret
=
mp_const_none
;
ret_kind
=
MP_VM_RETURN_NORMAL
;
}
// free the state if it was allocated on the heap
if
(
n_state
>
VM_MAX_STATE_ON_STACK
)
{
m_free
(
state
,
n_state
);
}
// free the exception state if it was allocated on the heap
if
(
n_exc_stack
>
VM_MAX_EXC_STATE_ON_STACK
)
{
m_free
(
exc_stack
,
n_exc_stack
);
}
switch
(
vm_return_kind
)
{
case
MP_VM_RETURN_NORMAL
:
*
ret
=
*
sp
;
// return value is in *sp
return
MP_VM_RETURN_NORMAL
;
case
MP_VM_RETURN_EXCEPTION
:
// return value is in state[n_state - 1], already loaded into *ret
return
MP_VM_RETURN_EXCEPTION
;
case
MP_VM_RETURN_YIELD
:
// byte-code shouldn't yield
default:
assert
(
0
);
*
ret
=
mp_const_none
;
return
MP_VM_RETURN_NORMAL
;
}
return
ret_kind
;
}
// fastn has items in reverse order (fastn[0] is local[0], fastn[-1] is local[1], etc)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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