Subject: [PATCH] Prevent NS event loop being re-entered (bug#11049)

From: Alan Third <[email-masked]>
Date: Sun, 26 Jun 2016 01:42:59 +0100

* nsterm.m (ns_read_socket, ns_select): Return -1 if already in event
loop instead of aborting.
---
 src/nsterm.m | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/nsterm.m b/src/nsterm.m
index eba75f1..60c0da8 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -4094,6 +4094,9 @@ in certain situations (rapid incoming events).
 
   NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_read_socket");
 
+  if (apploopnr > 0)
+    return -1; /* Already within event loop. */
+
 #ifdef HAVE_NATIVE_FS
   check_native_fs ();
 #endif
@@ -4178,6 +4181,9 @@ in certain situations (rapid incoming events).
 
   NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_select");
 
+  if (apploopnr > 0)
+    return -1; /* Already within event loop. */
+
 #ifdef HAVE_NATIVE_FS
   check_native_fs ();
 #endif
-- 
I'm happier with this one. There's already a mechanism available to
say that we can't process input just now, just return -1. This seems
neater than sending SIGABRT. I thought I could perhaps lose the
emacs_abort further down in both functions, but presumably the
function can be pre-empted between the check and ++apploopnr, which
could be a problem, so I just left it in.

-- 
Alan Third