8000 lib/utils/pyexec: Handle pending exceptions after disabling kbd intrs. · micropython/micropython@5a91cd9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5a91cd9

Browse files
committed
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.
1 parent 98a3911 commit 5a91cd9

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

lib/utils/pyexec.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,16 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
107107
#endif
108108
mp_call_function_0(module_fun);
109109
mp_hal_set_interrupt_char(-1); // disable interrupt
110+
mp_handle_pending(true); // handle any pending exceptions (and any callbacks)
110111
nlr_pop();
111112
ret = 1;
112113
if (exec_flags & EXEC_FLAG_PRINT_EOF) {
113114
mp_hal_stdout_tx_strn("\x04", 1);
114115
}
115116
} else {
116117
// uncaught exception
117-
// FIXME it could be that an interrupt happens just before we disable it here
118118
mp_hal_set_interrupt_char(-1); // disable interrupt
119+
mp_handle_pending(false); // clear any pending exceptions (and run any callbacks)
119120
// print EOF after normal output
120121
if (exec_flags & EXEC_FLAG_PRINT_EOF) {
121122
mp_hal_stdout_tx_strn("\x04", 1);

ports/unix/main.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,17 @@ STATIC int execute_from_lexer(int source_kind, const void *source, mp_parse_inpu
145145
if (!compile_only) {
146146
// execute it
147147
mp_call_function_0(module_fun);
148-
// check for pending exception
149-
if (MP_STATE_VM(mp_pending_exception) != MP_OBJ_NULL) {
150-
mp_obj_t obj = MP_STATE_VM(mp_pending_exception);
151-
MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL;
152-
nlr_raise(obj);
153-
}
154148
}
155149

156150
mp_hal_set_interrupt_char(-1);
151+
mp_handle_pending(true);
157152
nlr_pop();
158153
return 0;
159154

160155
} else {
161156
// uncaught exception
162157
mp_hal_set_interrupt_char(-1);
158+
mp_handle_pending(false);
163159
return handle_uncaught_exception(nlr.ret_val);
164160
}
165161
}

0 commit comments

Comments
 (0)
0