From d89ed3e62b152174c3eb5c96713e9b983b11f7ed Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 23 Jan 2020 14:11:13 -0600 Subject: [PATCH] unix/unix_mphal: Add compile check for incompatible GIL+ASYNC_KBD_INTR. It is not safe to enable MICROPY_ASYNC_KBD_INTR and MICROPY_PY_THREAD_GIL at the same time. This will trigger a compiler error to ensure that it is not possible to make this mistake. --- ports/unix/unix_mphal.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ports/unix/unix_mphal.c b/ports/unix/unix_mphal.c index 3e14409efb..25d1b022db 100644 --- a/ports/unix/unix_mphal.c +++ b/ports/unix/unix_mphal.c @@ -41,6 +41,11 @@ STATIC void sighandler(int signum) { if (signum == SIGINT) { #if MICROPY_ASYNC_KBD_INTR + #if MICROPY_PY_THREAD_GIL + // Since signals can occur at any time, we may not be holding the GIL when + // this callback is called, so it is not safe to raise an exception here + #error "MICROPY_ASYNC_KBD_INTR and MICROPY_PY_THREAD_GIL are not compatible" + #endif mp_obj_exception_clear_traceback(MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception))); sigset_t mask; sigemptyset(&mask);