summaryrefslogtreecommitdiff
path: root/py/vm.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-03-30 00:48:21 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-03-30 01:01:35 +0200
commit0c904df8e6c4cf9123a837861b97585a61b3d8df (patch)
tree9ff8dbdbb02b300f6b08a3570ea9e3e408bcb4b7 /py/vm.c
parent69975df3fffaae5f11caa6663f01f4a876d3ab41 (diff)
vm: Save current active exception on opening new try block.
Required to reraise correct exceptions in except block, regardless if more try blocks with active exceptions happen in the same except block. P.S. This "automagic reraise" appears to be quite wasteful feature of Python - we need to save pending exception just in case it *might* be reraised. Instead, programmer could explcitly capture exception to a variable using "except ... as var", and reraise that. So, consider disabling argless raise support as an optimization.
Diffstat (limited to 'py/vm.c')
-rw-r--r--py/vm.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/py/vm.c b/py/vm.c
index 731674266..b96cca142 100644
--- a/py/vm.c
+++ b/py/vm.c
@@ -51,10 +51,12 @@ typedef enum {
exc_sp->opcode = op; \
exc_sp->handler = ip + unum; \
exc_sp->val_sp = MP_TAGPTR_MAKE(sp, currently_in_except_block); \
+ exc_sp->prev_exc = nlr.ret_val; \
currently_in_except_block = 0; /* in a try block now */
#define POP_EXC_BLOCK() \
currently_in_except_block = MP_TAGPTR_TAG(exc_sp->val_sp); /* restore previous state */ \
+ if (currently_in_except_block) { nlr.ret_val = exc_sp->prev_exc; } \
exc_sp--; /* pop back to previous exception handler */
mp_vm_return_kind_t mp_execute_byte_code(const byte *code, const mp_obj_t *args, uint n_args, const mp_obj_t *args2, uint n_args2, mp_obj_t *ret) {