Subject: bug#22905: GUILE_INSTALL_LOCALE produces unavoidable noise

From: Zefram <[email-masked]>
Date: Fri, 4 Mar 2016 14:13:34 +0000

GUILE_INSTALL_LOCALE=1 breaks some of the robustness of non-locale-using
programs, marring their stderr output if the environment's locale settings
are faulty.

Suppose you have a program written in Guile Scheme that doesn't use any
locale facilities.  To be portable to the GUILE_INSTALL_LOCALE=1 situation
(which the documentation threatens will become the default in Guile 2.2),
it must be prepared to start up with some locale already selected, and
reconfigure from there as required.  Being a conscientious programmer,
you are of course willing to add the (setlocale LC_ALL "C") and whatever
other invocations are required to recover the non-locale state.  But then
this situation arises:

$ LANG=wibble GUILE_INSTALL_LOCALE=1 guile-2.0 -c '(setlocale LC_ALL "C") (write "hi") (newline)'
guile: warning: failed to install locale
"hi"

The warning shown goes to the program's stderr.  It does not come from
the program's setlocale call, which is succeeding and would signal a
perfectly ordinary (catchable) exception if it failed.  The warning comes
from the implicit setlocale call triggered by GUILE_INSTALL_LOCALE=1,
before the program gains control.  As far as I can see, there is no way
for the program to prevent the failing setlocale attempt or to muffle
the warning.  Or even to detect that this has happened.

Guile should not be saying anything on the program's stderr.  This is
damaging the program's visible behaviour, and making it impossible to
effectively port non-locale programs to new Guile versions.

If Guile must attempt this implicit setlocale and continue to run the
program if it fails, then it needs to keep quiet about the failure.
This is no disadvantage to a program that actually wants to use the
environmental locale, because the program is free to call (setlocale
LC_ALL "") itself and handle its failure in whatever manner it finds
appropriate.  Indeed, any such program predating Guile 2.0 must already
be performing that call itself, because the implicit setlocale didn't
occur then.  The same for any program portable to pre-2.0 Guiles.  And on
Guile 2.0+ such a program still really needs to perform the call itself,
because it can't predict how GUILE_INSTALL_LOCALE will be set in the
environment, so still can't rely on the implicit setlocale happening.

However, if it is deemed to be essential that Guile attempt the implicit
setlocale and gripe about its failure, then the message should not
precede or otherwise mix with the actual program run.  The message should
be emitted *instead of* running the program, declaring the absolute
incompatibility of the Guile framework with this environmental condition.

-zefram