From 733279abedc598a927e66c6f6ac10d1bd9271e79 Mon Sep 17 00:00:00 2001 From: Alan Third Date: Fri, 30 Mar 2018 12:25:15 +0100 Subject: [PATCH] Simplify represented filename handling (bug#30800) * src/nsfns.m (ns_set_represented_filename): Move function from nsterm.m and set represented filename directly. * src/nsterm.h (ns_set_represented_filename): Remove definition. * src/nsterm.m (ns_set_represented_filename): Move function to nsfns.m. (x_free_frame_resources): Remove references to represented_frame. (sendEvent): Don't set represented filename. --- src/nsfns.m | 41 +++++++++++++++++++++++++++++++++++++ src/nsterm.h | 6 ------ src/nsterm.m | 58 ---------------------------------------------------- 3 files changed, 41 insertions(+), 64 deletions(-) diff --git a/src/nsfns.m b/src/nsfns.m index 6df54b4eb50..7cf45a54f90 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -463,6 +463,47 @@ ns_set_name (struct frame *f, Lisp_Object name, int explicit) ns_set_name_internal (f, name); } +static void +ns_set_represented_filename (struct frame *f) +{ + Lisp_Object filename, encoded_filename; + Lisp_Object buf = XWINDOW (f->selected_window)->contents; + NSAutoreleasePool *pool; + NSString *fstr; + NSView *view = FRAME_NS_VIEW (f); + + NSTRACE ("ns_set_represented_filename"); + + if (f->explicit_name || ! NILP (f->title)) + return; + + block_input (); + pool = [[NSAutoreleasePool alloc] init]; + filename = BVAR (XBUFFER (buf), filename); + + if (! NILP (filename)) + { + encoded_filename = ENCODE_UTF_8 (filename); + + fstr = [NSString stringWithUTF8String: SSDATA (encoded_filename)]; + if (fstr == nil) fstr = @""; + } + else + fstr = @""; + +#ifdef NS_IMPL_COCOA + /* Work around a bug observed on 10.3 and later where + setTitleWithRepresentedFilename does not clear out previous state + if given filename does not exist. */ + if (! [[NSFileManager defaultManager] fileExistsAtPath: fstr]) + [[view window] setRepresentedFilename: @""]; +#endif + [[view window] setRepresentedFilename: fstr]; + + [pool release]; + unblock_input (); +} + /* This function should be called when the user's lisp code has specified a name for the frame; the name will override any set by the diff --git a/src/nsterm.h b/src/nsterm.h index a9635374c78..a99b517fd5e 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -1237,12 +1237,6 @@ struct input_event; extern void ns_init_events (struct input_event *); extern void ns_finish_events (void); -#ifdef __OBJC__ -/* Needed in nsfns.m. */ -extern void -ns_set_represented_filename (struct frame *f); - -#endif #ifdef NS_IMPL_GNUSTEP extern char gnustep_base_version[]; /* version tracking */ diff --git a/src/nsterm.m b/src/nsterm.m index 06ba2e1a4c7..3c95fedadc9 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -327,9 +327,6 @@ static struct { NULL, 0, 0 }; -static NSString *represented_filename = nil; -static struct frame *represented_frame = 0; - #ifdef NS_IMPL_COCOA /* * State for pending menu activation: @@ -472,40 +469,6 @@ static void ns_judge_scroll_bars (struct frame *f); ========================================================================== */ -void -ns_set_represented_filename (struct frame *f) -{ - Lisp_Object filename, encoded_filename; - Lisp_Object buf = XWINDOW (f->selected_window)->contents; - NSAutoreleasePool *pool; - NSString *fstr; - - NSTRACE ("ns_set_represented_filename"); - - if (f->explicit_name || ! NILP (f->title)) - return; - - block_input (); - pool = [[NSAutoreleasePool alloc] init]; - filename = BVAR (XBUFFER (buf), filename); - - if (! NILP (filename)) - { - encoded_filename = ENCODE_UTF_8 (filename); - - fstr = [NSString stringWithUTF8String: SSDATA (encoded_filename)]; - if (fstr == nil) fstr = @""; - } - else - fstr = @""; - - represented_filename = [fstr retain]; - represented_frame = f; - - [pool release]; - unblock_input (); -} - void ns_init_events (struct input_event *ev) { @@ -1783,10 +1746,6 @@ x_free_frame_resources (struct frame *f) dpyinfo->x_highlight_frame = 0; if (f == hlinfo->mouse_face_mouse_frame) reset_mouse_highlight (hlinfo); - /* Ensure that sendEvent does not attempt to dereference a freed - frame. (bug#30800) */ - if (represented_frame == f) - represented_frame = NULL; if (f->output_data.ns->miniimage != nil) [f->output_data.ns->miniimage release]; @@ -5630,23 +5589,6 @@ ns_term_shutdown (int sig) } #endif - if (represented_filename != nil && represented_frame) - { - NSString *fstr = represented_filename; - NSView *view = FRAME_NS_VIEW (represented_frame); -#ifdef NS_IMPL_COCOA - /* Work around a bug observed on 10.3 and later where - setTitleWithRepresentedFilename does not clear out previous state - if given filename does not exist. */ - if (! [[NSFileManager defaultManager] fileExistsAtPath: fstr]) - [[view window] setRepresentedFilename: @""]; -#endif - [[view window] setRepresentedFilename: fstr]; - [represented_filename release]; - represented_filename = nil; - represented_frame = NULL; - } - if (type == NSEventTypeApplicationDefined) { switch ([theEvent data2]) -- 2.39.2