Bug#931139: perl: switching locales no longer invalidates gettext translation cache

Niko Tyni ntyni at debian.org
Thu Jul 4 18:04:52 BST 2019


On Thu, Jun 27, 2019 at 12:08:53AM +0300, Niko Tyni wrote:
> Package: perl
> Version: 5.28.1-6
> Severity: important
> 
> As discussed in #924657, glibc has a cache of already loaded translations
> that gets invalidated (by incrementing _nl_msg_cat_cntr) in setlocale(3),
> bindtextdomain(3) and textdomain(3) but not uselocale(3).
> 
> Starting with Perl 5.28, Perl uses POSIX 2008 thread-safe locales, so
> it calls uselocale(3) underneath when the Perl side POSIX::setlocale()
> function is invoked.
> 
> This makes gettext think that a translation for the new locale is already
> loaded when it really corresponds to the old locale.
> 
> While this is a 5.28 regression for Perl, it's not clear to me
> whether glibc is working correctly here or not.

Attached is a C test program demonstrating the behaviour.

When called without arguments, it uses uselocale(3) so the first
translation gets used for all the languages. This is the "buggy" behaviour.

When called with any arguments, it uses setlocale(3) and works as
intended, outputting the string in three different languages.

The issue is only visible when using the LANGUAGE environment variable
to select the translation. Setting LC_MESSAGES, LANG or LC_ALL hides
the issue. This is because LC_*/LANG affect the locale value that is
used to compute the cache hashing key inside glibc (in DCIGETTEXT(),
a.k.a. __dcigettext() ) while LANGUAGE doesn't.

  https://sources.debian.org/src/glibc/2.28-10/intl/dcigettext.c/#L543

As noted above, the primary difference between using setlocale(3)
and uselocale(3) here is that the former invalidates the cache while
the latter does not.

The difference between Perl 5.26 and 5.28 is that when calling
&POSIX::setlocale(), the former uses setlocale(3) while the latter
uses uselocale(3).
-- 
Niko Tyni   ntyni at debian.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 931139.c
Type: text/x-csrc
Size: 728 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/perl-maintainers/attachments/20190704/4a8c6220/attachment-0001.c>


More information about the Perl-maintainers mailing list