From 997081634a3b6c2359226305db05c818c492a9b2 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sun, 11 Dec 2016 17:59:55 +0200 Subject: [PATCH] Avoid aborts when a thread signals an error * src/thread.h (struct thread_state): Add members m_waiting_for_input and m_input_available_clear_time. (waiting_for_input, input_available_clear_time): New macros. * src/keyboard.c (waiting_for_input, input_available_clear_time): Remove; they are now macros that reference the current thread. (Bug#25171) * src/w32select.c: Don't include keyboard.h. * test/src/thread-tests.el (thread-errors): New test. --- src/keyboard.c | 7 ------- src/keyboard.h | 7 ------- src/thread.h | 9 +++++++++ src/w32select.c | 1 - test/src/thread-tests.el | 15 +++++++++++++++ 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/keyboard.c b/src/keyboard.c index 01b9b3c6ba2..cc78548abd0 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -148,9 +148,6 @@ static Lisp_Object regular_top_level_message; static sys_jmp_buf getcjmp; -/* True while doing kbd input. */ -bool waiting_for_input; - /* True while displaying for echoing. Delays C-g throwing. */ static bool echoing; @@ -322,10 +319,6 @@ static ptrdiff_t echo_length (void); /* Incremented whenever a timer is run. */ unsigned timers_run; -/* Address (if not 0) of struct timespec to zero out if a SIGIO interrupt - happens. */ -struct timespec *input_available_clear_time; - /* True means use SIGIO interrupts; false means use CBREAK mode. Default is true if INTERRUPT_INPUT is defined. */ bool interrupt_input; diff --git a/src/keyboard.h b/src/keyboard.h index a5ed5e10a98..5084c39b7c1 100644 --- a/src/keyboard.h +++ b/src/keyboard.h @@ -415,13 +415,6 @@ extern void unuse_menu_items (void); #define EVENT_HEAD_KIND(event_head) \ (Fget ((event_head), Qevent_kind)) -/* True while doing kbd input. */ -extern bool waiting_for_input; - -/* Address (if not 0) of struct timespec to zero out if a SIGIO interrupt - happens. */ -extern struct timespec *input_available_clear_time; - extern bool ignore_mouse_drag_p; extern Lisp_Object parse_modifiers (Lisp_Object); diff --git a/src/thread.h b/src/thread.h index 61740321a5c..f10824f1983 100644 --- a/src/thread.h +++ b/src/thread.h @@ -155,6 +155,15 @@ struct thread_state int m_waiting_for_user_input_p; #define waiting_for_user_input_p (current_thread->m_waiting_for_user_input_p) + /* True while doing kbd input. */ + bool m_waiting_for_input; +#define waiting_for_input (current_thread->m_waiting_for_input) + + /* Address (if not 0) of struct timespec to zero out if a SIGIO interrupt + happens. */ + struct timespec *m_input_available_clear_time; +#define input_available_clear_time (current_thread->m_input_available_clear_time) + /* The OS identifier for this thread. */ sys_thread_t thread_id; diff --git a/src/w32select.c b/src/w32select.c index 1754534c3d3..36908f96afb 100644 --- a/src/w32select.c +++ b/src/w32select.c @@ -77,7 +77,6 @@ along with GNU Emacs. If not, see . */ #include "w32common.h" /* os_subtype */ #include "w32term.h" /* for all of the w32 includes */ #include "w32select.h" -#include "keyboard.h" /* for waiting_for_input */ #include "blockinput.h" #include "coding.h" diff --git a/test/src/thread-tests.el b/test/src/thread-tests.el index 4631882186c..4e7b052cba0 100644 --- a/test/src/thread-tests.el +++ b/test/src/thread-tests.el @@ -209,5 +209,20 @@ (string= "hi bob" (condition-name (make-condition-variable (make-mutex) "hi bob"))))) +(defun call-error () + "Call `error'." + (error "Error is called")) + +;; This signals an error internally; the error should be caught. +(defun thread-custom () + (defcustom thread-custom-face 'highlight + "Face used for thread customizations." + :type 'face + :group 'widget-faces)) + +(ert-deftest thread-errors () + "Test what happens when a thread signals an error." + (should (threadp (make-thread #'call-error "call-error"))) + (should (threadp (make-thread #'thread-custom "thread-custom")))) ;;; threads.el ends here -- 2.39.2