Subject: bug#60144: 30.0.50; PGTK Emacs crashes after signal

From: Eli Zaretskii <[email-masked]>
Date: Sun, 18 Dec 2022 14:33:22 +0200

> From: Po Lu <[email-masked]>
> Cc: [email-masked],  [email-masked]
> Date: Sun, 18 Dec 2022 20:12:53 +0800
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> >> No, signalling there is equally unsafe on the other platforms, where
> >> note_mouse_highlight is called from the same place(s): read_socket_hook,
> >> event_handler_gdk, et cetera.  Just look at the callers of
> >> x_note_mouse_movement in xterm.c, or [EmacsView mouseMoved:] in
> >> nsterm.m.
> >
> > Sorry, I'm afraid I don't see the danger on other platforms.  Please
> > explain.  AFAIK, read_socket_hook is called from keyboard.c code which
> > reads input, and that code has no problem signaling an error.  What am
> > I missing?
> 
> That code has problems signalling errors, unless it is okay for
> unblock_input to signal.

I don't understand this part.  Why and how is unblock_input part of
the picture?

> On the regular X build with GTK, handle_one_xevent is called from
> event_handler_gdk, which is called by GDK when it detects an event.
> handle_one_xevent can also be called from x_dispatch_event inside a
> popup menu, and during drag-and-drop.  On NS, [EmacsView mouseMoved:] is
> called by the system from Objective-C.

So in the X/GTK build we have the same problem as with PGTK?  If so,
why not change that as well, to work as I described, i.e. enqueue
events to our own event queue, which we will then read and process in
safe context?

AFAIU, w32 already works like that.  Does it not?

(As for NS, I know it does some very dangerous stuff.)

> Out of all of those places, the only place where it is safe to signal is
> inside the drag-and-drop event loop.  Signalling out of the rest will
> either lead to catastrophic blowups (if it happens inside
> event_handler_gdk or [EmacsView mouseMoved:]), or to grabs never being
> released and resource leaks inside a menu.

Yes, understood.  But it just tells me that we need to change the
architecture so that the events delivered by the window-system are not
processed in callbacks we install to be called by the window-system,
they should be processed in our own safe context.