bug#81510: 31.0.90; NS (macOS): clicking a disabled (:enable nil) tab-bar item crases Emacs

Alan Third <[email protected]> Tue, 4 Aug 2026 14:55:31 +0100
Newsgroups gmane.emacs.bugs
Message-ID <[email protected]>
--y1+ILxg9h+qt1Z/r
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

On Tue, Aug 04, 2026 at 02:58:16PM +0300, Eli Zaretskii wrote:
> > Date: Tue, 4 Aug 2026 08:47:27 +0100
> > From: Alan Third <[email protected]>
> > Cc: Stéphane Marks <[email protected]>,
> > 	Eli Zaretskii <[email protected]>, [email protected]
> > 
> > On Fri, Jul 31, 2026 at 08:19:36AM +0100, Al Haji-Ali wrote:
> > > 
> > > On 30/07/2026, Alan Third wrote:
> > > 
> > > > On Thu, Jul 30, 2026 at 08:56:13PM +0100, Al Haji-Ali wrote:
> > > >> In ns_term, the macro EV_TRAILER2 just checks if the event pointer
> > > >> q_event_ptr is non-nil, regardless of the value of emacs_event.kind.
> > > >
> > > > So something like the attached?
> > > 
> > > Yes! This fixed the crash that I found.
> > > 
> > > Can we also check the site in EV_TRAILER2? If q_event_ptr is not NULL,
> > > kbd_buffer_store_event_hold is called immediately and unconditionally
> > > rather than hold_event, so in that case kbd_buffer_store_buffered_event
> > > could be called with NO_EVENT.
> > 
> > I don't understand why we use NO_EVENT at all. It's just a way of
> > saying "discard this event", when surely the simplest solution is to
> > not even put it in the queue?
> 
> Which queue did you have in mind?  Using NO_EVENT is precisely the way
> of telling the socket-hook not to add the event to the queue:
> 
>       if (inev.kind != NO_EVENT)
> 	{
> 	  kbd_buffer_store_event_hold (&inev, hold_quit);
> 	  count++;
> 	}

Ah, because the NS port has different functions for different kinds of
events (mouseDown is different from keyDown, etc.) we have two queues.
One, the normal emacs event queue, and another internal to nsterm.m.

If a NO_EVENT event is never required to go in any queue, we can get
away with the attached. This should prevent us from putting NO_EVENT's
into either queue from any of the event functions.
-- 
Alan Third

--y1+ILxg9h+qt1Z/r
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
	filename=0001-Fix-freeze-in-NS-event-handling-bug-81510.patch

From 4d3de37a6944d1dfe7a728621f85681e05eaf21a Mon Sep 17 00:00:00 2001
From: Alan Third <[email protected]>
Date: Tue, 4 Aug 2026 14:47:48 +0100
Subject: [PATCH] Fix freeze in NS event handling (bug#81510)

* src/nsterm.m (EV_TRAILER): Don't queue event if it's of kind
'NO_EVENT'.
---
 src/nsterm.m | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/nsterm.m b/src/nsterm.m
index 2c6954f0264..20967b7581f 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -446,10 +446,11 @@ - (unsigned long)unsignedLong
 /* This is a piece of code which is common to all the event handling
    methods.  Maybe it should even be a function.  */
 #define EV_TRAILER(e)						\
-  {								\
-    XSETFRAME (emacs_event->frame_or_window, emacsframe);	\
-    EV_TRAILER2 (e);						\
-  }
+  if (emacs_event->kind != NO_EVENT)				\
+    {								\
+      XSETFRAME (emacs_event->frame_or_window, emacsframe);	\
+      EV_TRAILER2 (e);						\
+    }
 
 #define EV_TRAILER2(e)                                                  \
   {                                                                     \
-- 
2.54.0


--y1+ILxg9h+qt1Z/r--