diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e89c6187ae7..ef14d43bab0 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,20 @@ +2002-09-10 Paolo Carlini + + * include/bits/codecvt.h (class __codecvt_abstract_base): + Add __c_locale type _M_c_locale_codecvt member. + (class codecvt, + class codecvt): Add new + codecvt(__c_locale, size_t) constructor. + (codecvt_byname::codecvt_byname): Update. + * src/codecvt.cc (class codecvt, + class codecvt): Update codecvt(size_t) + constructor and ~codecvt() destructor; define + codecvt(__c_locale, size_t) constructor. + (codecvt::do_out): Switch to _M_c_locale_codecvt around wcsrtombs call. + (codecvt::do_in): Ditto for mbsrtowcs call. + * src/localename.cc (locale::_Impl::_Impl(const char*, size_t)): + Tweak construction of codecvt facets. + 2002-09-10 Danny Smith * include/bits/locale_facets.tcc (__convert_from_v): diff --git a/libstdc++-v3/include/bits/codecvt.h b/libstdc++-v3/include/bits/codecvt.h index 506752f3432..3a3f6044e5f 100644 --- a/libstdc++-v3/include/bits/codecvt.h +++ b/libstdc++-v3/include/bits/codecvt.h @@ -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 --git a/libstdc++-v3/src/codecvt.cc b/libstdc++-v3/src/codecvt.cc index 032667e3f13..dcce705d227 100644 --- a/libstdc++-v3/src/codecvt.cc +++ b/libstdc++-v3/src/codecvt.cc @@ -39,10 +39,19 @@ namespace std 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 @@ namespace std // 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 @@ namespace std { 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 @@ namespace std { 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 --git a/libstdc++-v3/src/localename.cc b/libstdc++-v3/src/localename.cc index 8fa91189170..a0c9e75ee80 100644 --- a/libstdc++-v3/src/localename.cc +++ b/libstdc++-v3/src/localename.cc @@ -127,7 +127,7 @@ namespace std // 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 @@ namespace std #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);