diff options
-rw-r--r-- | libstdc++-v3/ChangeLog | 21 | ||||
-rw-r--r-- | libstdc++-v3/config/locale/generic/time_members.h | 20 | ||||
-rw-r--r-- | libstdc++-v3/config/locale/gnu/c_locale.h | 21 | ||||
-rw-r--r-- | libstdc++-v3/config/locale/gnu/messages_members.h | 30 | ||||
-rw-r--r-- | libstdc++-v3/config/locale/gnu/time_members.h | 18 | ||||
-rw-r--r-- | libstdc++-v3/config/os/gnu-linux/ctype_noninline.h | 57 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/util/testsuite_allocator.h | 6 |
7 files changed, 122 insertions, 51 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 0c66fea67a2..02d6697c40a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,24 @@ +2007-05-24 Paolo Carlini <pcarlini@suse.de> + + * config/locale/gnu/c_locale.h (__convert_from_v): Only switch to the + "C" locale if the current one isn't already "C" (for old glibcs). + * config/os/gnu-linux/ctype_noninline.h (ctype<char>::classic_table, + ctype<char>::ctype(__c_locale, const mask*, bool, size_t), + ctype<char>::ctype(const mask*, bool, size_t)): Likewise, for generic + locale model. + * config/locale/gnu/messages_members.h + (messages<>::messages(__c_locale, const char*, size_t), + messages_byname<_CharT>::messages_byname(const char*, size_t)): + Only dynamically allocate memory if __s != "C". + * config/locale/gnu/time_members.h + (__timepunct<_CharT>::__timepunct(__c_locale, const char*, size_t)): + Likewise. + * config/locale/generic/time_members.h + (__timepunct<_CharT>::__timepunct(__c_locale, const char*, size_t)): + Likewise. + + * testsuite/util/testsuite_allocator.h: Revert last change. + 2007-05-22 Paolo Carlini <pcarlini@suse.de> * testsuite/util/testsuite_allocator.h (check_new): Assign false diff --git a/libstdc++-v3/config/locale/generic/time_members.h b/libstdc++-v3/config/locale/generic/time_members.h index dc387691d9a..20c2b54058d 100644 --- a/libstdc++-v3/config/locale/generic/time_members.h +++ b/libstdc++-v3/config/locale/generic/time_members.h @@ -62,17 +62,23 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __timepunct<_CharT>::__timepunct(__c_locale __cloc, const char* __s, size_t __refs) : facet(__refs), _M_data(NULL) - { - const size_t __len = __builtin_strlen(__s) + 1; - char* __tmp = new char[__len]; - __builtin_memcpy(__tmp, __s, __len); - _M_name_timepunct = __tmp; + { + if (__builtin_strcmp(__s, _S_get_c_name()) != 0) + { + const size_t __len = __builtin_strlen(__s) + 1; + char* __tmp = new char[__len]; + __builtin_memcpy(__tmp, __s, __len); + _M_name_timepunct = __tmp; + } + else + _M_name_timepunct = _S_get_c_name(); try { _M_initialize_timepunct(__cloc); } catch(...) - { - delete [] _M_name_timepunct; + { + if (_M_name_timepunct != _S_get_c_name()) + delete [] _M_name_timepunct; __throw_exception_again; } } diff --git a/libstdc++-v3/config/locale/gnu/c_locale.h b/libstdc++-v3/config/locale/gnu/c_locale.h index 33a2c07d8ac..67ecb7d13c7 100644 --- a/libstdc++-v3/config/locale/gnu/c_locale.h +++ b/libstdc++-v3/config/locale/gnu/c_locale.h @@ -76,11 +76,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std) #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) __c_locale __old = __gnu_cxx::__uselocale(__cloc); #else - char* __old = std::setlocale(LC_ALL, NULL); - const size_t __len = __builtin_strlen(__old) + 1; - char* __sav = new char[__len]; - __builtin_memcpy(__sav, __old, __len); - std::setlocale(LC_ALL, "C"); + char* __old = std::setlocale(LC_NUMERIC, NULL); + char* __sav = NULL; + if (__builtin_strcmp(__old, "C")) + { + const size_t __len = __builtin_strlen(__old) + 1; + char* __sav = new char[__len]; + __builtin_memcpy(__sav, __old, __len); + std::setlocale(LC_NUMERIC, "C"); + } #endif __builtin_va_list __args; @@ -97,8 +101,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) __gnu_cxx::__uselocale(__old); #else - std::setlocale(LC_ALL, __sav); - delete [] __sav; + if (__sav) + { + std::setlocale(LC_NUMERIC, __sav); + delete [] __sav; + } #endif return __ret; } diff --git a/libstdc++-v3/config/locale/gnu/messages_members.h b/libstdc++-v3/config/locale/gnu/messages_members.h index bfe25333697..28d783c136f 100644 --- a/libstdc++-v3/config/locale/gnu/messages_members.h +++ b/libstdc++-v3/config/locale/gnu/messages_members.h @@ -55,10 +55,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std) size_t __refs) : facet(__refs), _M_c_locale_messages(NULL), _M_name_messages(NULL) { - const size_t __len = __builtin_strlen(__s) + 1; - char* __tmp = new char[__len]; - __builtin_memcpy(__tmp, __s, __len); - _M_name_messages = __tmp; + if (__builtin_strcmp(__s, _S_get_c_name()) != 0) + { + const size_t __len = __builtin_strlen(__s) + 1; + char* __tmp = new char[__len]; + __builtin_memcpy(__tmp, __s, __len); + _M_name_messages = __tmp; + } + else + _M_name_messages = _S_get_c_name(); // Last to avoid leaking memory if new throws. _M_c_locale_messages = _S_clone_c_locale(__cloc); @@ -104,11 +109,18 @@ _GLIBCXX_BEGIN_NAMESPACE(std) : messages<_CharT>(__refs) { if (this->_M_name_messages != locale::facet::_S_get_c_name()) - delete [] this->_M_name_messages; - const size_t __len = __builtin_strlen(__s) + 1; - char* __tmp = new char[__len]; - __builtin_memcpy(__tmp, __s, __len); - this->_M_name_messages = __tmp; + { + delete [] this->_M_name_messages; + if (__builtin_strcmp(__s, locale::facet::_S_get_c_name()) != 0) + { + const size_t __len = __builtin_strlen(__s) + 1; + char* __tmp = new char[__len]; + __builtin_memcpy(__tmp, __s, __len); + this->_M_name_messages = __tmp; + } + else + this->_M_name_messages = locale::facet::_S_get_c_name(); + } if (__builtin_strcmp(__s, "C") != 0 && __builtin_strcmp(__s, "POSIX") != 0) diff --git a/libstdc++-v3/config/locale/gnu/time_members.h b/libstdc++-v3/config/locale/gnu/time_members.h index 7f97bcbbd7b..3e5e0c3ed20 100644 --- a/libstdc++-v3/config/locale/gnu/time_members.h +++ b/libstdc++-v3/config/locale/gnu/time_members.h @@ -59,17 +59,23 @@ _GLIBCXX_BEGIN_NAMESPACE(std) size_t __refs) : facet(__refs), _M_data(NULL), _M_c_locale_timepunct(NULL), _M_name_timepunct(NULL) - { - const size_t __len = __builtin_strlen(__s) + 1; - char* __tmp = new char[__len]; - __builtin_memcpy(__tmp, __s, __len); - _M_name_timepunct = __tmp; + { + if (__builtin_strcmp(__s, _S_get_c_name()) != 0) + { + const size_t __len = __builtin_strlen(__s) + 1; + char* __tmp = new char[__len]; + __builtin_memcpy(__tmp, __s, __len); + _M_name_timepunct = __tmp; + } + else + _M_name_timepunct = _S_get_c_name(); try { _M_initialize_timepunct(__cloc); } catch(...) { - delete [] _M_name_timepunct; + if (_M_name_timepunct != _S_get_c_name()) + delete [] _M_name_timepunct; __throw_exception_again; } } diff --git a/libstdc++-v3/config/os/gnu-linux/ctype_noninline.h b/libstdc++-v3/config/os/gnu-linux/ctype_noninline.h index 779b26a0d49..808b25c9328 100644 --- a/libstdc++-v3/config/os/gnu-linux/ctype_noninline.h +++ b/libstdc++-v3/config/os/gnu-linux/ctype_noninline.h @@ -50,17 +50,24 @@ { const ctype_base::mask* __ret; char* __old = setlocale(LC_CTYPE, NULL); - const size_t __len = __builtin_strlen(__old) + 1; - char* __sav = new char[__len]; - __builtin_memcpy(__sav, __old, __len); - setlocale(LC_CTYPE, "C"); + char* __sav = NULL; + if (__builtin_strcmp(__old, "C")) + { + const size_t __len = __builtin_strlen(__old) + 1; + __sav = new char[__len]; + __builtin_memcpy(__sav, __old, __len); + setlocale(LC_CTYPE, "C"); + } #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) __ret = *__ctype_b_loc(); #else __ret = __ctype_b; #endif - setlocale(LC_CTYPE, __sav); - delete [] __sav; + if (__sav) + { + setlocale(LC_CTYPE, __sav); + delete [] __sav; + } return __ret; } #endif @@ -85,10 +92,14 @@ _M_del(__table != 0 && __del), _M_widen_ok(0), _M_narrow_ok(0) { char* __old = setlocale(LC_CTYPE, NULL); - const size_t __len = __builtin_strlen(__old) + 1; - char* __sav = new char[__len]; - __builtin_memcpy(__sav, __old, __len); - setlocale(LC_CTYPE, "C"); + char* __sav = NULL; + if (__builtin_strcmp(__old, "C")) + { + const size_t __len = __builtin_strlen(__old) + 1; + __sav = new char[__len]; + __builtin_memcpy(__sav, __old, __len); + setlocale(LC_CTYPE, "C"); + } #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) _M_toupper = *__ctype_toupper_loc(); _M_tolower = *__ctype_tolower_loc(); @@ -98,8 +109,11 @@ _M_tolower = __ctype_tolower; _M_table = __table ? __table : __ctype_b; #endif - setlocale(LC_CTYPE, __sav); - delete [] __sav; + if (__sav) + { + setlocale(LC_CTYPE, __sav); + delete [] __sav; + } __builtin_memset(_M_widen, 0, sizeof(_M_widen)); __builtin_memset(_M_narrow, 0, sizeof(_M_narrow)); } @@ -123,10 +137,14 @@ _M_del(__table != 0 && __del), _M_widen_ok(0), _M_narrow_ok(0) { char* __old = setlocale(LC_CTYPE, NULL); - const size_t __len = __builtin_strlen(__old) + 1; - char* __sav = new char[__len]; - __builtin_memcpy(__sav, __old, __len); - setlocale(LC_CTYPE, "C"); + char* __sav = NULL; + if (__builtin_strcmp(__old, "C")) + { + const size_t __len = __builtin_strlen(__old) + 1; + __sav = new char[__len]; + __builtin_memcpy(__sav, __old, __len); + setlocale(LC_CTYPE, "C"); + } #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) _M_toupper = *__ctype_toupper_loc(); _M_tolower = *__ctype_tolower_loc(); @@ -136,8 +154,11 @@ _M_tolower = __ctype_tolower; _M_table = __table ? __table : __ctype_b; #endif - setlocale(LC_CTYPE, __sav); - delete [] __sav; + if (__sav) + { + setlocale(LC_CTYPE, __sav); + delete [] __sav; + } __builtin_memset(_M_widen, 0, sizeof(_M_widen)); __builtin_memset(_M_narrow, 0, sizeof(_M_narrow)); } diff --git a/libstdc++-v3/testsuite/util/testsuite_allocator.h b/libstdc++-v3/testsuite/util/testsuite_allocator.h index aaed7311f68..d6108cc6064 100644 --- a/libstdc++-v3/testsuite/util/testsuite_allocator.h +++ b/libstdc++-v3/testsuite/util/testsuite_allocator.h @@ -42,8 +42,8 @@ namespace { - bool new_called; - bool delete_called; + bool new_called = false; + bool delete_called = false; }; namespace __gnu_test @@ -189,7 +189,6 @@ namespace __gnu_test check_new(Alloc a = Alloc()) { bool test __attribute__((unused)) = true; - new_called = false; a.allocate(10); test &= ( new_called == uses_global_new ); return test; @@ -200,7 +199,6 @@ namespace __gnu_test check_delete(Alloc a = Alloc()) { bool test __attribute__((unused)) = true; - delete_called = false; typename Alloc::pointer p = a.allocate(10); a.deallocate(p, 10); test &= ( delete_called == uses_global_delete ); |