~_Impl() throw()
{
// Clean up facets, then caches. No cache refcounts for now.
- for (size_t __i = 0; __i < _M_facets_size; ++__i)
- if (_M_facets[__i])
- _M_facets[__i]->_M_remove_reference();
- for (size_t __i = _M_facets_size; __i < 2*_M_facets_size; ++__i)
- if (_M_facets[__i])
- delete (__locale_cache_base*)_M_facets[__i];
+ if (_M_facets)
+ {
+ for (size_t __i = 0; __i < _M_facets_size; ++__i)
+ if (_M_facets[__i])
+ _M_facets[__i]->_M_remove_reference();
+
+ for (size_t __i = _M_facets_size; __i < 2*_M_facets_size; ++__i)
+ if (_M_facets[__i])
+ delete (__locale_cache_base*)_M_facets[__i];
+ }
delete [] _M_facets;
for (size_t __i = 0;
__i < _S_categories_size + _S_extra_categories_size; ++__i)
- delete [] _M_names[__i];
+ delete [] _M_names[__i];
}
// Clone existing _Impl object.
_Impl(const _Impl& __imp, size_t __refs)
: _M_references(__refs), _M_facets_size(__imp._M_facets_size) // XXX
{
+ _M_facets = 0;
+ for (size_t __i = 0; __i < _S_categories_size
+ + _S_extra_categories_size; ++__i)
+ _M_names[__i] = 0;
try
{
// Space for facets and matching caches
_M_facets = new facet*[2*_M_facets_size];
for (size_t __i = 0; __i < 2*_M_facets_size; ++__i)
_M_facets[__i] = 0;
+ for (size_t __i = 0; __i < _M_facets_size; ++__i)
+ {
+ _M_facets[__i] = __imp._M_facets[__i];
+ if (_M_facets[__i])
+ _M_facets[__i]->_M_add_reference();
+ }
+ for (size_t __i = 0;
+ __i < _S_categories_size + _S_extra_categories_size; ++__i)
+ {
+ char* __new = new char[strlen(__imp._M_names[__i]) + 1];
+ strcpy(__new, __imp._M_names[__i]);
+ _M_names[__i] = __new;
+ }
}
- catch(...)
- {
- delete [] _M_facets;
- __throw_exception_again;
- }
- for (size_t __i = 0; __i < _M_facets_size; ++__i)
- {
- _M_facets[__i] = __imp._M_facets[__i];
- if (_M_facets[__i])
- _M_facets[__i]->_M_add_reference();
- }
- for (size_t __i = 0;
- __i < _S_categories_size + _S_extra_categories_size; ++__i)
+ catch(...)
{
- char* __new = new char[strlen(__imp._M_names[__i]) + 1];
- strcpy(__new, __imp._M_names[__i]);
- _M_names[__i] = __new;
+ this->~_Impl();
+ __throw_exception_again;
}
}
__c_locale __cloc;
locale::facet::_S_create_c_locale(__cloc, __s);
+ _M_facets = 0;
+ for (size_t __i = 0; __i < _S_categories_size
+ + _S_extra_categories_size; ++__i)
+ _M_names[__i] = 0;
try
{
// Space for facets and matching caches
_M_facets = new facet*[2*_M_facets_size];
for (size_t __i = 0; __i < 2*_M_facets_size; ++__i)
_M_facets[__i] = 0;
- }
- catch(...)
- {
- delete [] _M_facets;
- __throw_exception_again;
- }
- // Name all the categories.
- size_t __len = strlen(__s);
- if (!strchr(__s, ';'))
- {
- for (size_t __i = 0;
- __i < _S_categories_size + _S_extra_categories_size; ++__i)
+ // Name all the categories.
+ size_t __len = strlen(__s);
+ if (!strchr(__s, ';'))
{
- _M_names[__i] = new char[__len + 1];
- strcpy(_M_names[__i], __s);
+ for (size_t __i = 0;
+ __i < _S_categories_size + _S_extra_categories_size; ++__i)
+ {
+ _M_names[__i] = new char[__len + 1];
+ strcpy(_M_names[__i], __s);
+ }
}
- }
- else
- {
- const char* __beg = __s;
- for (size_t __i = 0;
- __i < _S_categories_size + _S_extra_categories_size; ++__i)
+ else
{
- __beg = strchr(__beg, '=') + 1;
- const char* __end = strchr(__beg, ';');
- if (!__end)
- __end = __s + __len;
- char* __new = new char[__end - __beg + 1];
- memcpy(__new, __beg, __end - __beg);
- __new[__end - __beg] = '\0';
- _M_names[__i] = __new;
+ const char* __beg = __s;
+ for (size_t __i = 0;
+ __i < _S_categories_size + _S_extra_categories_size; ++__i)
+ {
+ __beg = strchr(__beg, '=') + 1;
+ const char* __end = strchr(__beg, ';');
+ if (!__end)
+ __end = __s + __len;
+ char* __new = new char[__end - __beg + 1];
+ memcpy(__new, __beg, __end - __beg);
+ __new[__end - __beg] = '\0';
+ _M_names[__i] = __new;
+ }
}
- }
- // Construct all standard facets and add them to _M_facets.
- _M_init_facet(new std::ctype<char>(__cloc, 0, false));
- _M_init_facet(new codecvt<char, char, mbstate_t>);
- _M_init_facet(new numpunct<char>(__cloc));
- _M_init_facet(new num_get<char>);
- _M_init_facet(new num_put<char>);
- _M_init_facet(new std::collate<char>(__cloc));
- _M_init_facet(new moneypunct<char, false>(__cloc, __s));
- _M_init_facet(new moneypunct<char, true>(__cloc, __s));
- _M_init_facet(new money_get<char>);
- _M_init_facet(new money_put<char>);
- _M_init_facet(new __timepunct<char>(__cloc, __s));
- _M_init_facet(new time_get<char>);
- _M_init_facet(new time_put<char>);
- _M_init_facet(new std::messages<char>(__cloc, __s));
+ // Construct all standard facets and add them to _M_facets.
+ _M_init_facet(new std::ctype<char>(__cloc, 0, false));
+ _M_init_facet(new codecvt<char, char, mbstate_t>);
+ _M_init_facet(new numpunct<char>(__cloc));
+ _M_init_facet(new num_get<char>);
+ _M_init_facet(new num_put<char>);
+ _M_init_facet(new std::collate<char>(__cloc));
+ _M_init_facet(new moneypunct<char, false>(__cloc, __s));
+ _M_init_facet(new moneypunct<char, true>(__cloc, __s));
+ _M_init_facet(new money_get<char>);
+ _M_init_facet(new money_put<char>);
+ _M_init_facet(new __timepunct<char>(__cloc, __s));
+ _M_init_facet(new time_get<char>);
+ _M_init_facet(new time_put<char>);
+ _M_init_facet(new std::messages<char>(__cloc, __s));
#ifdef _GLIBCPP_USE_WCHAR_T
- _M_init_facet(new std::ctype<wchar_t>(__cloc));
- _M_init_facet(new codecvt<wchar_t, char, mbstate_t>);
- _M_init_facet(new numpunct<wchar_t>(__cloc));
- _M_init_facet(new num_get<wchar_t>);
- _M_init_facet(new num_put<wchar_t>);
- _M_init_facet(new std::collate<wchar_t>(__cloc));
- _M_init_facet(new moneypunct<wchar_t, false>(__cloc, __s));
- _M_init_facet(new moneypunct<wchar_t, true>(__cloc, __s));
- _M_init_facet(new money_get<wchar_t>);
- _M_init_facet(new money_put<wchar_t>);
- _M_init_facet(new __timepunct<wchar_t>(__cloc, __s));
- _M_init_facet(new time_get<wchar_t>);
- _M_init_facet(new time_put<wchar_t>);
- _M_init_facet(new std::messages<wchar_t>(__cloc, __s));
+ _M_init_facet(new std::ctype<wchar_t>(__cloc));
+ _M_init_facet(new codecvt<wchar_t, char, mbstate_t>);
+ _M_init_facet(new numpunct<wchar_t>(__cloc));
+ _M_init_facet(new num_get<wchar_t>);
+ _M_init_facet(new num_put<wchar_t>);
+ _M_init_facet(new std::collate<wchar_t>(__cloc));
+ _M_init_facet(new moneypunct<wchar_t, false>(__cloc, __s));
+ _M_init_facet(new moneypunct<wchar_t, true>(__cloc, __s));
+ _M_init_facet(new money_get<wchar_t>);
+ _M_init_facet(new money_put<wchar_t>);
+ _M_init_facet(new __timepunct<wchar_t>(__cloc, __s));
+ _M_init_facet(new time_get<wchar_t>);
+ _M_init_facet(new time_put<wchar_t>);
+ _M_init_facet(new std::messages<wchar_t>(__cloc, __s));
#endif
- locale::facet::_S_destroy_c_locale(__cloc);
+ locale::facet::_S_destroy_c_locale(__cloc);
+ }
+ catch(...)
+ {
+ locale::facet::_S_destroy_c_locale(__cloc);
+ this->~_Impl();
+ __throw_exception_again;
+ }
}
// Construct "C" _Impl.
if (strcmp(_M_names[__ix], "*") != 0
&& strcmp(__imp->_M_names[__ix], "*") != 0)
{
- delete [] _M_names[__ix];
char* __new = new char[strlen(__imp->_M_names[__ix]) + 1];
strcpy(__new, __imp->_M_names[__ix]);
+ delete [] _M_names[__ix];
_M_names[__ix] = __new;
}
}