From ae2c81ff388d9b06bc11ac1e14bd5d71b4f4637c Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 26 Apr 2015 01:20:49 +0300 Subject: vm: On exiting except block, clear sys.exc_info() value. This doesn't handle case fo enclosed except blocks, but once again, sys.exc_info() support is a workaround for software which uses it instead of properly catching exceptions via variable in except clause. --- py/vm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'py') diff --git a/py/vm.c b/py/vm.c index 3a7191368..997884d4f 100644 --- a/py/vm.c +++ b/py/vm.c @@ -78,6 +78,12 @@ typedef enum { #define TOP() (*sp) #define SET_TOP(val) *sp = (val) +#if MICROPY_PY_SYS_EXC_INFO +#define CLEAR_SYS_EXC_INFO() MP_STATE_VM(cur_exception) = MP_OBJ_NULL; +#else +#define CLEAR_SYS_EXC_INFO() +#endif + #define PUSH_EXC_BLOCK(with_or_finally) do { \ DECODE_ULABEL; /* except labels are always forward */ \ ++exc_sp; \ @@ -89,7 +95,8 @@ typedef enum { #define POP_EXC_BLOCK() \ currently_in_except_block = MP_TAGPTR_TAG0(exc_sp->val_sp); /* restore previous state */ \ - exc_sp--; /* pop back to previous exception handler */ + exc_sp--; /* pop back to previous exception handler */ \ + CLEAR_SYS_EXC_INFO() /* just clear sys.exc_info(), not compliant, but it shouldn't be used in 1st place */ // fastn has items in reverse order (fastn[0] is local[0], fastn[-1] is local[1], etc) // sp points to bottom of stack which grows up -- cgit v1.2.3