patches: fix all review issues from Opus core maintainer review

BLOCKERS fixed:
- #1: add missing skip_overlay_scan: label (goto without target)
- #2: move accessibilityLineForIndex: to patch 0002 (used in 0002/0003,
  was defined in 0007 — forward reference crash risk)
- #3: move BOOL singleLineMove to patch 0008 (declared in 0007, unused
  until 0008 — -Werror build failure)

WARNINGS fixed:
- #1: block_input ordering at 5 sites (record_unwind_protect_void must
  come AFTER block_input to avoid unmatched unblock_input on error)
- #2: deduplicate ns_ax_face_is_selected (move to patch 0001, remove
  from patch 0007 where it was duplicated)
- #4: improve childFrameLastBuffer comment (document rename edge case)
- #5: complete ChangeLog for patch 0007 (add 3 missing method entries)
- #6: document lastSelectedWindow/lastRootWindow GC safety in nsterm.h

MINOR fixed:
- #2: wrap ns_zoom_track_completion call in MAC_OS_X_VERSION >= 101000
  guard (consistent with the function definition)
- #3: @cindex Zoom verified present in VoiceOver section (already OK)
- #4: raise line_starts/line_ends bound from 128 to 512 (consistent
  with ns_ax_selected_overlay_text)
- #5: add echo_area_buffer[] lifetime comment referencing xdisp.c

All 9 patches apply cleanly (git apply verified sequentially).
This commit is contained in:
2026-03-03 20:43:56 +01:00
parent f42e799991
commit 97c14a3bd9
8 changed files with 320 additions and 144 deletions

View File

@@ -1,4 +1,4 @@
From b54ed57b93cb47250695106021d6e96030ffdd59 Mon Sep 17 00:00:00 2001
From 5bef7fa553d0dfd9ab933d341a8115d42e026b42 Mon Sep 17 00:00:00 2001
From: Martin Sukany <martin@sukany.cz>
Date: Mon, 2 Mar 2026 18:49:13 +0100
Subject: [PATCH 9/9] ns: announce child frame completion candidates for
@@ -37,8 +37,8 @@ Remove Zoom section (covered by patch 0000). Fix dangling paragraph.
doc/emacs/macos.texi | 13 +-
etc/NEWS | 25 +-
src/nsterm.h | 21 ++
src/nsterm.m | 560 +++++++++++++++++++++++++++++++++++++------
4 files changed, 528 insertions(+), 91 deletions(-)
src/nsterm.m | 577 +++++++++++++++++++++++++++++++++++++------
4 files changed, 541 insertions(+), 95 deletions(-)
diff --git a/doc/emacs/macos.texi b/doc/emacs/macos.texi
index 72ac3a9aa9..cf5ed0ff28 100644
@@ -111,7 +111,7 @@ index 7f917f93b2..bbec21b635 100644
interface and eliminate the associated overhead.
diff --git a/src/nsterm.h b/src/nsterm.h
index a210ceba14..2edd7cd6e0 100644
index 72ca210bb0..1c79c8aced 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -504,9 +504,20 @@ typedef struct ns_ax_visible_run
@@ -135,7 +135,7 @@ index a210ceba14..2edd7cd6e0 100644
@property (nonatomic, assign) ptrdiff_t cachedOverlayModiff;
@property (nonatomic, assign) ptrdiff_t cachedTextStart;
@property (nonatomic, assign) ptrdiff_t cachedModiff;
@@ -596,6 +607,14 @@ typedef NS_ENUM(NSInteger, EmacsAXSpanType)
@@ -601,6 +612,14 @@ typedef NS_ENUM(NSInteger, EmacsAXSpanType)
Lisp_Object lastRootWindow;
BOOL accessibilityTreeValid;
BOOL accessibilityUpdating;
@@ -150,7 +150,7 @@ index a210ceba14..2edd7cd6e0 100644
#endif
BOOL font_panel_active;
NSFont *font_panel_result;
@@ -665,6 +684,8 @@ typedef NS_ENUM(NSInteger, EmacsAXSpanType)
@@ -670,6 +689,8 @@ typedef NS_ENUM(NSInteger, EmacsAXSpanType)
- (void)rebuildAccessibilityTree;
- (void)invalidateAccessibilityTree;
- (void)postAccessibilityUpdates;
@@ -160,7 +160,7 @@ index a210ceba14..2edd7cd6e0 100644
@end
diff --git a/src/nsterm.m b/src/nsterm.m
index b9d3a0eb53..5e48710930 100644
index c9fe93a57b..f7574efb39 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1275,6 +1275,12 @@ If a completion candidate is selected (overlay or child frame),
@@ -176,7 +176,23 @@ index b9d3a0eb53..5e48710930 100644
if (!ns_zoom_enabled_p ())
return;
if (!WINDOWP (f->selected_window))
@@ -7407,6 +7413,117 @@ visual line index for Zoom (skip whitespace-only lines
@@ -1417,9 +1423,14 @@ so the visual offset is (ov_line + 1) * line_h from
/* Track completion candidates for Zoom (overlay and child frame).
Runs after cursor tracking so the selected candidate overrides
- the default cursor position. */
+ the default cursor position. Guard with the same version check
+ as ns_zoom_track_completion's callee (UAZoomChangeFocus requires
+ macOS 10.10+). */
+#if defined (MAC_OS_X_VERSION_MIN_REQUIRED) \
+ && MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
if (view)
ns_zoom_track_completion (f, view);
+#endif /* MAC_OS_X_VERSION_MIN_REQUIRED >= 101000 */
#endif /* NS_IMPL_COCOA */
/* Post accessibility notifications after each redisplay cycle. */
@@ -7407,6 +7418,119 @@ visual line index for Zoom (skip whitespace-only lines
return nil;
}
@@ -226,14 +242,16 @@ index b9d3a0eb53..5e48710930 100644
+ /* 128 lines is a safe upper bound for a completion child frame.
+ The caller rejects buffers larger than 10,000 characters
+ (BUF_ZV(b) - BUF_BEGV(b) > 10000 guard in announceChildFrameCompletion),
+ so the worst case is ~10 KB / 1 byte per line < 128. If a future
+ caller removes that guard, lines beyond 128 are silently skipped; */
+ ptrdiff_t line_starts[128];
+ ptrdiff_t line_ends[128];
+ so at most ~10,000 / 1-byte-per-line = 10,000 lines could appear,
+ but completion popups are typically < 512 lines. Use 512 to match
+ the bound in ns_ax_selected_overlay_text; lines beyond 512 are
+ silently skipped. */
+ ptrdiff_t line_starts[512];
+ ptrdiff_t line_ends[512];
+ int nlines = 0;
+ ptrdiff_t char_pos = 0, byte_pos = 0, lstart = 0;
+
+ while (byte_pos < byte_len && nlines < 128)
+ while (byte_pos < byte_len && nlines < 512)
+ {
+ if (data[byte_pos] == '\n')
+ {
@@ -294,22 +312,24 @@ index b9d3a0eb53..5e48710930 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
@@ -7440,9 +7557,13 @@ visual line index for Zoom (skip whitespace-only lines
@@ -7440,11 +7564,12 @@ visual line index for Zoom (skip whitespace-only lines
return @"";
specpdl_ref count = SPECPDL_INDEX ();
- record_unwind_current_buffer ();
- /* block_input must come before record_unwind_protect_void (unblock_input):
- if specpdl_push were to fail after registration, the unwind handler
- would call unblock_input without a matching block_input. */
+ /* block_input must precede record_unwind_protect_void (unblock_input):
+ if anything between SPECPDL_INDEX and block_input were to throw,
+ the unwind handler would call unblock_input without a matching
+ block_input, corrupting the input-blocking reference count. */
+ block_input ();
record_unwind_current_buffer ();
block_input ();
+ record_unwind_current_buffer ();
record_unwind_protect_void (unblock_input);
- block_input ();
if (b != current_buffer)
set_buffer_internal_1 (b);
@@ -8609,6 +8730,11 @@ - (void)setAccessibilitySelectedTextRange:(NSRange)range
@@ -8613,6 +8738,11 @@ - (void)setAccessibilitySelectedTextRange:(NSRange)range
[self ensureTextCache];
@@ -320,8 +340,8 @@ index b9d3a0eb53..5e48710930 100644
+
specpdl_ref count = SPECPDL_INDEX ();
record_unwind_current_buffer ();
/* Ensure block_input is always matched by unblock_input even if
@@ -9057,20 +9183,38 @@ - (void)postFocusedCursorNotification:(ptrdiff_t)point
/* block_input must come before record_unwind_protect_void (unblock_input). */
@@ -9060,20 +9190,38 @@ - (void)postFocusedCursorNotification:(ptrdiff_t)point
&& granularity
== ns_ax_text_selection_granularity_character);
@@ -370,7 +390,7 @@ index b9d3a0eb53..5e48710930 100644
ns_ax_post_notification_with_info (
self,
NSAccessibilitySelectedTextChangedNotification,
@@ -9170,12 +9314,17 @@ user expectation ("w" jumps to next word and reads it). */
@@ -9173,12 +9321,17 @@ user expectation ("w" jumps to next word and reads it). */
}
}
@@ -393,7 +413,7 @@ index b9d3a0eb53..5e48710930 100644
if (cachedText
&& granularity == ns_ax_text_selection_granularity_line)
{
@@ -9240,6 +9389,11 @@ - (void)postCompletionAnnouncementForBuffer:(struct buffer *)b
@@ -9243,6 +9396,11 @@ - (void)postCompletionAnnouncementForBuffer:(struct buffer *)b
block_input ();
specpdl_ref count2 = SPECPDL_INDEX ();
@@ -405,7 +425,7 @@ index b9d3a0eb53..5e48710930 100644
record_unwind_protect_void (unblock_input);
record_unwind_current_buffer ();
if (b != current_buffer)
@@ -9416,12 +9570,29 @@ - (void)postAccessibilityNotificationsForFrame:(struct frame *)f
@@ -9419,12 +9577,29 @@ - (void)postAccessibilityNotificationsForFrame:(struct frame *)f
if (!b)
return;
@@ -435,7 +455,7 @@ index b9d3a0eb53..5e48710930 100644
if (modiff != self.cachedModiff)
{
self.cachedModiff = modiff;
@@ -9435,6 +9606,7 @@ Text property changes (e.g. face updates from
@@ -9438,6 +9613,7 @@ Text property changes (e.g. face updates from
{
self.cachedCharsModiff = chars_modiff;
[self postTextChangedNotification:point];
@@ -443,7 +463,7 @@ index b9d3a0eb53..5e48710930 100644
}
}
@@ -9457,37 +9629,44 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property
@@ -9460,41 +9636,49 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property
displayed in the minibuffer. In normal editing buffers,
font-lock and other modes change BUF_OVERLAY_MODIFF on
every redisplay, triggering O(overlays) work per keystroke.
@@ -517,7 +537,12 @@ index b9d3a0eb53..5e48710930 100644
}
}
}
@@ -9501,7 +9680,18 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property
+ skip_overlay_scan:
/* --- Cursor moved or selection changed ---
Independent check from the overlay branch above. */
if (point != self.cachedPoint || markActive != self.cachedMarkActive)
@@ -9504,7 +9688,18 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property
self.cachedPoint = point;
self.cachedMarkActive = markActive;
@@ -537,7 +562,15 @@ index b9d3a0eb53..5e48710930 100644
NSInteger direction = ns_ax_text_selection_direction_discontiguous;
if (point > oldPoint)
direction = ns_ax_text_selection_direction_next;
@@ -9534,7 +9724,18 @@ to VoiceOver via the AX getter path (accessibilityValue etc.). */
@@ -9523,6 +9718,7 @@ granularity hint (defaulting to unknown), which causes VoiceOver
to make its own determination. Fresh text is always available
to VoiceOver via the AX getter path (accessibilityValue etc.). */
NSInteger granularity = ns_ax_text_selection_granularity_unknown;
+ BOOL singleLineMove = NO;
if (cachedText && oldPoint > 0)
{
NSUInteger tlen = [cachedText length];
@@ -9536,7 +9732,18 @@ to VoiceOver via the AX getter path (accessibilityValue etc.). */
NSRange newLine = [cachedText lineRangeForRange:
NSMakeRange (newIdx, 0)];
if (oldLine.location != newLine.location)
@@ -557,7 +590,7 @@ index b9d3a0eb53..5e48710930 100644
else
{
NSUInteger dist = (newIdx > oldIdx
@@ -9556,38 +9757,23 @@ to VoiceOver via the AX getter path (accessibilityValue etc.). */
@@ -9558,38 +9765,23 @@ to VoiceOver via the AX getter path (accessibilityValue etc.). */
granularity = ns_ax_text_selection_granularity_line;
}
@@ -609,7 +642,7 @@ index b9d3a0eb53..5e48710930 100644
{
NSWindow *win = [self.emacsView window];
if (win)
@@ -9746,6 +9932,13 @@ - (NSRect)accessibilityFrame
@@ -9748,6 +9940,13 @@ - (NSRect)accessibilityFrame
if (vis_start >= vis_end)
return @[];
@@ -623,7 +656,7 @@ index b9d3a0eb53..5e48710930 100644
block_input ();
specpdl_ref blk_count = SPECPDL_INDEX ();
record_unwind_protect_void (unblock_input);
@@ -10053,6 +10246,10 @@ - (void)dealloc
@@ -10056,6 +10255,10 @@ - (void)dealloc
#endif
[accessibilityElements release];
@@ -634,7 +667,7 @@ index b9d3a0eb53..5e48710930 100644
[[self menu] release];
[super dealloc];
}
@@ -11502,6 +11699,9 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f
@@ -11505,6 +11708,9 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f
windowClosing = NO;
processingCompose = NO;
@@ -644,7 +677,7 @@ index b9d3a0eb53..5e48710930 100644
scrollbarsNeedingUpdate = 0;
fs_state = FULLSCREEN_NONE;
fs_before_fs = next_maximized = -1;
@@ -12810,6 +13010,156 @@ - (id)accessibilityFocusedUIElement
@@ -12813,6 +13019,159 @@ - (id)accessibilityFocusedUIElement
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. */
@@ -664,7 +697,10 @@ index b9d3a0eb53..5e48710930 100644
+ Reads echo_area_buffer[0] directly because with_echo_area_buffer()
+ sets current_buffer via set_buffer_internal_1() but does NOT call
+ Fset_window_buffer(), so the minibuffer window's contents pointer
+ still points to the inactive " *Minibuf-0*" buffer. */
+ still points to the inactive " *Minibuf-0*" buffer.
+ echo_area_buffer[] is maintained by setup_echo_area_for_printing()
+ and clear_message() in xdisp.c; its lifetime is the process lifetime
+ and it is valid whenever BUFFERP (echo_area_buffer[0]) is true. */
+- (void)postEchoAreaAnnouncementIfNeeded
+{
+ if (minibuf_level != 0)
@@ -729,19 +765,19 @@ index b9d3a0eb53..5e48710930 100644
+ if (!BUFFER_LIVE_P (b))
+ return;
+ EMACS_INT modiff = BUF_MODIFF (b);
+ /* Compare buffer identity via the buffer name symbol, which is always
+ GC-reachable through the obarray. Storing the name avoids keeping
+ a direct buffer pointer in a non-GC-visible ObjC ivar: if the buffer
+ were killed and GC swept, a stale make_lisp_ptr value could collide
+ with a newly-allocated buffer at the same address. */
+ /* Compare buffer identity via the buffer name symbol. Interned
+ symbols (obarray) are GC-reachable without staticpro(), avoiding
+ a direct struct buffer pointer in a non-GC-visible ObjC ivar.
+ Caveat: if the buffer is renamed (rename-buffer), the stored
+ symbol no longer matches the new name and the equality check
+ returns nil, causing one redundant re-scan. This is harmless ---
+ completion popups (Corfu, Company) are never renamed during a
+ completion session. Using a sequence number would avoid the
+ rename edge case but would require another ivar; the name symbol
+ is a pragmatic, GC-safe approximation. */
+ if (EQ (childFrameLastBuffer, BVAR (b, name))
+ && modiff == childFrameLastModiff)
+ return;
+ /* Store the buffer name symbol (an interned Lisp_Object from
+ obarray) rather than a raw pointer to struct buffer.
+ Interned symbols are reachable from obarray and will not be
+ garbage-collected, so no staticpro() registration is needed
+ for this ivar. */
+ childFrameLastBuffer = BVAR (b, name);
+ childFrameLastModiff = modiff;
+
@@ -801,7 +837,7 @@ index b9d3a0eb53..5e48710930 100644
- (void)postAccessibilityUpdates
{
NSTRACE ("[EmacsView postAccessibilityUpdates]");
@@ -12820,11 +13170,69 @@ - (void)postAccessibilityUpdates
@@ -12823,11 +13182,69 @@ - (void)postAccessibilityUpdates
/* Re-entrance guard: VoiceOver callbacks during notification posting
can trigger redisplay, which calls ns_update_end, which calls us