diff -urN libstdc++-v3-orig/config/locale/ieee_1003.1-2001/codecvt_specializations.h libstdc++-v3/config/locale/ieee_1003.1-2001/codecvt_specializations.h --- libstdc++-v3-orig/config/locale/ieee_1003.1-2001/codecvt_specializations.h 2002-05-26 16:35:04.000000000 +0200 +++ libstdc++-v3/config/locale/ieee_1003.1-2001/codecvt_specializations.h 2002-09-08 19:18:29.000000000 +0200 @@ -190,6 +190,10 @@ typedef __enc_traits::__desc_type __desc_type; typedef __enc_traits __enc_type; + protected: + __c_locale _M_c_locale_codecvt; + + public: // Data Members: static locale::id id; diff -urN libstdc++-v3-orig/include/bits/codecvt.h libstdc++-v3/include/bits/codecvt.h --- libstdc++-v3-orig/include/bits/codecvt.h 2001-11-02 18:38:10.000000000 +0100 +++ libstdc++-v3/include/bits/codecvt.h 2002-09-08 19:35:30.000000000 +0200 @@ -219,6 +219,10 @@ typedef char extern_type; typedef mbstate_t state_type; + protected: + __c_locale _M_c_locale_codecvt; + + public: // Data Members: static locale::id id; @@ -271,6 +275,10 @@ typedef char extern_type; typedef mbstate_t state_type; + protected: + __c_locale _M_c_locale_codecvt; + + public: // Data Members: static locale::id id; @@ -320,8 +328,14 @@ { public: explicit - codecvt_byname(const char*, size_t __refs = 0) - : codecvt<_InternT, _ExternT, _StateT>(__refs) { } + codecvt_byname(const char* __s, size_t __refs = 0) + : codecvt<_InternT, _ExternT, _StateT>(__refs) + { + if (_M_c_locale_codecvt != _S_c_locale) + _S_destroy_c_locale(_M_c_locale_codecvt); + _S_create_c_locale(_M_c_locale_codecvt, __s); + } + protected: virtual ~codecvt_byname() { } diff -urN libstdc++-v3-orig/src/codecvt.cc libstdc++-v3/src/codecvt.cc --- libstdc++-v3-orig/src/codecvt.cc 2002-02-08 02:34:40.000000000 +0100 +++ libstdc++-v3/src/codecvt.cc 2002-09-08 20:50:57.000000000 +0200 @@ -39,10 +39,14 @@ codecvt:: codecvt(size_t __refs) : __codecvt_abstract_base(__refs) - { } + { _M_c_locale_codecvt = _S_c_locale; } codecvt:: - ~codecvt() { } + ~codecvt() + { + if (_M_c_locale_codecvt != _S_c_locale) + _S_destroy_c_locale(_M_c_locale_codecvt); + } codecvt_base::result codecvt:: @@ -106,10 +110,15 @@ // codecvt required specialization codecvt:: codecvt(size_t __refs) - : __codecvt_abstract_base(__refs) { } + : __codecvt_abstract_base(__refs) + { _M_c_locale_codecvt = _S_c_locale; } codecvt:: - ~codecvt() { } + ~codecvt() + { + if (_M_c_locale_codecvt != _S_c_locale) + _S_destroy_c_locale(_M_c_locale_codecvt); + } codecvt_base::result codecvt:: @@ -120,7 +129,13 @@ { result __ret = error; size_t __len = min(__from_end - __from, __to_end - __to); +#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) + __c_locale __old = __uselocale(_M_c_locale_codecvt); +#endif size_t __conv = wcsrtombs(__to, &__from, __len, &__state); +#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) + __uselocale(__old); +#endif if (__conv == __len) { @@ -158,7 +173,13 @@ { result __ret = error; size_t __len = min(__from_end - __from, __to_end - __to); +#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) + __c_locale __old = __uselocale(_M_c_locale_codecvt); +#endif size_t __conv = mbsrtowcs(__to, &__from, __len, &__state); +#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) + __uselocale(__old); +#endif if (__conv == __len) {