Daiki Ueno <[email protected]> writes: > See <https://savannah.gnu.org/bugs/?38162>.
> So, if dcigettext is called twice on a same string with different global > locale settings, the search hits and returns the translation for a > locale previously set with setlocale(). > it merely adds a guard: > > if (uselocale (NULL) != LC_GLOBAL_LOCALE) > > to the cache lookup. Sorry, this approach is probably wrong. The cache should be automatically invalidated when the global variable _nl_msg_cat_cntr is incremented. However, while setlocale in glibc code (glibc/intl/*) increments it, the replacement setlocale (libintl_setlocale) in gettext code (gettext-runtime/intl/*) doesn't. Although I'm still wondering how to properly handle this case, here is a patch to increment it in libintl_setlocale. Regards, -- Daiki Ueno
>From 13f6ecc3d680c943c16e9842a12d9716e7380c02 Mon Sep 17 00:00:00 2001 From: Daiki Ueno <[email protected]> Date: Thu, 7 Mar 2013 17:47:37 +0900 Subject: [PATCH] Increment _nl_msg_cat_cntr in libintl_setlocale. --- gettext-runtime/intl/ChangeLog | 7 +++++++ gettext-runtime/intl/setlocale.c | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/gettext-runtime/intl/ChangeLog b/gettext-runtime/intl/ChangeLog index 9eb4109..9d601cb 100644 --- a/gettext-runtime/intl/ChangeLog +++ b/gettext-runtime/intl/ChangeLog @@ -1,3 +1,10 @@ +2013-03-07 Daiki Ueno <[email protected]> + + * setlocale.c (libintl_setlocale): Increment _nl_msg_cat_cntr when + locale is set, to invalidate translation cache. + Reported by Guido Flohr at + <https://savannah.gnu.org/bugs/?38162>. + 2013-03-05 Daiki Ueno <[email protected]> * verify.h: Update copyright year. diff --git a/gettext-runtime/intl/setlocale.c b/gettext-runtime/intl/setlocale.c index b33bff5..1455d83 100644 --- a/gettext-runtime/intl/setlocale.c +++ b/gettext-runtime/intl/setlocale.c @@ -885,6 +885,7 @@ libintl_setlocale (int category, const char *locale) /* All steps were successful. */ free (saved_locale); + ++_nl_msg_cat_cntr; return setlocale (LC_ALL, NULL); fail: @@ -900,6 +901,7 @@ libintl_setlocale (int category, const char *locale) if (name == NULL) name = gl_locale_name_default (); + ++_nl_msg_cat_cntr; return setlocale_single (category, name); } } @@ -937,10 +939,13 @@ libintl_setlocale (int category, const char *locale) /* It was really successful. */ free (saved_locale); + ++_nl_msg_cat_cntr; return setlocale (LC_ALL, NULL); } else # endif + if (locale != NULL) + ++_nl_msg_cat_cntr; return setlocale_single (category, locale); } } -- 1.8.1.4
