Prevent GC of window referenced from EmacsScroller

* src/nsterm.m (EmacsScroller.mark, mark_nsterm): New functions.
* src/nsterm.h (EmacsScroller.mark, mark_nsterm): Declare.
* src/alloc.c (garbage_collect) [MAVE_NS]: Call mark_nsterm.
(Bug#56095)

(cherry picked from commit 5f1bd87247)
This commit is contained in:
Gerd Moellmann 2022-06-21 15:49:44 +02:00 committed by Eli Zaretskii
parent cb911febc6
commit f02944f5a1
3 changed files with 39 additions and 0 deletions

View file

@ -6145,6 +6145,11 @@ garbage_collect (void)
mark_fringe_data (); mark_fringe_data ();
#endif #endif
#ifdef HAVE_NS
mark_nsterm ();
#endif
/* Everything is now marked, except for the data in font caches, /* Everything is now marked, except for the data in font caches,
undo lists, and finalizers. The first two are compacted by undo lists, and finalizers. The first two are compacted by
removing an items which aren't reachable otherwise. */ removing an items which aren't reachable otherwise. */

View file

@ -683,6 +683,7 @@ typedef id instancetype;
int em_whole; int em_whole;
} }
- (void) mark;
- (instancetype) initFrame: (NSRect )r window: (Lisp_Object)win; - (instancetype) initFrame: (NSRect )r window: (Lisp_Object)win;
- (void)setFrame: (NSRect)r; - (void)setFrame: (NSRect)r;
@ -1347,4 +1348,7 @@ enum NSWindowTabbingMode
#define NSControlStateValueOff NSOffState #define NSControlStateValueOff NSOffState
#define NSBezelStyleRounded NSRoundedBezelStyle #define NSBezelStyleRounded NSRoundedBezelStyle
#endif #endif
extern void mark_nsterm (void);
#endif /* HAVE_NS */ #endif /* HAVE_NS */

View file

@ -9039,6 +9039,16 @@ -(bool)judge
return ret; return ret;
} }
- (void) mark
{
if (window)
{
Lisp_Object win;
XSETWINDOW (win, window);
mark_object (win);
}
}
- (void)resetCursorRects - (void)resetCursorRects
{ {
@ -9780,6 +9790,26 @@ Convert an X font name (XLFD) to an NS font name.
return ret; return ret;
} }
void
mark_nsterm (void)
{
NSTRACE ("mark_nsterm");
Lisp_Object tail, frame;
FOR_EACH_FRAME (tail, frame)
{
struct frame *f = XFRAME (frame);
if (FRAME_NS_P (f))
{
NSArray *subviews = [[FRAME_NS_VIEW (f) superview] subviews];
for (int i = [subviews count] - 1; i >= 0; --i)
{
id scroller = [subviews objectAtIndex: i];
if ([scroller isKindOfClass: [EmacsScroller class]])
[scroller mark];
}
}
}
}
void void
syms_of_nsterm (void) syms_of_nsterm (void)