diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-12-18 01:10:58 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-12-18 01:12:59 +0200 |
commit | 2195046365c661551c30d4156cecafa603214375 (patch) | |
tree | 84bb71dee0a4c911e060253fff5e16d47c963973 | |
parent | 5efd3f0dcac6e2f3f33c3edce7d3f2974bbf8e78 (diff) | |
download | micropython-2195046365c661551c30d4156cecafa603214375.tar.gz micropython-2195046365c661551c30d4156cecafa603214375.zip |
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.
-rw-r--r-- | windows/windows_mphal.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/windows/windows_mphal.c b/windows/windows_mphal.c index 702efa4960..91025d6cf4 100644 --- a/windows/windows_mphal.c +++ b/windows/windows_mphal.c @@ -30,6 +30,7 @@ #include <windows.h> #include <unistd.h> +#include <signal.h> HANDLE std_in = NULL; HANDLE con_out = NULL; @@ -66,6 +67,17 @@ void mp_hal_stdio_mode_orig(void) { SetConsoleMode(std_in, orig_mode); } +STATIC void sighandler(int signum) { + if (signum == SIGINT) { + if (MP_STATE_VM(mp_pending_exception) == MP_STATE_VM(keyboard_interrupt_obj)) { + // this is the second time we are called, so die straight away + exit(1); + } + mp_obj_exception_clear_traceback(MP_STATE_VM(keyboard_interrupt_obj)); + MP_STATE_VM(mp_pending_exception) = MP_STATE_VM(keyboard_interrupt_obj); + } +} + void mp_hal_set_interrupt_char(char c) { assure_stdin_handle(); if (c == CHAR_CTRL_C) { @@ -73,11 +85,13 @@ void mp_hal_set_interrupt_char(char c) { GetConsoleMode(std_in, &mode); mode |= ENABLE_PROCESSED_INPUT; SetConsoleMode(std_in, mode); + signal(SIGINT, sighandler); } else { DWORD mode; GetConsoleMode(std_in, &mode); mode &= ~ENABLE_PROCESSED_INPUT; SetConsoleMode(std_in, mode); + signal(SIGINT, SIG_DFL); } } |