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-10 20:06:44.000000000 +0200 @@ -70,7 +70,11 @@ typedef _InternT intern_type; typedef _ExternT extern_type; typedef _StateT state_type; - + + protected: + __c_locale _M_c_locale_codecvt; + + public: // 22.2.1.5.1 codecvt members result out(state_type& __state, const intern_type* __from, @@ -225,6 +229,10 @@ explicit codecvt(size_t __refs = 0); + // Non-standard. + explicit + codecvt(__c_locale __cloc, size_t __refs = 0); + protected: virtual ~codecvt(); @@ -277,6 +285,10 @@ explicit codecvt(size_t __refs = 0); + // Non-standard. + explicit + codecvt(__c_locale __cloc, size_t __refs = 0); + protected: virtual ~codecvt(); @@ -320,8 +332,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-10 20:14:38.000000000 +0200 @@ -39,10 +39,19 @@ codecvt:: codecvt(size_t __refs) : __codecvt_abstract_base(__refs) - { } + { _M_c_locale_codecvt = _S_c_locale; } codecvt:: - ~codecvt() { } + codecvt(__c_locale __cloc, size_t __refs) + : __codecvt_abstract_base(__refs) + { _M_c_locale_codecvt = _S_clone_c_locale(__cloc); } + + codecvt:: + ~codecvt() + { + if (_M_c_locale_codecvt != _S_c_locale) + _S_destroy_c_locale(_M_c_locale_codecvt); + } codecvt_base::result codecvt:: @@ -106,10 +115,20 @@ // 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(__c_locale __cloc, size_t __refs) + : __codecvt_abstract_base(__refs) + { _M_c_locale_codecvt = _S_clone_c_locale(__cloc); } + + codecvt:: + ~codecvt() + { + if (_M_c_locale_codecvt != _S_c_locale) + _S_destroy_c_locale(_M_c_locale_codecvt); + } codecvt_base::result codecvt:: @@ -120,7 +139,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 +183,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) { diff -urN libstdc++-v3-orig/src/localename.cc libstdc++-v3/src/localename.cc --- libstdc++-v3-orig/src/localename.cc 2002-07-03 08:29:26.000000000 +0200 +++ libstdc++-v3/src/localename.cc 2002-09-10 19:45:47.000000000 +0200 @@ -127,7 +127,7 @@ // Construct all standard facets and add them to _M_facets. _M_init_facet(new std::ctype(__cloc)); - _M_init_facet(new codecvt); + _M_init_facet(new codecvt(__cloc)); _M_init_facet(new numpunct(__cloc)); _M_init_facet(new num_get); _M_init_facet(new num_put); @@ -143,7 +143,7 @@ #ifdef _GLIBCPP_USE_WCHAR_T _M_init_facet(new std::ctype(__cloc)); - _M_init_facet(new codecvt); + _M_init_facet(new codecvt(__cloc)); _M_init_facet(new numpunct(__cloc)); _M_init_facet(new num_get); _M_init_facet(new num_put);