lib/utils/pyexec: Handle pending exceptions after disabling kbd intrs.
Pending exceptions would otherwise be handled later on where there may not be an NLR handler in place. A similar fix is also made to the unix port's REPL handler. Fixes issues #4921 and #5488.
This commit is contained in:
parent
98a3911c43
commit
5a91cd9ff3
@ -107,6 +107,7 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
|
|||||||
#endif
|
#endif
|
||||||
mp_call_function_0(module_fun);
|
mp_call_function_0(module_fun);
|
||||||
mp_hal_set_interrupt_char(-1); // disable interrupt
|
mp_hal_set_interrupt_char(-1); // disable interrupt
|
||||||
|
mp_handle_pending(true); // handle any pending exceptions (and any callbacks)
|
||||||
nlr_pop();
|
nlr_pop();
|
||||||
ret = 1;
|
ret = 1;
|
||||||
if (exec_flags & EXEC_FLAG_PRINT_EOF) {
|
if (exec_flags & EXEC_FLAG_PRINT_EOF) {
|
||||||
@ -114,8 +115,8 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// uncaught exception
|
// uncaught exception
|
||||||
// FIXME it could be that an interrupt happens just before we disable it here
|
|
||||||
mp_hal_set_interrupt_char(-1); // disable interrupt
|
mp_hal_set_interrupt_char(-1); // disable interrupt
|
||||||
|
mp_handle_pending(false); // clear any pending exceptions (and run any callbacks)
|
||||||
// print EOF after normal output
|
// print EOF after normal output
|
||||||
if (exec_flags & EXEC_FLAG_PRINT_EOF) {
|
if (exec_flags & EXEC_FLAG_PRINT_EOF) {
|
||||||
mp_hal_stdout_tx_strn("\x04", 1);
|
mp_hal_stdout_tx_strn("\x04", 1);
|
||||||
|
@ -145,21 +145,17 @@ STATIC int execute_from_lexer(int source_kind, const void *source, mp_parse_inpu
|
|||||||
if (!compile_only) {
|
if (!compile_only) {
|
||||||
// execute it
|
// execute it
|
||||||
mp_call_function_0(module_fun);
|
mp_call_function_0(module_fun);
|
||||||
// check for pending exception
|
|
||||||
if (MP_STATE_VM(mp_pending_exception) != MP_OBJ_NULL) {
|
|
||||||
mp_obj_t obj = MP_STATE_VM(mp_pending_exception);
|
|
||||||
MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL;
|
|
||||||
nlr_raise(obj);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_hal_set_interrupt_char(-1);
|
mp_hal_set_interrupt_char(-1);
|
||||||
|
mp_handle_pending(true);
|
||||||
nlr_pop();
|
nlr_pop();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// uncaught exception
|
// uncaught exception
|
||||||
mp_hal_set_interrupt_char(-1);
|
mp_hal_set_interrupt_char(-1);
|
||||||
|
mp_handle_pending(false);
|
||||||
return handle_uncaught_exception(nlr.ret_val);
|
return handle_uncaught_exception(nlr.ret_val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user