unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Third <alan@idiocy.org>
To: Stefan Kangas <stefankangas@gmail.com>
Cc: "Gerd Möllmann" <gerd.moellmann@gmail.com>,
	75275@debbugs.gnu.org, "Eli Zaretskii" <eliz@gnu.org>
Subject: bug#75275: 30.0.92; `make-thread` bug on macOS 15.2
Date: Thu, 2 Jan 2025 16:06:25 +0000	[thread overview]
Message-ID: <Z3a5gQqv7_7qHjrf@breton.holly.idiocy.org> (raw)
In-Reply-To: <CADwFkmk6ekS_BwNdLRJu-JRk8TOkawjatUXEp6e0Gtxnh6AxMQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 502 bytes --]

On Thu, Jan 02, 2025 at 09:19:36AM -0600, Stefan Kangas wrote:
> That patch fixes it for me, indeed.  Thanks!

Hi Stefan, any chance you could check this version?

I have a suspicion that Gerd's will break C-g again. I'm not sure this
will be suitable for Emacs 30 though as it's a slightly larger change.

The C-g thing is hard to test as I think it relied on Gerd's machine
randomly hanging and him hammering C-g and it doing nothing. I'm not
sure how to replicate that original hang.
-- 
Alan Third

[-- Attachment #2: 0001-Fix-C-g-handling-on-NS-bug-75275.patch --]
[-- Type: text/plain, Size: 3781 bytes --]

From 528dcb934485a5a1331b4cf851216a3750df3210 Mon Sep 17 00:00:00 2001
From: Alan Third <alan@idiocy.org>
Date: Thu, 2 Jan 2025 15:56:20 +0000
Subject: [PATCH] Fix C-g handling on NS (bug#75275)

* src/nsterm.m (ns_select_1): Remove function.
(ns_select): Reinstate by copying the contents of ns_select_1 back
in. Add check for C-g at top. Stop fall-through to NS run loop when not
required.
([EmacsView showFontPanel]): Just call [NSApp run] directly, calling
ns_select for this makes ns_select more complex.
---
 src/nsterm.m | 44 ++++++++++++++++++--------------------------
 1 file changed, 18 insertions(+), 26 deletions(-)

diff --git a/src/nsterm.m b/src/nsterm.m
index a4398e79211..652eee1f988 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -4826,9 +4826,9 @@ Function modeled after x_draw_glyph_string_box ().
 
 
 static int
-ns_select_1 (int nfds, fd_set *readfds, fd_set *writefds,
-	     fd_set *exceptfds, struct timespec *timeout,
-	     sigset_t *sigmask, BOOL run_loop_only)
+ns_select (int nfds, fd_set *readfds, fd_set *writefds,
+           fd_set *exceptfds, struct timespec *timeout,
+           sigset_t *sigmask)
 /* --------------------------------------------------------------------------
      Replacement for select, checking for events
    -------------------------------------------------------------------------- */
@@ -4837,6 +4837,7 @@ Function modeled after x_draw_glyph_string_box ().
   int t, k, nr = 0;
   struct input_event event;
   char c;
+  NSEvent *ev;
 
   NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_select");
 
@@ -4844,15 +4845,16 @@ Function modeled after x_draw_glyph_string_box ().
   check_native_fs ();
 #endif
 
-  /* 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)
+  /* Check if there are any C-g events on the queue.  */
+  while ([NSThread isMainThread]
+         && (ev = [NSApp nextEventMatchingMask:NSEventMaskKeyDown
+                                    untilDate:nil
+                                       inMode:NSDefaultRunLoopMode
+                                       dequeue:NO]))
     {
-      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;
+      if ([ev modifierFlags] == NSEventModifierFlagControl
+          && [[ev charactersIgnoringModifiers] isEqualToString:@"g"])
+        Vquit_flag = Qt;
     }
 
   eassert (nfds <= FD_SETSIZE);
@@ -4863,13 +4865,10 @@ Function modeled after x_draw_glyph_string_box ().
     }
 
   /* emacs -nw doesn't have an NSApp, so we're done.  */
-  if (NSApp == nil)
-    return thread_select (pselect, nfds, readfds, writefds, exceptfds,
-			  timeout, sigmask);
-
-  if (![NSThread isMainThread]
+  if (NSApp == nil
+      || ![NSThread isMainThread]
       || (timeout && timeout->tv_sec == 0 && timeout->tv_nsec == 0))
-    thread_select (pselect, nfds, readfds, writefds,
+    return thread_select (pselect, nfds, readfds, writefds,
 		   exceptfds, timeout, sigmask);
   else
     {
@@ -4992,14 +4991,6 @@ Function modeled after x_draw_glyph_string_box ().
   return result;
 }
 
-int
-ns_select (int nfds, fd_set *readfds, fd_set *writefds,
-	   fd_set *exceptfds, struct timespec *timeout,
-	   sigset_t *sigmask)
-{
-  return ns_select_1 (nfds, readfds, writefds, exceptfds,
-		      timeout, sigmask, NO);
-}
 
 #ifdef HAVE_PTHREAD
 void
@@ -6790,7 +6781,8 @@ - (Lisp_Object) showFontPanel
 	 && [[fm fontPanel: YES] isVisible]
 #endif
 	 )
-    ns_select_1 (0, NULL, NULL, NULL, &timeout, NULL, YES);
+
+  [NSApp run];
   unblock_input ();
 
   if (font_panel_result)
-- 
2.41.0


  reply	other threads:[~2025-01-02 16:06 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-02  4:57 bug#75275: 30.0.92; `make-thread` bug on macOS 15.2 Stefan Kangas
2025-01-02  5:46 ` Gerd Möllmann
2025-01-02  5:55   ` Gerd Möllmann
2025-01-02  6:47   ` Stefan Kangas
2025-01-02  7:12     ` Gerd Möllmann
2025-01-02 14:35       ` Stefan Kangas
2025-01-02 14:38         ` Gerd Möllmann
2025-01-02 14:45           ` Gerd Möllmann
2025-01-02 15:19             ` Stefan Kangas
2025-01-02 16:06               ` Alan Third [this message]
2025-01-02 16:47                 ` Alan Third
2025-01-02 16:58                 ` Eli Zaretskii
2025-01-02 17:09                   ` Gerd Möllmann
2025-01-02 17:22                     ` Eli Zaretskii
2025-01-02 17:25                       ` Gerd Möllmann
2025-01-02 17:42                         ` Alan Third
2025-01-02 17:48                           ` Gerd Möllmann
2025-01-02 17:37                       ` Alan Third
2025-01-02 17:46                         ` Gerd Möllmann
2025-01-02 17:52                           ` Gerd Möllmann
2025-01-02 19:26                             ` Alan Third
2025-01-02 19:59                               ` Gerd Möllmann
2025-01-02 16:46               ` Eli Zaretskii
2025-01-02  7:53     ` Eli Zaretskii
2025-01-02  7:58       ` Stefan Kangas
2025-01-02  7:13 ` Eli Zaretskii
2025-01-02  7:30   ` Gerd Möllmann
2025-01-02  8:28     ` Eli Zaretskii
2025-01-02  8:33       ` Gerd Möllmann
2025-01-02  8:41         ` Gerd Möllmann
2025-01-02  8:55           ` Eli Zaretskii
2025-01-02 10:04             ` Gerd Möllmann
2025-01-02 11:03               ` Alan Third
2025-01-02 13:05                 ` Gerd Möllmann
2025-01-02 13:53                   ` Alan Third
2025-01-02 14:03                     ` Gerd Möllmann
2025-01-02 14:17                       ` Alan Third
2025-01-02 15:31                 ` Eli Zaretskii
2025-01-02 15:37                   ` Gerd Möllmann
2025-01-02 15:55                     ` Alan Third
2025-01-02 16:08                       ` Gerd Möllmann
2025-01-02  8:51         ` Gerd Möllmann
2025-01-02  7:31   ` Stefan Kangas
2025-01-02  8:31     ` Eli Zaretskii
2025-01-02 10:31     ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z3a5gQqv7_7qHjrf@breton.holly.idiocy.org \
    --to=alan@idiocy.org \
    --cc=75275@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=gerd.moellmann@gmail.com \
    --cc=stefankangas@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).