unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#22910: read-only setlocale has side effect
@ 2016-03-04 16:48 Zefram
  2016-03-04 19:55 ` Zefram
  2016-08-07 21:58 ` Andy Wingo
  0 siblings, 2 replies; 3+ messages in thread
From: Zefram @ 2016-03-04 16:48 UTC (permalink / raw)
  To: 22910

A call to setlocale with no second argument is documented to be
a read-only operation, querying the current locale configuration.
In fact it has a side effect of setting the encoding on primordial ports:

$ guile-2.0 -c '(write (port-encoding (current-input-port))) (newline) (setlocale LC_TIME) (write (port-encoding (current-input-port))) (newline)'
#f
"ANSI_X3.4-1968"

Observe that this occurs even if the locale reading operation is for a
category unrelated to character encoding.  The actual decoding behaviour
of read-char is altered in accordance with the reported encoding.
Non-primordial ports opened before or after the setlocale call are
not affected.

-zefram





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#22910: read-only setlocale has side effect
  2016-03-04 16:48 bug#22910: read-only setlocale has side effect Zefram
@ 2016-03-04 19:55 ` Zefram
  2016-08-07 21:58 ` Andy Wingo
  1 sibling, 0 replies; 3+ messages in thread
From: Zefram @ 2016-03-04 19:55 UTC (permalink / raw)
  To: 22910

Additional information: setlocale's side effect on primordial ports
happens even if the port's encoding has been individually set using
set-port-encoding!.  This means that to maintain a specific encoding on
these ports (other than the locale's nominal encoding, which is likely to
not be binary compatible) it is necessary to set the encoding repeatedly,
before any I/O operation after setlocale might have been called.
Since the read-only mode of setlocale has this effect, and arbitrary
library code might feel entitled to call setlocale for read purposes
without documenting that it does so, this really amounts to setting the
encoding before every I/O operation.

-zefram





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#22910: read-only setlocale has side effect
  2016-03-04 16:48 bug#22910: read-only setlocale has side effect Zefram
  2016-03-04 19:55 ` Zefram
@ 2016-08-07 21:58 ` Andy Wingo
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Wingo @ 2016-08-07 21:58 UTC (permalink / raw)
  To: Zefram; +Cc: 22910

On Fri 04 Mar 2016 17:48, Zefram <zefram@fysh.org> writes:

> A call to setlocale with no second argument is documented to be
> a read-only operation, querying the current locale configuration.
> In fact it has a side effect of setting the encoding on primordial ports:

This sounds like a bug indeed :/

Andy





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-08-07 21:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-04 16:48 bug#22910: read-only setlocale has side effect Zefram
2016-03-04 19:55 ` Zefram
2016-08-07 21:58 ` Andy Wingo

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).