locale_classes.h (locale::_Impl): Change _M_names from fixed size array.

2003-04-27  Benjamin Kosnik  <bkoz@redhat.com>

	* include/bits/locale_classes.h (locale::_Impl): Change _M_names
	from fixed size array.
	(locale): Change _S_categories as well.
	Formatting tweaks.
	* include/bits/locale_facets.tcc: Tweak.
	* config/locale/gnu/c_locale.cc: Assign _S_categories.
	* config/locale/generic/c_locale.cc: Same.
	* src/locale.cc: Tweak.
	* src/globals.cc: Change facet_name to name_vec, add names_c.
	* src/localename.cc: Use them.
	(locale::_Impl::~_Impl): Destroy _M_names.
	(locale::_Impl::_Impl): Create _M_names.

From-SVN: r66147
This commit is contained in:
Benjamin Kosnik 2003-04-28 03:41:49 +00:00 committed by Benjamin Kosnik
parent 0c227849f6
commit 73c4dcc675
8 changed files with 79 additions and 22 deletions

View File

@ -1,3 +1,18 @@
2003-04-27 Benjamin Kosnik <bkoz@redhat.com>
* include/bits/locale_classes.h (locale::_Impl): Change _M_names
from fixed size array.
(locale): Change _S_categories as well.
Formatting tweaks.
* include/bits/locale_facets.tcc: Tweak.
* config/locale/gnu/c_locale.cc: Assign _S_categories.
* config/locale/generic/c_locale.cc: Same.
* src/locale.cc: Tweak.
* src/globals.cc: Change facet_name to name_vec, add names_c.
* src/localename.cc: Use them.
(locale::_Impl::~_Impl): Destroy _M_names.
(locale::_Impl::_Impl): Create _M_names.
2003-04-27 Andreas Schwab <schwab@suse.de>
* config/locale/ieee_1003.1-2001/codecvt_specializations.h

View File

@ -227,8 +227,11 @@ namespace std
__c_locale
locale::facet::_S_clone_c_locale(__c_locale&)
{ return __c_locale(); }
} // namespace std
const char* locale::_S_categories[_S_categories_size] =
namespace __gnu_cxx
{
const char* category_names[6 + _GLIBCPP_NUM_CATEGORIES] =
{
"LC_CTYPE",
"LC_NUMERIC",
@ -237,4 +240,9 @@ namespace std
"LC_MONETARY",
"LC_MESSAGES"
};
}
namespace std
{
const char** locale::_S_categories = __gnu_cxx::category_names;
} // namespace std

View File

@ -186,8 +186,11 @@ namespace std
__c_locale
locale::facet::_S_clone_c_locale(__c_locale& __cloc)
{ return __duplocale(__cloc); }
} // namespace std
const char* locale::_S_categories[_S_categories_size] =
namespace __gnu_cxx
{
const char* category_names[6 + _GLIBCPP_NUM_CATEGORIES] =
{
"LC_CTYPE",
"LC_NUMERIC",
@ -202,4 +205,9 @@ namespace std
"LC_MEASUREMENT",
"LC_IDENTIFICATION"
};
}
namespace std
{
const char** locale::_S_categories = __gnu_cxx::category_names;
} // namespace std

View File

@ -157,7 +157,7 @@ namespace std
// NB: locale::global() has to know how to modify all the
// underlying categories, not just the ones required by the C++
// standard.
static const char* _S_categories[_S_categories_size];
static const char** _S_categories;
explicit
locale(_Impl*) throw();
@ -198,7 +198,7 @@ namespace std
_Atomic_word _M_references;
const facet** _M_facets;
size_t _M_facets_size;
char* _M_names[_S_categories_size];
char** _M_names;
static const locale::id* const _S_id_ctype[];
static const locale::id* const _S_id_numeric[];
static const locale::id* const _S_id_collate[];
@ -266,7 +266,7 @@ namespace std
{
_M_impl = new _Impl(*__other._M_impl, 1);
_M_impl->_M_install_facet(&_Facet::id, __f);
for (size_t __i = 0; __i < _S_categories_size ; ++__i)
for (size_t __i = 0; __i < _S_categories_size; ++__i)
{
delete [] _M_impl->_M_names[__i];
char* __new = new char[2];

View File

@ -2279,7 +2279,7 @@ namespace std
}
if (__builtin_expect(has_facet<ctype<_CharT> >(__loc), true))
{
const ctype<_CharT>& __ct = use_facet< ctype<_CharT> >(__loc);
const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__loc);
__ct.widen(__num_base::_S_atoms_out,
__num_base::_S_atoms_out + __num_base::_S_end,
_M_literals);

View File

@ -95,10 +95,6 @@ namespace __gnu_cxx
fake_wfilebuf buf_wcerr;
#endif
typedef char fake_facet_name[sizeof(char*)]
__attribute__ ((aligned(__alignof__(char*))));
fake_facet_name facet_name[6 + _GLIBCPP_NUM_CATEGORIES];
typedef char fake_locale_Impl[sizeof(locale::_Impl)]
__attribute__ ((aligned(__alignof__(locale::_Impl))));
fake_locale_Impl c_locale_impl;
@ -107,6 +103,14 @@ namespace __gnu_cxx
__attribute__ ((aligned(__alignof__(locale))));
fake_locale c_locale;
typedef char fake_name_vec[sizeof(char*)]
__attribute__ ((aligned(__alignof__(char*))));
fake_name_vec name_vec[6 + _GLIBCPP_NUM_CATEGORIES];
typedef char fake_names[sizeof(char[2])]
__attribute__ ((aligned(__alignof__(char[2]))));
fake_names name_c[6 + _GLIBCPP_NUM_CATEGORIES];
typedef char fake_facet_vec[sizeof(locale::facet*)]
__attribute__ ((aligned(__alignof__(locale::facet*))));
fake_facet_vec facet_vec[_GLIBCPP_NUM_FACETS];

View File

@ -207,7 +207,7 @@ namespace std
// different from LANG.
size_t __i = 0;
if (strcmp(__res, "C") == 0)
for (; __i < _S_categories_size ; ++__i)
for (; __i < _S_categories_size; ++__i)
{
__env = getenv(_S_categories[__i]);
if (__env && strcmp(__env, "") != 0
@ -216,7 +216,7 @@ namespace std
break;
}
else
for (; __i < _S_categories_size ; ++__i)
for (; __i < _S_categories_size; ++__i)
{
__env = getenv(_S_categories[__i]);
if (__env && strcmp(__env, "") != 0
@ -241,7 +241,7 @@ namespace std
__str += __env;
__str += ';';
__i++;
for (; __i < _S_categories_size ; ++__i)
for (; __i < _S_categories_size; ++__i)
{
__env = getenv(_S_categories[__i]);
if (!__env || strcmp(__env, "") == 0)
@ -345,7 +345,7 @@ namespace std
__ret += _S_categories[0];
__ret += '=';
__ret += _M_impl->_M_names[0];
for (size_t __i = 1; __i < _S_categories_size ; ++__i)
for (size_t __i = 1; __i < _S_categories_size; ++__i)
{
__ret += ';';
__ret += _S_categories[__i];

View File

@ -36,7 +36,8 @@ namespace __gnu_cxx
// Defined in globals.cc.
extern locale::facet* facet_vec[_GLIBCPP_NUM_FACETS];
extern char* facet_name[6 + _GLIBCPP_NUM_CATEGORIES];
extern char* name_vec[6 + _GLIBCPP_NUM_CATEGORIES];
extern char name_c[6 + _GLIBCPP_NUM_CATEGORIES][2];
extern std::ctype<char> ctype_c;
extern std::collate<char> collate_c;
@ -82,8 +83,9 @@ namespace std
_M_facets[__i]->_M_remove_reference();
delete [] _M_facets;
for (size_t __i = 0; __i < _S_categories_size ; ++__i)
for (size_t __i = 0; __i < _S_categories_size; ++__i)
delete [] _M_names[__i];
delete [] _M_names;
}
// Clone existing _Impl object.
@ -108,7 +110,17 @@ namespace std
if (_M_facets[__i])
_M_facets[__i]->_M_add_reference();
}
for (size_t __i = 0; __i < _S_categories_size ; ++__i)
try
{
_M_names = new char*[_S_categories_size];
}
catch(...)
{
delete [] _M_names;
__throw_exception_again;
}
for (size_t __i = 0; __i < _S_categories_size; ++__i)
{
char* __new = new char[strlen(__imp._M_names[__i]) + 1];
strcpy(__new, __imp._M_names[__i]);
@ -139,10 +151,19 @@ namespace std
}
// Name all the categories.
try
{
_M_names = new char*[_S_categories_size];
}
catch(...)
{
delete [] _M_names;
__throw_exception_again;
}
size_t __len = strlen(__s);
if (!strchr(__s, ';'))
{
for (size_t __i = 0; __i < _S_categories_size ; ++__i)
for (size_t __i = 0; __i < _S_categories_size; ++__i)
{
_M_names[__i] = new char[__len + 1];
strcpy(_M_names[__i], __s);
@ -151,7 +172,7 @@ namespace std
else
{
const char* __beg = __s;
for (size_t __i = 0; __i < _S_categories_size ; ++__i)
for (size_t __i = 0; __i < _S_categories_size; ++__i)
{
__beg = strchr(__beg, '=') + 1;
const char* __end = strchr(__beg, ';');
@ -210,14 +231,15 @@ namespace std
locale::facet::_S_create_c_locale(locale::facet::_S_c_locale,
locale::facet::_S_c_name);
_M_facets = new(&facet_vec) const facet*[_M_facets_size];
_M_facets = new (&facet_vec) const facet*[_M_facets_size];
for (size_t __i = 0; __i < _M_facets_size; ++__i)
_M_facets[__i] = 0;
// Name all the categories.
for (size_t __i = 0; __i < _S_categories_size ; ++__i)
_M_names = new (&name_vec) char*[_S_categories_size];
for (size_t __i = 0; __i < _S_categories_size; ++__i)
{
_M_names[__i] = new (&facet_name[__i]) char[2];
_M_names[__i] = new (&name_c[__i]) char[2];
strcpy(_M_names[__i], locale::facet::_S_c_name);
}