diff options
| author | Alan Third | 2023-10-09 22:21:05 +0100 |
|---|---|---|
| committer | Alan Third | 2023-12-30 11:24:12 +0000 |
| commit | 66656bf5f86c7623072a08fa3f29ba9c879d3f6d (patch) | |
| tree | dbcc2ce5b41499755300b8b3e31b5a80f8503335 /src | |
| parent | f3dec3439fd5aee885a76622f384f6c7ca67d128 (diff) | |
| download | emacs-66656bf5f86c7623072a08fa3f29ba9c879d3f6d.tar.gz emacs-66656bf5f86c7623072a08fa3f29ba9c879d3f6d.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/emacs.c | 24 | ||||
| -rw-r--r-- | src/nsterm.h | 1 | ||||
| -rw-r--r-- | 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" | |||
| 401 | /* True if handling a fatal error already. */ | 401 | /* True if handling a fatal error already. */ |
| 402 | bool fatal_error_in_progress; | 402 | bool fatal_error_in_progress; |
| 403 | 403 | ||
| 404 | #ifdef HAVE_NS | ||
| 405 | /* NS autorelease pool, for memory management. */ | ||
| 406 | static void *ns_pool; | ||
| 407 | #endif | ||
| 408 | |||
| 409 | #if !HAVE_SETLOCALE | 404 | #if !HAVE_SETLOCALE |
| 410 | static char * | 405 | static char * |
| 411 | setlocale (int cat, char const *locale) | 406 | setlocale (int cat, char const *locale) |
| @@ -1424,6 +1419,11 @@ main (int argc, char **argv) | |||
| 1424 | w32_init_main_thread (); | 1419 | w32_init_main_thread (); |
| 1425 | #endif | 1420 | #endif |
| 1426 | 1421 | ||
| 1422 | #ifdef HAVE_NS | ||
| 1423 | /* Initialize the Obj C autorelease pool. */ | ||
| 1424 | ns_init_pool (); | ||
| 1425 | #endif | ||
| 1426 | |||
| 1427 | #ifdef HAVE_PDUMPER | 1427 | #ifdef HAVE_PDUMPER |
| 1428 | if (attempt_load_pdump) | 1428 | if (attempt_load_pdump) |
| 1429 | initial_emacs_executable = load_pdump (argc, argv, dump_file); | 1429 | initial_emacs_executable = load_pdump (argc, argv, dump_file); |
| @@ -1643,7 +1643,6 @@ main (int argc, char **argv) | |||
| 1643 | if (! (lc_all && strcmp (lc_all, "C") == 0)) | 1643 | if (! (lc_all && strcmp (lc_all, "C") == 0)) |
| 1644 | { | 1644 | { |
| 1645 | #ifdef HAVE_NS | 1645 | #ifdef HAVE_NS |
| 1646 | ns_pool = ns_alloc_autorelease_pool (); | ||
| 1647 | ns_init_locale (); | 1646 | ns_init_locale (); |
| 1648 | #endif | 1647 | #endif |
| 1649 | setlocale (LC_ALL, ""); | 1648 | setlocale (LC_ALL, ""); |
| @@ -2993,10 +2992,6 @@ killed. */ | |||
| 2993 | 2992 | ||
| 2994 | shut_down_emacs (0, (STRINGP (arg) && !feof (stdin)) ? arg : Qnil); | 2993 | shut_down_emacs (0, (STRINGP (arg) && !feof (stdin)) ? arg : Qnil); |
| 2995 | 2994 | ||
| 2996 | #ifdef HAVE_NS | ||
| 2997 | ns_release_autorelease_pool (ns_pool); | ||
| 2998 | #endif | ||
| 2999 | |||
| 3000 | /* If we have an auto-save list file, | 2995 | /* If we have an auto-save list file, |
| 3001 | kill it because we are exiting Emacs deliberately (not crashing). | 2996 | kill it because we are exiting Emacs deliberately (not crashing). |
| 3002 | Do it after shut_down_emacs, which does an auto-save. */ | 2997 | 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) | |||
| 3331 | { | 3326 | { |
| 3332 | const char *path, *p; | 3327 | const char *path, *p; |
| 3333 | Lisp_Object lpath, element, tem; | 3328 | Lisp_Object lpath, element, tem; |
| 3334 | #ifdef NS_SELF_CONTAINED | ||
| 3335 | void *autorelease = NULL; | ||
| 3336 | #endif | ||
| 3337 | /* Default is to use "." for empty path elements. | 3329 | /* Default is to use "." for empty path elements. |
| 3338 | But if argument EMPTY is true, use nil instead. */ | 3330 | But if argument EMPTY is true, use nil instead. */ |
| 3339 | Lisp_Object empty_element = empty ? Qnil : build_string ("."); | 3331 | Lisp_Object empty_element = empty ? Qnil : build_string ("."); |
| @@ -3361,8 +3353,6 @@ decode_env_path (const char *evarname, const char *defalt, bool empty) | |||
| 3361 | if (!path) | 3353 | if (!path) |
| 3362 | { | 3354 | { |
| 3363 | #ifdef NS_SELF_CONTAINED | 3355 | #ifdef NS_SELF_CONTAINED |
| 3364 | /* ns_relocate needs a valid autorelease pool around it. */ | ||
| 3365 | autorelease = ns_alloc_autorelease_pool (); | ||
| 3366 | path = ns_relocate (defalt); | 3356 | path = ns_relocate (defalt); |
| 3367 | #else | 3357 | #else |
| 3368 | path = defalt; | 3358 | path = defalt; |
| @@ -3466,10 +3456,6 @@ decode_env_path (const char *evarname, const char *defalt, bool empty) | |||
| 3466 | break; | 3456 | break; |
| 3467 | } | 3457 | } |
| 3468 | 3458 | ||
| 3469 | #ifdef NS_SELF_CONTAINED | ||
| 3470 | if (autorelease) | ||
| 3471 | ns_release_autorelease_pool (autorelease); | ||
| 3472 | #endif | ||
| 3473 | return Fnreverse (lpath); | 3459 | return Fnreverse (lpath); |
| 3474 | } | 3460 | } |
| 3475 | 3461 | ||
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); | |||
| 1180 | extern void *ns_alloc_autorelease_pool (void); | 1180 | extern void *ns_alloc_autorelease_pool (void); |
| 1181 | extern void ns_release_autorelease_pool (void *); | 1181 | extern void ns_release_autorelease_pool (void *); |
| 1182 | extern const char *ns_get_defaults_value (const char *key); | 1182 | extern const char *ns_get_defaults_value (const char *key); |
| 1183 | extern void ns_init_pool (void); | ||
| 1183 | extern void ns_init_locale (void); | 1184 | extern void ns_init_locale (void); |
| 1184 | 1185 | ||
| 1185 | /* in nsmenu */ | 1186 | /* in nsmenu */ |
diff --git a/src/nsterm.m b/src/nsterm.m index dc4aef55113..dbb54632add 100644 --- a/src/nsterm.m +++ b/src/nsterm.m | |||
| @@ -550,6 +550,15 @@ ns_relocate (const char *epath) | |||
| 550 | 550 | ||
| 551 | 551 | ||
| 552 | void | 552 | void |
| 553 | ns_init_pool (void) | ||
| 554 | /* Initialize the 'outerpool' autorelease pool. This should be called | ||
| 555 | from main before any Objective C code is run. */ | ||
| 556 | { | ||
| 557 | outerpool = [[NSAutoreleasePool alloc] init]; | ||
| 558 | } | ||
| 559 | |||
| 560 | |||
| 561 | void | ||
| 553 | ns_init_locale (void) | 562 | ns_init_locale (void) |
| 554 | /* macOS doesn't set any environment variables for the locale when run | 563 | /* macOS doesn't set any environment variables for the locale when run |
| 555 | from the GUI. Get the locale from the OS and set LANG. */ | 564 | from the GUI. Get the locale from the OS and set LANG. */ |