On Thu, Jul 04, 2019 at 09:06:33PM +0300, Niko Tyni wrote:
> On Thu, Jul 04, 2019 at 08:04:52PM +0300, Niko Tyni wrote:
> 
> > > 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.
> 
> This is now reported upstream as [perl #134264].
> 
> I'm attaching an updated test case in C, which just sets LANG at startup
> (as glibc won't look at LANGUAGE if the locale is totally unset / set to
> "C".)

Upstream Karl Williamson thinks this is a bug in glibc but Perl could
use a workaround.

I've filed #931456 on the glibc side and will look at filing it upstream
too.

As for working around it in Perl, the attached first version of a patch
works for me but will need some more work for proper upstreaming.
-- 
Niko
>From 2a410d595ef74bf36c0ea5d06a7afbf59e5d485f Mon Sep 17 00:00:00 2001
From: Niko Tyni <nt...@debian.org>
Date: Thu, 4 Jul 2019 23:57:59 +0300
Subject: Invalidate glibc translation cache when switching locales

Bug: https://rt.perl.org/Public/Bug/Display.html?id=134264
Bug-Debian: https://bugs.debian.org/931139
Patch-Name: fixes/gettext-caching.diff
---
 locale.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/locale.c b/locale.c
index aedd7da0c..183fd9bdf 100644
--- a/locale.c
+++ b/locale.c
@@ -54,6 +54,8 @@
 #  include <wchar.h>
 #endif
 
+#include <libintl.h>
+
 /* If the environment says to, we can output debugging information during
  * initialization.  This is done before option parsing, and before any thread
  * creation, so can be a file-level static */
@@ -1128,6 +1130,9 @@ S_emulate_setlocale(const int category,
 
 #  endif
 
+    /* Invalidate glibc cache of loaded translations, see [perl #134264] */
+    textdomain(textdomain(NULL));
+
     return locale;
 }
 

Reply via email to