]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
localename: Fix storage allocation of gl_locale_name_thread's result.
authorBruno Haible <bruno@clisp.org>
Sat, 26 Dec 2009 13:37:23 +0000 (14:37 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 26 Dec 2009 13:39:02 +0000 (14:39 +0100)
gettext-runtime/intl/ChangeLog
gettext-runtime/intl/localename.c

index 9acf1d9b4a6d6c5539d77f806881f7ad036b62f1..2841ec8bfe9d09bba44ff11226d6bb465be066f8 100644 (file)
@@ -1,3 +1,14 @@
+2009-12-26  Bruno Haible  <bruno@clisp.org>
+
+       localename: Fix storage allocation of gl_locale_name_thread's result.
+       * localename.c (SIZE_BITS, string_hash, struct hash_node,
+       HASH_TABLE_SIZE, struniq_hash_table, struniq_lock, struniq): Define on
+       all platforms that have 'uselocale'.
+       (gl_locale_name_thread_unsafe): New function, extracted from
+       gl_locale_name_thread.
+       (gl_locale_name_thread): Call struniq on all platforms that have
+       'uselocale'.
+
 2009-12-23  Bruno Haible  <bruno@clisp.org>
 
        localename: Make aware of thread locale.
index 4b77c95fae1e6f4473457357e49c4796a81cce2c..03328b9ec1675ee01b53bce5f5ce69e97f21b5c9 100644 (file)
@@ -2507,7 +2507,7 @@ gl_locale_name_from_win32_LCID (LCID lcid)
 #endif
 
 
-#if defined __APPLE__ && defined __MACH__ && HAVE_USELOCALE /* MacOS X */
+#if HAVE_USELOCALE /* glibc or MacOS X */
 
 /* Simple hash set of strings.  We don't want to drag in lots of hash table
    code here.  */
@@ -2592,8 +2592,13 @@ struniq (const char *string)
 #endif
 
 
+/* Like gl_locale_name_thread, except that the result is not in storage of
+   indefinite extent.  */
+#if !defined IN_LIBINTL
+static
+#endif
 const char *
-gl_locale_name_thread (int category, const char *categoryname)
+gl_locale_name_thread_unsafe (int category, const char *categoryname)
 {
 #if HAVE_USELOCALE
   {
@@ -2686,26 +2691,26 @@ gl_locale_name_thread (int category, const char *categoryname)
         switch (category)
           {
           case LC_CTYPE:
-            return struniq (tlp->__lc_ctype->__ctype_encoding);
+            return tlp->__lc_ctype->__ctype_encoding;
           case LC_NUMERIC:
             return tlp->_numeric_using_locale
-                   ? struniq (tlp->__lc_numeric->_numeric_locale_buf)
+                   ? tlp->__lc_numeric->_numeric_locale_buf
                    : "C";
           case LC_TIME:
             return tlp->_time_using_locale
-                   ? struniq (tlp->__lc_time->_time_locale_buf)
+                   ? tlp->__lc_time->_time_locale_buf
                    : "C";
           case LC_COLLATE:
             return !tlp->__collate_load_error
-                   ? struniq (tlp->__lc_collate->__encoding)
+                   ? tlp->__lc_collate->__encoding
                    : "C";
           case LC_MONETARY:
             return tlp->_monetary_using_locale
-                   ? struniq (tlp->__lc_monetary->_monetary_locale_buf)
+                   ? tlp->__lc_monetary->_monetary_locale_buf
                    : "C";
           case LC_MESSAGES:
             return tlp->_messages_using_locale
-                   ? struniq (tlp->__lc_messages->_messages_locale_buf)
+                   ? tlp->__lc_messages->_messages_locale_buf
                    : "C";
           default: /* We shouldn't get here.  */
             return "";
@@ -2717,6 +2722,17 @@ gl_locale_name_thread (int category, const char *categoryname)
   return NULL;
 }
 
+const char *
+gl_locale_name_thread (int category, const char *categoryname)
+{
+#if HAVE_USELOCALE
+  const char *name = gl_locale_name_thread_unsafe (category, categoryname);
+  if (name != NULL)
+    return struniq (name);
+#endif
+  return NULL;
+}
+
 /* XPG3 defines the result of 'setlocale (category, NULL)' as:
    "Directs 'setlocale()' to query 'category' and return the current
     setting of 'local'."