From: Jonathan Wakely Date: Wed, 18 Mar 2015 16:17:47 +0000 (+0000) Subject: re PR libstdc++/13631 (Problems in messages) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2a9611d03b038040da9ed0f38ea25898cefdc98a;p=gcc.git re PR libstdc++/13631 (Problems in messages) PR libstdc++/13631 * config/locale/gnu/messages_members.cc (get_glibc_msg): Fix fallback implementation for old glibc. Fix whitespace. From-SVN: r221494 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index ae6445e3b86..534927fc92a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2015-03-18 Jonathan Wakely + + PR libstdc++/13631 + * config/locale/gnu/messages_members.cc (get_glibc_msg): Fix fallback + implementation for old glibc. Fix whitespace. + 2015-03-18 Jonathan Wakely Torvald Riegel diff --git a/libstdc++-v3/config/locale/gnu/messages_members.cc b/libstdc++-v3/config/locale/gnu/messages_members.cc index f115d5fe6f6..2e6122d2ea5 100644 --- a/libstdc++-v3/config/locale/gnu/messages_members.cc +++ b/libstdc++-v3/config/locale/gnu/messages_members.cc @@ -34,6 +34,8 @@ #include #include #include +#include // std::free +#include // ::strdup #include #include @@ -139,28 +141,28 @@ namespace } const char* - get_glibc_msg(__c_locale __attribute__((unused)) __locale_messages, + get_glibc_msg(__c_locale __locale_messages __attribute__((unused)), + const char* __name_messages __attribute__((unused)), const char* __domainname, const char* __dfault) { #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) std::__c_locale __old = __uselocale(__locale_messages); - const char* __msg = - const_cast(dgettext(__domainname, __dfault)); - __uselocale(__old); -#else - char* __old = setlocale(LC_ALL, 0); - const size_t __len = strlen(__old) + 1; - char* __sav = new char[__len]; - memcpy(__sav, __old, __len); - setlocale(LC_ALL, _M_name_messages); const char* __msg = dgettext(__domainname, __dfault); - setlocale(LC_ALL, __sav); - delete [] __sav; -#endif - + __uselocale(__old); return __msg; - } +#else + if (char* __sav = strdup(setlocale(LC_ALL, 0))) + { + setlocale(LC_ALL, __name_messages); + const char* __msg = dgettext(__domainname, __dfault); + setlocale(LC_ALL, __sav); + free(__sav); + return __msg; + } + return __dfault; +#endif + } } namespace std _GLIBCXX_VISIBILITY(default) @@ -172,14 +174,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typename messages::catalog messages::do_open(const basic_string& __s, const locale& __l) const - { - typedef codecvt __codecvt_t; - const __codecvt_t& __codecvt = use_facet<__codecvt_t>(__l); + { + typedef codecvt __codecvt_t; + const __codecvt_t& __codecvt = use_facet<__codecvt_t>(__l); - bind_textdomain_codeset(__s.c_str(), - __nl_langinfo_l(CODESET, __codecvt._M_c_locale_codecvt)); - return get_catalogs()._M_add(__s, __l); - } + bind_textdomain_codeset(__s.c_str(), + __nl_langinfo_l(CODESET, __codecvt._M_c_locale_codecvt)); + return get_catalogs()._M_add(__s, __l); + } template<> void @@ -199,7 +201,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (!__cat_info) return __dfault; - return get_glibc_msg(_M_c_locale_messages, + return get_glibc_msg(_M_c_locale_messages, _M_name_messages, __cat_info->_M_domain.c_str(), __dfault.c_str()); } @@ -209,15 +211,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typename messages::catalog messages::do_open(const basic_string& __s, const locale& __l) const - { - typedef codecvt __codecvt_t; - const __codecvt_t& __codecvt = use_facet<__codecvt_t>(__l); + { + typedef codecvt __codecvt_t; + const __codecvt_t& __codecvt = use_facet<__codecvt_t>(__l); - bind_textdomain_codeset(__s.c_str(), - __nl_langinfo_l(CODESET, __codecvt._M_c_locale_codecvt)); + bind_textdomain_codeset(__s.c_str(), + __nl_langinfo_l(CODESET, __codecvt._M_c_locale_codecvt)); - return get_catalogs()._M_add(__s, __l); - } + return get_catalogs()._M_add(__s, __l); + } template<> void @@ -257,15 +259,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Make sure string passed to dgettext is \0 terminated. *__dfault_next = '\0'; - __translation - = get_glibc_msg(_M_c_locale_messages, - __cat_info->_M_domain.c_str(), __dfault); + __translation = get_glibc_msg(_M_c_locale_messages, _M_name_messages, + __cat_info->_M_domain.c_str(), __dfault); // If we end up getting default value back we can simply return original // default value. if (__translation == __dfault) return __wdfault; - } + } __builtin_memset(&__state, 0, sizeof(mbstate_t)); size_t __size = __builtin_strlen(__translation);