From e89cc13e5c4fa05d7f14dabedf3ac21a2dd57084 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 15 Feb 2015 20:23:52 +0300 Subject: [PATCH] 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). --- py/nlr.h | 5 +++++ 1 file changed, 5 insertions(+) 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__