From def9790d51a51a78a700567bb677225a90bc854e Mon Sep 17 00:00:00 2001 From: Benjamin Kosnik Date: Sat, 15 Dec 2001 07:05:04 +0000 Subject: Clean up initialization and simplfy caching of underlying "C" locale objects. 2001-12-14 Benjamin Kosnik Clean up initialization and simplfy caching of underlying "C" locale objects. * src/localename.cc (locale::_Impl::_Impl(string, size_t): Unconditionally create __clocale object for all named locales, including "C" and "POSIX". * config/locale/c_locale_generic.cc (locale::facet::_S_create_c_locale): Always set __cloc to zero. * config/locale/c_locale_gnu.cc: Always delete. * include/bits/localefwd.h (locale::facet::_S_c_locale): New. * src/locale.cc (locale::classic()): Initialize locale::facet::_S_c_locale. (locale::facet::_S_c_locale): Define. * include/bits/locale_facets.h: Add ctype_byname ctor specialization. * src/locale.cc: Add definition here. * config/os/gnu-linux/bits/ctype_inline.h: Tweak. * config/os/gnu-linux/bits/ctype_noninline.h: Adjust initializations. * include/bits/locale_facets.h (ctype::_M_c_locale_ctype): Add. Adjust ctors, dtors. (ctype::_M_toupper): Remove const&. (ctype::_M_tolower): Remove const&. (ctype::_M_ctable): Remove const&. * include/bits/locale_facets.h (collate): Clean up initialization of _M_c_locale_collate in ctors and dtors. * config/locale/collate_members_gnu.cc: Always use extended functions. * include/bits/locale_facets.h (messages): Clean up inits in ctor/dtor. (messages_byname): Same. * config/locale/messages_members_generic.h (messages::~messages): Remove. * config/locale/messages_members_gnu.h: Same. * include/bits/localefwd.h: Clean. Move dtor definitions to * src/locale.cc: Here. * testsuite/22_locale/facet.cc: Fix spelling. Named locale support for ctype. * acinclude.m4 (GLIBCPP_ENABLE_CLOCALE): Add variable ctype_members_* bits. * aclocal.m4: Regenerate. * configure: Regenerate. * src/Makefile.am (sources): Add ctype.cc. * src/Makefile.in: Regenerate. * config/locale/ctype_members_generic.cc: New file. * config/locale/ctype_members_gnu.cc: New file. * src/locale.cc: Remove ctype definitions. From-SVN: r48034 --- libstdc++-v3/src/Makefile.am | 15 +-- libstdc++-v3/src/Makefile.in | 27 +++--- libstdc++-v3/src/locale.cc | 201 ++++++++--------------------------------- libstdc++-v3/src/localename.cc | 26 +++--- 4 files changed, 73 insertions(+), 196 deletions(-) (limited to 'libstdc++-v3/src') diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am index 0e12404..e0015ba 100644 --- a/libstdc++-v3/src/Makefile.am +++ b/libstdc++-v3/src/Makefile.am @@ -60,13 +60,14 @@ INCLUDES = \ $(TOPLEVEL_INCLUDES) sources = \ - basic_file.cc bitset.cc c++locale.cc cmath.cc codecvt.cc \ - complex_io.cc functexcept.cc globals.cc ios.cc limits.cc \ - locale.cc locale-inst.cc localename.cc \ - collate.cc messages.cc moneypunct.cc numpunct.cc time.cc \ - vterminate.cc \ - misc-inst.cc stdexcept.cc stl-inst.cc string-inst.cc strstream.cc \ - valarray-inst.cc wstring-inst.cc concept-inst.cc ext-inst.cc + globals.cc limits.cc \ + basic_file.cc complex_io.cc ios.cc strstream.cc \ + cmath.cc bitset.cc \ + functexcept.cc stdexcept.cc vterminate.cc \ + c++locale.cc locale.cc localename.cc codecvt.cc \ + collate.cc ctype.cc messages.cc moneypunct.cc numpunct.cc time.cc \ + concept-inst.cc locale-inst.cc misc-inst.cc stl-inst.cc \ + string-inst.cc wstring-inst.cc valarray-inst.cc ext-inst.cc VPATH = $(top_srcdir)/src:$(top_srcdir) diff --git a/libstdc++-v3/src/Makefile.in b/libstdc++-v3/src/Makefile.in index 643aebe..125d1c2 100644 --- a/libstdc++-v3/src/Makefile.in +++ b/libstdc++-v3/src/Makefile.in @@ -185,13 +185,14 @@ INCLUDES = \ sources = \ - basic_file.cc bitset.cc c++locale.cc cmath.cc codecvt.cc \ - complex_io.cc functexcept.cc globals.cc ios.cc limits.cc \ - locale.cc locale-inst.cc localename.cc \ - collate.cc messages.cc moneypunct.cc numpunct.cc time.cc \ - vterminate.cc \ - misc-inst.cc stdexcept.cc stl-inst.cc string-inst.cc strstream.cc \ - valarray-inst.cc wstring-inst.cc concept-inst.cc ext-inst.cc + globals.cc limits.cc \ + basic_file.cc complex_io.cc ios.cc strstream.cc \ + cmath.cc bitset.cc \ + functexcept.cc stdexcept.cc vterminate.cc \ + c++locale.cc locale.cc localename.cc codecvt.cc \ + collate.cc ctype.cc messages.cc moneypunct.cc numpunct.cc time.cc \ + concept-inst.cc locale-inst.cc misc-inst.cc stl-inst.cc \ + string-inst.cc wstring-inst.cc valarray-inst.cc ext-inst.cc VPATH = $(top_srcdir)/src:$(top_srcdir) @@ -264,12 +265,12 @@ DEFS = @DEFS@ -I. -I$(srcdir) -I.. CPPFLAGS = @CPPFLAGS@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ -libstdc___la_OBJECTS = basic_file.lo bitset.lo c++locale.lo cmath.lo \ -codecvt.lo complex_io.lo functexcept.lo globals.lo ios.lo limits.lo \ -locale.lo locale-inst.lo localename.lo collate.lo messages.lo \ -moneypunct.lo numpunct.lo time.lo vterminate.lo misc-inst.lo \ -stdexcept.lo stl-inst.lo string-inst.lo strstream.lo valarray-inst.lo \ -wstring-inst.lo concept-inst.lo ext-inst.lo +libstdc___la_OBJECTS = globals.lo limits.lo basic_file.lo complex_io.lo \ +ios.lo strstream.lo cmath.lo bitset.lo functexcept.lo stdexcept.lo \ +vterminate.lo c++locale.lo locale.lo localename.lo codecvt.lo \ +collate.lo ctype.lo messages.lo moneypunct.lo numpunct.lo time.lo \ +concept-inst.lo locale-inst.lo misc-inst.lo stl-inst.lo string-inst.lo \ +wstring-inst.lo valarray-inst.lo ext-inst.lo CXXFLAGS = @CXXFLAGS@ CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) CXXLD = $(CXX) diff --git a/libstdc++-v3/src/locale.cc b/libstdc++-v3/src/locale.cc index 0e899c1..13c85ab 100644 --- a/libstdc++-v3/src/locale.cc +++ b/libstdc++-v3/src/locale.cc @@ -348,9 +348,18 @@ namespace std return __ret; } + __c_locale + locale::facet::_S_c_locale; + + locale::facet:: + ~facet() { } + locale::facet:: facet(size_t __refs) throw() : _M_references(__refs) - { } + { + if (!_S_c_locale) + _S_create_c_locale(_S_c_locale, "C"); + } void locale::facet:: @@ -370,6 +379,8 @@ namespace std } } + locale::id::id() { } + // Definitions for static const data members of ctype_base. const ctype_base::mask ctype_base::space; const ctype_base::mask ctype_base::print; @@ -389,7 +400,12 @@ namespace std const size_t ctype::table_size; ctype::~ctype() - { if (_M_del) delete[] this->table(); } + { + if (_M_c_locale_ctype) + _S_destroy_c_locale(_M_c_locale_ctype); + if (_M_del) + delete[] this->table(); + } // These are dummy placeholders as these virtual functions are never called. bool @@ -431,171 +447,26 @@ namespace std return __hi; } - template<> - ctype_byname::ctype_byname(const char* /*__s*/, size_t __refs) - : ctype(new mask[table_size], true, __refs) - { } - -#ifdef _GLIBCPP_USE_WCHAR_T - ctype::__wmask_type - ctype::_M_convert_to_wmask(const mask __m) const - { - __wmask_type __ret; - switch (__m) - { - case space: - __ret = wctype("space"); - break; - case print: - __ret = wctype("print"); - break; - case cntrl: - __ret = wctype("cntrl"); - break; - case upper: - __ret = wctype("upper"); - break; - case lower: - __ret = wctype("lower"); - break; - case alpha: - __ret = wctype("alpha"); - break; - case digit: - __ret = wctype("digit"); - break; - case punct: - __ret = wctype("punct"); - break; - case xdigit: - __ret = wctype("xdigit"); - break; - case alnum: - __ret = wctype("alnum"); - break; - case graph: - __ret = wctype("graph"); - break; - default: - __ret = 0; - } - return __ret; - }; - - ctype::~ctype() { } - - // NB: These ctype methods are not configuration-specific, - // unlike the ctype bits. +#ifdef _GLIBCPP_USE_WCHAR_T ctype::ctype(size_t __refs) - : __ctype_abstract_base(__refs) { } + : __ctype_abstract_base(__refs) + { _M_c_locale_ctype = _S_clone_c_locale(_S_c_locale); } - ctype::ctype(__c_locale /*__cloc*/, size_t __refs) - : __ctype_abstract_base(__refs) { } + ctype::ctype(__c_locale __cloc, size_t __refs) + : __ctype_abstract_base(__refs) + { _M_c_locale_ctype = _S_clone_c_locale(__cloc); } - wchar_t - ctype::do_toupper(wchar_t __c) const - { return towupper(__c); } - - const wchar_t* - ctype::do_toupper(wchar_t* __lo, const wchar_t* __hi) const - { - while (__lo < __hi) - { - *__lo = towupper(*__lo); - ++__lo; - } - return __hi; - } - - wchar_t - ctype::do_tolower(wchar_t __c) const - { return towlower(__c); } - - const wchar_t* - ctype::do_tolower(wchar_t* __lo, const wchar_t* __hi) const - { - while (__lo < __hi) - { - *__lo = towlower(*__lo); - ++__lo; - } - return __hi; - } - - bool - ctype:: - do_is(mask __m, char_type __c) const - { return static_cast(iswctype(__c, _M_convert_to_wmask(__m))); } - - const wchar_t* - ctype:: - do_is(const wchar_t* __lo, const wchar_t* __hi, mask* __m) const - { - while (__lo < __hi && !this->is(*__m, *__lo)) - ++__lo; - return __lo; - } - - const wchar_t* - ctype:: - do_scan_is(mask __m, const wchar_t* __lo, const wchar_t* __hi) const - { - while (__lo < __hi && !this->is(__m, *__lo)) - ++__lo; - return __lo; - } - - const wchar_t* - ctype:: - do_scan_not(mask __m, const char_type* __lo, const char_type* __hi) const - { - while (__lo < __hi && this->is(__m, *__lo) != 0) - ++__lo; - return __lo; - } - - wchar_t - ctype:: - do_widen(char __c) const - { return btowc(__c); } - - const char* - ctype:: - do_widen(const char* __lo, const char* __hi, wchar_t* __dest) const - { - mbstate_t __state; - memset(static_cast(&__state), 0, sizeof(mbstate_t)); - mbsrtowcs(__dest, &__lo, __hi - __lo, &__state); - return __hi; - } - - char - ctype:: - do_narrow(wchar_t __wc, char __dfault) const - { - int __c = wctob(__wc); - return (__c == EOF ? __dfault : static_cast(__c)); - } - - const wchar_t* - ctype:: - do_narrow(const wchar_t* __lo, const wchar_t* __hi, char __dfault, - char* __dest) const - { - mbstate_t __state; - memset(static_cast(&__state), 0, sizeof(mbstate_t)); - size_t __len = __hi - __lo; - size_t __conv = wcsrtombs(__dest, &__lo, __len, &__state); - if (__conv == __len) - *__dest = __dfault; - return __hi; - } + ctype::~ctype() + { _S_destroy_c_locale(_M_c_locale_ctype); } template<> - ctype_byname:: - ctype_byname(const char* /*__s*/, size_t __refs) - : ctype(__refs) { } -#endif // _GLIBCPP_USE_WCHAR_T + ctype_byname::ctype_byname(const char* __s, size_t __refs) + : ctype(__refs) + { + _S_destroy_c_locale(_M_c_locale_ctype); + _S_create_c_locale(_M_c_locale_ctype, __s); + } +#endif // Definitions for static const data members of time_base template<> @@ -618,7 +489,7 @@ namespace std // Definitions for static const data members of money_base const money_base::pattern - money_base::_S_default_pattern = {{symbol, sign, none, value}}; + money_base::_S_default_pattern = { {symbol, sign, none, value} }; template<> const ctype& @@ -708,12 +579,12 @@ namespace std } template<> - moneypunct_byname::moneypunct_byname(const char* /*__s*/, + moneypunct_byname::moneypunct_byname(const char*, size_t __refs) : moneypunct(__refs) { } template<> - moneypunct_byname::moneypunct_byname(const char* /*__s*/, + moneypunct_byname::moneypunct_byname(const char*, size_t __refs) : moneypunct(__refs) { } } // namespace std diff --git a/libstdc++-v3/src/localename.cc b/libstdc++-v3/src/localename.cc index 2bd34cd..8c2db9d 100644 --- a/libstdc++-v3/src/localename.cc +++ b/libstdc++-v3/src/localename.cc @@ -72,9 +72,14 @@ namespace std { // Initialize the underlying locale model, which also checks to // see if the given name is valid. - __c_locale __cloc = NULL; + __c_locale __cloc; + locale::facet::_S_create_c_locale(__cloc, __str.c_str()); + + // This is needed as presently "C" locales != required data in + // __timepunct, numpunct, and moneypunct. + __c_locale __cloc_c = NULL; if (__str != "C" && __str != "POSIX") - locale::facet::_S_create_c_locale(__cloc, __str.c_str()); + __cloc_c = __cloc; // Allocate facet container. try @@ -90,18 +95,17 @@ namespace std _M_names[i] = __str; // Construct all standard facets and add them to _M_facets. - // XXX How to deal cleanly, consistently with null ("C") __cloc? _M_init_facet(new std::collate(__cloc)); _M_init_facet(new std::ctype(__cloc)); _M_init_facet(new codecvt); - _M_init_facet(new moneypunct(__cloc)); - _M_init_facet(new moneypunct(__cloc)); + _M_init_facet(new moneypunct(__cloc_c)); + _M_init_facet(new moneypunct(__cloc_c)); _M_init_facet(new money_get); _M_init_facet(new money_put); - _M_init_facet(new numpunct(__cloc)); + _M_init_facet(new numpunct(__cloc_c)); _M_init_facet(new num_get); _M_init_facet(new num_put); - _M_init_facet(new __timepunct(__cloc, __str.c_str())); + _M_init_facet(new __timepunct(__cloc_c, __str.c_str())); _M_init_facet(new time_get); _M_init_facet(new time_put); _M_init_facet(new std::messages(__cloc, __str.c_str())); @@ -110,14 +114,14 @@ namespace std _M_init_facet(new std::collate(__cloc)); _M_init_facet(new std::ctype(__cloc)); _M_init_facet(new codecvt); - _M_init_facet(new moneypunct(__cloc)); - _M_init_facet(new moneypunct(__cloc)); + _M_init_facet(new moneypunct(__cloc_c)); + _M_init_facet(new moneypunct(__cloc_c)); _M_init_facet(new money_get); _M_init_facet(new money_put); - _M_init_facet(new numpunct(__cloc)); + _M_init_facet(new numpunct(__cloc_c)); _M_init_facet(new num_get); _M_init_facet(new num_put); - _M_init_facet(new __timepunct(__cloc, __str.c_str())); + _M_init_facet(new __timepunct(__cloc_c, __str.c_str())); _M_init_facet(new time_get); _M_init_facet(new time_put); _M_init_facet(new std::messages(__cloc, __str.c_str())); -- cgit v1.1