Subject: Re: bug#25171: Error in thread causes Emacs to abort

From: Eli Zaretskii <[email-masked]>
Date: Sun, 11 Dec 2016 18:13:34 +0200

> From: Andreas Schwab <[email-masked]>
> Date: Sun, 11 Dec 2016 15:23:15 +0100
> 
> When the function called by make-thread throws an error while Emacs is
> reading from keyboard then it aborts in signal_or_quit because
> waiting_for_input is non-zero.

Right, thanks.

I think I fixed that now; the patch is below.

Tom, could you perhaps look at the patch and comment?  I'm puzzled why
you didn't do this in the first place, like you did with
waiting_for_user_input_p.  Are there any issues here that I'm missing?

TIA

diff --git a/src/keyboard.c b/src/keyboard.c
index 01b9b3c..cc78548 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 a5ed5e1..5084c39 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 6174032..f10824f 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;