From c6809e97e4e74a3d29c69eab86aad7de9fcd3293 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Mon, 25 Apr 2022 13:42:44 +0800 Subject: [PATCH] Get rid of autorelease warnings during building on GNUstep * src/emacs.c (decode_env_path): * src/nsfns.m (ns_appkit_version_str): * src/nsterm.m (ns_term_shutdown): Setup autorelease when objects might be autoreleased during building. --- src/emacs.c | 10 ++++++++++ src/nsfns.m | 8 +++++++- src/nsterm.m | 15 ++++++++------- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/emacs.c b/src/emacs.c index 3100852b2c0..ca99a8c787d 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -3153,6 +3153,9 @@ decode_env_path (const char *evarname, const char *defalt, bool empty) { const char *path, *p; Lisp_Object lpath, element, tem; +#ifdef NS_SELF_CONTAINED + void *autorelease = NULL; +#endif /* Default is to use "." for empty path elements. But if argument EMPTY is true, use nil instead. */ Lisp_Object empty_element = empty ? Qnil : build_string ("."); @@ -3180,6 +3183,8 @@ decode_env_path (const char *evarname, const char *defalt, bool empty) if (!path) { #ifdef NS_SELF_CONTAINED + /* ns_relocate needs a valid autorelease pool around it. */ + autorelease = ns_alloc_autorelease_pool (); path = ns_relocate (defalt); #else path = defalt; @@ -3282,6 +3287,11 @@ decode_env_path (const char *evarname, const char *defalt, bool empty) else break; } + +#ifdef NS_SELF_CONTAINED + if (autorelease) + ns_release_autorelease_pool (autorelease); +#endif return Fnreverse (lpath); } diff --git a/src/nsfns.m b/src/nsfns.m index f3dc235b893..cff31f7fe0e 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -891,7 +891,10 @@ static Lisp_Object ns_appkit_version_str (void) { NSString *tmp; + Lisp_Object string; + NSAutoreleasePool *autorelease; + autorelease = [[NSAutoreleasePool alloc] init]; #ifdef NS_IMPL_GNUSTEP tmp = [NSString stringWithFormat:@"gnustep-gui-%s", Xstr(GNUSTEP_GUI_VERSION)]; #elif defined (NS_IMPL_COCOA) @@ -901,7 +904,10 @@ ns_appkit_version_str (void) #else tmp = [NSString initWithUTF8String:@"ns-unknown"]; #endif - return [tmp lispString]; + string = [tmp lispString]; + [autorelease release]; + + return string; } diff --git a/src/nsterm.m b/src/nsterm.m index 5a6a4d663b9..4737cb1b352 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -5404,20 +5404,21 @@ ns_term_init (Lisp_Object display_name) void ns_term_shutdown (int sig) { + NSAutoreleasePool *pool; + /* We also need an autorelease pool here, since this can be called + during dumping. */ + pool = [[NSAutoreleasePool alloc] init]; [[NSUserDefaults standardUserDefaults] synchronize]; + [pool release]; /* code not reached in emacs.c after this is called by shut_down_emacs: */ if (STRINGP (Vauto_save_list_file_name)) unlink (SSDATA (Vauto_save_list_file_name)); if (sig == 0 || sig == SIGTERM) - { - [NSApp terminate: NSApp]; - } - else // force a stack trace to happen - { - emacs_abort (); - } + [NSApp terminate: NSApp]; + else /* Force a stack trace to happen. */ + emacs_abort (); } -- 2.39.2