Commit 1f46fc8e by Benjamin Kosnik Committed by Benjamin Kosnik

localefwd.h: Format.


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.

From-SVN: r43747
parent ec97333e
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
......
......@@ -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);
}
......
......@@ -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
......@@ -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
}
......@@ -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()
......
......@@ -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 (...)
{ }
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment