1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-01 08:17:38 +00:00

Simplify Objective C autorelease pool handling

* src/emacs.c: Remove ns_pool.
(main): Replace ns_pool stuff with call to ns_init_pool.
(Fkill_emacs): The pools are drained automatically when the
application exits, so it's probably not worth draining the pool here.
(decode_env_path): No longer required as this is handled by
`outerpool' defined in nsterm.m.
* src/nsterm.h:
* src/nsterm.m (ns_init_pool): New function.
This commit is contained in:
Alan Third 2023-10-09 22:21:05 +01:00
parent f3dec3439f
commit 66656bf5f8
3 changed files with 15 additions and 19 deletions

View File

@ -401,11 +401,6 @@ section of the Emacs manual or the file BUGS.\n"
/* True if handling a fatal error already. */
bool fatal_error_in_progress;
#ifdef HAVE_NS
/* NS autorelease pool, for memory management. */
static void *ns_pool;
#endif
#if !HAVE_SETLOCALE
static char *
setlocale (int cat, char const *locale)
@ -1424,6 +1419,11 @@ main (int argc, char **argv)
w32_init_main_thread ();
#endif
#ifdef HAVE_NS
/* Initialize the Obj C autorelease pool. */
ns_init_pool ();
#endif
#ifdef HAVE_PDUMPER
if (attempt_load_pdump)
initial_emacs_executable = load_pdump (argc, argv, dump_file);
@ -1643,7 +1643,6 @@ main (int argc, char **argv)
if (! (lc_all && strcmp (lc_all, "C") == 0))
{
#ifdef HAVE_NS
ns_pool = ns_alloc_autorelease_pool ();
ns_init_locale ();
#endif
setlocale (LC_ALL, "");
@ -2993,10 +2992,6 @@ killed. */
shut_down_emacs (0, (STRINGP (arg) && !feof (stdin)) ? arg : Qnil);
#ifdef HAVE_NS
ns_release_autorelease_pool (ns_pool);
#endif
/* If we have an auto-save list file,
kill it because we are exiting Emacs deliberately (not crashing).
Do it after shut_down_emacs, which does an auto-save. */
@ -3331,9 +3326,6 @@ 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 (".");
@ -3361,8 +3353,6 @@ 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;
@ -3466,10 +3456,6 @@ decode_env_path (const char *evarname, const char *defalt, bool empty)
break;
}
#ifdef NS_SELF_CONTAINED
if (autorelease)
ns_release_autorelease_pool (autorelease);
#endif
return Fnreverse (lpath);
}

View File

@ -1180,6 +1180,7 @@ extern void ns_retain_object (void *obj);
extern void *ns_alloc_autorelease_pool (void);
extern void ns_release_autorelease_pool (void *);
extern const char *ns_get_defaults_value (const char *key);
extern void ns_init_pool (void);
extern void ns_init_locale (void);
/* in nsmenu */

View File

@ -549,6 +549,15 @@ - (unsigned long)unsignedLong
}
void
ns_init_pool (void)
/* Initialize the 'outerpool' autorelease pool. This should be called
from main before any Objective C code is run. */
{
outerpool = [[NSAutoreleasePool alloc] init];
}
void
ns_init_locale (void)
/* macOS doesn't set any environment variables for the locale when run