all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kai Ma <justksqsf@gmail.com>
To: Po Lu <luangruo@yahoo.com>
Cc: emacs-devel@gnu.org
Subject: Re: [PATCH] On the nasty "ghost key" problem on NS
Date: Fri, 4 Nov 2022 19:04:48 +0800	[thread overview]
Message-ID: <CE9B1601-3FAD-4FD4-9A63-A2E63B65629E@gmail.com> (raw)
In-Reply-To: <878rkrcbkx.fsf@yahoo.com>

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



> On Nov 4, 2022, at 17:29, Po Lu <luangruo@yahoo.com> wrote:
> 
> Kai Ma <justksqsf@gmail.com <mailto:justksqsf@gmail.com>> writes:
> 
>> Yes and no. Emacs still responds to new key events, but a previous
>> call is stuck and does not return. Presumably in another thread. To be
>> more clear: changing that code to be
>> 
>>  static int enter_cnt, leave_cnt;
>>  enter_cnt++;
>>  [referenced piece of code]
>>  leave_cnt++;
>>  /* (Or just count the return/leave counts of (ns-in-echo-area).) */
>> 
>> leave_cnt can be less than enter_cnt. I’ve confirmed re-entrance to
>> [firstRectForCharacterRange] leads to the problem.
> 
> I'm going to guess what actually happened is that ns-in-echo-area
> signalled.
> 
> What happens if you replace ns-in-echo-area with:
> 
>  safe_call (0, Qns_in_echo_area)
> 
> ?

Yes, this indeed is related to signals, but it’s not (ns-in-echo-area) that signals. It seems that there are problems in nsterm.m regarding waiting_for_input, which caused aborts for me ([eval.c:signal_or_quit] asserts !waiting_for_input). It’s also observed that inhibit-quit must be set, or the bug persists.

I believe the attached patch fixes this bug, but I don’t know why Vthrow_on_input is not correctly handled by safe_call. 



[-- Attachment #2.1: Type: text/html, Size: 8557 bytes --]

[-- Attachment #2.2: fix-ghost-key-v2.patch --]
[-- Type: application/octet-stream, Size: 2318 bytes --]

diff --git a/src/lisp.h b/src/lisp.h
index eafa241adf..2ba18ec684 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4603,6 +4603,7 @@ xsignal (Lisp_Object error_symbol, Lisp_Object data)
 extern Lisp_Object call_debugger (Lisp_Object arg);
 extern void init_eval_once (void);
 extern Lisp_Object safe_call (ptrdiff_t, Lisp_Object, ...);
+extern Lisp_Object safe_call_inhibit_quit (ptrdiff_t, Lisp_Object, ...);
 extern Lisp_Object safe_call1 (Lisp_Object, Lisp_Object);
 extern Lisp_Object safe_call2 (Lisp_Object, Lisp_Object, Lisp_Object);
 extern void init_eval (void);
diff --git a/src/nsterm.m b/src/nsterm.m
index 17f40dc7e3..e4b998410d 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -7063,16 +7063,20 @@ - (NSRect)firstRectForCharacterRange: (NSRange)theRange
   NSRect rect;
   NSPoint pt;
   struct window *win;
+  bool owfi;
 
   NSTRACE ("[EmacsView firstRectForCharacterRange:]");
 
   if (NS_KEYLOG)
     NSLog (@"firstRectForCharRange request");
 
-  if (WINDOWP (echo_area_window) && ! NILP (call0 (intern ("ns-in-echo-area"))))
+  owfi = waiting_for_input;
+  waiting_for_input = false;
+  if (WINDOWP (echo_area_window) && ! NILP (safe_call_inhibit_quit (0, Qns_in_echo_area)))
     win = XWINDOW (echo_area_window);
   else
     win = XWINDOW (FRAME_SELECTED_WINDOW (emacsframe));
+  waiting_for_input = owfi;
 
   rect.size.width = theRange.length * FRAME_COLUMN_WIDTH (emacsframe);
   rect.size.height = FRAME_LINE_HEIGHT (emacsframe);
@@ -11012,6 +11016,7 @@ Nil means use fullscreen the old (< 10.7) way.  The old way works better with
   DEFSYM (Qcondensed, "condensed");
   DEFSYM (Qreverse_italic, "reverse-italic");
   DEFSYM (Qexpanded, "expanded");
+  DEFSYM (Qns_in_echo_area, "ns-in-echo-area")
 
 #ifdef NS_IMPL_COCOA
   Fprovide (Qcocoa, Qnil);
diff --git a/src/xdisp.c b/src/xdisp.c
index dd243eca98..af697d0050 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -3041,6 +3041,18 @@ safe_call (ptrdiff_t nargs, Lisp_Object func, ...)
   return retval;
 }
 
+Lisp_Object
+safe_call_inhibit_quit (ptrdiff_t nargs, Lisp_Object func, ...)
+{
+  Lisp_Object retval;
+  va_list ap;
+
+  va_start (ap, func);
+  retval = safe__call (true, nargs, func, ap);
+  va_end (ap);
+  return retval;
+}
+
 /* Call function FN with one argument ARG.
    Return the result, or nil if something went wrong.  */
 

[-- Attachment #2.3: Type: text/html, Size: 212 bytes --]

  reply	other threads:[~2022-11-04 11:04 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-03 18:07 [PATCH] On the nasty "ghost key" problem on NS Kai Ma
2022-11-04  0:32 ` Po Lu
2022-11-04  6:28   ` Kai Ma
2022-11-04  7:16     ` Po Lu
2022-11-04  8:53       ` Kai Ma
2022-11-04  9:29         ` Po Lu
2022-11-04 11:04           ` Kai Ma [this message]
2022-11-04 11:27             ` Po Lu
2022-11-04 12:09               ` Kai Ma
2022-11-04 12:17                 ` Po Lu
2022-11-04 15:09                   ` Stefan Monnier
2022-11-05  0:43                     ` Po Lu
2022-11-05 14:40                       ` Stefan Monnier
2022-11-05 15:26                         ` Kai Ma
2022-11-05 15:47                           ` Stefan Monnier
2022-11-06  0:25                         ` Po Lu
2022-11-10 11:59                     ` Kai Ma
2022-11-10 12:25                       ` Po Lu
2022-11-12 17:49                         ` Stefan Monnier
2022-11-04 11:40         ` Eli Zaretskii

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

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

  git send-email \
    --in-reply-to=CE9B1601-3FAD-4FD4-9A63-A2E63B65629E@gmail.com \
    --to=justksqsf@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=luangruo@yahoo.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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.