Commit 6c564aa4 authored by Damien George's avatar Damien George
Browse files

unix, windows: Use core-provided KeyboardInterrupt exception object.

parent 9156c8b4
......@@ -425,9 +425,6 @@ MP_NOINLINE int main_(int argc, char **argv) {
mp_init();
// create keyboard interrupt object
MP_STATE_VM(keyboard_interrupt_obj) = mp_obj_new_exception(&mp_type_KeyboardInterrupt);
char *home = getenv("HOME");
char *path = getenv("MICROPYPATH");
if (path == NULL) {
......
......@@ -156,6 +156,7 @@
#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (256)
#define MICROPY_KBD_EXCEPTION (1)
#define MICROPY_ASYNC_KBD_INTR (1)
extern const struct _mp_obj_module_t mp_module_machine;
......@@ -283,7 +284,6 @@ void mp_unix_mark_exec(void);
#define MICROPY_PORT_ROOT_POINTERS \
const char *readline_hist[50]; \
mp_obj_t keyboard_interrupt_obj; \
void *mmap_region_head; \
// We need to provide a declaration/definition of alloca()
......
......@@ -47,6 +47,7 @@
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_TERSE)
#define MICROPY_WARNINGS (0)
#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (0)
#define MICROPY_KBD_EXCEPTION (1)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE)
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE)
#define MICROPY_STREAMS_NON_BLOCK (0)
......@@ -99,7 +100,6 @@ extern const struct _mp_obj_module_t mp_module_os;
{ MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&mp_module_os }, \
#define MICROPY_PORT_ROOT_POINTERS \
mp_obj_t keyboard_interrupt_obj;
//////////////////////////////////////////
// Do not change anything beyond this line
......
......@@ -40,20 +40,20 @@
STATIC void sighandler(int signum) {
if (signum == SIGINT) {
#if MICROPY_ASYNC_KBD_INTR
mp_obj_exception_clear_traceback(MP_STATE_VM(keyboard_interrupt_obj));
mp_obj_exception_clear_traceback(MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)));
sigset_t mask;
sigemptyset(&mask);
// On entry to handler, its signal is blocked, and unblocked on
// normal exit. As we instead perform longjmp, unblock it manually.
sigprocmask(SIG_SETMASK, &mask, NULL);
nlr_raise(MP_STATE_VM(keyboard_interrupt_obj));
nlr_raise(MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)));
#else
if (MP_STATE_VM(mp_pending_exception) == MP_STATE_VM(keyboard_interrupt_obj)) {
if (MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception))) {
// 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);
mp_obj_exception_clear_traceback(MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)));
MP_STATE_VM(mp_pending_exception) = MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception));
#endif
}
}
......
......@@ -104,6 +104,7 @@
#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (256)
#define MICROPY_KBD_EXCEPTION (1)
#define MICROPY_PORT_INIT_FUNC init()
#define MICROPY_PORT_DEINIT_FUNC deinit()
......@@ -161,8 +162,7 @@ extern const struct _mp_obj_module_t mp_module_time;
#if MICROPY_USE_READLINE == 1
#define MICROPY_PORT_ROOT_POINTERS \
char *readline_hist[50]; \
mp_obj_t keyboard_interrupt_obj;
char *readline_hist[50];
#endif
#define MP_STATE_PORT MP_STATE_VM
......
......@@ -79,12 +79,12 @@ void mp_hal_stdio_mode_orig(void) {
// the thread created for handling it might not be running yet so we'd miss the notification.
BOOL WINAPI console_sighandler(DWORD evt) {
if (evt == CTRL_C_EVENT) {
if (MP_STATE_VM(mp_pending_exception) == MP_STATE_VM(keyboard_interrupt_obj)) {
if (MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception))) {
// 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);
mp_obj_exception_clear_traceback(MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)));
MP_STATE_VM(mp_pending_exception) = MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception));
return TRUE;
}
return FALSE;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment