aboutsummaryrefslogtreecommitdiff
path: root/py/nlr.h
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-02-15 20:23:52 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-02-15 20:23:52 +0300
commite89cc13e5c4fa05d7f14dabedf3ac21a2dd57084 (patch)
tree7997f906b1af294b2e724dd37062c2915eea0515 /py/nlr.h
parent53e5e0fa28d0f81be8671303ea0388da71fd20b6 (diff)
nlr: If DEBUG, guard against recursive nlr_push().
Pushing same NLR record twice would lead to "infinite loop" in nlr_jump (but more realistically, it will crash as soon as NLR record on stack is overwritten).
Diffstat (limited to 'py/nlr.h')
-rw-r--r--py/nlr.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/py/nlr.h b/py/nlr.h
index f414588a5..58e3fa23f 100644
--- a/py/nlr.h
+++ b/py/nlr.h
@@ -88,6 +88,7 @@ void nlr_jump_fail(void *val);
#ifndef DEBUG
#define nlr_raise(val) nlr_jump(val)
#else
+#include "mpstate.h"
#define nlr_raise(val) \
do { \
void *_val = val; \
@@ -95,6 +96,10 @@ void nlr_jump_fail(void *val);
assert(mp_obj_is_exception_instance(_val)); \
nlr_jump(_val); \
} while (0)
+
+#define nlr_push(val) \
+ assert(MP_STATE_VM(nlr_top) != val),nlr_push(val)
+
#endif
#endif // __MICROPY_INCLUDED_PY_NLR_H__