Commit 603aec67 by Jonathan Wakely Committed by Jonathan Wakely

Adjust extension types to use allocator_traits

This makes these extensions work with types meeting the Cpp17Allocator
requirements as well as the C++98 Allocator requirements.

	* include/backward/hash_set (hash_set): Use __alloc_traits.
	* include/backward/hashtable.h (_Hashtable): Likewise.
	* include/ext/alloc_traits.h (__alloc_traits::allocate): Add overload
	taking a hint.
	* include/ext/extptr_allocator.h (_ExtPtr_allocator::allocate): Ignore
	hint.
	* include/ext/slist (_Slist_base): Use __alloc_traits.
	* include/tr1/hashtable.h (_Hashtable): Likewise.
	* include/tr1/regex (match_results): Use vector::const_reference
	instead of assuming the allocator defines it.
	* testsuite/backward/hash_map/23528.cc: Use allocator_traits in C++11.
	* testsuite/tr1/6_containers/unordered_map/capacity/29134-map.cc: Use
	__gnu_test::max_size.
	* testsuite/tr1/6_containers/unordered_multimap/capacity/
	29134-multimap.cc: Likewise.
	* testsuite/tr1/6_containers/unordered_multiset/capacity/
	29134-multiset.cc: Likewise.
	* testsuite/tr1/6_containers/unordered_set/capacity/29134-set.cc:
	Likewise.

From-SVN: r277335
parent 2ccbd21d
2019-10-23 Jonathan Wakely <jwakely@redhat.com>
* include/backward/hash_set (hash_set): Use __alloc_traits.
* include/backward/hashtable.h (_Hashtable): Likewise.
* include/ext/alloc_traits.h (__alloc_traits::allocate): Add overload
taking a hint.
* include/ext/extptr_allocator.h (_ExtPtr_allocator::allocate): Ignore
hint.
* include/ext/slist (_Slist_base): Use __alloc_traits.
* include/tr1/hashtable.h (_Hashtable): Likewise.
* include/tr1/regex (match_results): Use vector::const_reference
instead of assuming the allocator defines it.
* testsuite/backward/hash_map/23528.cc: Use allocator_traits in C++11.
* testsuite/tr1/6_containers/unordered_map/capacity/29134-map.cc: Use
__gnu_test::max_size.
* testsuite/tr1/6_containers/unordered_multimap/capacity/
29134-multimap.cc: Likewise.
* testsuite/tr1/6_containers/unordered_multiset/capacity/
29134-multiset.cc: Likewise.
* testsuite/tr1/6_containers/unordered_set/capacity/29134-set.cc:
Likewise.
2019-10-22 Jonathan Wakely <jwakely@redhat.com> 2019-10-22 Jonathan Wakely <jwakely@redhat.com>
* testsuite/util/testsuite_abi.h: Restore use of tr1/unordered_map * testsuite/util/testsuite_abi.h: Restore use of tr1/unordered_map
......
...@@ -88,6 +88,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -88,6 +88,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__glibcxx_class_requires3(_HashFcn, size_t, _Value, _UnaryFunctionConcept) __glibcxx_class_requires3(_HashFcn, size_t, _Value, _UnaryFunctionConcept)
__glibcxx_class_requires3(_EqualKey, _Value, _Value, _BinaryPredicateConcept) __glibcxx_class_requires3(_EqualKey, _Value, _Value, _BinaryPredicateConcept)
typedef __alloc_traits<_Alloc> _Alloc_traits;
private: private:
typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>, typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>,
_EqualKey, _Alloc> _Ht; _EqualKey, _Alloc> _Ht;
...@@ -101,10 +103,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -101,10 +103,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
typedef typename _Ht::size_type size_type; typedef typename _Ht::size_type size_type;
typedef typename _Ht::difference_type difference_type; typedef typename _Ht::difference_type difference_type;
typedef typename _Alloc::pointer pointer; typedef typename _Alloc_traits::pointer pointer;
typedef typename _Alloc::const_pointer const_pointer; typedef typename _Alloc_traits::const_pointer const_pointer;
typedef typename _Alloc::reference reference; typedef typename _Alloc_traits::reference reference;
typedef typename _Alloc::const_reference const_reference; typedef typename _Alloc_traits::const_reference const_reference;
typedef typename _Ht::const_iterator iterator; typedef typename _Ht::const_iterator iterator;
typedef typename _Ht::const_iterator const_iterator; typedef typename _Ht::const_iterator const_iterator;
......
...@@ -63,6 +63,7 @@ ...@@ -63,6 +63,7 @@
#include <iterator> #include <iterator>
#include <algorithm> #include <algorithm>
#include <bits/stl_function.h> #include <bits/stl_function.h>
#include <ext/alloc_traits.h>
#include <backward/hash_fun.h> #include <backward/hash_fun.h>
namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
...@@ -280,14 +281,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -280,14 +281,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
typedef _Hashtable_node<_Val> _Node; typedef _Hashtable_node<_Val> _Node;
public: public:
typedef typename _Alloc::template rebind<value_type>::other allocator_type; typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
rebind<value_type>::other allocator_type;
allocator_type allocator_type
get_allocator() const get_allocator() const
{ return _M_node_allocator; } { return _M_node_allocator; }
private: private:
typedef typename _Alloc::template rebind<_Node>::other _Node_Alloc; typedef __gnu_cxx::__alloc_traits<allocator_type> _Alloc_traits;
typedef typename _Alloc::template rebind<_Node*>::other _Nodeptr_Alloc; typedef typename _Alloc_traits::template rebind<_Node>::other
_Node_Alloc;
typedef typename _Alloc_traits::template rebind<_Node*>::other
_Nodeptr_Alloc;
typedef std::vector<_Node*, _Nodeptr_Alloc> _Vector_type; typedef std::vector<_Node*, _Nodeptr_Alloc> _Vector_type;
_Node_Alloc _M_node_allocator; _Node_Alloc _M_node_allocator;
...@@ -608,7 +614,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -608,7 +614,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__n->_M_next = 0; __n->_M_next = 0;
__try __try
{ {
this->get_allocator().construct(&__n->_M_val, __obj); allocator_type __a = this->get_allocator();
_Alloc_traits::construct(__a, &__n->_M_val, __obj);
return __n; return __n;
} }
__catch(...) __catch(...)
...@@ -621,7 +628,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -621,7 +628,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
void void
_M_delete_node(_Node* __n) _M_delete_node(_Node* __n)
{ {
this->get_allocator().destroy(&__n->_M_val); allocator_type __a = this->get_allocator();
_Alloc_traits::destroy(__a, &__n->_M_val);
_M_put_node(__n); _M_put_node(__n);
} }
......
...@@ -132,6 +132,11 @@ template<typename _Alloc, typename = typename _Alloc::value_type> ...@@ -132,6 +132,11 @@ template<typename _Alloc, typename = typename _Alloc::value_type>
allocate(_Alloc& __a, size_type __n) allocate(_Alloc& __a, size_type __n)
{ return __a.allocate(__n); } { return __a.allocate(__n); }
template<typename _Hint>
_GLIBCXX_NODISCARD static pointer
allocate(_Alloc& __a, size_type __n, _Hint __hint)
{ return __a.allocate(__n, __hint); }
static void deallocate(_Alloc& __a, pointer __p, size_type __n) static void deallocate(_Alloc& __a, pointer __p, size_type __n)
{ __a.deallocate(__p, __n); } { __a.deallocate(__p, __n); }
......
...@@ -92,8 +92,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -92,8 +92,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
const_pointer address(const_reference __x) const _GLIBCXX_NOEXCEPT const_pointer address(const_reference __x) const _GLIBCXX_NOEXCEPT
{ return std::__addressof(__x); } { return std::__addressof(__x); }
_GLIBCXX_NODISCARD pointer allocate(size_type __n, void* __hint = 0) _GLIBCXX_NODISCARD pointer allocate(size_type __n, const void* = 0)
{ return _M_real_alloc.allocate(__n,__hint); } { return _M_real_alloc.allocate(__n); }
void deallocate(pointer __p, size_type __n) void deallocate(pointer __p, size_type __n)
{ _M_real_alloc.deallocate(__p.get(), __n); } { _M_real_alloc.deallocate(__p.get(), __n); }
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include <bits/stl_construct.h> #include <bits/stl_construct.h>
#include <bits/stl_uninitialized.h> #include <bits/stl_uninitialized.h>
#include <bits/concept_check.h> #include <bits/concept_check.h>
#include <ext/alloc_traits.h>
namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
{ {
...@@ -251,7 +252,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -251,7 +252,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Slist_node<_Tp>* __next = (_Slist_node<_Tp>*) (__pos->_M_next); _Slist_node<_Tp>* __next = (_Slist_node<_Tp>*) (__pos->_M_next);
_Slist_node_base* __next_next = __next->_M_next; _Slist_node_base* __next_next = __next->_M_next;
__pos->_M_next = __next_next; __pos->_M_next = __next_next;
get_allocator().destroy(&__next->_M_data); allocator_type __a = get_allocator();
__alloc_traits<allocator_type>::destroy(__a, &__next->_M_data);
_M_put_node(__next); _M_put_node(__next);
return __next_next; return __next_next;
} }
...@@ -268,7 +270,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -268,7 +270,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ {
_Slist_node<_Tp>* __tmp = __cur; _Slist_node<_Tp>* __tmp = __cur;
__cur = (_Slist_node<_Tp>*) __cur->_M_next; __cur = (_Slist_node<_Tp>*) __cur->_M_next;
get_allocator().destroy(&__tmp->_M_data); allocator_type __a = get_allocator();
__alloc_traits<allocator_type>::destroy(__a, &__tmp->_M_data);
_M_put_node(__tmp); _M_put_node(__tmp);
} }
__before_first->_M_next = __last_node; __before_first->_M_next = __last_node;
...@@ -318,7 +321,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -318,7 +321,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Node* __node = this->_M_get_node(); _Node* __node = this->_M_get_node();
__try __try
{ {
get_allocator().construct(&__node->_M_data, __x); allocator_type __a = get_allocator();
__alloc_traits<allocator_type>::construct(__a, &__node->_M_data,
__x);
__node->_M_next = 0; __node->_M_next = 0;
} }
__catch(...) __catch(...)
...@@ -335,7 +340,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -335,7 +340,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Node* __node = this->_M_get_node(); _Node* __node = this->_M_get_node();
__try __try
{ {
get_allocator().construct(&__node->_M_data, value_type()); allocator_type __a = get_allocator();
__alloc_traits<allocator_type>::construct(__a, &__node->_M_data,
value_type());
__node->_M_next = 0; __node->_M_next = 0;
} }
__catch(...) __catch(...)
...@@ -481,7 +488,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -481,7 +488,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ {
_Node* __node = (_Node*) this->_M_head._M_next; _Node* __node = (_Node*) this->_M_head._M_next;
this->_M_head._M_next = __node->_M_next; this->_M_head._M_next = __node->_M_next;
get_allocator().destroy(&__node->_M_data); allocator_type __a = get_allocator();
__alloc_traits<allocator_type>::destroy(__a, &__node->_M_data);
this->_M_put_node(__node); this->_M_put_node(__node);
} }
......
...@@ -126,6 +126,8 @@ namespace tr1 ...@@ -126,6 +126,8 @@ namespace tr1
__constant_iterators, __constant_iterators,
__unique_keys> > __unique_keys> >
{ {
typedef __gnu_cxx::__alloc_traits<_Allocator> _Alloc_traits;
public: public:
typedef _Allocator allocator_type; typedef _Allocator allocator_type;
typedef _Value value_type; typedef _Value value_type;
...@@ -135,10 +137,10 @@ namespace tr1 ...@@ -135,10 +137,10 @@ namespace tr1
// hasher, if present, comes from _Hash_code_base. // hasher, if present, comes from _Hash_code_base.
typedef typename _Allocator::difference_type difference_type; typedef typename _Allocator::difference_type difference_type;
typedef typename _Allocator::size_type size_type; typedef typename _Allocator::size_type size_type;
typedef typename _Allocator::pointer pointer; typedef typename _Alloc_traits::pointer pointer;
typedef typename _Allocator::const_pointer const_pointer; typedef typename _Alloc_traits::const_pointer const_pointer;
typedef typename _Allocator::reference reference; typedef typename _Alloc_traits::reference reference;
typedef typename _Allocator::const_reference const_reference; typedef typename _Alloc_traits::const_reference const_reference;
typedef __detail::_Node_iterator<value_type, __constant_iterators, typedef __detail::_Node_iterator<value_type, __constant_iterators,
__cache_hash_code> __cache_hash_code>
...@@ -162,13 +164,13 @@ namespace tr1 ...@@ -162,13 +164,13 @@ namespace tr1
private: private:
typedef __detail::_Hash_node<_Value, __cache_hash_code> _Node; typedef __detail::_Hash_node<_Value, __cache_hash_code> _Node;
typedef typename _Allocator::template rebind<_Node>::other typedef typename _Alloc_traits::template rebind<_Node>::other
_Node_allocator_type; _Node_allocator_type;
typedef typename _Allocator::template rebind<_Node*>::other typedef typename _Alloc_traits::template rebind<_Node*>::other
_Bucket_allocator_type; _Bucket_allocator_type;
typedef typename _Allocator::template rebind<_Value>::other typedef typename _Alloc_traits::template rebind<_Value>::other
_Value_allocator_type; _Value_allocator_type;
_Node_allocator_type _M_node_allocator; _Node_allocator_type _M_node_allocator;
_Node** _M_buckets; _Node** _M_buckets;
...@@ -259,7 +261,10 @@ namespace tr1 ...@@ -259,7 +261,10 @@ namespace tr1
size_type size_type
max_size() const max_size() const
{ return _M_node_allocator.max_size(); } {
typedef __gnu_cxx::__alloc_traits<_Node_allocator_type> _Traits;
return _Traits::max_size(_M_node_allocator);
}
// Observers // Observers
key_equal key_equal
......
...@@ -1789,7 +1789,7 @@ namespace regex_constants ...@@ -1789,7 +1789,7 @@ namespace regex_constants
*/ */
//@{ //@{
typedef sub_match<_Bi_iter> value_type; typedef sub_match<_Bi_iter> value_type;
typedef typename _Allocator::const_reference const_reference; typedef typename _Base_type::const_reference const_reference;
typedef const_reference reference; typedef const_reference reference;
typedef typename _Base_type::const_iterator const_iterator; typedef typename _Base_type::const_iterator const_iterator;
typedef const_iterator iterator; typedef const_iterator iterator;
......
...@@ -30,9 +30,13 @@ void test01() ...@@ -30,9 +30,13 @@ void test01()
__gnu_cxx::hash_map<int, int>::value_type *y = a.allocate(1); __gnu_cxx::hash_map<int, int>::value_type *y = a.allocate(1);
#if __cplusplus >= 201103L
std::allocator_traits<decltype(a)>::construct(a, y, *m.begin());
std::allocator_traits<decltype(a)>::destroy(a, y);
#else
a.construct(y, *m.begin()); a.construct(y, *m.begin());
a.destroy(y); a.destroy(y);
#endif
a.deallocate(y, 1); a.deallocate(y, 1);
} }
......
...@@ -19,14 +19,16 @@ ...@@ -19,14 +19,16 @@
#include <tr1/unordered_map> #include <tr1/unordered_map>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_allocator.h>
// libstdc++/29134 // libstdc++/29134
void test01() void test01()
{ {
std::tr1::unordered_map<int, int> um; std::tr1::unordered_map<int, int> um;
VERIFY( (um.max_size() == std::allocator<std::tr1::__detail::_Hash_node< std::allocator<std::tr1::__detail::_Hash_node<std::pair<const int, int>,
std::pair<const int, int>, false> >().max_size())); false> > a;
VERIFY( um.max_size() == __gnu_test::max_size(a) );
} }
int main() int main()
......
...@@ -19,14 +19,16 @@ ...@@ -19,14 +19,16 @@
#include <tr1/unordered_map> #include <tr1/unordered_map>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_allocator.h>
// libstdc++/29134 // libstdc++/29134
void test01() void test01()
{ {
std::tr1::unordered_multimap<int, int> umm; std::tr1::unordered_multimap<int, int> umm;
VERIFY( (umm.max_size() == std::allocator<std::tr1::__detail::_Hash_node< std::allocator<std::tr1::__detail::_Hash_node<std::pair<const int, int>,
std::pair<const int, int>, false> >().max_size()) ); false> > a;
VERIFY( umm.max_size() == __gnu_test::max_size(a) );
} }
int main() int main()
......
...@@ -19,14 +19,15 @@ ...@@ -19,14 +19,15 @@
#include <tr1/unordered_set> #include <tr1/unordered_set>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_allocator.h>
// libstdc++/29134 // libstdc++/29134
void test01() void test01()
{ {
std::tr1::unordered_multiset<int> ums; std::tr1::unordered_multiset<int> ums;
VERIFY( (ums.max_size() == std::allocator<std::tr1::__detail::_Hash_node< std::allocator<std::tr1::__detail::_Hash_node<int, false> > a;
int, false> >().max_size()) ); VERIFY( ums.max_size() == __gnu_test::max_size(a) );
} }
int main() int main()
......
...@@ -19,14 +19,15 @@ ...@@ -19,14 +19,15 @@
#include <tr1/unordered_set> #include <tr1/unordered_set>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_allocator.h>
// libstdc++/29134 // libstdc++/29134
void test01() void test01()
{ {
std::tr1::unordered_set<int> us; std::tr1::unordered_set<int> us;
VERIFY( (us.max_size() == std::allocator<std::tr1::__detail::_Hash_node< std::allocator<std::tr1::__detail::_Hash_node<int, false> > a;
int, false> >().max_size()) ); VERIFY( us.max_size() == __gnu_test::max_size(a) );
} }
int main() int main()
......
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