diff options
author | bkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-07-04 02:39:02 +0000 |
---|---|---|
committer | bkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-07-04 02:39:02 +0000 |
commit | 6a2b8c8a9accc955322dabe7f01c983d2e2df054 (patch) | |
tree | f612347829a52ea680a008783a91a7871961466f /libstdc++-v3 | |
parent | f720f386fac29ec0d8d913d36ebe32b53160bd08 (diff) | |
download | ppe42-gcc-6a2b8c8a9accc955322dabe7f01c983d2e2df054.tar.gz ppe42-gcc-6a2b8c8a9accc955322dabe7f01c983d2e2df054.zip |
2001-07-03 Benjamin Kosnik <bkoz@redhat.com>
* include/bits/localefwd.h: Format.
* include/bits/locale_facts.tcc (locale::combine): Adjust.
* src/locale.cc (locale::locale::(_Impl)): Don't call
_M_add_reference.
(locale::facet::_M_remove_reference): Simplify.
* src/globals.cc (locale_impl_c): New. Format.
(locale_c): New.
* src/ios.cc (ios_base::Init::Init): Increment _S_ios_base_init last.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@43747 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/ChangeLog | 11 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/locale_facets.tcc | 2 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/localefwd.h | 7 | ||||
-rw-r--r-- | libstdc++-v3/src/globals.cc | 51 | ||||
-rw-r--r-- | libstdc++-v3/src/ios.cc | 3 | ||||
-rw-r--r-- | libstdc++-v3/src/locale.cc | 50 |
6 files changed, 70 insertions, 54 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c9b74ce00f1..c0e29494450 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,14 @@ +2001-07-03 Benjamin Kosnik <bkoz@redhat.com> + + * include/bits/localefwd.h: Format. + * include/bits/locale_facts.tcc (locale::combine): Adjust. + * src/locale.cc (locale::locale::(_Impl)): Don't call + _M_add_reference. + (locale::facet::_M_remove_reference): Simplify. + * src/globals.cc (locale_impl_c): New. Format. + (locale_c): New. + * src/ios.cc (ios_base::Init::Init): Increment _S_ios_base_init last. + 2001-07-02 Loren J. Rittle <ljrittle@acm.org> * acinclude.m4 (GLIBCPP_ENABLE_THREADS): Protect variable from shell diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 6eceed1ea59..982914fb5f4 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -48,7 +48,7 @@ namespace std locale locale::combine(const locale& __other) { - _Impl* __tmp = new _Impl(*_M_impl, 0); + _Impl* __tmp = new _Impl(*_M_impl, 1); __tmp->_M_replace_facet(__other._M_impl, &_Facet::id); return locale(__tmp); } diff --git a/libstdc++-v3/include/bits/localefwd.h b/libstdc++-v3/include/bits/localefwd.h index da84110746e..b24ff073606 100644 --- a/libstdc++-v3/include/bits/localefwd.h +++ b/libstdc++-v3/include/bits/localefwd.h @@ -451,9 +451,4 @@ namespace std has_facet(const locale& __loc) throw(); } // namespace std -#endif /* _CPP_BITS_LOCCORE_H */ - -// Local Variables: -// mode:c++ -// End: - +#endif diff --git a/libstdc++-v3/src/globals.cc b/libstdc++-v3/src/globals.cc index d70cc295407..d7a733e5daa 100644 --- a/libstdc++-v3/src/globals.cc +++ b/libstdc++-v3/src/globals.cc @@ -44,6 +44,17 @@ // allocate the actual file buffers in this file. namespace std { + // Standard "C" locale. + typedef char fake_locale_Impl[sizeof(locale::_Impl)] + __attribute__ ((aligned(__alignof__(locale::_Impl)))); + fake_locale_Impl locale_impl_c; + + typedef char fake_locale[sizeof(locale)] + __attribute__ ((aligned(__alignof__(locale)))); + fake_locale locale_c; + + + // Standard stream objects. typedef char fake_istream[sizeof(istream)] __attribute__ ((aligned(__alignof__(istream)))); typedef char fake_ostream[sizeof(ostream)] @@ -76,30 +87,28 @@ namespace std fake_wfilebuf buf_wcerr; #endif -// Globals for once-only runtime initialization of mutex objects. This -// allows static initialization of these objects on systems that need a -// function call to initialize a mutex. For example, see stl_threads.h. + + // Globals for once-only runtime initialization of mutex objects. This + // allows static initialization of these objects on systems that need a + // function call to initialize a mutex. For example, see stl_threads.h. #if __GTHREADS #ifdef __GTHREAD_MUTEX_INIT -// This path is not needed since static initialization of mutexs works -// on this platform. + // This path is not needed since static initialization of mutexs works + // on this platform. #elif defined(__GTHREAD_MUTEX_INIT_FUNCTION) -__gthread_once_t _GLIBCPP_once = __GTHREAD_ONCE_INIT; -__gthread_mutex_t _GLIBCPP_mutex; -__gthread_mutex_t *_GLIBCPP_mutex_address; + __gthread_once_t _GLIBCPP_once = __GTHREAD_ONCE_INIT; + __gthread_mutex_t _GLIBCPP_mutex; + __gthread_mutex_t *_GLIBCPP_mutex_address; + + // Once-only initializer function for _GLIBCPP_mutex. + void + _GLIBCPP_mutex_init () + { __GTHREAD_MUTEX_INIT_FUNCTION (&_GLIBCPP_mutex); } -// Once-only initializer function for _GLIBCPP_mutex. -void -_GLIBCPP_mutex_init () -{ - __GTHREAD_MUTEX_INIT_FUNCTION (&_GLIBCPP_mutex); -} -// Once-only initializer function for _GLIBCPP_mutex_address. -void -_GLIBCPP_mutex_address_init () -{ - __GTHREAD_MUTEX_INIT_FUNCTION (_GLIBCPP_mutex_address); -} -#endif + // Once-only initializer function for _GLIBCPP_mutex_address. + void + _GLIBCPP_mutex_address_init () + { __GTHREAD_MUTEX_INIT_FUNCTION (_GLIBCPP_mutex_address); } #endif +#endif // __GTHREADS } diff --git a/libstdc++-v3/src/ios.cc b/libstdc++-v3/src/ios.cc index 182f5046ed1..faa11fbeea1 100644 --- a/libstdc++-v3/src/ios.cc +++ b/libstdc++-v3/src/ios.cc @@ -205,12 +205,13 @@ namespace std ios_base::Init::Init() { - if (++_S_ios_base_init == 1) + if (_S_ios_base_init == 0) { // Standard streams default to synced with "C" operations. ios_base::Init::_S_synced_with_stdio = true; _S_ios_create(ios_base::Init::_S_synced_with_stdio); } + ++_S_ios_base_init; } ios_base::Init::~Init() diff --git a/libstdc++-v3/src/locale.cc b/libstdc++-v3/src/locale.cc index fb0b406eed4..0d4020065a2 100644 --- a/libstdc++-v3/src/locale.cc +++ b/libstdc++-v3/src/locale.cc @@ -43,6 +43,10 @@ namespace std { + // Defined in globals.cc. + extern locale::_Impl locale_impl_c; + extern locale locale_c; + // Definitions for static const data members of locale. const locale::category locale::none; const locale::category locale::ctype; @@ -362,10 +366,10 @@ namespace std locale::locale(const locale& __other) throw() { (_M_impl = __other._M_impl)->_M_add_reference(); } - // This is used to initialize global and classic locales. - locale::locale(_Impl* __ip) throw() - : _M_impl(__ip) - { __ip->_M_add_reference(); } + // This is used to initialize global and classic locales, and + // assumes that the _Impl objects are constructed correctly. + locale::locale(_Impl* __ip) throw() : _M_impl(__ip) + { } locale::locale(const char* __s) { @@ -415,13 +419,18 @@ namespace std { // XXX MT _S_initialize(); - locale __old(_S_global); + _Impl* __old = _S_global; __other._M_impl->_M_add_reference(); - _S_global->_M_remove_reference(); _S_global = __other._M_impl; if (_S_global->_M_check_same_name() && _S_global->_M_names[0] != "*") setlocale(LC_ALL, __other.name().c_str()); - return __old; + + // Reference count sanity check: one reference removed for the + // subsition of __other locale, one added by return-by-value. Net + // difference: zero. When the returned locale object's destrutor + // is called, then the reference count is decremented and possibly + // destroyed. + return locale(__old); } string @@ -446,7 +455,6 @@ namespace std locale const& locale::classic() { - static locale* __classic_locale; // XXX MT if (!_S_classic) { @@ -454,26 +462,21 @@ namespace std { // 26 Standard facets, 2 references. // One reference for _M_classic, one for _M_global - _S_classic = new _Impl("C", 2); + _S_classic = new (&locale_impl_c) _Impl("C", 2); _S_global = _S_classic; - - // Finesse static init order hassles - __classic_locale = new locale(_S_classic); + new (&locale_c) locale(_S_classic); } catch(...) { - delete __classic_locale; + // Just call destructor, so that locale_impl_c's memory is + // not deallocated via a call to delete. if (_S_classic) - { - _S_classic->_M_remove_reference(); - _S_global->_M_remove_reference(); - } + _S_classic->~_Impl(); _S_classic = _S_global = 0; - // XXX MT __throw_exception_again; } } - return *__classic_locale; + return locale_c; } locale::category @@ -518,8 +521,7 @@ namespace std } locale::facet:: - facet(size_t __refs) throw() - : _M_references(__refs) + facet(size_t __refs) throw() : _M_references(__refs) { } void @@ -531,12 +533,10 @@ namespace std locale::facet:: _M_remove_reference() throw() { - if (_M_references) - --_M_references; - else + if (_M_references-- == 0) { try - { delete this; } // XXX MT + { delete this; } catch (...) { } } |