summaryrefslogtreecommitdiff
path: root/py/vm.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-12-24 12:47:39 +0000
committerDamien George <damien.p.george@gmail.com>2015-12-24 12:47:39 +0000
commit8047340d7532ec32bc9f2d603bffc0bc9544297f (patch)
tree2a1eced095349199a049e82f0c9a080de13fb9b3 /py/vm.c
parent117158fcd560a84318a0b9cb5332c5599acdb84b (diff)
py: Handle case of return within the finally block of try-finally.
Addresses issue #1636.
Diffstat (limited to 'py/vm.c')
-rw-r--r--py/vm.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/py/vm.c b/py/vm.c
index 8bf59f1e0..8c7c2265e 100644
--- a/py/vm.c
+++ b/py/vm.c
@@ -1032,6 +1032,14 @@ unwind_jump:;
ENTRY(MP_BC_RETURN_VALUE):
MARK_EXC_IP_SELECTIVE();
+ // These next 3 lines pop a try-finally exception handler, if one
+ // is there on the exception stack. Without this the finally block
+ // is executed a second time when the return is executed, because
+ // the try-finally exception handler is still on the stack.
+ // TODO Possibly find a better way to handle this case.
+ if (currently_in_except_block) {
+ POP_EXC_BLOCK();
+ }
unwind_return:
while (exc_sp >= exc_stack) {
if (MP_TAGPTR_TAG1(exc_sp->val_sp)) {