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

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: guile; Reported by: Tomas Volf <~@wolfsden.cz>; Keywords: patch; dated Wed, 29 May 2024 18:01:01 UTC; Maintainer for guile is bug-guile@HIDDEN.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 29 May 2024 18:00:37 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed May 29 14:00:37 2024
Received: from localhost ([127.0.0.1]:47050 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sCNbI-00024j-IL
	for submit <at> debbugs.gnu.org; Wed, 29 May 2024 14:00:37 -0400
Received: from lists.gnu.org ([209.51.188.17]:47002)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <~@wolfsden.cz>) id 1sCNbG-00024a-Kt
 for submit <at> debbugs.gnu.org; Wed, 29 May 2024 14:00:36 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <~@wolfsden.cz>) id 1sCNb5-0002LH-T9
 for bug-guile@HIDDEN; Wed, 29 May 2024 14:00:24 -0400
Received: from wolfsden.cz ([37.205.8.62])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <~@wolfsden.cz>) id 1sCNb1-0004od-3R
 for bug-guile@HIDDEN; Wed, 29 May 2024 14:00:23 -0400
Received: by wolfsden.cz (Postfix, from userid 104)
 id 7DF7024B1FD; Wed, 29 May 2024 18:00:14 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wolfsden.cz; s=mail;
 t=1717005614; bh=MY4rOHfy5vGA9W+KyX8LaSvl5kXssjpzZRI1i1EUaBw=;
 h=From:To:Cc:Subject:Date;
 b=WVHGMqBk2O0P7a0+e2DO01h8i6phxwqgrKOLkNufa5y2fGvaYvNFCkHNJQCJ6/wZE
 4JKGSGMnpdNzH2VCPTRH8F7UqJwmzqtJuKD1npOg16hO4XtCS/oTtoqD0Km5AS/FaZ
 wWt9z8V5rEbB/AqYgUQ+ImfCvviYnayuPmwjsGDAzZpQkwhiukxoun0PipR7VuBr9z
 3YZHoImp/H9lfevJ1Ml6A8G/8YSjZYMyTN6hMH1VA32wAEIsKlv8o908TxkuTPk/R9
 muNhLDsedOlE8GM8v2mwuDNU6IvfpPozmOgEd/NV3Xn6Mfqw7/0k4RxUzgEagBOpZ7
 cBsaDyyAMA7foBkrNwOIcU+bkfVFsg0bJD5pDMcbs9J/dbus7z5CeEwCtKN1M4A7lF
 48c2P+A2R3D5/XMAG/wZl+tagge08lmAX3guhNE4EhZX2SVIpGp8+xknBFhPSYbrHy
 7pt2ftJARF3rREt2oEk0lZKlnKNmo0mvHpayJ8WQNJD/XQWTtPVi4rTk5KOmxIpej4
 QHEV1fLE7tC7z1BsTnaoo+xYJUdwRFNM7E9YZCajl3G5B1D+H/T/DfcKWHVo+HZDAO
 dXfL6WTTzwCza0QyHn1fHBKWTdWTcq6PpJFiLL0QBFF9J1OuWqMfjx1ffRgv6gxKsj
 dgYfjxMln0zA2AEws41kMmco=
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on wolfsden
X-Spam-Level: 
X-Spam-Status: No, score=-1.2 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED,
 DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,T_SCC_BODY_TEXT_LINE,
 URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6
Received: from localhost (unknown [193.32.127.145])
 by wolfsden.cz (Postfix) with ESMTPSA id 8E35D24C3A2;
 Wed, 29 May 2024 18:00:13 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wolfsden.cz; s=mail;
 t=1717005613; bh=MY4rOHfy5vGA9W+KyX8LaSvl5kXssjpzZRI1i1EUaBw=;
 h=From:To:Cc:Subject:Date;
 b=BOrCFcvnHXFsYA4KNscDMEbC1KdfeM/8Lk6xEnK8dPWAvanLYSZ+2KfsH1Dy4Yggc
 QmHlGfOtQgN4D2T12XjPNLpIc5v9v6ij8NwOcV2ENt0IUxO08JiZh9eU03iMM9efcH
 zOEY4MoeWBA3Euy4sVUk/aPsWZew88ZAe2M7uQkxPjGYPwqVoLcdwhDYKBYqw3a0cM
 mN3i/iQAScxCQy2aCp9fbU4RB512LcKsPIy7NCnwu52KeiP9NyvKtgQaw03Fi/eeJw
 DXGIRUDwRIXAYVcJKygTuGZBIV9rmtg/lUZiL2WlMaBR/nK0+jBakgN1B5cPvtVfm9
 lwKq1+M1vZij8Nxq4nOwTp5Q2jXnOu95FWfXtJbteE3axTFp2C+DcZzwyoNO7onjiD
 e7nTw9cUaj2CHIHugqZmiXUtQUTEjZa9Jo6Dc5Sy4DB/U1pW5LlMoHi5Wo6gzj6n/d
 Y75JnuRVZm4yi0TYimwwk+5mHcul3scgvIUwYOhS3A2aZsNsSOiGcSZIdrgSxKPtVn
 nU4i69Zo/A9YUKDd1vQtaHrnu009qyZpuTFFH2QS9G6RxNBG3dFBLNjMFCq8/NPSUD
 bCxhz2KxhVbOu764B8LYWZWlnqdYWO1TOyLOZpdc0vnCi8Ldj3LZAXGcapS1XR+uiJ
 OpwVTRJ7+NnQn9706rnVq5BI=
From: Tomas Volf <~@wolfsden.cz>
To: bug-guile@HIDDEN
Subject: [PATCH] Try to install C.UTF-8 locale before falling back to C.
Date: Wed, 29 May 2024 20:00:03 +0200
Message-ID: <20240529180003.11398-1-~@wolfsden.cz>
X-Mailer: git-send-email 2.41.0
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Received-SPF: pass client-ip=37.205.8.62; envelope-from=~@wolfsden.cz;
 helo=wolfsden.cz
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001,
 SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.3 (-)
X-Debbugs-Envelope-To: submit
Cc: Tomas Volf <~@wolfsden.cz>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)

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





Acknowledgement sent to Tomas Volf <~@wolfsden.cz>:
New bug report received and forwarded. Copy sent to bug-guile@HIDDEN. Full text available.
Report forwarded to bug-guile@HIDDEN:
bug#71262; Package guile. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Wed, 29 May 2024 18:15:01 UTC

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