This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] locale globals
- To: gcc-patches at gcc dot gnu dot org
- Subject: [v3] locale globals
- From: Benjamin Kosnik <bkoz at redhat dot com>
- Date: Tue, 3 Jul 2001 19:38:27 -0700
Makes a global _Impl and c_locale object.
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.
Index: include/bits/locale_facets.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/locale_facets.tcc,v
retrieving revision 1.18
diff -c -p -r1.18 locale_facets.tcc
*** locale_facets.tcc 2001/07/02 23:08:28 1.18
--- locale_facets.tcc 2001/07/04 02:36:53
*************** namespace std
*** 48,54 ****
locale
locale::combine(const locale& __other)
{
! _Impl* __tmp = new _Impl(*_M_impl, 0);
__tmp->_M_replace_facet(__other._M_impl, &_Facet::id);
return locale(__tmp);
}
--- 48,54 ----
locale
locale::combine(const locale& __other)
{
! _Impl* __tmp = new _Impl(*_M_impl, 1);
__tmp->_M_replace_facet(__other._M_impl, &_Facet::id);
return locale(__tmp);
}
Index: include/bits/localefwd.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/localefwd.h,v
retrieving revision 1.16
diff -c -p -r1.16 localefwd.h
*** localefwd.h 2001/06/30 04:35:47 1.16
--- localefwd.h 2001/07/04 02:36:54
*************** namespace std
*** 451,459 ****
has_facet(const locale& __loc) throw();
} // namespace std
! #endif /* _CPP_BITS_LOCCORE_H */
!
! // Local Variables:
! // mode:c++
! // End:
!
--- 451,454 ----
has_facet(const locale& __loc) throw();
} // namespace std
! #endif
Index: src/globals.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/globals.cc,v
retrieving revision 1.3
diff -c -p -r1.3 globals.cc
*** globals.cc 2001/06/14 06:06:48 1.3
--- globals.cc 2001/07/04 02:36:55
***************
*** 44,49 ****
--- 44,60 ----
// 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)]
*************** namespace std
*** 75,105 ****
fake_wfilebuf buf_wcin;
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.
#if __GTHREADS
#ifdef __GTHREAD_MUTEX_INIT
! // 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;
!
! // 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
#endif
}
--- 86,114 ----
fake_wfilebuf buf_wcin;
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.
#if __GTHREADS
#ifdef __GTHREAD_MUTEX_INIT
! // 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;
!
! // 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
+ #endif // __GTHREADS
}
Index: src/ios.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/ios.cc,v
retrieving revision 1.20
diff -c -p -r1.20 ios.cc
*** ios.cc 2001/07/02 20:50:40 1.20
--- ios.cc 2001/07/04 02:36:56
*************** namespace std
*** 205,216 ****
ios_base::Init::Init()
{
! if (++_S_ios_base_init == 1)
{
// 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);
}
}
ios_base::Init::~Init()
--- 205,217 ----
ios_base::Init::Init()
{
! 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()
Index: src/locale.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/locale.cc,v
retrieving revision 1.35
diff -c -p -r1.35 locale.cc
*** locale.cc 2001/07/02 23:08:28 1.35
--- locale.cc 2001/07/04 02:36:58
***************
*** 43,48 ****
--- 43,52 ----
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;
*************** namespace std
*** 362,371 ****
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(); }
locale::locale(const char* __s)
{
--- 366,375 ----
locale::locale(const locale& __other) throw()
{ (_M_impl = __other._M_impl)->_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)
{
*************** namespace std
*** 415,427 ****
{
// XXX MT
_S_initialize();
! locale __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;
}
string
--- 419,436 ----
{
// XXX MT
_S_initialize();
! _Impl* __old = _S_global;
__other._M_impl->_M_add_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());
!
! // 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
*************** namespace std
*** 446,452 ****
locale const&
locale::classic()
{
- static locale* __classic_locale;
// XXX MT
if (!_S_classic)
{
--- 455,460 ----
*************** namespace std
*** 454,479 ****
{
// 26 Standard facets, 2 references.
// One reference for _M_classic, one for _M_global
! _S_classic = new _Impl("C", 2);
_S_global = _S_classic;
!
! // Finesse static init order hassles
! __classic_locale = new locale(_S_classic);
}
catch(...)
{
! delete __classic_locale;
if (_S_classic)
! {
! _S_classic->_M_remove_reference();
! _S_global->_M_remove_reference();
! }
_S_classic = _S_global = 0;
- // XXX MT
__throw_exception_again;
}
}
! return *__classic_locale;
}
locale::category
--- 462,482 ----
{
// 26 Standard facets, 2 references.
// One reference for _M_classic, one for _M_global
! _S_classic = new (&locale_impl_c) _Impl("C", 2);
_S_global = _S_classic;
! new (&locale_c) locale(_S_classic);
}
catch(...)
{
! // Just call destructor, so that locale_impl_c's memory is
! // not deallocated via a call to delete.
if (_S_classic)
! _S_classic->~_Impl();
_S_classic = _S_global = 0;
__throw_exception_again;
}
}
! return locale_c;
}
locale::category
*************** namespace std
*** 518,525 ****
}
locale::facet::
! facet(size_t __refs) throw()
! : _M_references(__refs)
{ }
void
--- 521,527 ----
}
locale::facet::
! facet(size_t __refs) throw() : _M_references(__refs)
{ }
void
*************** namespace std
*** 531,542 ****
locale::facet::
_M_remove_reference() throw()
{
! if (_M_references)
! --_M_references;
! else
{
try
! { delete this; } // XXX MT
catch (...)
{ }
}
--- 533,542 ----
locale::facet::
_M_remove_reference() throw()
{
! if (_M_references-- == 0)
{
try
! { delete this; }
catch (...)
{ }
}