patches: fix 2 blockers from Opus review

BLOCKER #1: accessibilityUpdating flag exception safety.
A Lisp signal (longjmp) during postAccessibilityUpdates left
the re-entrance flag permanently YES, suppressing all future
AX notifications → VoiceOver goes silent randomly.
Fix: specpdl unwind protection (record_unwind_protect_ptr)
resets the flag on any longjmp. All 3 exit points use unbind_to.

BLOCKER #2: static struct buffer *lastBuffer dangling pointer.
Raw C pointer to buffer struct has no GC protection. After
kill-buffer, the pointer dangles.
Fix: file-scope Lisp_Object lastChildFrameBuffer with staticpro.
EQ comparison instead of pointer equality.

Also: revert accidental em-dash → triple-dash in title bar (0007),
fix README factual error (BUF_OVERLAY_MODIFF cache key).
This commit is contained in:
2026-02-28 18:29:19 +01:00
parent 4f37a8660e
commit 0f7608326c
3 changed files with 72 additions and 40 deletions

View File

@@ -1,4 +1,4 @@
From bdb5aefe515662fb294b719ad32fabc4008a5cb8 Mon Sep 17 00:00:00 2001
From 8564e4989f5f358092bd1494c3894a42974ee6e1 Mon Sep 17 00:00:00 2001
From: Martin Sukany <martin@sukany.cz>
Date: Sat, 28 Feb 2026 16:01:29 +0100
Subject: [PATCH 2/2] ns: announce child frame completion candidates for
@@ -43,8 +43,8 @@ childFrameCompletionActive flag.
refocus parent buffer element when child frame closes.
---
src/nsterm.h | 2 +
src/nsterm.m | 253 ++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 254 insertions(+), 1 deletion(-)
src/nsterm.m | 279 ++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 278 insertions(+), 3 deletions(-)
diff --git a/src/nsterm.h b/src/nsterm.h
index 5c15639..8b34300 100644
@@ -67,7 +67,7 @@ index 5c15639..8b34300 100644
@end
diff --git a/src/nsterm.m b/src/nsterm.m
index 6efeb1d..0255239 100644
index 143e784..da1a319 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -7066,6 +7066,110 @@ ns_ax_selected_overlay_text (struct buffer *b,
@@ -181,7 +181,7 @@ index 6efeb1d..0255239 100644
/* Build accessibility text for window W, skipping invisible text.
Populates *OUT_START with the buffer start charpos.
Populates *OUT_RUNS with an array of visible runs and *OUT_NRUNS
@@ -12311,6 +12415,105 @@ ns_ax_collect_windows (Lisp_Object window, EmacsView *view,
@@ -12311,6 +12415,122 @@ ns_ax_collect_windows (Lisp_Object window, EmacsView *view,
The existing elements carry cached state (modiff, point) from the
previous redisplay cycle. Rebuilding first would create fresh
elements with current values, making change detection impossible. */
@@ -194,9 +194,7 @@ index 6efeb1d..0255239 100644
+ after the parent's draw_window_cursor. */
+- (void)announceChildFrameCompletion
+{
+ static char *lastCandidate;
+ static struct buffer *lastBuffer;
+ static EMACS_INT lastModiff;
+
+
+ /* Validate frame state --- child frames may be partially
+ initialized during creation. */
@@ -212,10 +210,11 @@ index 6efeb1d..0255239 100644
+ also guards against re-entrance: if Lisp calls below
+ trigger redisplay, the modiff check short-circuits. */
+ EMACS_INT modiff = BUF_MODIFF (b);
+ if (b == lastBuffer && modiff == lastModiff)
+ if (EQ (w->contents, lastChildFrameBuffer)
+ && modiff == lastChildFrameModiff)
+ return;
+ lastBuffer = b;
+ lastModiff = modiff;
+ lastChildFrameBuffer = w->contents;
+ lastChildFrameModiff = modiff;
+
+ /* Skip buffers larger than a typical completion popup.
+ This avoids scanning eldoc, which-key, or other child
@@ -232,10 +231,10 @@ index 6efeb1d..0255239 100644
+
+ /* Deduplicate --- avoid re-announcing the same candidate. */
+ const char *cstr = [candidate UTF8String];
+ if (lastCandidate && strcmp (cstr, lastCandidate) == 0)
+ if (lastChildFrameCandidate && strcmp (cstr, lastChildFrameCandidate) == 0)
+ return;
+ xfree (lastCandidate);
+ lastCandidate = xstrdup (cstr);
+ xfree (lastChildFrameCandidate);
+ lastChildFrameCandidate = xstrdup (cstr);
+
+ NSDictionary *annInfo = @{
+ NSAccessibilityAnnouncementKey: candidate,
@@ -283,11 +282,29 @@ index 6efeb1d..0255239 100644
+ kUAZoomFocusTypeInsertionPoint);
+ }
+}
+
+/* Child frame completion dedup state. File-scope so that
+ lastChildFrameBuffer can be staticpro'd against GC. */
+static Lisp_Object lastChildFrameBuffer;
+static EMACS_INT lastChildFrameModiff;
+static char *lastChildFrameCandidate;
+
+/* Reset the re-entrance guard when unwinding past
+ postAccessibilityUpdates due to a Lisp signal (longjmp).
+ Without this, a signal during Lisp calls (e.g. Fget_char_property
+ in overlay or child frame scanning) would leave
+ accessibilityUpdating = YES permanently, suppressing all future
+ accessibility notifications. */
+static void
+ns_ax_reset_accessibility_updating (void *view)
+{
+ ((EmacsView *)view)->accessibilityUpdating = NO;
+}
+
- (void)postAccessibilityUpdates
{
NSTRACE ("[EmacsView postAccessibilityUpdates]");
@@ -12321,11 +12524,59 @@ ns_ax_collect_windows (Lisp_Object window, EmacsView *view,
@@ -12321,10 +12541,60 @@ ns_ax_collect_windows (Lisp_Object window, EmacsView *view,
/* Re-entrance guard: VoiceOver callbacks during notification posting
can trigger redisplay, which calls ns_update_end, which calls us
@@ -298,14 +315,16 @@ index 6efeb1d..0255239 100644
if (accessibilityUpdating)
return;
accessibilityUpdating = YES;
+ specpdl_ref axCount = SPECPDL_INDEX ();
+ record_unwind_protect_ptr (ns_ax_reset_accessibility_updating, self);
+
+ /* Child frame completion popup (Corfu, Company-box, etc.).
+ Child frames don't participate in the accessibility tree;
+ announce the selected candidate directly. */
+ if (FRAME_PARENT_FRAME (emacsframe))
+ {
+ [self announceChildFrameCompletion];
+ accessibilityUpdating = NO;
+ unbind_to (axCount, Qnil);
+ return;
+ }
+
@@ -344,10 +363,37 @@ index 6efeb1d..0255239 100644
+ NSAccessibilityFocusedUIElementChangedNotification);
+ }
+ }
+
/* Detect window tree change (split, delete, new buffer). Compare
FRAME_ROOT_WINDOW --- if it changed, the tree structure changed. */
Lisp_Object curRoot = FRAME_ROOT_WINDOW (emacsframe);
@@ -12355,7 +12625,7 @@ ns_ax_collect_windows (Lisp_Object window, EmacsView *view,
NSAccessibilityFocusedUIElementChangedNotification);
lastSelectedWindow = emacsframe->selected_window;
- accessibilityUpdating = NO;
+ unbind_to (axCount, Qnil);
return;
}
@@ -12399,7 +12669,7 @@ ns_ax_collect_windows (Lisp_Object window, EmacsView *view,
NSAccessibilityFocusedUIElementChangedNotification);
}
- accessibilityUpdating = NO;
+ unbind_to (axCount, Qnil);
}
/* ---- Cursor position for Zoom (via accessibilityBoundsForRange:) ----
@@ -14341,6 +14611,9 @@ syms_of_nsterm (void)
DEFSYM (Qns_ax_completion, "completion");
DEFSYM (Qns_ax_completions_highlight, "completions-highlight");
DEFSYM (Qns_ax_backtab, "backtab");
+
+ lastChildFrameBuffer = Qnil;
+ staticpro (&lastChildFrameBuffer);
/* Qmouse_face and Qkeymap are defined in textprop.c / keymap.c. */
Fput (Qalt, Qmodifier_value, make_fixnum (alt_modifier));
Fput (Qhyper, Qmodifier_value, make_fixnum (hyper_modifier));
--
2.43.0