8000 windows/windows_mphal: Add basic support for raising KeyboardInterrupt. · micropython/micropython@2195046 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2195046

Browse files
author
Paul Sokolovsky
committed
windows/windows_mphal: Add basic support for raising KeyboardInterrupt.
Compiles with mingw32, tested to work erratically under Wine due to not fully implemented emulation in it.
1 parent 5efd3f0 commit 2195046

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

windows/windows_mphal.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include <windows.h>
3232
#include <unistd.h>
33+
#include <signal.h>
3334

3435
HANDLE std_in = NULL;
3536
HANDLE con_out = NULL;
@@ -66,18 +67,31 @@ void mp_hal_stdio_mode_orig(void) {
6667
SetConsoleMode(std_in, orig_mode);
6768
}
6869

70+
STATIC void sighandler(int signum) {
71+
if (signum == SIGINT) {
72+
if (MP_STATE_VM(mp_pending_exception) == MP_STATE_VM(keyboard_interrupt_obj)) {
73+
// this is the second time we are called, so die straight away
74+
exit(1);
75+
}
76+
mp_obj_exception_clear_traceback(MP_STATE_VM(keyboard_interrupt_obj));
77+
MP_STATE_VM(mp_pending_exception) = MP_STATE_VM(keyboard_interrupt_obj);
78+
}
79+
}
80+
6981
void mp_hal_set_interrupt_char(char c) {
7082
assure_stdin_handle();
7183
if (c == CHAR_CTRL_C) {
7284
DWORD mode;
7385
GetConsoleMode(std_in, &mode);
7486
mode |= ENABLE_PROCESSED_INPUT;
7587
SetConsoleMode(std_in, mode);
88+
signal(SIGINT, sighandler);
7689
} else {
7790
DWORD mode;
7891
GetConsoleMode(std_in, &mode);
7992
mode &= ~ENABLE_PROCESSED_INPUT;
8093
SetConsoleMode(std_in, mode);
94+
signal(SIGINT, SIG_DFL);
8195
}
8296
}
8397

0 commit comments

Comments
 (0)
0