[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
localename: ensure multithread-safety in future changes
From: |
Bruno Haible |
Subject: |
localename: ensure multithread-safety in future changes |
Date: |
Wed, 18 Dec 2019 17:19:21 +0100 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-166-generic; KDE/5.18.0; x86_64; ; ) |
This patch makes sure we don't use MT-unsafe primitives in future
changes of module 'localename'.
- In function get_locale_t_name - currently not used on any platform,
because it's in a #if HAVE_NAMELESS_LOCALES - it's better to use the
MT-safe setlocale_null.
- In function gl_locale_name_posix, there is a call to
setlocale (category, NULL), but only on glibc systems, where it
happens to be MT-safe. I plan to extend this to many more systems, once
gettext bug <https://savannah.gnu.org/bugs/?38162> is fixed. At that
point, it will be necessary to use the MT-safe primitive.
Other than that, there is one call to setlocale (_, NULL) left. It is
MT-safe because this code is for native Windows only. Another issue,
however, is a possible circular dependency between localename.c and
setlocale.c. Better cut this circular dependency; setlocale.c is
meant to use localename.c, not the other way around.
2019-12-18 Bruno Haible <address@hidden>
localename: Ensure multithread-safety in future changes.
* lib/localename.c (setlocale): Reference the system's setlocale().
(get_locale_t_name): Invoke setlocale_null instead of setlocale.
(gl_locale_name_posix): Likewise.
* modules/localename (Depends-on): Add setlocale-null.
diff --git a/lib/localename.c b/lib/localename.c
index d88743e..65dddeb 100644
--- a/lib/localename.c
+++ b/lib/localename.c
@@ -1151,6 +1151,10 @@ extern char * getlocalename_l(int, locale_t);
# endif
#endif
+/* We want to use the system's setlocale() function here, not the gnulib
+ override. */
+#undef setlocale
+
#if HAVE_CFPREFERENCESCOPYAPPVALUE
/* Mac OS X 10.4 or newer */
@@ -2725,7 +2729,7 @@ get_locale_t_name (int category, locale_t locale)
if (locale == LC_GLOBAL_LOCALE)
{
/* Query the global locale. */
- const char *name = setlocale (category, NULL);
+ const char *name = setlocale_null (category);
if (name != NULL)
return struniq (name);
else
@@ -3241,7 +3245,10 @@ gl_locale_name_posix (int category, const char
*categoryname)
#if defined WINDOWS_NATIVE
if (LC_MIN <= category && category <= LC_MAX)
{
- const char *locname = setlocale (category, NULL);
+ const char *locname =
+ /* setlocale_null (category) is identical to setlocale (category, NULL)
+ on this platform. */
+ setlocale (category, NULL);
/* Convert locale name to LCID. We don't want to use
LocaleNameToLCID because (a) it is only available since Vista,
@@ -3258,7 +3265,7 @@ gl_locale_name_posix (int category, const char
*categoryname)
/* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
On some systems this can be done by the 'setlocale' function itself. */
#if defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL
- locname = setlocale (category, NULL);
+ locname = setlocale_null (category);
#else
/* On other systems we ignore what setlocale reports and instead look at
the
environment variables directly. This is necessary
diff --git a/modules/localename b/modules/localename
index 9eed220..c528acb 100644
--- a/modules/localename
+++ b/modules/localename
@@ -18,6 +18,7 @@ flexmember
strdup
lock
langinfo
+setlocale-null
configure.ac:
gl_LOCALENAME
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- localename: ensure multithread-safety in future changes,
Bruno Haible <=