unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#70311: Crash when dnd-indicate-insertion-point is non-nil
@ 2024-04-09 10:26 Greg Sexton
  2024-04-13  9:20 ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Greg Sexton @ 2024-04-09 10:26 UTC (permalink / raw)
  To: 70311

Emacs (29.1.90) can crash on Mac OS X when dnd-indicate-insertion-point
is non-nil.

I'm not able to deterministically reproduce this, but I have a high
success rate dragging a file over the window and just randomly moving
it around without releasing the click.

This said, I attached a debugger and found the root cause.

There is code that looks like this in dnd-handle-movement:

  (when dnd-indicate-insertion-point
     (ignore-errors
       (goto-char (posn-point posn))))

posn-point can return nil, which causes goto-char to call
wrong_type_argument, this reaches signal_or_quit (eval.c), which calls
emacs_abort as waiting_for_input is true.

A quick fix might be to when-let the result of posn-point, but I'm
unsure if waiting_for_input being true points to a deeper issue.

--

Greg





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#70311: Crash when dnd-indicate-insertion-point is non-nil
  2024-04-09 10:26 bug#70311: Crash when dnd-indicate-insertion-point is non-nil Greg Sexton
@ 2024-04-13  9:20 ` Eli Zaretskii
  2024-04-13 11:58   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2024-04-13  9:20 UTC (permalink / raw)
  To: Greg Sexton, Po Lu; +Cc: 70311

> From: Greg Sexton <gregsexton@gmail.com>
> Date: Tue, 9 Apr 2024 11:26:41 +0100
> 
> Emacs (29.1.90) can crash on Mac OS X when dnd-indicate-insertion-point
> is non-nil.
> 
> I'm not able to deterministically reproduce this, but I have a high
> success rate dragging a file over the window and just randomly moving
> it around without releasing the click.
> 
> This said, I attached a debugger and found the root cause.
> 
> There is code that looks like this in dnd-handle-movement:
> 
>   (when dnd-indicate-insertion-point
>      (ignore-errors
>        (goto-char (posn-point posn))))
> 
> posn-point can return nil, which causes goto-char to call
> wrong_type_argument, this reaches signal_or_quit (eval.c), which calls
> emacs_abort as waiting_for_input is true.
> 
> A quick fix might be to when-let the result of posn-point, but I'm
> unsure if waiting_for_input being true points to a deeper issue.

Po Lu, any comments or suggestions?





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#70311: Crash when dnd-indicate-insertion-point is non-nil
  2024-04-13  9:20 ` Eli Zaretskii
@ 2024-04-13 11:58   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-04-13 12:06     ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-04-13 11:58 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 70311, Greg Sexton

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Greg Sexton <gregsexton@gmail.com>
>> Date: Tue, 9 Apr 2024 11:26:41 +0100
>> 
>> Emacs (29.1.90) can crash on Mac OS X when dnd-indicate-insertion-point
>> is non-nil.
>> 
>> I'm not able to deterministically reproduce this, but I have a high
>> success rate dragging a file over the window and just randomly moving
>> it around without releasing the click.
>> 
>> This said, I attached a debugger and found the root cause.
>> 
>> There is code that looks like this in dnd-handle-movement:
>> 
>>   (when dnd-indicate-insertion-point
>>      (ignore-errors
>>        (goto-char (posn-point posn))))
>> 
>> posn-point can return nil, which causes goto-char to call
>> wrong_type_argument, this reaches signal_or_quit (eval.c), which calls
>> emacs_abort as waiting_for_input is true.
>> 
>> A quick fix might be to when-let the result of posn-point, but I'm
>> unsure if waiting_for_input being true points to a deeper issue.
>
> Po Lu, any comments or suggestions?

As regards suggestions, none at present.  It's not clear to me why
waiting_for_input should continue to exist, but neither am I especially
satisfied with the present arrangements for calling drag-and-drop
callbacks in nsterm.m: some means should be devised of returning to the
event loop during a DND session, rather than calling Lisp and parts of
redisplay from non-reentrant input handlers that the toolkit can call at
will.

Come to think of it, at the time this kludge was written, I never quite
understood why DND events were never received on Mac OS, when the same
was smooth sailing on GNUstep.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#70311: Crash when dnd-indicate-insertion-point is non-nil
  2024-04-13 11:58   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-04-13 12:06     ` Eli Zaretskii
  2024-04-13 12:28       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2024-04-13 12:06 UTC (permalink / raw)
  To: Po Lu; +Cc: 70311, gregsexton

> From: Po Lu <luangruo@yahoo.com>
> Cc: Greg Sexton <gregsexton@gmail.com>,  70311@debbugs.gnu.org
> Date: Sat, 13 Apr 2024 19:58:25 +0800
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> From: Greg Sexton <gregsexton@gmail.com>
> >> Date: Tue, 9 Apr 2024 11:26:41 +0100
> >> 
> >> Emacs (29.1.90) can crash on Mac OS X when dnd-indicate-insertion-point
> >> is non-nil.
> >> 
> >> I'm not able to deterministically reproduce this, but I have a high
> >> success rate dragging a file over the window and just randomly moving
> >> it around without releasing the click.
> >> 
> >> This said, I attached a debugger and found the root cause.
> >> 
> >> There is code that looks like this in dnd-handle-movement:
> >> 
> >>   (when dnd-indicate-insertion-point
> >>      (ignore-errors
> >>        (goto-char (posn-point posn))))
> >> 
> >> posn-point can return nil, which causes goto-char to call
> >> wrong_type_argument, this reaches signal_or_quit (eval.c), which calls
> >> emacs_abort as waiting_for_input is true.
> >> 
> >> A quick fix might be to when-let the result of posn-point, but I'm
> >> unsure if waiting_for_input being true points to a deeper issue.
> >
> > Po Lu, any comments or suggestions?
> 
> As regards suggestions, none at present.  It's not clear to me why
> waiting_for_input should continue to exist, but neither am I especially
> satisfied with the present arrangements for calling drag-and-drop
> callbacks in nsterm.m: some means should be devised of returning to the
> event loop during a DND session, rather than calling Lisp and parts of
> redisplay from non-reentrant input handlers that the toolkit can call at
> will.
> 
> Come to think of it, at the time this kludge was written, I never quite
> understood why DND events were never received on Mac OS, when the same
> was smooth sailing on GNUstep.

So you think the suggested bad-aid is the best we can currently do to
prevent crashes in those cases?





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#70311: Crash when dnd-indicate-insertion-point is non-nil
  2024-04-13 12:06     ` Eli Zaretskii
@ 2024-04-13 12:28       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-04-13 16:00         ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-04-13 12:28 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 70311, gregsexton

Eli Zaretskii <eliz@gnu.org> writes:

> So you think the suggested bad-aid is the best we can currently do to
> prevent crashes in those cases?

Yes, unfortunately.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#70311: Crash when dnd-indicate-insertion-point is non-nil
  2024-04-13 12:28       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-04-13 16:00         ` Eli Zaretskii
  2024-04-14  9:24           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2024-04-13 16:00 UTC (permalink / raw)
  To: Po Lu; +Cc: 70311, gregsexton

> From: Po Lu <luangruo@yahoo.com>
> Cc: gregsexton@gmail.com,  70311@debbugs.gnu.org
> Date: Sat, 13 Apr 2024 20:28:14 +0800
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > So you think the suggested band-aid is the best we can currently do to
> > prevent crashes in those cases?
> 
> Yes, unfortunately.

Does the band-aid below look OK to you?

diff --git a/lisp/dnd.el b/lisp/dnd.el
index 89652d3..de1c58a 100644
--- a/lisp/dnd.el
+++ b/lisp/dnd.el
@@ -149,8 +149,13 @@ dnd-handle-movement
                 (with-selected-window window
                   (scroll-down 1))))))))
       (when dnd-indicate-insertion-point
-        (ignore-errors
-          (goto-char (posn-point posn)))))))
+        (let ((pos (posn-point posn)))
+          ;; We avoid errors here, since on some systems this runs
+          ;; when waiting_for_input is non-zero, and that aborts on
+          ;; error.
+          (if (and pos (<= (point-min) pos (point-max)))
+              (goto-char pos)
+            pos))))))
 
 (defun dnd-handle-one-url (window action url)
   "Handle one dropped url by calling the appropriate handler.





^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#70311: Crash when dnd-indicate-insertion-point is non-nil
  2024-04-13 16:00         ` Eli Zaretskii
@ 2024-04-14  9:24           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-04-14 10:17             ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-04-14  9:24 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 70311, gregsexton

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Po Lu <luangruo@yahoo.com>
>> Cc: gregsexton@gmail.com,  70311@debbugs.gnu.org
>> Date: Sat, 13 Apr 2024 20:28:14 +0800
>> 
>> Eli Zaretskii <eliz@gnu.org> writes:
>> 
>> > So you think the suggested band-aid is the best we can currently do to
>> > prevent crashes in those cases?
>> 
>> Yes, unfortunately.
>
> Does the band-aid below look OK to you?
>
> diff --git a/lisp/dnd.el b/lisp/dnd.el
> index 89652d3..de1c58a 100644
> --- a/lisp/dnd.el
> +++ b/lisp/dnd.el
> @@ -149,8 +149,13 @@ dnd-handle-movement
>                  (with-selected-window window
>                    (scroll-down 1))))))))
>        (when dnd-indicate-insertion-point
> -        (ignore-errors
> -          (goto-char (posn-point posn)))))))
> +        (let ((pos (posn-point posn)))
> +          ;; We avoid errors here, since on some systems this runs
> +          ;; when waiting_for_input is non-zero, and that aborts on
> +          ;; error.
> +          (if (and pos (<= (point-min) pos (point-max)))
> +              (goto-char pos)
> +            pos))))))

Yes, please install.  Thanks.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#70311: Crash when dnd-indicate-insertion-point is non-nil
  2024-04-14  9:24           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-04-14 10:17             ` Eli Zaretskii
  0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2024-04-14 10:17 UTC (permalink / raw)
  To: Po Lu; +Cc: 70311-done, gregsexton

> From: Po Lu <luangruo@yahoo.com>
> Cc: gregsexton@gmail.com,  70311@debbugs.gnu.org
> Date: Sun, 14 Apr 2024 17:24:12 +0800
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> From: Po Lu <luangruo@yahoo.com>
> >> Cc: gregsexton@gmail.com,  70311@debbugs.gnu.org
> >> Date: Sat, 13 Apr 2024 20:28:14 +0800
> >> 
> >> Eli Zaretskii <eliz@gnu.org> writes:
> >> 
> >> > So you think the suggested band-aid is the best we can currently do to
> >> > prevent crashes in those cases?
> >> 
> >> Yes, unfortunately.
> >
> > Does the band-aid below look OK to you?
> >
> > diff --git a/lisp/dnd.el b/lisp/dnd.el
> > index 89652d3..de1c58a 100644
> > --- a/lisp/dnd.el
> > +++ b/lisp/dnd.el
> > @@ -149,8 +149,13 @@ dnd-handle-movement
> >                  (with-selected-window window
> >                    (scroll-down 1))))))))
> >        (when dnd-indicate-insertion-point
> > -        (ignore-errors
> > -          (goto-char (posn-point posn)))))))
> > +        (let ((pos (posn-point posn)))
> > +          ;; We avoid errors here, since on some systems this runs
> > +          ;; when waiting_for_input is non-zero, and that aborts on
> > +          ;; error.
> > +          (if (and pos (<= (point-min) pos (point-max)))
> > +              (goto-char pos)
> > +            pos))))))
> 
> Yes, please install.  Thanks.

Thanks, installed on the emacs-29 branch, and closing the bug.





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-04-14 10:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-09 10:26 bug#70311: Crash when dnd-indicate-insertion-point is non-nil Greg Sexton
2024-04-13  9:20 ` Eli Zaretskii
2024-04-13 11:58   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-13 12:06     ` Eli Zaretskii
2024-04-13 12:28       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-13 16:00         ` Eli Zaretskii
2024-04-14  9:24           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-14 10:17             ` Eli Zaretskii

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).