]> git.eshelyaron.com Git - emacs.git/commitdiff
Prevent freezes on macOS (bug#69561)
authorGerd Möllmann <gerd@gnu.org>
Sat, 9 Mar 2024 14:06:29 +0000 (15:06 +0100)
committerEshel Yaron <me@eshelyaron.com>
Fri, 15 Mar 2024 08:58:54 +0000 (09:58 +0100)
* src/nsterm.m (ns_select_1): Store pending input_events. Always call
[NSApp run].

(cherry picked from commit 4ac4cec652ffaca4333d8f297b8a6c0e5bd79c68)

src/nsterm.m

index f094b145fe301fb53ba51709aa909131b4544983..f161edc4ac2f1cc22cbc5361f2649ec24d4c6797 100644 (file)
@@ -4739,12 +4739,15 @@ ns_select_1 (int nfds, fd_set *readfds, fd_set *writefds,
   check_native_fs ();
 #endif
 
-  if (hold_event_q.nr > 0 && !run_loop_only)
+  /* If there are input events pending, store them so that Emacs can
+     recognize C-g.  (And we must make sure [NSApp run] is called in
+     this function, so that C-g has a chance to land in
+     hold_event_q.)  */
+  if (hold_event_q.nr > 0)
     {
-      /* We already have events pending.  */
-      raise (SIGIO);
-      errno = EINTR;
-      return -1;
+      for (int i = 0; i < hold_event_q.nr; ++i)
+        kbd_buffer_store_event_hold (&hold_event_q.q[i], NULL);
+      hold_event_q.nr = 0;
     }
 
   eassert (nfds <= FD_SETSIZE);
@@ -4757,8 +4760,8 @@ ns_select_1 (int nfds, fd_set *readfds, fd_set *writefds,
   if (NSApp == nil
       || ![NSThread isMainThread]
       || (timeout && timeout->tv_sec == 0 && timeout->tv_nsec == 0))
-    return thread_select (pselect, nfds, readfds, writefds,
-                         exceptfds, timeout, sigmask);
+    thread_select (pselect, nfds, readfds, writefds,
+                  exceptfds, timeout, sigmask);
   else
     {
       struct timespec t = {0, 0};