From: Bruno Haible Date: Sat, 26 Dec 2009 13:37:23 +0000 (+0100) Subject: localename: Fix storage allocation of gl_locale_name_thread's result. X-Git-Tag: v0.18~78 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0349960bcfe436f2e851dd35833e59f16159d4ca;p=thirdparty%2Fgettext.git localename: Fix storage allocation of gl_locale_name_thread's result. --- diff --git a/gettext-runtime/intl/ChangeLog b/gettext-runtime/intl/ChangeLog index 9acf1d9b4..2841ec8bf 100644 --- a/gettext-runtime/intl/ChangeLog +++ b/gettext-runtime/intl/ChangeLog @@ -1,3 +1,14 @@ +2009-12-26 Bruno Haible + + 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 localename: Make aware of thread locale. diff --git a/gettext-runtime/intl/localename.c b/gettext-runtime/intl/localename.c index 4b77c95fa..03328b9ec 100644 --- a/gettext-runtime/intl/localename.c +++ b/gettext-runtime/intl/localename.c @@ -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'."