GNU bug report logs - #71262
[PATCH] Try to install C.UTF-8 locale before falling back to C.

Previous Next

Package: guile;

Reported by: Tomas Volf <~@wolfsden.cz>

Date: Wed, 29 May 2024 18:01:01 UTC

Severity: normal

Tags: patch

To reply to this bug, email your comments to 71262 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#71262; Package guile. (Wed, 29 May 2024 18:01:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Tomas Volf <~@wolfsden.cz>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Wed, 29 May 2024 18:01:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Tomas Volf <~@wolfsden.cz>
To: bug-guile <at> gnu.org
Cc: Tomas Volf <~@wolfsden.cz>
Subject: [PATCH] Try to install C.UTF-8 locale before falling back to C.
Date: Wed, 29 May 2024 20:00:03 +0200
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





Information forwarded to bug-guile <at> gnu.org:
bug#71262; Package guile. (Sat, 07 Sep 2024 14:41:01 GMT) Full text and rfc822 format available.

Message #8 received at 71262 <at> debbugs.gnu.org (full text, mbox):

From: Tomas Volf <~@wolfsden.cz>
To: bug#71262 <71262 <at> debbugs.gnu.org>
Subject: Re: Status: [PATCH] Try to install C.UTF-8 locale before falling
 back to C.
Date: Sat, 07 Sep 2024 16:40:53 +0200
[Message part 1 (text/plain, inline)]
Does anyone has any opinion regarding this?  I think it is sensible
default in the year 2024.

Tomas
[signature.asc (application/pgp-signature, inline)]

Information forwarded to bug-guile <at> gnu.org:
bug#71262; Package guile. (Sat, 07 Sep 2024 15:59:01 GMT) Full text and rfc822 format available.

Message #11 received at 71262 <at> debbugs.gnu.org (full text, mbox):

From: "Dr. Arne Babenhauserheide" <arne_bab <at> web.de>
To: Tomas Volf <~@wolfsden.cz>
Cc: bug#71262 <71262 <at> debbugs.gnu.org>
Subject: Re: bug#71262: Status: [PATCH] Try to install C.UTF-8 locale before
 falling back to C.
Date: Sat, 07 Sep 2024 17:52:47 +0200
[Message part 1 (text/plain, inline)]
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
[signature.asc (application/pgp-signature, inline)]

Information forwarded to bug-guile <at> gnu.org:
bug#71262; Package guile. (Mon, 21 Oct 2024 21:13:01 GMT) Full text and rfc822 format available.

Message #14 received at 71262 <at> debbugs.gnu.org (full text, mbox):

From: Tomas Volf <~@wolfsden.cz>
To: "Dr. Arne Babenhauserheide" <arne_bab <at> web.de>
Cc: bug#71262 <71262 <at> debbugs.gnu.org>
Subject: Re: bug#71262: Status: [PATCH] Try to install C.UTF-8 locale before
 falling back to C.
Date: Mon, 21 Oct 2024 23:11:29 +0200
[Message part 1 (text/plain, inline)]
"Dr. Arne Babenhauserheide" <arne_bab <at> 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
[signature.asc (application/pgp-signature, inline)]

This bug report was last modified 236 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.