Commit 831a3a9e by Jonathan Wakely Committed by Jonathan Wakely

re PR target/64368 (Several libstdc++ test failures on non-linux platforms after r218964.)

	PR libstdc++/64368
	* config/locale/gnu/numeric_members.cc (numpunct<char>::~numpunct(),
	numpunct<wchar_t>::~numpunct()): Do not set _M_data->_M_grouping.
	* src/c++11/cxx11-shim_facets.cc (numpunct_shim): Remove _M_grouping
	and use cache's _M_grouping field.
	(__numpunct_fill_cache): Likewise.
	(__moneypunct_fill_cache): Improve comments.

From-SVN: r220143
parent 26570a9b
2015-01-26 Jonathan Wakely <jwakely@redhat.com> 2015-01-26 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/64368
* config/locale/gnu/numeric_members.cc (numpunct<char>::~numpunct(),
numpunct<wchar_t>::~numpunct()): Do not set _M_data->_M_grouping.
* src/c++11/cxx11-shim_facets.cc (numpunct_shim): Remove _M_grouping
and use cache's _M_grouping field.
(__numpunct_fill_cache): Likewise.
(__moneypunct_fill_cache): Improve comments.
2015-01-26 Jonathan Wakely <jwakely@redhat.com>
* testsuite/23_containers/set/operations/2.cc: Add test for * testsuite/23_containers/set/operations/2.cc: Add test for
non-transparent comparison function. non-transparent comparison function.
......
...@@ -117,7 +117,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -117,7 +117,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ {
if (_M_data->_M_grouping_size) if (_M_data->_M_grouping_size)
delete [] _M_data->_M_grouping; delete [] _M_data->_M_grouping;
_M_data->_M_grouping = 0;
delete _M_data; delete _M_data;
} }
...@@ -210,7 +209,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -210,7 +209,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ {
if (_M_data->_M_grouping_size) if (_M_data->_M_grouping_size)
delete [] _M_data->_M_grouping; delete [] _M_data->_M_grouping;
_M_data->_M_grouping = 0;
delete _M_data; delete _M_data;
} }
#endif #endif
......
...@@ -170,8 +170,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -170,8 +170,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename C> template<typename C>
void void
__numpunct_fill_cache(other_abi, const facet*, __numpunct_cache<C>*, __numpunct_fill_cache(other_abi, const facet*, __numpunct_cache<C>*);
const char*&, size_t&);
template<typename C> template<typename C>
int int
...@@ -235,24 +234,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -235,24 +234,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
numpunct_shim(const facet* f, __cache_type* c = new __cache_type) numpunct_shim(const facet* f, __cache_type* c = new __cache_type)
: std::numpunct<_CharT>(c), __shim(f), _M_cache(c) : std::numpunct<_CharT>(c), __shim(f), _M_cache(c)
{ {
__numpunct_fill_cache(other_abi{}, f, c, _M_grouping, __numpunct_fill_cache(other_abi{}, f, c);
_M_grouping_size);
} }
~numpunct_shim() { delete[] _M_grouping; } ~numpunct_shim()
{
virtual string // Stop GNU locale's ~numpunct() from freeing the cached string.
do_grouping() const _M_cache->_M_grouping_size = 0;
{ return string(_M_grouping, _M_grouping_size); } }
// No need to override other virtual functions, the base definitions // No need to override any virtual functions, the base definitions
// will return the cached data. // will return the cached data.
__cache_type* _M_cache; __cache_type* _M_cache;
// numpunct uses __numpunct_cache<C>::_M_grouping for its own purposes
// so we can't store that in the cache
const char* _M_grouping;
size_t _M_grouping_size;
}; };
template<typename _CharT> template<typename _CharT>
...@@ -348,7 +342,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -348,7 +342,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
~moneypunct_shim() ~moneypunct_shim()
{ {
// stop GNU locale's ~moneypunct() from freeing these strings // Stop GNU locale's ~moneypunct() from freeing the cached strings.
_M_cache->_M_grouping_size = 0; _M_cache->_M_grouping_size = 0;
_M_cache->_M_curr_symbol_size = 0; _M_cache->_M_curr_symbol_size = 0;
_M_cache->_M_positive_sign_size = 0; _M_cache->_M_positive_sign_size = 0;
...@@ -497,37 +491,36 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -497,37 +491,36 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Now define and instantiate the functions that will be called by the // Now define and instantiate the functions that will be called by the
// shim facets defined when this file is recompiled for the other ABI. // shim facets defined when this file is recompiled for the other ABI.
// Cache the values returned by the numpunct facet f.
// Sets c->_M_allocated so that the __numpunct_cache destructor will
// delete[] the strings allocated by this function.
template<typename C> template<typename C>
void void
__numpunct_fill_cache(current_abi, const facet* f, __numpunct_cache<C>* c, __numpunct_fill_cache(current_abi, const facet* f, __numpunct_cache<C>* c)
const char*& grouping, size_t& grouping_size)
{ {
auto* m = static_cast<const numpunct<C>*>(f); auto* m = static_cast<const numpunct<C>*>(f);
c->_M_decimal_point = m->decimal_point(); c->_M_decimal_point = m->decimal_point();
c->_M_thousands_sep = m->thousands_sep(); c->_M_thousands_sep = m->thousands_sep();
c->_M_grouping = nullptr;
c->_M_truename = nullptr; c->_M_truename = nullptr;
c->_M_falsename = nullptr; c->_M_falsename = nullptr;
// set _M_allocated so that if any allocation fails the previously // set _M_allocated so that if any allocation fails the previously
// allocated strings will be deleted in ~__numpunct_c() // allocated strings will be deleted in ~__numpunct_cache()
c->_M_allocated = true; c->_M_allocated = true;
c->_M_grouping_size = __copy(c->_M_grouping, m->grouping());
c->_M_truename_size = __copy(c->_M_truename, m->truename()); c->_M_truename_size = __copy(c->_M_truename, m->truename());
c->_M_falsename_size = __copy(c->_M_falsename, m->falsename()); c->_M_falsename_size = __copy(c->_M_falsename, m->falsename());
// Set grouping last as it is only deleted by ~numpunct_shim() which
// won't run if this function throws an exception.
grouping_size = __copy(grouping, m->grouping());
} }
template void template void
__numpunct_fill_cache(current_abi, const facet*, __numpunct_cache<char>*, __numpunct_fill_cache(current_abi, const facet*, __numpunct_cache<char>*);
const char*&, size_t&);
#ifdef _GLIBCXX_USE_WCHAR_T #ifdef _GLIBCXX_USE_WCHAR_T
template void template void
__numpunct_fill_cache(current_abi, const facet*, __numpunct_cache<wchar_t>*, __numpunct_fill_cache(current_abi, const facet*, __numpunct_cache<wchar_t>*);
const char*&, size_t&);
#endif #endif
template<typename C> template<typename C>
...@@ -567,6 +560,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -567,6 +560,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
const wchar_t*, const wchar_t*); const wchar_t*, const wchar_t*);
#endif #endif
// Cache the values returned by the moneypunct facet, f.
// Sets c->_M_allocated so that the __moneypunct_cache destructor will
// delete[] the strings allocated by this function.
template<typename C, bool Intl> template<typename C, bool Intl>
void void
__moneypunct_fill_cache(current_abi, const facet* f, __moneypunct_fill_cache(current_abi, const facet* f,
...@@ -582,8 +578,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -582,8 +578,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
c->_M_curr_symbol = nullptr; c->_M_curr_symbol = nullptr;
c->_M_positive_sign = nullptr; c->_M_positive_sign = nullptr;
c->_M_negative_sign = nullptr; c->_M_negative_sign = nullptr;
// set _M_allocated so that if any allocation fails the previously // Set _M_allocated so that if any allocation fails the previously
// allocated strings will be deleted in ~__moneypunct_c() // allocated strings will be deleted in ~__moneypunct_cache().
c->_M_allocated = true; c->_M_allocated = true;
c->_M_grouping_size = __copy(c->_M_grouping, m->grouping()); c->_M_grouping_size = __copy(c->_M_grouping, m->grouping());
......
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