GNU bug report logs - #24186
setlocale can't be localised

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: Zefram <zefram@HIDDEN>; dated Mon, 8 Aug 2016 16:33:01 UTC; Maintainer for guile is bug-guile@HIDDEN.

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


Received: (at 24186) by debbugs.gnu.org; 11 Oct 2016 12:50:05 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Oct 11 08:50:05 2016
Received: from localhost ([127.0.0.1]:51832 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1btwVR-0000uV-3G
	for submit <at> debbugs.gnu.org; Tue, 11 Oct 2016 08:50:05 -0400
Received: from river.fysh.org ([87.98.248.19]:60396 ident=Debian-exim)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <zefram@HIDDEN>) id 1btwVP-0000uJ-2s
 for 24186 <at> debbugs.gnu.org; Tue, 11 Oct 2016 08:50:03 -0400
Received: from zefram by river.fysh.org with local (Exim 4.84_2 #1 (Debian))
 id 1btwVL-00077x-DD; Tue, 11 Oct 2016 13:49:59 +0100
Date: Tue, 11 Oct 2016 13:49:59 +0100
From: Zefram <zefram@HIDDEN>
To: Ludovic Courtes <ludo@HIDDEN>
Subject: Re: bug#24186: setlocale can't be localised
Message-ID: <20161011124959.GI533@HIDDEN>
References: <20160808163214.GF24721@HIDDEN> <87invbm25x.fsf@HIDDEN>
 <20160808223037.GI24721@HIDDEN> <87h98j1f9k.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <87h98j1f9k.fsf@HIDDEN>
X-Spam-Score: -0.3 (/)
X-Debbugs-Envelope-To: 24186
Cc: Andy Wingo <wingo@HIDDEN>, 24186 <at> debbugs.gnu.org
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: -0.3 (/)

Ludovic Courtes wrote:
>That wouldn't help with the "setlocale" issue you describe per se, but
>this would address such use cases in a different way.
>
>WDYT?

Yes, explicit locale objects and locale parameters to relevant functions
are a good thing.  In general, the model of a global locale state is
broken, at least by threading, so some advance beyond the setlocale system
is necessary.  Note the new(er) "uselocale" system in libc, which gives
a per-thread locale state, fixing the biggest problem with setlocale.
Some form of that could also be mapped into Guile; it would be reasonable
to have a fluid that determines the locale to use where not overridden
by an explicit parameter.

All of that is welcome, but, as you say, doesn't deal with the actual
problem I identified with setlocale.  One can expect that setlocale will
continue to be used for the foreseeable future, and it needs to be shorn
of its unwanted side effects.

-zefram




Information forwarded to bug-guile@HIDDEN:
bug#24186; Package guile. Full text available.

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


Received: (at 24186) by debbugs.gnu.org; 11 Oct 2016 08:06:37 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Oct 11 04:06:37 2016
Received: from localhost ([127.0.0.1]:51682 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1bts53-0004CJ-MK
	for submit <at> debbugs.gnu.org; Tue, 11 Oct 2016 04:06:37 -0400
Received: from eggs.gnu.org ([208.118.235.92]:48683)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <ludo@HIDDEN>) id 1bts4y-0004C1-S2
 for 24186 <at> debbugs.gnu.org; Tue, 11 Oct 2016 04:06:32 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <ludo@HIDDEN>) id 1bts4p-00044z-3p
 for 24186 <at> debbugs.gnu.org; Tue, 11 Oct 2016 04:06:23 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_40,RP_MATCHES_RCVD
 autolearn=disabled version=3.3.2
Received: from fencepost.gnu.org ([2001:4830:134:3::e]:33492)
 by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <ludo@HIDDEN>)
 id 1bts4p-000445-1O; Tue, 11 Oct 2016 04:06:19 -0400
Received: from pluto.bordeaux.inria.fr ([193.50.110.57]:59570 helo=pluto)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <ludo@HIDDEN>)
 id 1bts4n-0001pv-Bw; Tue, 11 Oct 2016 04:06:17 -0400
From: ludo@HIDDEN (Ludovic =?utf-8?Q?Court=C3=A8s?=)
To: Zefram <zefram@HIDDEN>
Subject: Re: bug#24186: setlocale can't be localised
References: <20160808163214.GF24721@HIDDEN> <87invbm25x.fsf@HIDDEN>
 <20160808223037.GI24721@HIDDEN>
Date: Tue, 11 Oct 2016 10:06:15 +0200
In-Reply-To: <20160808223037.GI24721@HIDDEN> (zefram@HIDDEN's message of
 "Mon, 8 Aug 2016 23:30:37 +0100")
Message-ID: <87h98j1f9k.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 2001:4830:134:3::e
X-Spam-Score: -5.3 (-----)
X-Debbugs-Envelope-To: 24186
Cc: Andy Wingo <wingo@HIDDEN>, 24186 <at> debbugs.gnu.org
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: -5.3 (-----)

Hi,

Zefram <zefram@HIDDEN> skribis:

>     (define (call-with-locale cat val body)
>       (let ((oldval #f))
> 	(dynamic-wind
> 	  (lambda () (set! oldval (setlocale cat)) (setlocale cat val))
> 	  body (lambda () (setlocale cat oldval)))))
>
>     (define (day-of-week-string)
>       (strftime "%A" (localtime (current-time))))=20
>
>     (define (day-of-week-string-for-locale loc)
>       (call-with-locale LC_TIME loc day-of-week-string))
>
>     ;; user-locale is application-specific code defined elsewhere
>     (define (day-of-week-string-for-user user)
>       (day-of-week-string-for-locale (user-locale user)))

This does not really answer your question, but (ice-9 i18n) provides
first-class locale objects, which avoid the whole global locale issue
(info "(guile) Internationalization").

Currently important procedures such as =E2=80=98strftime=E2=80=99 or SRFI-1=
9=E2=80=99s
=E2=80=98date->string=E2=80=99 cannot use such locale objects, though.  I t=
hink it would
make sense to add an optional locale object argument to =E2=80=98srftime=E2=
=80=99 and
=E2=80=98date->string=E2=80=99 (though we should create a (srfi srfi-19 gnu=
) module for
that to make it clear that this is a GNU extension.)

That wouldn=E2=80=99t help with the =E2=80=98setlocale=E2=80=99 issue you d=
escribe per se, but
this would address such use cases in a different way.

WDYT?

Ludo=E2=80=99.




Information forwarded to bug-guile@HIDDEN:
bug#24186; Package guile. Full text available.

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


Received: (at 24186) by debbugs.gnu.org; 9 Aug 2016 17:44:10 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Aug 09 13:44:10 2016
Received: from localhost ([127.0.0.1]:33357 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1bXB4T-0004jT-R8
	for submit <at> debbugs.gnu.org; Tue, 09 Aug 2016 13:44:09 -0400
Received: from pb-sasl2.pobox.com ([64.147.108.67]:51264
 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <wingo@HIDDEN>) id 1bXB4R-0004jL-RM
 for 24186 <at> debbugs.gnu.org; Tue, 09 Aug 2016 13:44:08 -0400
Received: from sasl.smtp.pobox.com (unknown [127.0.0.1])
 by pb-sasl2.pobox.com (Postfix) with ESMTP id 8936C2E9EE;
 Tue,  9 Aug 2016 13:44:06 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc
 :subject:references:date:in-reply-to:message-id:mime-version
 :content-type; s=sasl; bh=42qdpA8FR5MRQlDVvL72gyOiL4w=; b=rcpfBH
 eKs/q1eX8tcQbc+sLCyxhJAZFpAdOINpbD2GMSluiqp2euLxR9yPPTgJsxELw3/2
 QANLOBvLDfiUBoegPAfZm6TcJu/Af81UbqN19rrDGmjGpPdz72ERKFzWOvI9Fn+h
 gdPFbcXgkIv0Pag3G6UET73s9rkmSCBRQxI5k=
DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc
 :subject:references:date:in-reply-to:message-id:mime-version
 :content-type; q=dns; s=sasl; b=vbEEAwUys3xyJc72dnxaNjuDLWkkL1Gy
 yvB2UozH5M5I4+ZETCrsRk8Y8wB2ZQF3Yd4E6enxZxL8MvkmNFMSpa97OJfQkOqB
 ckHQ8tqd3GIYJ4EAGh3NGNZy+Z7a2M63rez0ZpXO7qJvCxmPCp3Pj1I6qfAX7wqR
 pssMxY0j7rA=
Received: from pb-sasl2.nyi.icgroup.com (unknown [127.0.0.1])
 by pb-sasl2.pobox.com (Postfix) with ESMTP id 81AB22E9ED;
 Tue,  9 Aug 2016 13:44:06 -0400 (EDT)
Received: from clucks (unknown [88.160.190.192])
 (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by pb-sasl2.pobox.com (Postfix) with ESMTPSA id 98DA52E9EC;
 Tue,  9 Aug 2016 13:44:05 -0400 (EDT)
From: Andy Wingo <wingo@HIDDEN>
To: Zefram <zefram@HIDDEN>
Subject: Re: bug#24186: setlocale can't be localised
References: <20160808163214.GF24721@HIDDEN> <87invbm25x.fsf@HIDDEN>
 <20160808223037.GI24721@HIDDEN> <20160809121535.GA13115@HIDDEN>
Date: Tue, 09 Aug 2016 19:43:58 +0200
In-Reply-To: <20160809121535.GA13115@HIDDEN> (zefram@HIDDEN's message of
 "Tue, 9 Aug 2016 13:15:35 +0100")
Message-ID: <87vaz9ltwh.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Pobox-Relay-ID: DE2F7196-5E58-11E6-B2A7-28A6F1301B6D-02397024!pb-sasl2.pobox.com
X-Spam-Score: -0.4 (/)
X-Debbugs-Envelope-To: 24186
Cc: 24186 <at> debbugs.gnu.org
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: -0.4 (/)

On Tue 09 Aug 2016 14:15, Zefram <zefram@HIDDEN> writes:

> I wrote:
>>is my first time compiling a Guile myself.  It's failing on a missing
>>library for which Debian supplies no package.
>
> Turns out there was a package.  It was complaining about a lack of
> "bdw-gc", and Debian doesn't have anything of that name, but it does
> have it under the name "libgc".  So I've now got 2.1.3 running.
>
> All of the code in my day-of-week-string-for-locale sketch works exactly
> the same on 2.1.3 as it did on 2.0.

Tx for this testing and thanks again for these excellent bug reports :)

Andy




Information forwarded to bug-guile@HIDDEN:
bug#24186; Package guile. Full text available.

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


Received: (at 24186) by debbugs.gnu.org; 9 Aug 2016 12:15:42 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Aug 09 08:15:42 2016
Received: from localhost ([127.0.0.1]:60783 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1bX5wb-0000Wq-S0
	for submit <at> debbugs.gnu.org; Tue, 09 Aug 2016 08:15:41 -0400
Received: from river.fysh.org ([87.98.248.19]:60010 ident=Debian-exim)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <zefram@HIDDEN>) id 1bX5wZ-0000Wg-Hr
 for 24186 <at> debbugs.gnu.org; Tue, 09 Aug 2016 08:15:40 -0400
Received: from zefram by river.fysh.org with local (Exim 4.84_2 #1 (Debian))
 id 1bX5wV-0003jM-LF; Tue, 09 Aug 2016 13:15:35 +0100
Date: Tue, 9 Aug 2016 13:15:35 +0100
From: Zefram <zefram@HIDDEN>
To: Andy Wingo <wingo@HIDDEN>
Subject: Re: bug#24186: setlocale can't be localised
Message-ID: <20160809121535.GA13115@HIDDEN>
References: <20160808163214.GF24721@HIDDEN> <87invbm25x.fsf@HIDDEN>
 <20160808223037.GI24721@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20160808223037.GI24721@HIDDEN>
X-Spam-Score: -0.4 (/)
X-Debbugs-Envelope-To: 24186
Cc: 24186 <at> debbugs.gnu.org
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: -0.4 (/)

I wrote:
>is my first time compiling a Guile myself.  It's failing on a missing
>library for which Debian supplies no package.

Turns out there was a package.  It was complaining about a lack of
"bdw-gc", and Debian doesn't have anything of that name, but it does
have it under the name "libgc".  So I've now got 2.1.3 running.

All of the code in my day-of-week-string-for-locale sketch works exactly
the same on 2.1.3 as it did on 2.0.

-zefram




Information forwarded to bug-guile@HIDDEN:
bug#24186; Package guile. Full text available.

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


Received: (at 24186) by debbugs.gnu.org; 8 Aug 2016 22:30:43 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Aug 08 18:30:43 2016
Received: from localhost ([127.0.0.1]:60423 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1bWt4F-00007n-At
	for submit <at> debbugs.gnu.org; Mon, 08 Aug 2016 18:30:43 -0400
Received: from river.fysh.org ([87.98.248.19]:50518 ident=Debian-exim)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <zefram@HIDDEN>) id 1bWt4D-00007e-Nx
 for 24186 <at> debbugs.gnu.org; Mon, 08 Aug 2016 18:30:42 -0400
Received: from zefram by river.fysh.org with local (Exim 4.84_2 #1 (Debian))
 id 1bWt49-0003QY-H2; Mon, 08 Aug 2016 23:30:37 +0100
Date: Mon, 8 Aug 2016 23:30:37 +0100
From: Zefram <zefram@HIDDEN>
To: Andy Wingo <wingo@HIDDEN>
Subject: Re: bug#24186: setlocale can't be localised
Message-ID: <20160808223037.GI24721@HIDDEN>
References: <20160808163214.GF24721@HIDDEN>
 <87invbm25x.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <87invbm25x.fsf@HIDDEN>
X-Spam-Score: -0.5 (/)
X-Debbugs-Envelope-To: 24186
Cc: 24186 <at> debbugs.gnu.org
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: -0.5 (/)

Andy Wingo wrote:
>Firstly, just to make sure that we are getting things right in 2.2 (and
>if not we need to know), would you mind testing with the latest 2.1.x
>release?

Inspection of the 2.1.3 code shows that, like 2.0, it sets the default
port encoding fluid and the encoding of the three currently-selected
ports, as a side effect of every setlocale call (both read and write).

I'm afraid I'm having difficulty compiling it.  I mostly install software
via the Debian packages, which is how I have used 1.8 and 2.0, so this
is my first time compiling a Guile myself.  It's failing on a missing
library for which Debian supplies no package.  I may sort this out later,
but right now I can't run 2.1.3.

>Also, do you have a concrete program whose behavior you expect to be
>different?

Anything I show you would be quite artificial.  Let's have a go at
getting closer to a real program.

A likely use of a temporary locale change is to format a numeric or
time string through a function that uses the currently-selected locale.
A temporary locale change would be required if the program needs to
format it in someone else's locale, or needs this string to be in a
predictable form for a particular file format regardless of user locale.
For example, strftime is such a function, and a web service might need
to format a time string for the user who made a particular request.
We can have users all over the world, so we identify each user's locale,
while the program as a whole uses either the "C" locale or the locale
of whoever is hosting the service.

    (define (call-with-locale cat val body)
      (let ((oldval #f))
	(dynamic-wind
	  (lambda () (set! oldval (setlocale cat)) (setlocale cat val))
	  body (lambda () (setlocale cat oldval)))))

    (define (day-of-week-string)
      (strftime "%A" (localtime (current-time)))) 

    (define (day-of-week-string-for-locale loc)
      (call-with-locale LC_TIME loc day-of-week-string))

    ;; user-locale is application-specific code defined elsewhere
    (define (day-of-week-string-for-user user)
      (day-of-week-string-for-locale (user-locale user)))

This much of the usage works fine:

scheme@(guile-user)> (day-of-week-string)
$1 = "Monday"
scheme@(guile-user)> (day-of-week-string-for-locale "de_DE")
$2 = "Montag"
scheme@(guile-user)> (day-of-week-string)
$3 = "Monday"

Observe that calling day-of-week-string-for-locale doesn't change the
prevailing locale of the program.  Thus the subsequent day-of-week-string
call uses the same locale that the first one did.  The above works
identically on Guile 1.8 and 2.0.

But things are different when we look at port encoding.  (Obviously now
we're on 2.0-specific code.)  Suppose that we have a currently-selected
input that is encoded in UTF-8.  Suppose further that this choice of
encoding is specific to this part of the application, not reflecting any
locale choice, and the program generally runs in the default "C" locale.
Now we get:

scheme@(guile-user)> (set-port-encoding! (current-input-port) "UTF-8")
scheme@(guile-user)> (day-of-week-string)
$5 = "Monday"
scheme@(guile-user)> (port-encoding (current-input-port))
$6 = "UTF-8"
scheme@(guile-user)> (day-of-week-string-for-locale "de_DE")
$7 = "Montag"
scheme@(guile-user)> (port-encoding (current-input-port))
$8 = "ANSI_X3.4-1968"

The locale-restoring part of call-with-locale, called via
day-of-week-string-for-locale, now has the side effect of setting the
input's encoding to the nominal encoding of the "C" locale, namely ASCII.
If not worked around, input processing breaks.

Is that sketch close enough to a concrete example?

>I believe that the intention (for better or for worse) is that calling
>`setlocale' with 2 arguments changes the "default port encoding".

(Aside:) *any* two-argument call, even if not relevant to encoding?
The encoding thing is only derived from LC_CTYPE, so even if one is
expecting something like this it's a bit surprising for an LC_TIME call
to affect encoding.

>the next port you open will have the encoding specified by the
>`setlocale', if you don't change it explicitly later.

To achieve the effect you've stated there, there is potentially a better
way.  You have quite sensibly described the effect at a higher user-story
kind of level, rather than say exactly what happens to the fluid.
You've put the fluid there, and documented it, as a perfectly sensible
way for the user to control the default port encoding.  As things stand,
the setlocale side effect is interfering with that control.

Suppose that instead the default port encoding fluid can take a special
value #:locale-at-open, which has the effect that when a port is opened
it will get its encoding set from the current locale.  You then have
the fluid default to that value, and have setlocale not touch the fluid
at all.  This way, if the user doesn't touch the fluid but does call
setlocale then the locale controls the encoding of new ports.  But if
the user does set the fluid (to something other than #:locale-at-open),
indicating a desire to specifically control default port encoding, then
setlocale doesn't clobber the user's choice.  How does this sound to you?

>                                                       But I don't think
>it should change the encoding of already-open ports, should it?

In a situation where setlocale is expected to deliberately side-effect
the default port encoding fluid, I can't figure out whether to expect it
to do more.  I suppose on general principle it's less surprising for it
to do less.  It's certainly less work to work around it, where the side
effects are unwanted.

If you go with the #:locale-at-open plan that I described above, then
setlocale should definitely not touch the encoding of already-open ports.
Just so that it is localisable as originally designed.

There's another way to get the best of both worlds.  In addition to the
#:locale-at-open value for the default port encoding fluid, there could
also be some special encoding value for a port, #:locale-at-io, meaning
to use whatever locale is in effect at the time of an I/O operation.
#:locale-at-io is also a valid value for the fluid, which will be copied
into a new port in the regular way.  The stdin, stdout, and stderr ports
that are automatically opened at program initialisation can be set to
#:locale-at-io, and setlocale now doesn't directly set the encoding of
any port.  If the user calls setlocale without otherwise controlling port
encoding then the locale controls the encoding of the primordial ports.
I expect that's the effect that the setlocale code was aiming for,
given that when setlocale is called it's too late to affect the opening
of the primordial ports.

-zefram




Information forwarded to bug-guile@HIDDEN:
bug#24186; Package guile. Full text available.

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


Received: (at 24186) by debbugs.gnu.org; 8 Aug 2016 20:33:28 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Aug 08 16:33:28 2016
Received: from localhost ([127.0.0.1]:60381 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1bWrEm-0005m9-8p
	for submit <at> debbugs.gnu.org; Mon, 08 Aug 2016 16:33:28 -0400
Received: from pb-sasl1.pobox.com ([64.147.108.66]:61329
 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <wingo@HIDDEN>) id 1bWrEk-0005m1-Lb
 for 24186 <at> debbugs.gnu.org; Mon, 08 Aug 2016 16:33:27 -0400
Received: from sasl.smtp.pobox.com (unknown [127.0.0.1])
 by pb-sasl1.pobox.com (Postfix) with ESMTP id 3D2222FD27;
 Mon,  8 Aug 2016 16:33:23 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc
 :subject:references:date:in-reply-to:message-id:mime-version
 :content-type; s=sasl; bh=9eKliXpqHtKIsPQ6MMUKDf2Pyok=; b=ybtdWH
 mddmDVGjXMDEoB0rM7s/mllnNnbRNxcGKXaPpR+D7WYrdJMhklUyLSEoAjEIg9Ey
 80GZoMIkQ/vVcBoDFDIySy8ELsTgPThztjFhXyn7fQkO9NWNYtBJvE1ZlX+tL9hj
 Qzxsf62Ys3JumBeU3ySNtP42A0U55lVjPuPHA=
DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc
 :subject:references:date:in-reply-to:message-id:mime-version
 :content-type; q=dns; s=sasl; b=oP71EM9gdirbI+az46L0PE79G7kOTu9f
 WQCWkzo8Q3MZEKgzFeXCl//P9bz/6gEfku81HOK0knAuLXwb2H3J/tLCT6RW5pg2
 t/9kt7mf03zer+lr5ok5HLLPF4Fv7yz+xhg6f+e2JGwxSDjdc1oY+/FdTbTFwZpk
 GIFITIePAr0=
Received: from pb-sasl1.nyi.icgroup.com (unknown [127.0.0.1])
 by pb-sasl1.pobox.com (Postfix) with ESMTP id 2C86A2FD26;
 Mon,  8 Aug 2016 16:33:23 -0400 (EDT)
Received: from clucks (unknown [88.160.190.192])
 (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by pb-sasl1.pobox.com (Postfix) with ESMTPSA id 1CD992FD25;
 Mon,  8 Aug 2016 16:33:21 -0400 (EDT)
From: Andy Wingo <wingo@HIDDEN>
To: Zefram <zefram@HIDDEN>
Subject: Re: bug#24186: setlocale can't be localised
References: <20160808163214.GF24721@HIDDEN>
Date: Mon, 08 Aug 2016 22:33:14 +0200
In-Reply-To: <20160808163214.GF24721@HIDDEN> (zefram@HIDDEN's message of
 "Mon, 8 Aug 2016 17:32:14 +0100")
Message-ID: <87invbm25x.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Pobox-Relay-ID: 598E61EC-5DA7-11E6-82B3-C1836462E9F6-02397024!pb-sasl1.pobox.com
X-Spam-Score: -0.4 (/)
X-Debbugs-Envelope-To: 24186
Cc: 24186 <at> debbugs.gnu.org
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: -0.4 (/)

Greets :)

Firstly, just to make sure that we are getting things right in 2.2 (and
if not we need to know), would you mind testing with the latest 2.1.x
release?

Also, do you have a concrete program whose behavior you expect to be
different?  I appreciate the call-with-locale example but I'm not sure
what is going wrong so having an example invocation would be useful.

On Mon 08 Aug 2016 18:32, Zefram <zefram@HIDDEN> writes:

> The setlocale *write* operation also affects port encoding (actually
> the default port encoding fluid and the encoding of currently-selected
> ports), and that seems to be an intentional change, but it also breaks
> the above code.

I believe that the intention (for better or for worse) is that calling
`setlocale' with 2 arguments changes the "default port encoding".  Like,
the next port you open will have the encoding specified by the
`setlocale', if you don't change it explicitly later.  But I don't think
it should change the encoding of already-open ports, should it?

Andy




Information forwarded to bug-guile@HIDDEN:
bug#24186; Package guile. Full text available.

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


Received: (at submit) by debbugs.gnu.org; 8 Aug 2016 16:32:39 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Aug 08 12:32:39 2016
Received: from localhost ([127.0.0.1]:60262 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1bWnTj-0000BA-Bu
	for submit <at> debbugs.gnu.org; Mon, 08 Aug 2016 12:32:39 -0400
Received: from eggs.gnu.org ([208.118.235.92]:43897)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <zefram@HIDDEN>) id 1bWnTh-0000Ay-IA
 for submit <at> debbugs.gnu.org; Mon, 08 Aug 2016 12:32:37 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <zefram@HIDDEN>) id 1bWnTb-00080n-4S
 for submit <at> debbugs.gnu.org; Mon, 08 Aug 2016 12:32:32 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled
 version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:40577)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <zefram@HIDDEN>) id 1bWnTb-00080O-1h
 for submit <at> debbugs.gnu.org; Mon, 08 Aug 2016 12:32:31 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:34840)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <zefram@HIDDEN>) id 1bWnTY-0001fc-KR
 for bug-guile@HIDDEN; Mon, 08 Aug 2016 12:32:29 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <zefram@HIDDEN>) id 1bWnTS-0007yt-JX
 for bug-guile@HIDDEN; Mon, 08 Aug 2016 12:32:27 -0400
Received: from river.fysh.org ([87.98.248.19]:48290)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <zefram@HIDDEN>) id 1bWnTS-0007xa-De
 for bug-guile@HIDDEN; Mon, 08 Aug 2016 12:32:22 -0400
Received: from zefram by river.fysh.org with local (Exim 4.84_2 #1 (Debian))
 id 1bWnTK-0007yZ-Ld; Mon, 08 Aug 2016 17:32:14 +0100
Date: Mon, 8 Aug 2016 17:32:14 +0100
From: Zefram <zefram@HIDDEN>
To: bug-guile@HIDDEN
Subject: setlocale can't be localised
Message-ID: <20160808163214.GF24721@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -5.0 (-----)
X-Debbugs-Envelope-To: submit
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: -5.0 (-----)

In Guile 1.8 it was possible to localise the effect of a setlocale
operation, but in Guile 2.0 it's no longer possible by natural use of the
locale API.  This loss of a useful facility is either a bug or something
that needs to be discussed in the documentation.

In Guile 1.8 one could perform a temporary setlocale for the execution of
some piece of code, and revert its effect by another setlocale on unwind.
This looks like:

    (define (call-with-locale cat newval body)
      (let ((oldval #f))
	(dynamic-wind
	  (lambda () (set! oldval (setlocale cat)) (setlocale cat newval))
	  body (lambda () (setlocale cat oldval)))))

Some difficulty arises from this being temporally scoped, where dynamic
or lexical scoping would be nicer, but in single-threaded programs it
works pretty well.  The C setlocale(3) API, after which Guile's setlocale
is modelled, is obviously designed to enable this kind of mechanism: the
read operation reports all relevant state, and the write operation with
the old value sets it all back as it was.  It is critical to this ability
that the read operation does indeed report all the state that will be set.

In Guile 2.0, the setlocale function no longer corresponds so closely to
the C setlocale(3), and this critical guarantee has been lost.  I have
previously reported in bug#22910 that the setlocale read operation
has a side effect on port encoding, and obviously that interferes with
the above code, but actually there's still a problem if that's fixed.
The setlocale *write* operation also affects port encoding (actually
the default port encoding fluid and the encoding of currently-selected
ports), and that seems to be an intentional change, but it also breaks
the above code.  The setlocale read operation doesn't report the encoding
of the currently-selected ports, so doesn't represent everything that
setlocale will set.  The setlocale write operation is not even capable
of setting the port encodings independently: it sets all three to the
encoding nominated by the locale selected for LC_CTYPE purposes.

I think adding this extra effect to setlocale was a mistake.  It doesn't
fit the locale API.  If the extra effect is removed, that would resolve
this problem.

If you really want setlocale to have this effect, then something needs to
be done to address the ability that has been lost.  The documentation
certainly needs to describe the effect on port encoding, which it
currently doesn't.  (There is a mention of some interaction with the
%default-port-encoding fluid in the documentation of that fluid, but it
doesn't match reality: it doesn't say that setlocale writes to the fluid.)
It also ought to specifically warn that the setlocale save-and-restore
dance that works in C doesn't work here.  It should explain what needs
to be done by library functions that want to achieve a localised locale
change.  Are they entirely forbidden to use setlocale?  Are they expected
to manually save and restore port encodings around setlocale calls?
(This is complicated by set-port-encoding! not accepting #f as an encoding
value, despite it actually being a permitted value for the encoding slot.)
Some example code equivalent to the above call-with-locale would be
useful.

-zefram




Acknowledgement sent to Zefram <zefram@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-guile@HIDDEN. Full text available.
Report forwarded to bug-guile@HIDDEN:
bug#24186; 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: Mon, 25 Nov 2019 12:00:02 UTC

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