From 5c848d3759ea6b9e70668a7aba7514078cfda282 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 30 Jun 2024 00:36:34 +0100 Subject: [PATCH] Assume setlocale exists Like locale.h, it was standardized by C89, is universally available now, and some code already assumes it. * configure.ac: Do not check for setlocale. * src/emacs.c (setlocale) [!HAVE_SETLOCALE]: Remove. (fixup_locale, synchronize_locale, Vprevious_system_time_locale) (synchronize_system_time_locale): Define even if !HAVE_SETLOCALE. * src/sysdep.c (emacs_setlocale): Simplify by assuming HAVE_SETLOCALE. (cherry picked from commit 69374fbe827b83c49eff084de8635220bd6d3ccf) --- configure.ac | 2 +- src/emacs.c | 24 +++++++----------------- src/lisp.h | 6 ------ src/sysdep.c | 4 ---- 4 files changed, 8 insertions(+), 28 deletions(-) diff --git a/configure.ac b/configure.ac index 1bc67a846b6..daff8195005 100644 --- a/configure.ac +++ b/configure.ac @@ -5960,7 +5960,7 @@ LIBS="$LIB_PTHREAD $LIB_MATH $LIBS" AC_CHECK_FUNCS([accept4 fchdir gethostname \ getrusage get_current_dir_name \ lrand48 random rint tcdrain trunc \ -select getpagesize setlocale newlocale \ +select getpagesize newlocale \ getrlimit setrlimit shutdown \ pthread_sigmask strsignal setitimer \ sendto recvfrom getsockname getifaddrs freeifaddrs \ diff --git a/src/emacs.c b/src/emacs.c index 56de9d8ba20..22b7a4f1038 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -399,14 +399,6 @@ section of the Emacs manual or the file BUGS.\n" /* True if handling a fatal error already. */ bool fatal_error_in_progress; -#if !HAVE_SETLOCALE -static char * -setlocale (int cat, char const *locale) -{ - return 0; -} -#endif - /* True if the current system locale uses UTF-8 encoding. */ static bool using_utf8 (void) @@ -3270,7 +3262,6 @@ You must run Emacs in batch mode in order to dump it. */) #endif -#if HAVE_SETLOCALE /* Recover from setlocale (LC_ALL, ""). */ void fixup_locale (void) @@ -3290,7 +3281,7 @@ synchronize_locale (int category, Lisp_Object *plocale, Lisp_Object desired_loca *plocale = desired_locale; char const *locale_string = STRINGP (desired_locale) ? SSDATA (desired_locale) : ""; -# ifdef WINDOWSNT +#ifdef WINDOWSNT /* Changing categories like LC_TIME usually requires specifying an encoding suitable for the new locale, but MS-Windows's 'setlocale' will only switch the encoding when LC_ALL is @@ -3299,9 +3290,9 @@ synchronize_locale (int category, Lisp_Object *plocale, Lisp_Object desired_loca numbers is unaffected. */ setlocale (LC_ALL, locale_string); fixup_locale (); -# else /* !WINDOWSNT */ +#else setlocale (category, locale_string); -# endif /* !WINDOWSNT */ +#endif } } @@ -3315,21 +3306,20 @@ synchronize_system_time_locale (void) Vsystem_time_locale); } -# ifdef LC_MESSAGES +#ifdef LC_MESSAGES static Lisp_Object Vprevious_system_messages_locale; -# endif +#endif /* Set system messages locale to match Vsystem_messages_locale, if possible. */ void synchronize_system_messages_locale (void) { -# ifdef LC_MESSAGES +#ifdef LC_MESSAGES synchronize_locale (LC_MESSAGES, &Vprevious_system_messages_locale, Vsystem_messages_locale); -# endif +#endif } -#endif /* HAVE_SETLOCALE */ /* Return a diagnostic string for ERROR_NUMBER, in the wording and encoding appropriate for the current locale. */ diff --git a/src/lisp.h b/src/lisp.h index 59d8e497f13..68b77a88aa7 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -5190,15 +5190,9 @@ extern AVOID terminate_due_to_signal (int, int); #ifdef WINDOWSNT extern Lisp_Object Vlibrary_cache; #endif -#if HAVE_SETLOCALE void fixup_locale (void); void synchronize_system_messages_locale (void); void synchronize_system_time_locale (void); -#else -INLINE void fixup_locale (void) {} -INLINE void synchronize_system_messages_locale (void) {} -INLINE void synchronize_system_time_locale (void) {} -#endif extern char *emacs_strerror (int) ATTRIBUTE_RETURNS_NONNULL; extern void shut_down_emacs (int, Lisp_Object); diff --git a/src/sysdep.c b/src/sysdep.c index 9e4f3b211bb..089fc74deb8 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -4593,15 +4593,11 @@ freelocale (locale_t loc) static char * emacs_setlocale (int category, char const *locale) { -# ifdef HAVE_SETLOCALE errno = 0; char *loc = setlocale (category, locale); if (loc || errno) return loc; errno = EINVAL; -# else - errno = ENOTSUP; -# endif return 0; } -- 2.39.2