py/nlrsetjmp: Add check for failed NLR jump.

Also optimise the function so it only needs to call the MP_STATE_THREAD
macro once (following how other nlr code is written).
This commit is contained in:
Damien George 2017-04-12 13:50:31 +10:00
parent fe79234ca0
commit 08242eed26

View File

@ -29,10 +29,14 @@
#if MICROPY_NLR_SETJMP
void nlr_setjmp_jump(void *val) {
nlr_buf_t *buf = MP_STATE_THREAD(nlr_top);
MP_STATE_THREAD(nlr_top) = buf->prev;
buf->ret_val = val;
longjmp(buf->jmpbuf, 1);
nlr_buf_t **top_ptr = &MP_STATE_THREAD(nlr_top);
nlr_buf_t *top = *top_ptr;
if (top == NULL) {
nlr_jump_fail(val);
}
top->ret_val = val;
*top_ptr = top->prev;
longjmp(top->jmpbuf, 1);
}
#endif