[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 66656bf5f86 4/4: Simplify Objective C autorelease pool handling
From: |
Alan Third |
Subject: |
master 66656bf5f86 4/4: Simplify Objective C autorelease pool handling |
Date: |
Sat, 30 Dec 2023 06:24:35 -0500 (EST) |
branch: master
commit 66656bf5f86c7623072a08fa3f29ba9c879d3f6d
Author: Alan Third <alan@idiocy.org>
Commit: Alan Third <alan@idiocy.org>
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.
---
src/emacs.c | 24 +++++-------------------
src/nsterm.h | 1 +
src/nsterm.m | 9 +++++++++
3 files changed, 15 insertions(+), 19 deletions(-)
diff --git a/src/emacs.c b/src/emacs.c
index 6101ed4004c..0489363082b 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -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);
}
diff --git a/src/nsterm.h b/src/nsterm.h
index cb162039ad8..324c23532de 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -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 */
diff --git a/src/nsterm.m b/src/nsterm.m
index dc4aef55113..dbb54632add 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -549,6 +549,15 @@ ns_relocate (const char *epath)
}
+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