Skip to content

Commit 75c1f93

Browse files
committed
Simplify locale setup
Stop exporting Vprevious_system_time_locale and Vprevious_system_messages_locale to Elisp. I did that export by mistake in 1999, and the Elisp variables have never been used. Simplifying this cruft should make it easier to fix Bug#39248. * etc/NEWS: Mention this. * src/emacs.c (main): Simplify locale initialization. (synchronize_locale): Simplify. (Vprevious_system_time_locale, Vprevious_system_messages_locale): Now static variables not visible to Lisp, and defined only if HAVE_SETLOCALE. (Vprevious_system_messages_locale): Define only if LC_MESSAGES.
1 parent 04ca1a1 commit 75c1f93

File tree

2 files changed

+34
-40
lines changed

2 files changed

+34
-40
lines changed

etc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ Formerly it made an exception for integer components of SOA records,
110110
because SOA serial numbers can exceed fixnum ranges on 32-bit platforms.
111111
Emacs now supports bignums so this old glitch is no longer needed.
112112

113+
** The Lisp variables 'previous-system-messages-locale' and
114+
'previous-system-time-locale' have been removed, as they were created
115+
by mistake and were not useful to Lisp code.
116+
113117

114118
* Lisp Changes in Emacs 28.1
115119

src/emacs.c

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,6 @@ main (int argc, char **argv)
930930
for pointers. */
931931
void *stack_bottom_variable;
932932

933-
bool do_initial_setlocale;
934933
bool no_loadup = false;
935934
char *junk = 0;
936935
char *dname_arg = 0;
@@ -1235,19 +1234,17 @@ main (int argc, char **argv)
12351234
set_binary_mode (STDOUT_FILENO, O_BINARY);
12361235
#endif /* MSDOS */
12371236

1238-
/* Skip initial setlocale if LC_ALL is "C", as it's not needed in that case.
1239-
The build procedure uses this while dumping, to ensure that the
1240-
dumped Emacs does not have its system locale tables initialized,
1241-
as that might cause screwups when the dumped Emacs starts up. */
1242-
{
1243-
char *lc_all = getenv ("LC_ALL");
1244-
do_initial_setlocale = ! lc_all || strcmp (lc_all, "C");
1245-
}
1246-
1247-
/* Set locale now, so that initial error messages are localized properly.
1248-
fixup_locale must wait until later, since it builds strings. */
1249-
if (do_initial_setlocale)
1250-
setlocale (LC_ALL, "");
1237+
/* Set locale, so that initial error messages are localized properly.
1238+
However, skip this if LC_ALL is "C", as it's not needed in that case.
1239+
Skipping helps if dumping with unexec, to ensure that the dumped
1240+
Emacs does not have its system locale tables initialized, as that
1241+
might cause screwups when the dumped Emacs starts up. */
1242+
char *lc_all = getenv ("LC_ALL");
1243+
if (! (lc_all && strcmp (lc_all, "C") == 0))
1244+
{
1245+
setlocale (LC_ALL, "");
1246+
fixup_locale ();
1247+
}
12511248
text_quoting_flag = using_utf8 ();
12521249

12531250
inhibit_window_system = 0;
@@ -1576,14 +1573,6 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
15761573
init_alloc ();
15771574
init_bignum ();
15781575
init_threads ();
1579-
1580-
if (do_initial_setlocale)
1581-
{
1582-
fixup_locale ();
1583-
Vsystem_messages_locale = Vprevious_system_messages_locale;
1584-
Vsystem_time_locale = Vprevious_system_time_locale;
1585-
}
1586-
15871576
init_eval ();
15881577
init_atimer ();
15891578
running_asynch_code = 0;
@@ -2617,25 +2606,25 @@ synchronize_locale (int category, Lisp_Object *plocale, Lisp_Object desired_loca
26172606
if (! EQ (*plocale, desired_locale))
26182607
{
26192608
*plocale = desired_locale;
2620-
#ifdef WINDOWSNT
2609+
char const *locale_string
2610+
= STRINGP (desired_locale) ? SSDATA (desired_locale) : "";
2611+
# ifdef WINDOWSNT
26212612
/* Changing categories like LC_TIME usually requires specifying
26222613
an encoding suitable for the new locale, but MS-Windows's
26232614
'setlocale' will only switch the encoding when LC_ALL is
26242615
specified. So we ignore CATEGORY, use LC_ALL instead, and
26252616
then restore LC_NUMERIC to "C", so reading and printing
26262617
numbers is unaffected. */
2627-
setlocale (LC_ALL, (STRINGP (desired_locale)
2628-
? SSDATA (desired_locale)
2629-
: ""));
2618+
setlocale (LC_ALL, locale_string);
26302619
fixup_locale ();
2631-
#else /* !WINDOWSNT */
2632-
setlocale (category, (STRINGP (desired_locale)
2633-
? SSDATA (desired_locale)
2634-
: ""));
2635-
#endif /* !WINDOWSNT */
2620+
# else /* !WINDOWSNT */
2621+
setlocale (category, locale_string);
2622+
# endif /* !WINDOWSNT */
26362623
}
26372624
}
26382625

2626+
static Lisp_Object Vprevious_system_time_locale;
2627+
26392628
/* Set system time locale to match Vsystem_time_locale, if possible. */
26402629
void
26412630
synchronize_system_time_locale (void)
@@ -2644,15 +2633,19 @@ synchronize_system_time_locale (void)
26442633
Vsystem_time_locale);
26452634
}
26462635

2636+
# ifdef LC_MESSAGES
2637+
static Lisp_Object Vprevious_system_messages_locale;
2638+
# endif
2639+
26472640
/* Set system messages locale to match Vsystem_messages_locale, if
26482641
possible. */
26492642
void
26502643
synchronize_system_messages_locale (void)
26512644
{
2652-
#ifdef LC_MESSAGES
2645+
# ifdef LC_MESSAGES
26532646
synchronize_locale (LC_MESSAGES, &Vprevious_system_messages_locale,
26542647
Vsystem_messages_locale);
2655-
#endif
2648+
# endif
26562649
}
26572650
#endif /* HAVE_SETLOCALE */
26582651

@@ -2974,19 +2967,16 @@ build directory. */);
29742967
DEFVAR_LISP ("system-messages-locale", Vsystem_messages_locale,
29752968
doc: /* System locale for messages. */);
29762969
Vsystem_messages_locale = Qnil;
2977-
2978-
DEFVAR_LISP ("previous-system-messages-locale",
2979-
Vprevious_system_messages_locale,
2980-
doc: /* Most recently used system locale for messages. */);
2970+
#ifdef LC_MESSAGES
29812971
Vprevious_system_messages_locale = Qnil;
2972+
staticpro (&Vprevious_system_messages_locale);
2973+
#endif
29822974

29832975
DEFVAR_LISP ("system-time-locale", Vsystem_time_locale,
29842976
doc: /* System locale for time. */);
29852977
Vsystem_time_locale = Qnil;
2986-
2987-
DEFVAR_LISP ("previous-system-time-locale", Vprevious_system_time_locale,
2988-
doc: /* Most recently used system locale for time. */);
29892978
Vprevious_system_time_locale = Qnil;
2979+
staticpro (&Vprevious_system_time_locale);
29902980

29912981
DEFVAR_LISP ("before-init-time", Vbefore_init_time,
29922982
doc: /* Value of `current-time' before Emacs begins initialization. */);

0 commit comments

Comments
 (0)