* bug#71262: [PATCH] Try to install C.UTF-8 locale before falling back to C.
@ 2024-05-29 18:00 Tomas Volf
2024-09-07 14:40 ` bug#71262: Status: " Tomas Volf
0 siblings, 1 reply; 4+ messages in thread
From: Tomas Volf @ 2024-05-29 18:00 UTC (permalink / raw)
To: 71262; +Cc: Tomas Volf
If user does not have LANG or LC_ALL set (as does often happen in
various sandboxes) glibc will just install C locale. That is fine (and
permissible by POSIX), however in Guile's context it is of a mixed
usefulness due to the absence of UTF-8 support.
This commit changes the locale auto-installation logic to attempt
C.UTF-8 locale first (if user did not request another one).
User can still get C locale by either GUILE_INSTALL_LOCALE=0 or LANG=C.
This default should be more useful in this day and age, at least for
Guile users.
* libguile/guile.c (should_install_default_locale): New function.
(main)[should_install_locale ()]: Try to install C.UTF-8 before falling
back to C.
* doc/ref/guile-invoke.texi (Environment Variables): Document the
change.
---
doc/ref/guile-invoke.texi | 6 ++++--
libguile/guile.c | 19 +++++++++++++++++--
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/doc/ref/guile-invoke.texi b/doc/ref/guile-invoke.texi
index 856bce7b8..e08d78200 100644
--- a/doc/ref/guile-invoke.texi
+++ b/doc/ref/guile-invoke.texi
@@ -344,8 +344,10 @@ variable. By default, the history file is @file{$HOME/.guile_history}.
This is a flag that can be used to tell Guile whether or not to install
the current locale at startup, via a call to @code{(setlocale LC_ALL
"")}@footnote{The @code{GUILE_INSTALL_LOCALE} environment variable was
-ignored in Guile versions prior to 2.0.9.}. @xref{Locales}, for more
-information on locales.
+ignored in Guile versions prior to 2.0.9.}. If no explicit locale is
+set by the user (via @code{LC_ALL} or @code{LANG} environment
+variables), @samp{C.UTF-8} is tried before falling back to @samp{C}.
+@xref{Locales}, for more information on locales.
You may explicitly indicate that you do not want to install
the locale by setting @env{GUILE_INSTALL_LOCALE} to @code{0}, or
diff --git a/libguile/guile.c b/libguile/guile.c
index 8283ef6fa..a4ad10400 100644
--- a/libguile/guile.c
+++ b/libguile/guile.c
@@ -80,6 +80,16 @@ should_install_locale (void)
return get_integer_from_environment ("GUILE_INSTALL_LOCALE", 1);
}
+static int
+should_install_default_locale (void)
+{
+ /* This logic is derived from a precedence order described in section
+ 8.2 of The Open Group Base Specifications Issue 7, 2018 edition. */
+ const char *lang = getenv ("LANG");
+ const char *lc_all = getenv ("LC_ALL");
+ return (!lc_all || *lc_all == 0) && (!lang || *lang == 0);
+}
+
int
main (int argc, char **argv)
{
@@ -88,8 +98,13 @@ main (int argc, char **argv)
error messages, use the right locale. See
<https://lists.gnu.org/archive/html/guile-devel/2011-11/msg00041.html>
for the rationale. */
- if (should_install_locale () && setlocale (LC_ALL, "") == NULL)
- fprintf (stderr, "guile: warning: failed to install locale\n");
+ if (should_install_locale ()) {
+ if (should_install_default_locale ()
+ && setlocale(LC_ALL, "C.UTF-8") != NULL)
+ ;
+ else if (setlocale (LC_ALL, "") == NULL)
+ fprintf (stderr, "guile: warning: failed to install locale\n");
+ }
scm_boot_guile (argc, argv, inner_main, 0);
return 0; /* never reached */
--
2.41.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* bug#71262: Status: [PATCH] Try to install C.UTF-8 locale before falling back to C.
2024-05-29 18:00 bug#71262: [PATCH] Try to install C.UTF-8 locale before falling back to C Tomas Volf
@ 2024-09-07 14:40 ` Tomas Volf
2024-09-07 15:52 ` Dr. Arne Babenhauserheide via Bug reports for GUILE, GNU's Ubiquitous Extension Language
0 siblings, 1 reply; 4+ messages in thread
From: Tomas Volf @ 2024-09-07 14:40 UTC (permalink / raw)
To: bug#71262
[-- Attachment #1: Type: text/plain, Size: 102 bytes --]
Does anyone has any opinion regarding this? I think it is sensible
default in the year 2024.
Tomas
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 853 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#71262: Status: [PATCH] Try to install C.UTF-8 locale before falling back to C.
2024-09-07 14:40 ` bug#71262: Status: " Tomas Volf
@ 2024-09-07 15:52 ` Dr. Arne Babenhauserheide via Bug reports for GUILE, GNU's Ubiquitous Extension Language
2024-10-21 21:11 ` Tomas Volf
0 siblings, 1 reply; 4+ messages in thread
From: Dr. Arne Babenhauserheide via Bug reports for GUILE, GNU's Ubiquitous Extension Language @ 2024-09-07 15:52 UTC (permalink / raw)
To: Tomas Volf; +Cc: bug#71262
[-- Attachment #1: Type: text/plain, Size: 413 bytes --]
Tomas Volf <~@wolfsden.cz> writes:
> Does anyone has any opinion regarding this? I think it is sensible
> default in the year 2024.
I like the idea — I just don’t know enough of the platforms where Guile
is used (like embedded tools / tiny computers?) to know whether there is
danger in doing so.
Best wishes,
Arne
--
Unpolitisch sein
heißt politisch sein,
ohne es zu merken.
draketo.de
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 1125 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#71262: Status: [PATCH] Try to install C.UTF-8 locale before falling back to C.
2024-09-07 15:52 ` Dr. Arne Babenhauserheide via Bug reports for GUILE, GNU's Ubiquitous Extension Language
@ 2024-10-21 21:11 ` Tomas Volf
0 siblings, 0 replies; 4+ messages in thread
From: Tomas Volf @ 2024-10-21 21:11 UTC (permalink / raw)
To: Dr. Arne Babenhauserheide; +Cc: bug#71262
[-- Attachment #1: Type: text/plain, Size: 603 bytes --]
"Dr. Arne Babenhauserheide" <arne_bab@web.de> writes:
> Tomas Volf <~@wolfsden.cz> writes:
>
>> Does anyone has any opinion regarding this? I think it is sensible
>> default in the year 2024.
>
> I like the idea — I just don’t know enough of the platforms where Guile
> is used (like embedded tools / tiny computers?) to know whether there is
> danger in doing so.
I am pretty sure there should not be any (I know I know, famous last
words). If the installation of the locale fail, it falls back to the
previous behavior. I would hope this patch can only improve things.
Tomas
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 853 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-10-21 21:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-29 18:00 bug#71262: [PATCH] Try to install C.UTF-8 locale before falling back to C Tomas Volf
2024-09-07 14:40 ` bug#71262: Status: " Tomas Volf
2024-09-07 15:52 ` Dr. Arne Babenhauserheide via Bug reports for GUILE, GNU's Ubiquitous Extension Language
2024-10-21 21:11 ` Tomas Volf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).