From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tomas Volf <~@wolfsden.cz> Newsgroups: gmane.lisp.guile.bugs Subject: bug#71262: [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> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19199"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Tomas Volf <~@wolfsden.cz> To: 71262@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Wed May 29 20:01:19 2024 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sCNbz-0004pO-9M for guile-bugs@m.gmane-mx.org; Wed, 29 May 2024 20:01:19 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCNbb-0002Us-Ho; Wed, 29 May 2024 14:00:55 -0400 Original-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 ) id 1sCNbZ-0002UI-MF for bug-guile@gnu.org; Wed, 29 May 2024 14:00:53 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCNbZ-0004sN-BD for bug-guile@gnu.org; Wed, 29 May 2024 14:00:53 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sCNbi-00025x-18 for bug-guile@gnu.org; Wed, 29 May 2024 14:01:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tomas Volf <~@wolfsden.cz> Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Wed, 29 May 2024 18:01:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 71262 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-guile@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.17170056377986 (code B ref -1); Wed, 29 May 2024 18:01:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 29 May 2024 18:00:37 +0000 Original-Received: from localhost ([127.0.0.1]:47050 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sCNbI-00024j-IL for submit@debbugs.gnu.org; Wed, 29 May 2024 14:00:37 -0400 Original-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@debbugs.gnu.org; Wed, 29 May 2024 14:00:36 -0400 Original-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@gnu.org; Wed, 29 May 2024 14:00:24 -0400 Original-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@gnu.org; Wed, 29 May 2024 14:00:23 -0400 Original-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= Original-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= X-Mailer: git-send-email 2.41.0 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.bugs:10842 Archived-At: 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 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