From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Kai Ma Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] On the nasty "ghost key" problem on NS Date: Thu, 10 Nov 2022 19:59:38 +0800 Message-ID: <36443E84-7646-4BD3-B1E4-C671C2BB46BC@gmail.com> References: <87leord0ei.fsf@yahoo.com> <87h6zfchpu.fsf@yahoo.com> <394D8618-AF36-44C4-BA64-7AFDFBBDC429@gmail.com> <878rkrcbkx.fsf@yahoo.com> <87sfizaria.fsf@yahoo.com> <87k04ac3s6.fsf@yahoo.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.200.110.1.12\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_F2FDBB22-E7AA-4EA3-BA76-511127E25651" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31507"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Po Lu , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Nov 10 13:00:53 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ot6Em-0007yZ-UF for ged-emacs-devel@m.gmane-mx.org; Thu, 10 Nov 2022 13:00:53 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ot6Du-00006e-EC; Thu, 10 Nov 2022 06:59:58 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ot6Dt-00006I-5v for emacs-devel@gnu.org; Thu, 10 Nov 2022 06:59:57 -0500 Original-Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ot6Dr-0000Sf-Hv for emacs-devel@gnu.org; Thu, 10 Nov 2022 06:59:56 -0500 Original-Received: by mail-pf1-x444.google.com with SMTP id 140so371718pfz.6 for ; Thu, 10 Nov 2022 03:59:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=wyJUjd1KJC2CQDJzz6R+FEACLvwac7Vqf5EuFBZLF2s=; b=eyLyJGovGVOQRqFrc+v16v9mPjNRFvYaW/am+G7CVr8AbT2ZtXzyF0t1v88Frhl2rU 8TXMV5N1WvFOK4Qf1P7zxpVFG8g+x02pweNk3vbnUgTTUDO3wD84Uo18wlHeVTUKR/Uc NLNS8K/0QcKC9wdzfjU0/D3QjgiAKuUxUOnH/Q0aFIwfd579Gs+mUIDatqqBRl270m/F jUI7k/jAGRND/px2zz8yPrq4Wpl1X4FVM/JPVNwffIX0Ww4Z9lw1UyIerf+oHlmHw/Tn nKWySV7fgfkqh0+8kX/ioWtfDG4Mr9TdL6tY+ndllxZFVOHRTAuoXCOD2nzcsiDFBu8H UX6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wyJUjd1KJC2CQDJzz6R+FEACLvwac7Vqf5EuFBZLF2s=; b=TesuLUPcwCZGpaGlD3HRjxkZ1sIgVPXDI2FXFWgsK5rA9xAkihbJcewSV2FCTJ0x00 W2gifNBuiKpnwIfuYwuU2OaxLomeVfmLwhYld96qqB4ZGVXePFnsF37KwpgkMwT+02qx ux5QZr96EExDV1083WiV/Di8KPelVZkChCerauzBbDLfoSxl7A80jHuOCuoRcAfNFAf/ DEmkb6O56Uo3ihZumgVNYs+AUUYN/N9EFOhHDdmrMtHT1Yd99yFmgK/qPcxy3IfhuwFF wf1iwjhsSk80kQjYwA8FICEl0ZB2grANCxS1euPHhZZ+/qEHknaUggt/0kRd3+dJUqp/ TgoA== X-Gm-Message-State: ACrzQf3Vp36H0pnrQz03S0yKcAIbRFgsBwJXzQ0kJPb05UvQwBvfyi7C frdMs9zs1IZOkyjeVgOPkxM= X-Google-Smtp-Source: AMsMyM6ulxHDR6OHkGqKl2niQcFlxdI8xTY8KyGb9t/ywi+OfmJg00iNVb0hEYEq6n5BbtxW6mHOhw== X-Received: by 2002:aa7:9ddd:0:b0:56b:c616:287 with SMTP id g29-20020aa79ddd000000b0056bc6160287mr2504823pfq.73.1668081593576; Thu, 10 Nov 2022 03:59:53 -0800 (PST) Original-Received: from smtpclient.apple (n058153170106.netvigator.com. [58.153.170.106]) by smtp.gmail.com with ESMTPSA id i3-20020a17090332c300b00174c235e1fdsm10978792plr.199.2022.11.10.03.59.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Nov 2022 03:59:53 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3731.200.110.1.12) Received-SPF: pass client-ip=2607:f8b0:4864:20::444; envelope-from=justksqsf@gmail.com; helo=mail-pf1-x444.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, FROM_LOCAL_NOVOWEL=0.5, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:299483 Archived-At: --Apple-Mail=_F2FDBB22-E7AA-4EA3-BA76-511127E25651 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Nov 4, 2022, at 23:09, Stefan Monnier = wrote: >=20 > I'm glad we found a way to make the code work, apparently, but > Here we need a comment explaining why we do this gymnastic of > `safe_call` + `inhibit_quit` + `waiting_for_input`. > It's very unusual to have to do that. Thanks for the pointer, this indeed turned out unnecessary (and = dangerous). A tester informed me of a problem in the v3 patch: safe_call (0, Qns_in_echo_area) is incorrect. The 0 should be 1, or nargs will be -1 for = funcall_general. =20 This will cause an error to be signaled, which explains why=20 `waiting_for_input` has to be masked. [ I guess we could add an assertion that numargs >=3D 0 in = funcall_general or somewhere else? ] This patch should be correct even without the ugly `waiting_for_input` = hack. I=E2=80=99ve been running patched Emacs for some time without issues. With the current understanding of the bug, I guess the comment line = could be /* Protect against throw-on-input. */ WDYT? =EF=BF=BC= --Apple-Mail=_F2FDBB22-E7AA-4EA3-BA76-511127E25651 Content-Type: multipart/mixed; boundary="Apple-Mail=_F8F3073C-0A06-4A40-A5B5-B95741F824C4" --Apple-Mail=_F8F3073C-0A06-4A40-A5B5-B95741F824C4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
On Nov 4, = 2022, at 23:09, Stefan Monnier <monnier@iro.umontreal.ca> = wrote:

I'm glad we found a way to make the code work, = apparently, but
Here we need a comment explaining why we do this = gymnastic of
`safe_call` + `inhibit_quit` + = `waiting_for_input`.
It's very unusual to have to do = that.

Thanks for the = pointer, this indeed turned out unnecessary (and = dangerous).

A tester informed me of a problem in = the v3 patch:

  safe_call (0, = Qns_in_echo_area)

is = incorrect. The 0 should be 1, or nargs will be -1 for funcall_general. =  
This will cause an error to be signaled, which = explains why 
`waiting_for_input` has = to be masked.

[ I guess we = could add an assertion that numargs >=3D 0 in funcall_general = or
  somewhere else? ]

This patch should be correct even without the = ugly `waiting_for_input` hack.
I=E2=80=99ve been running = patched Emacs for some time without = issues.

With the current understanding of the = bug, I guess the comment line could be
  /* Protect = against throw-on-input. = */

WDYT?

= --Apple-Mail=_F8F3073C-0A06-4A40-A5B5-B95741F824C4 Content-Disposition: attachment; filename=fix-ghost-key-v4.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="fix-ghost-key-v4.patch" Content-Transfer-Encoding: 7bit diff --git a/src/nsterm.m b/src/nsterm.m index 17f40dc7e3..0ed047849a 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -7063,16 +7063,19 @@ - (NSRect)firstRectForCharacterRange: (NSRange)theRange NSRect rect; NSPoint pt; struct window *win; + specpdl_ref count = SPECPDL_INDEX (); NSTRACE ("[EmacsView firstRectForCharacterRange:]"); if (NS_KEYLOG) NSLog (@"firstRectForCharRange request"); - if (WINDOWP (echo_area_window) && ! NILP (call0 (intern ("ns-in-echo-area")))) + specbind (Qinhibit_quit, Qt); + if (WINDOWP (echo_area_window) && ! NILP (safe_call (1, Qns_in_echo_area))) win = XWINDOW (echo_area_window); else win = XWINDOW (FRAME_SELECTED_WINDOW (emacsframe)); + unbind_to (count, Qnil); rect.size.width = theRange.length * FRAME_COLUMN_WIDTH (emacsframe); rect.size.height = FRAME_LINE_HEIGHT (emacsframe); @@ -11012,6 +11015,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); --Apple-Mail=_F8F3073C-0A06-4A40-A5B5-B95741F824C4 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii
--Apple-Mail=_F8F3073C-0A06-4A40-A5B5-B95741F824C4-- --Apple-Mail=_F2FDBB22-E7AA-4EA3-BA76-511127E25651--