2003-01-14 05:56:56 +01:00
|
|
|
// -*- C++ -*-
|
2002-11-26 01:53:12 +01:00
|
|
|
// Testing allocator for the C++ library testsuite.
|
|
|
|
//
|
2019-01-01 13:31:55 +01:00
|
|
|
// Copyright (C) 2002-2019 Free Software Foundation, Inc.
|
2002-11-26 01:53:12 +01:00
|
|
|
//
|
|
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
|
|
|
// software; you can redistribute it and/or modify it under the
|
|
|
|
// terms of the GNU General Public License as published by the
|
2009-04-09 17:00:19 +02:00
|
|
|
// Free Software Foundation; either version 3, or (at your option)
|
2002-11-26 01:53:12 +01:00
|
|
|
// any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
2009-04-09 17:00:19 +02:00
|
|
|
// with this library; see the file COPYING3. If not see
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
2002-11-26 01:53:12 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
// This file provides an test instrumentation allocator that can be
|
|
|
|
// used to verify allocation functionality of standard library
|
|
|
|
// containers. 2002.11.25 smw
|
|
|
|
|
2003-07-05 06:05:45 +02:00
|
|
|
#ifndef _GLIBCXX_TESTSUITE_ALLOCATOR_H
|
|
|
|
#define _GLIBCXX_TESTSUITE_ALLOCATOR_H
|
2002-11-26 01:53:12 +01:00
|
|
|
|
2006-01-03 14:19:23 +01:00
|
|
|
#include <tr1/unordered_map>
|
2008-06-21 18:55:17 +02:00
|
|
|
#include <bits/move.h>
|
2013-06-16 19:13:34 +02:00
|
|
|
#include <ext/pointer.h>
|
2014-07-29 21:47:19 +02:00
|
|
|
#include <ext/alloc_traits.h>
|
2011-06-10 19:14:40 +02:00
|
|
|
#include <testsuite_hooks.h>
|
Add initial version of C++17 <memory_resource> header
This is missing the synchronized_pool_resource and
unsynchronized_pool_resource classes but is otherwise complete.
This is a new implementation, not based on the existing code in
<experimental/memory_resource>, but memory_resource and
polymorphic_allocator ended up looking almost the same anyway.
The constant_init kluge in src/c++17/memory_resource.cc is apparently
due to Richard Smith and ensures that the objects are constructed during
constant initialiation phase and not destroyed (because the
constant_init destructor doesn't destroy the union member and the
storage is not reused).
* config/abi/pre/gnu.ver: Export new symbols.
* configure: Regenerate.
* include/Makefile.am: Add new <memory_resource> header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <memory_resource> for C++17.
* include/std/memory_resource: New header.
(memory_resource, polymorphic_allocator, new_delete_resource)
(null_memory_resource, set_default_resource, get_default_resource)
(pool_options, monotonic_buffer_resource): Define.
* src/Makefile.am: Add c++17 directory.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.am: Fix comment.
* src/c++17/Makefile.am: Add makefile for new sub-directory.
* src/c++17/Makefile.in: Generate.
* src/c++17/memory_resource.cc: New.
(newdel_res_t, null_res_t, constant_init, newdel_res, null_res)
(default_res, new_delete_resource, null_memory_resource)
(set_default_resource, get_default_resource): Define.
* testsuite/20_util/memory_resource/1.cc: New test.
* testsuite/20_util/memory_resource/2.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/1.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/deallocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/release.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/upstream_resource.cc:
New test.
* testsuite/20_util/polymorphic_allocator/1.cc: New test.
* testsuite/20_util/polymorphic_allocator/resource.cc: New test.
* testsuite/20_util/polymorphic_allocator/select.cc: New test.
* testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource):
Define concrete memory resource for testing.
(__gnu_test::default_resource_mgr): Define RAII helper for changing
default resource.
From-SVN: r262953
2018-07-24 23:09:55 +02:00
|
|
|
#if __cplusplus >= 201703L
|
|
|
|
# include <memory_resource>
|
|
|
|
# include <new>
|
|
|
|
#endif
|
2002-11-26 01:53:12 +01:00
|
|
|
|
2003-07-24 23:08:03 +02:00
|
|
|
namespace __gnu_test
|
2002-11-26 01:53:12 +01:00
|
|
|
{
|
2006-10-03 19:01:57 +02:00
|
|
|
class tracker_allocator_counter
|
2002-11-26 01:53:12 +01:00
|
|
|
{
|
2003-01-14 05:56:56 +01:00
|
|
|
public:
|
2016-04-29 18:11:43 +02:00
|
|
|
typedef std::size_t size_type;
|
2011-09-02 17:54:16 +02:00
|
|
|
|
2014-07-29 21:47:19 +02:00
|
|
|
static void
|
2003-01-14 05:56:56 +01:00
|
|
|
allocate(size_type blocksize)
|
2014-07-29 21:47:19 +02:00
|
|
|
{ allocationCount_ += blocksize; }
|
2011-09-02 17:54:16 +02:00
|
|
|
|
2003-01-14 05:56:56 +01:00
|
|
|
static void
|
2014-07-29 21:47:19 +02:00
|
|
|
construct() { ++constructCount_; }
|
2002-11-26 01:53:12 +01:00
|
|
|
|
2003-01-14 05:56:56 +01:00
|
|
|
static void
|
2014-07-29 21:47:19 +02:00
|
|
|
destroy() { ++destructCount_; }
|
2002-11-26 01:53:12 +01:00
|
|
|
|
2003-01-14 05:56:56 +01:00
|
|
|
static void
|
2014-07-29 21:47:19 +02:00
|
|
|
deallocate(size_type blocksize)
|
|
|
|
{ deallocationCount_ += blocksize; }
|
2011-09-02 17:54:16 +02:00
|
|
|
|
2003-01-14 05:56:56 +01:00
|
|
|
static size_type
|
2006-10-03 19:01:57 +02:00
|
|
|
get_allocation_count() { return allocationCount_; }
|
2011-09-02 17:54:16 +02:00
|
|
|
|
2003-01-14 05:56:56 +01:00
|
|
|
static size_type
|
2006-10-03 19:01:57 +02:00
|
|
|
get_deallocation_count() { return deallocationCount_; }
|
2011-09-02 17:54:16 +02:00
|
|
|
|
2003-01-14 05:56:56 +01:00
|
|
|
static int
|
2006-10-03 19:01:57 +02:00
|
|
|
get_construct_count() { return constructCount_; }
|
2002-11-26 01:53:12 +01:00
|
|
|
|
2003-01-14 05:56:56 +01:00
|
|
|
static int
|
2006-10-03 19:01:57 +02:00
|
|
|
get_destruct_count() { return destructCount_; }
|
2011-09-02 17:54:16 +02:00
|
|
|
|
2003-01-14 05:56:56 +01:00
|
|
|
static void
|
2006-10-03 19:01:57 +02:00
|
|
|
reset()
|
2003-01-14 05:56:56 +01:00
|
|
|
{
|
2006-10-03 19:01:57 +02:00
|
|
|
allocationCount_ = 0;
|
|
|
|
deallocationCount_ = 0;
|
2003-01-14 05:56:56 +01:00
|
|
|
constructCount_ = 0;
|
2006-10-03 19:01:57 +02:00
|
|
|
destructCount_ = 0;
|
2003-01-14 05:56:56 +01:00
|
|
|
}
|
2002-11-26 01:53:12 +01:00
|
|
|
|
|
|
|
private:
|
2006-10-03 19:01:57 +02:00
|
|
|
static size_type allocationCount_;
|
|
|
|
static size_type deallocationCount_;
|
2003-01-14 05:56:56 +01:00
|
|
|
static int constructCount_;
|
|
|
|
static int destructCount_;
|
|
|
|
};
|
|
|
|
|
2014-07-29 21:47:19 +02:00
|
|
|
// Helper to detect inconsistency between type used to instantiate an
|
|
|
|
// allocator and the underlying allocator value_type.
|
|
|
|
template<typename T, typename Alloc,
|
|
|
|
typename = typename Alloc::value_type>
|
|
|
|
struct check_consistent_alloc_value_type;
|
|
|
|
|
|
|
|
template<typename T, typename Alloc>
|
|
|
|
struct check_consistent_alloc_value_type<T, Alloc, T>
|
|
|
|
{ typedef T value_type; };
|
|
|
|
|
|
|
|
// An allocator facade that intercepts allocate/deallocate/construct/destroy
|
|
|
|
// calls and track them through the tracker_allocator_counter class. This
|
|
|
|
// class is templated on the target object type, but tracker isn't.
|
|
|
|
template<typename T, typename Alloc = std::allocator<T> >
|
|
|
|
class tracker_allocator : public Alloc
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
typedef tracker_allocator_counter counter_type;
|
2002-11-26 01:53:12 +01:00
|
|
|
|
2014-07-29 21:47:19 +02:00
|
|
|
typedef __gnu_cxx::__alloc_traits<Alloc> AllocTraits;
|
2014-06-27 22:03:26 +02:00
|
|
|
|
2014-07-29 21:47:19 +02:00
|
|
|
public:
|
|
|
|
typedef typename
|
|
|
|
check_consistent_alloc_value_type<T, Alloc>::value_type value_type;
|
|
|
|
typedef typename AllocTraits::pointer pointer;
|
|
|
|
typedef typename AllocTraits::size_type size_type;
|
2014-06-27 22:03:26 +02:00
|
|
|
|
2014-07-29 21:47:19 +02:00
|
|
|
template<class U>
|
|
|
|
struct rebind
|
|
|
|
{
|
|
|
|
typedef tracker_allocator<U,
|
|
|
|
typename AllocTraits::template rebind<U>::other> other;
|
|
|
|
};
|
2016-04-29 18:11:43 +02:00
|
|
|
|
2014-07-29 21:47:19 +02:00
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
tracker_allocator() = default;
|
|
|
|
tracker_allocator(const tracker_allocator&) = default;
|
|
|
|
tracker_allocator(tracker_allocator&&) = default;
|
2015-09-11 13:02:14 +02:00
|
|
|
tracker_allocator& operator=(const tracker_allocator&) = default;
|
|
|
|
tracker_allocator& operator=(tracker_allocator&&) = default;
|
2014-07-29 21:47:19 +02:00
|
|
|
|
|
|
|
// Perfect forwarding constructor.
|
|
|
|
template<typename... _Args>
|
|
|
|
tracker_allocator(_Args&&... __args)
|
|
|
|
: Alloc(std::forward<_Args>(__args)...)
|
|
|
|
{ }
|
|
|
|
#else
|
|
|
|
tracker_allocator()
|
|
|
|
{ }
|
2002-11-26 01:53:12 +01:00
|
|
|
|
2014-07-29 21:47:19 +02:00
|
|
|
tracker_allocator(const tracker_allocator&)
|
2014-06-26 20:42:41 +02:00
|
|
|
{ }
|
2002-11-26 01:53:12 +01:00
|
|
|
|
2014-07-29 21:47:19 +02:00
|
|
|
~tracker_allocator()
|
|
|
|
{ }
|
|
|
|
#endif
|
2002-11-26 01:53:12 +01:00
|
|
|
|
2014-07-29 21:47:19 +02:00
|
|
|
template<class U>
|
|
|
|
tracker_allocator(const tracker_allocator<U,
|
|
|
|
typename AllocTraits::template rebind<U>::other>& alloc)
|
|
|
|
_GLIBCXX_USE_NOEXCEPT
|
|
|
|
: Alloc(alloc)
|
|
|
|
{ }
|
2002-11-26 01:53:12 +01:00
|
|
|
|
2014-07-29 21:47:19 +02:00
|
|
|
pointer
|
|
|
|
allocate(size_type n, const void* = 0)
|
|
|
|
{
|
|
|
|
pointer p = AllocTraits::allocate(*this, n);
|
|
|
|
counter_type::allocate(n * sizeof(T));
|
|
|
|
return p;
|
|
|
|
}
|
2014-06-26 20:42:41 +02:00
|
|
|
|
2014-06-27 22:03:26 +02:00
|
|
|
#if __cplusplus >= 201103L
|
2014-07-29 21:47:19 +02:00
|
|
|
template<typename U, typename... Args>
|
|
|
|
void
|
2016-04-29 18:11:43 +02:00
|
|
|
construct(U* p, Args&&... args)
|
2014-07-29 21:47:19 +02:00
|
|
|
{
|
|
|
|
AllocTraits::construct(*this, p, std::forward<Args>(args)...);
|
|
|
|
counter_type::construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename U>
|
|
|
|
void
|
|
|
|
destroy(U* p)
|
|
|
|
{
|
|
|
|
AllocTraits::destroy(*this, p);
|
|
|
|
counter_type::destroy();
|
|
|
|
}
|
|
|
|
#else
|
2011-06-04 19:17:57 +02:00
|
|
|
void
|
2014-07-29 21:47:19 +02:00
|
|
|
construct(pointer p, const T& value)
|
2011-06-04 19:17:57 +02:00
|
|
|
{
|
2014-07-29 21:47:19 +02:00
|
|
|
AllocTraits::construct(*this, p, value);
|
2011-06-04 19:17:57 +02:00
|
|
|
counter_type::construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-29 21:47:19 +02:00
|
|
|
destroy(pointer p)
|
2011-06-04 19:17:57 +02:00
|
|
|
{
|
2014-07-29 21:47:19 +02:00
|
|
|
AllocTraits::destroy(*this, p);
|
2011-06-04 19:17:57 +02:00
|
|
|
counter_type::destroy();
|
|
|
|
}
|
2014-06-27 22:03:26 +02:00
|
|
|
#endif
|
2002-11-26 01:53:12 +01:00
|
|
|
|
2014-07-29 21:47:19 +02:00
|
|
|
void
|
|
|
|
deallocate(pointer p, size_type num)
|
|
|
|
{
|
|
|
|
counter_type::deallocate(num * sizeof(T));
|
|
|
|
AllocTraits::deallocate(*this, p, num);
|
|
|
|
}
|
2014-06-26 20:42:41 +02:00
|
|
|
|
2014-07-29 21:47:19 +02:00
|
|
|
// Implement swap for underlying allocators that might need it.
|
|
|
|
friend inline void
|
|
|
|
swap(tracker_allocator& a, tracker_allocator& b)
|
|
|
|
{
|
|
|
|
using std::swap;
|
|
|
|
|
|
|
|
Alloc& aa = a;
|
|
|
|
Alloc& ab = b;
|
|
|
|
swap(aa, ab);
|
2016-04-29 18:11:43 +02:00
|
|
|
}
|
2014-07-29 21:47:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class T1, class Alloc1, class T2, class Alloc2>
|
2003-01-14 05:56:56 +01:00
|
|
|
bool
|
2016-04-29 18:11:43 +02:00
|
|
|
operator==(const tracker_allocator<T1, Alloc1>& lhs,
|
2014-07-29 21:47:19 +02:00
|
|
|
const tracker_allocator<T2, Alloc2>& rhs) throw()
|
|
|
|
{
|
|
|
|
const Alloc1& alloc1 = lhs;
|
|
|
|
const Alloc2& alloc2 = rhs;
|
2014-11-04 17:54:49 +01:00
|
|
|
return alloc1 == alloc2;
|
2014-07-29 21:47:19 +02:00
|
|
|
}
|
2003-01-14 05:56:56 +01:00
|
|
|
|
2014-07-29 21:47:19 +02:00
|
|
|
template<class T1, class Alloc1, class T2, class Alloc2>
|
2003-01-14 05:56:56 +01:00
|
|
|
bool
|
2016-04-29 18:11:43 +02:00
|
|
|
operator!=(const tracker_allocator<T1, Alloc1>& lhs,
|
2014-07-29 21:47:19 +02:00
|
|
|
const tracker_allocator<T2, Alloc2>& rhs) throw()
|
|
|
|
{ return !(lhs == rhs); }
|
2004-07-28 18:37:20 +02:00
|
|
|
|
2004-09-02 00:17:00 +02:00
|
|
|
bool
|
|
|
|
check_construct_destroy(const char* tag, int expected_c, int expected_d);
|
2004-07-28 18:37:20 +02:00
|
|
|
|
2004-10-15 01:03:26 +02:00
|
|
|
template<typename Alloc>
|
2005-12-28 12:47:56 +01:00
|
|
|
bool
|
2004-10-15 01:03:26 +02:00
|
|
|
check_deallocate_null()
|
|
|
|
{
|
|
|
|
// Let's not core here...
|
2014-07-29 21:47:19 +02:00
|
|
|
Alloc a;
|
2010-06-03 21:15:56 +02:00
|
|
|
a.deallocate(0, 1);
|
|
|
|
a.deallocate(0, 10);
|
2005-12-28 12:47:56 +01:00
|
|
|
return true;
|
2004-10-15 01:03:26 +02:00
|
|
|
}
|
2004-10-21 02:06:02 +02:00
|
|
|
|
|
|
|
template<typename Alloc>
|
2016-04-29 18:11:43 +02:00
|
|
|
bool
|
2004-10-21 02:06:02 +02:00
|
|
|
check_allocate_max_size()
|
|
|
|
{
|
|
|
|
Alloc a;
|
|
|
|
try
|
|
|
|
{
|
2019-01-29 01:47:32 +01:00
|
|
|
(void) a.allocate(a.max_size() + 1);
|
2004-10-21 02:06:02 +02:00
|
|
|
}
|
|
|
|
catch(std::bad_alloc&)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
throw;
|
|
|
|
}
|
re PR libstdc++/25288 (std::list insert members should have no effects if an exception is thrown)
2005-12-09 Paolo Carlini <pcarlini@suse.de>
Howard Hinnant <hhinnant@apple.com>
PR libstdc++/25288
* include/bits/stl_list.h (list<>::_M_insert_dispatch, _M_fill_insert):
Remove.
(_M_initialize_dispatch, _M_fill_initialize): Add.
(list(size_type, const value_type&, const allocator_type&),
list(const list&), list(_InputIterator, _InputIterator,
const allocator_type&): Use the latter.
(insert(iterator, size_type, const value_type&), insert(iterator,
_InputIterator, _InputIterator)): Use construction & splice.
* testsuite/23_containers/list/modifiers/insert/25288.cc: New.
* testsuite/testsuite_allocator.h (class throw_allocator): Add.
* include/bits/stl_list.h (list<>::insert, erase): Fix wrong comments.
Co-Authored-By: Howard Hinnant <hhinnant@apple.com>
From-SVN: r108313
2005-12-09 19:24:53 +01:00
|
|
|
|
2006-01-03 14:19:23 +01:00
|
|
|
// A simple allocator which can be constructed endowed of a given
|
|
|
|
// "personality" (an integer), queried in operator== to simulate the
|
|
|
|
// behavior of realworld "unequal" allocators (i.e., not exploiting
|
|
|
|
// the provision in 20.1.5/4, first bullet). A global unordered_map,
|
|
|
|
// filled at allocation time with (pointer, personality) pairs, is
|
|
|
|
// then consulted to enforce the requirements in Table 32 about
|
|
|
|
// deallocation vs allocator equality. Note that this allocator is
|
2014-07-29 21:47:19 +02:00
|
|
|
// swappable, not copy assignable, consistently with Option 3 of DR 431
|
2006-01-03 14:19:23 +01:00
|
|
|
// (see N1599).
|
|
|
|
struct uneq_allocator_base
|
|
|
|
{
|
|
|
|
typedef std::tr1::unordered_map<void*, int> map_type;
|
|
|
|
|
|
|
|
// Avoid static initialization troubles and/or bad interactions
|
|
|
|
// with tests linking testsuite_allocator.o and playing globally
|
|
|
|
// with operator new/delete.
|
|
|
|
static map_type&
|
|
|
|
get_map()
|
|
|
|
{
|
|
|
|
static map_type alloc_map;
|
|
|
|
return alloc_map;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-07-29 21:47:19 +02:00
|
|
|
template<typename Tp, typename Alloc = std::allocator<Tp> >
|
2006-01-03 14:19:23 +01:00
|
|
|
class uneq_allocator
|
2014-07-29 21:47:19 +02:00
|
|
|
: private uneq_allocator_base,
|
|
|
|
public Alloc
|
2006-01-03 14:19:23 +01:00
|
|
|
{
|
2014-07-29 21:47:19 +02:00
|
|
|
typedef __gnu_cxx::__alloc_traits<Alloc> AllocTraits;
|
|
|
|
|
|
|
|
Alloc& base() { return *this; }
|
|
|
|
const Alloc& base() const { return *this; }
|
2017-01-27 17:17:04 +01:00
|
|
|
void swap_base(Alloc& b) { using std::swap; swap(b, this->base()); }
|
2014-07-29 21:47:19 +02:00
|
|
|
|
2006-01-03 14:19:23 +01:00
|
|
|
public:
|
2014-07-29 21:47:19 +02:00
|
|
|
typedef typename check_consistent_alloc_value_type<Tp, Alloc>::value_type
|
|
|
|
value_type;
|
|
|
|
typedef typename AllocTraits::size_type size_type;
|
|
|
|
typedef typename AllocTraits::pointer pointer;
|
2011-10-07 18:20:31 +02:00
|
|
|
|
2012-11-10 18:27:22 +01:00
|
|
|
#if __cplusplus >= 201103L
|
2014-07-29 21:47:19 +02:00
|
|
|
typedef std::true_type propagate_on_container_swap;
|
2016-10-10 14:17:45 +02:00
|
|
|
typedef std::false_type is_always_equal;
|
2011-10-07 18:20:31 +02:00
|
|
|
#endif
|
|
|
|
|
2006-01-03 14:19:23 +01:00
|
|
|
template<typename Tp1>
|
2014-07-29 21:47:19 +02:00
|
|
|
struct rebind
|
|
|
|
{
|
|
|
|
typedef uneq_allocator<Tp1,
|
|
|
|
typename AllocTraits::template rebind<Tp1>::other> other;
|
|
|
|
};
|
2006-01-03 14:19:23 +01:00
|
|
|
|
2011-06-10 19:14:40 +02:00
|
|
|
uneq_allocator() _GLIBCXX_USE_NOEXCEPT
|
2006-01-03 14:19:23 +01:00
|
|
|
: personality(0) { }
|
|
|
|
|
2011-06-10 19:14:40 +02:00
|
|
|
uneq_allocator(int person) _GLIBCXX_USE_NOEXCEPT
|
2006-01-03 14:19:23 +01:00
|
|
|
: personality(person) { }
|
2014-07-29 21:47:19 +02:00
|
|
|
|
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
uneq_allocator(const uneq_allocator&) = default;
|
|
|
|
uneq_allocator(uneq_allocator&&) = default;
|
|
|
|
#endif
|
2016-04-29 18:11:43 +02:00
|
|
|
|
2006-01-03 14:19:23 +01:00
|
|
|
template<typename Tp1>
|
2014-07-29 21:47:19 +02:00
|
|
|
uneq_allocator(const uneq_allocator<Tp1,
|
|
|
|
typename AllocTraits::template rebind<Tp1>::other>& b)
|
|
|
|
_GLIBCXX_USE_NOEXCEPT
|
2006-01-03 14:19:23 +01:00
|
|
|
: personality(b.get_personality()) { }
|
|
|
|
|
2011-06-10 19:14:40 +02:00
|
|
|
~uneq_allocator() _GLIBCXX_USE_NOEXCEPT
|
|
|
|
{ }
|
|
|
|
|
2006-01-03 14:19:23 +01:00
|
|
|
int get_personality() const { return personality; }
|
2016-04-29 18:11:43 +02:00
|
|
|
|
2006-01-03 14:19:23 +01:00
|
|
|
pointer
|
2019-04-26 00:43:15 +02:00
|
|
|
allocate(size_type n, const void* = 0)
|
2016-04-29 18:11:43 +02:00
|
|
|
{
|
2014-07-29 21:47:19 +02:00
|
|
|
pointer p = AllocTraits::allocate(*this, n);
|
|
|
|
|
2006-01-03 14:19:23 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
get_map().insert(map_type::value_type(reinterpret_cast<void*>(p),
|
|
|
|
personality));
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
2014-07-29 21:47:19 +02:00
|
|
|
AllocTraits::deallocate(*this, p, n);
|
2006-01-03 14:19:23 +01:00
|
|
|
__throw_exception_again;
|
|
|
|
}
|
2014-07-29 21:47:19 +02:00
|
|
|
|
2006-01-03 14:19:23 +01:00
|
|
|
return p;
|
|
|
|
}
|
2011-06-10 19:14:40 +02:00
|
|
|
|
2006-01-03 14:19:23 +01:00
|
|
|
void
|
2014-07-29 21:47:19 +02:00
|
|
|
deallocate(pointer p, size_type n)
|
2006-01-03 14:19:23 +01:00
|
|
|
{
|
2011-06-10 19:14:40 +02:00
|
|
|
VERIFY( p );
|
|
|
|
|
2006-01-03 14:19:23 +01:00
|
|
|
map_type::iterator it = get_map().find(reinterpret_cast<void*>(p));
|
2011-06-10 19:14:40 +02:00
|
|
|
VERIFY( it != get_map().end() );
|
2006-01-03 14:19:23 +01:00
|
|
|
|
|
|
|
// Enforce requirements in Table 32 about deallocation vs
|
|
|
|
// allocator equality.
|
2011-06-10 19:14:40 +02:00
|
|
|
VERIFY( it->second == personality );
|
|
|
|
|
2006-01-03 14:19:23 +01:00
|
|
|
get_map().erase(it);
|
2014-07-29 21:47:19 +02:00
|
|
|
AllocTraits::deallocate(*this, p, n);
|
2006-01-03 14:19:23 +01:00
|
|
|
}
|
2011-06-10 19:14:40 +02:00
|
|
|
|
2012-11-10 18:27:22 +01:00
|
|
|
#if __cplusplus >= 201103L
|
2011-05-19 19:20:22 +02:00
|
|
|
// Not copy assignable...
|
|
|
|
uneq_allocator&
|
|
|
|
operator=(const uneq_allocator&) = delete;
|
2014-06-27 22:03:26 +02:00
|
|
|
|
2014-07-29 21:47:19 +02:00
|
|
|
// ... but still moveable if base allocator is.
|
|
|
|
uneq_allocator&
|
|
|
|
operator=(uneq_allocator&&) = default;
|
|
|
|
#else
|
2011-06-04 19:17:57 +02:00
|
|
|
private:
|
2006-01-03 14:19:23 +01:00
|
|
|
// Not assignable...
|
|
|
|
uneq_allocator&
|
|
|
|
operator=(const uneq_allocator&);
|
2011-05-19 19:20:22 +02:00
|
|
|
#endif
|
2006-01-03 14:19:23 +01:00
|
|
|
|
2011-06-04 19:17:57 +02:00
|
|
|
private:
|
2006-01-03 14:19:23 +01:00
|
|
|
// ... yet swappable!
|
|
|
|
friend inline void
|
|
|
|
swap(uneq_allocator& a, uneq_allocator& b)
|
2014-07-29 21:47:19 +02:00
|
|
|
{
|
|
|
|
std::swap(a.personality, b.personality);
|
|
|
|
a.swap_base(b);
|
2016-04-29 18:11:43 +02:00
|
|
|
}
|
2014-07-29 21:47:19 +02:00
|
|
|
|
2006-01-03 14:19:23 +01:00
|
|
|
template<typename Tp1>
|
2014-07-29 21:47:19 +02:00
|
|
|
friend inline bool
|
|
|
|
operator==(const uneq_allocator& a,
|
|
|
|
const uneq_allocator<Tp1,
|
|
|
|
typename AllocTraits::template rebind<Tp1>::other>& b)
|
|
|
|
{ return a.personality == b.personality; }
|
2006-01-03 14:19:23 +01:00
|
|
|
|
|
|
|
template<typename Tp1>
|
2014-07-29 21:47:19 +02:00
|
|
|
friend inline bool
|
|
|
|
operator!=(const uneq_allocator& a,
|
|
|
|
const uneq_allocator<Tp1,
|
|
|
|
typename AllocTraits::template rebind<Tp1>::other>& b)
|
|
|
|
{ return !(a == b); }
|
2016-04-29 18:11:43 +02:00
|
|
|
|
2006-01-03 14:19:23 +01:00
|
|
|
int personality;
|
|
|
|
};
|
2011-07-09 15:06:29 +02:00
|
|
|
|
2012-11-10 18:27:22 +01:00
|
|
|
#if __cplusplus >= 201103L
|
2011-07-09 15:06:29 +02:00
|
|
|
// An uneq_allocator which can be used to test allocator propagation.
|
2014-07-29 21:47:19 +02:00
|
|
|
template<typename Tp, bool Propagate, typename Alloc = std::allocator<Tp>>
|
|
|
|
class propagating_allocator : public uneq_allocator<Tp, Alloc>
|
2011-07-09 15:06:29 +02:00
|
|
|
{
|
2014-07-29 21:47:19 +02:00
|
|
|
typedef __gnu_cxx::__alloc_traits<Alloc> AllocTraits;
|
|
|
|
|
|
|
|
typedef uneq_allocator<Tp, Alloc> base_alloc;
|
2011-07-09 15:06:29 +02:00
|
|
|
base_alloc& base() { return *this; }
|
|
|
|
const base_alloc& base() const { return *this; }
|
|
|
|
void swap_base(base_alloc& b) { swap(b, this->base()); }
|
|
|
|
|
|
|
|
typedef std::integral_constant<bool, Propagate> trait_type;
|
|
|
|
|
|
|
|
public:
|
2011-10-04 22:34:54 +02:00
|
|
|
// default allocator_traits::rebind_alloc would select
|
|
|
|
// uneq_allocator::rebind so we must define rebind here
|
2011-07-09 15:06:29 +02:00
|
|
|
template<typename Up>
|
2014-07-29 21:47:19 +02:00
|
|
|
struct rebind
|
|
|
|
{
|
|
|
|
typedef propagating_allocator<Up, Propagate,
|
|
|
|
typename AllocTraits::template rebind<Up>::other> other;
|
|
|
|
};
|
2011-07-09 15:06:29 +02:00
|
|
|
|
|
|
|
propagating_allocator(int i) noexcept
|
|
|
|
: base_alloc(i)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
template<typename Up>
|
2014-07-29 21:47:19 +02:00
|
|
|
propagating_allocator(const propagating_allocator<Up, Propagate,
|
|
|
|
typename AllocTraits::template rebind<Up>::other>& a)
|
|
|
|
noexcept
|
2011-07-09 15:06:29 +02:00
|
|
|
: base_alloc(a)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
propagating_allocator() noexcept = default;
|
|
|
|
|
|
|
|
propagating_allocator(const propagating_allocator&) noexcept = default;
|
|
|
|
|
2011-10-18 19:39:15 +02:00
|
|
|
propagating_allocator&
|
|
|
|
operator=(const propagating_allocator& a) noexcept
|
2013-11-15 16:34:14 +01:00
|
|
|
{
|
|
|
|
static_assert(Propagate, "assigning propagating_allocator<T, true>");
|
|
|
|
propagating_allocator(a).swap_base(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
2011-10-18 19:39:15 +02:00
|
|
|
|
2011-07-09 15:06:29 +02:00
|
|
|
template<bool P2>
|
2014-07-29 21:47:19 +02:00
|
|
|
propagating_allocator&
|
|
|
|
operator=(const propagating_allocator<Tp, P2, Alloc>& a) noexcept
|
2011-07-09 15:06:29 +02:00
|
|
|
{
|
|
|
|
static_assert(P2, "assigning propagating_allocator<T, true>");
|
|
|
|
propagating_allocator(a).swap_base(*this);
|
2011-07-11 19:19:53 +02:00
|
|
|
return *this;
|
2011-07-09 15:06:29 +02:00
|
|
|
}
|
|
|
|
|
2019-05-17 06:55:37 +02:00
|
|
|
// postcondition: LWG2593 a.get_personality() un-changed.
|
2011-07-09 15:06:29 +02:00
|
|
|
propagating_allocator(propagating_allocator&& a) noexcept
|
2019-05-17 06:55:37 +02:00
|
|
|
: base_alloc(std::move(a.base()))
|
|
|
|
{ }
|
2011-07-09 15:06:29 +02:00
|
|
|
|
2019-05-17 06:55:37 +02:00
|
|
|
// postcondition: LWG2593 a.get_personality() un-changed
|
2011-07-09 15:06:29 +02:00
|
|
|
propagating_allocator&
|
|
|
|
operator=(propagating_allocator&& a) noexcept
|
|
|
|
{
|
|
|
|
propagating_allocator(std::move(a)).swap_base(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef trait_type propagate_on_container_copy_assignment;
|
|
|
|
typedef trait_type propagate_on_container_move_assignment;
|
|
|
|
typedef trait_type propagate_on_container_swap;
|
|
|
|
|
|
|
|
propagating_allocator select_on_container_copy_construction() const
|
|
|
|
{ return Propagate ? *this : propagating_allocator(); }
|
|
|
|
};
|
|
|
|
|
2011-10-04 22:34:54 +02:00
|
|
|
// Class template supporting the minimal interface that satisfies the
|
|
|
|
// Allocator requirements, from example in [allocator.requirements]
|
|
|
|
template <class Tp>
|
|
|
|
struct SimpleAllocator
|
|
|
|
{
|
|
|
|
typedef Tp value_type;
|
|
|
|
|
2014-01-23 00:50:58 +01:00
|
|
|
SimpleAllocator() noexcept { }
|
2011-10-04 22:34:54 +02:00
|
|
|
|
|
|
|
template <class T>
|
2015-05-13 14:21:45 +02:00
|
|
|
SimpleAllocator(const SimpleAllocator<T>&) { }
|
2011-10-04 22:34:54 +02:00
|
|
|
|
|
|
|
Tp *allocate(std::size_t n)
|
|
|
|
{ return std::allocator<Tp>().allocate(n); }
|
|
|
|
|
|
|
|
void deallocate(Tp *p, std::size_t n)
|
|
|
|
{ std::allocator<Tp>().deallocate(p, n); }
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
bool operator==(const SimpleAllocator<T>&, const SimpleAllocator<U>&)
|
|
|
|
{ return true; }
|
|
|
|
template <class T, class U>
|
|
|
|
bool operator!=(const SimpleAllocator<T>&, const SimpleAllocator<U>&)
|
|
|
|
{ return false; }
|
|
|
|
|
2017-06-12 22:38:16 +02:00
|
|
|
template<typename T>
|
|
|
|
struct default_init_allocator
|
|
|
|
{
|
|
|
|
using value_type = T;
|
|
|
|
|
|
|
|
default_init_allocator() = default;
|
|
|
|
|
|
|
|
template<typename U>
|
|
|
|
default_init_allocator(const default_init_allocator<U>& a)
|
|
|
|
: state(a.state)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
T*
|
|
|
|
allocate(std::size_t n)
|
|
|
|
{ return std::allocator<T>().allocate(n); }
|
|
|
|
|
|
|
|
void
|
|
|
|
deallocate(T* p, std::size_t n)
|
|
|
|
{ std::allocator<T>().deallocate(p, n); }
|
|
|
|
|
|
|
|
int state;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T, typename U>
|
|
|
|
bool operator==(const default_init_allocator<T>& t,
|
|
|
|
const default_init_allocator<U>& u)
|
|
|
|
{ return t.state == u.state; }
|
|
|
|
|
|
|
|
template<typename T, typename U>
|
|
|
|
bool operator!=(const default_init_allocator<T>& t,
|
|
|
|
const default_init_allocator<U>& u)
|
|
|
|
{ return !(t == u); }
|
2011-07-09 15:06:29 +02:00
|
|
|
#endif
|
|
|
|
|
re PR libstdc++/50118 (node-based containers cannot use allocators with explicit constructor template)
2011-08-29 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/50118
* include/bits/stl_list.h (_List_base<>::
_List_base(const allocator_type&)): Remove.
(_List_base<>::_List_base(const _Node_alloc_type&)): Add.
(list<>:list(const allocator_type&), list(size_type, const
value_type&, const allocator_type&),
list(initializer_list<, const allocator_type&),
list(_InputIterator, _InputIterator, const allocator_type&),
insert(iterator, size_type, const value_type&),
insert(iterator, _InputIterator, _InputIterator)): Adjust.
* include/bits/stl_tree.h (_Rb_tree<>::_Rb_tree(const _Compare&,
const allocator_type&)): Fix.
* include/bits/stl_map.h (map<>::map(const _Compare&,
const allocator_type&), map(initializer_list<>,
const _Compare&, const allocator_type&), map(_InputIterator,
_InputIterator, const _Compare&, const allocator_type&),
get_allocator): Adjust.
* include/bits/stl_set.h (set<>::set(const _Compare&,
const allocator_type&), set(initializer_list<>,
const _Compare&, const allocator_type&), set(_InputIterator,
_InputIterator, const _Compare&, const allocator_type&),
get_allocator): Likewise.
* include/bits/stl_multimap.h (multimap<>::multimap(const _Compare&,
const allocator_type&), multimap(initializer_list<>,
const _Compare&, const allocator_type&), multimap(_InputIterator,
_InputIterator, const _Compare&, const allocator_type&),
get_allocator): Likewise.
* include/bits/stl_multiset.h (multiset<>::multiset(const _Compare&,
const allocator_type&), multiset(initializer_list<>,
const _Compare&, const allocator_type&), multiset(_InputIterator,
_InputIterator, const _Compare&, const allocator_type&),
get_allocator): Likewise.
* include/bits/forward_list.h (_Fwd_list_base<>::
_Fwd_list_base(const _Alloc&), _Fwd_list_base(const _Fwd_list_base&,
const _Alloc&), _Fwd_list_base(_Fwd_list_base&&, const _Alloc&)):
Remove.
(_Fwd_list_base<>::_Fwd_list_base(const _Node_alloc_type&),
_Fwd_list_base(const _Fwd_list_base&,
const _Node_alloc_type&), _Fwd_list_base(_Fwd_list_base&&,
const _Node_alloc_type&)): Add.
(forward_list<>::forward_list(const _Alloc&),
forward_list(const forward_list&, const _Alloc&),
forward_list(forward_list&&, const _Alloc&),
forward_list(size_type, const _Tp&, const _Alloc&),
forward_list(_InputIterator, _InputIterator, const _Alloc&),
forward_list(std::initializer_list<>, const _Alloc&),
get_allocator): Adjust.
* include/bits/forward_list.tcc
* testsuite/util/testsuite_allocator.h (ExplicitConsAlloc): Add.
* testsuite/23_containers/unordered_map/requirements/
explicit_instantiation/5.cc: New.
* testsuite/23_containers/multimap/requirements/
explicit_instantiation/5.cc: Likewise.
* testsuite/23_containers/multimap/requirements/
explicit_instantiation/5_c++0x.cc: Likewise.
* testsuite/23_containers/set/requirements/explicit_instantiation/
5.cc: Likewise.
* testsuite/23_containers/set/requirements/explicit_instantiation/
5_c++0x.cc: Likewise.
* testsuite/23_containers/unordered_multimap/requirements/
explicit_instantiation/5.cc: Likewise.
* testsuite/23_containers/forward_list/requirements/
explicit_instantiation/5.cc: Likewise.
* testsuite/23_containers/unordered_set/requirements/
explicit_instantiation/5.cc: Likewise.
testsuite/23_containers/multiset/requirements/explicit_instantiation/
5.cc: Likewise.
* testsuite/23_containers/multiset/requirements/
explicit_instantiation/5_c++0x.cc: Likewise.
* testsuite/23_containers/list/requirements/explicit_instantiation/
5_c++0x.cc: Likewise.
* testsuite/23_containers/list/requirements/explicit_instantiation/
5.cc: Likewise.
* testsuite/23_containers/unordered_multiset/requirements/
explicit_instantiation/5.cc: Likewise.
* testsuite/23_containers/map/requirements/explicit_instantiation/
5.cc: Likewise.
* testsuite/23_containers/map/requirements/explicit_instantiation/
5_c++0x.cc: Likewise.
* testsuite/23_containers/forward_list/requirements/dr438/
assign_neg.cc: Adjust dg-error line number.
* testsuite/23_containers/forward_list/requirements/dr438/
insert_neg.cc: Likewise.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_1_neg.cc: Likewise.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_2_neg.cc: Likewise.
* testsuite/23_containers/list/requirements/dr438/assign_neg.cc:
Likewise.
* testsuite/23_containers/list/requirements/dr438/insert_neg.cc:
Likewise.
* testsuite/23_containers/list/requirements/dr438/
constructor_1_neg.cc: Likewise.
* testsuite/23_containers/list/requirements/dr438/
constructor_2_neg.cc: Likewise.
From-SVN: r178230
2011-08-29 15:40:33 +02:00
|
|
|
template<typename Tp>
|
|
|
|
struct ExplicitConsAlloc : std::allocator<Tp>
|
|
|
|
{
|
|
|
|
ExplicitConsAlloc() { }
|
|
|
|
|
|
|
|
template<typename Up>
|
|
|
|
explicit
|
|
|
|
ExplicitConsAlloc(const ExplicitConsAlloc<Up>&) { }
|
|
|
|
|
|
|
|
template<typename Up>
|
|
|
|
struct rebind
|
|
|
|
{ typedef ExplicitConsAlloc<Up> other; };
|
|
|
|
};
|
|
|
|
|
2013-06-16 19:13:34 +02:00
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
template<typename Tp>
|
|
|
|
class CustomPointerAlloc : public std::allocator<Tp>
|
|
|
|
{
|
|
|
|
template<typename Up, typename Sp = __gnu_cxx::_Std_pointer_impl<Up>>
|
|
|
|
using Ptr = __gnu_cxx::_Pointer_adapter<Sp>;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CustomPointerAlloc() = default;
|
|
|
|
|
|
|
|
template<typename Up>
|
|
|
|
CustomPointerAlloc(const CustomPointerAlloc<Up>&) { }
|
|
|
|
|
|
|
|
template<typename Up>
|
|
|
|
struct rebind
|
|
|
|
{ typedef CustomPointerAlloc<Up> other; };
|
|
|
|
|
|
|
|
typedef Ptr<Tp> pointer;
|
|
|
|
typedef Ptr<const Tp> const_pointer;
|
|
|
|
typedef Ptr<void> void_pointer;
|
|
|
|
typedef Ptr<const void> const_void_pointer;
|
|
|
|
|
2018-12-23 19:11:38 +01:00
|
|
|
pointer allocate(std::size_t n, const_void_pointer = {})
|
2013-06-16 19:13:34 +02:00
|
|
|
{ return pointer(std::allocator<Tp>::allocate(n)); }
|
|
|
|
|
|
|
|
void deallocate(pointer p, std::size_t n)
|
|
|
|
{ std::allocator<Tp>::deallocate(std::addressof(*p), n); }
|
|
|
|
};
|
2014-01-29 15:57:35 +01:00
|
|
|
|
2019-05-14 13:17:23 +02:00
|
|
|
// A class type meeting *only* the Cpp17NullablePointer requirements.
|
|
|
|
// Can be used as a base class for fancy pointers (like PointerBase, below)
|
|
|
|
// or to wrap a built-in pointer type to remove operations not required
|
|
|
|
// by the Cpp17NullablePointer requirements (dereference, increment etc.)
|
|
|
|
template<typename Ptr>
|
|
|
|
struct NullablePointer
|
|
|
|
{
|
|
|
|
// N.B. default constructor does not initialize value
|
|
|
|
NullablePointer() = default;
|
|
|
|
NullablePointer(std::nullptr_t) noexcept : value() { }
|
|
|
|
|
2019-05-14 22:01:28 +02:00
|
|
|
explicit operator bool() const noexcept { return value != nullptr; }
|
2019-05-14 13:17:23 +02:00
|
|
|
|
|
|
|
friend inline bool
|
|
|
|
operator==(NullablePointer lhs, NullablePointer rhs) noexcept
|
|
|
|
{ return lhs.value == rhs.value; }
|
|
|
|
|
|
|
|
friend inline bool
|
|
|
|
operator!=(NullablePointer lhs, NullablePointer rhs) noexcept
|
|
|
|
{ return lhs.value != rhs.value; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
explicit NullablePointer(Ptr p) noexcept : value(p) { }
|
|
|
|
Ptr value;
|
|
|
|
};
|
|
|
|
|
|
|
|
// NullablePointer<void> is an empty type that models Cpp17NullablePointer.
|
|
|
|
template<>
|
|
|
|
struct NullablePointer<void>
|
|
|
|
{
|
|
|
|
NullablePointer() = default;
|
|
|
|
NullablePointer(std::nullptr_t) noexcept { }
|
|
|
|
explicit NullablePointer(const volatile void*) noexcept { }
|
|
|
|
|
|
|
|
explicit operator bool() const noexcept { return false; }
|
|
|
|
|
|
|
|
friend inline bool
|
|
|
|
operator==(NullablePointer, NullablePointer) noexcept
|
|
|
|
{ return true; }
|
|
|
|
|
|
|
|
friend inline bool
|
|
|
|
operator!=(NullablePointer, NullablePointer) noexcept
|
|
|
|
{ return false; }
|
|
|
|
};
|
|
|
|
|
2014-01-29 15:57:35 +01:00
|
|
|
// Utility for use as CRTP base class of custom pointer types
|
|
|
|
template<typename Derived, typename T>
|
2019-05-14 13:17:23 +02:00
|
|
|
struct PointerBase : NullablePointer<T*>
|
2014-01-29 15:57:35 +01:00
|
|
|
{
|
|
|
|
typedef T element_type;
|
|
|
|
|
|
|
|
// typedefs for iterator_traits
|
|
|
|
typedef T value_type;
|
|
|
|
typedef std::ptrdiff_t difference_type;
|
|
|
|
typedef std::random_access_iterator_tag iterator_category;
|
|
|
|
typedef Derived pointer;
|
|
|
|
typedef T& reference;
|
|
|
|
|
2019-05-14 13:17:23 +02:00
|
|
|
using NullablePointer<T*>::NullablePointer;
|
2014-01-29 15:57:35 +01:00
|
|
|
|
2019-05-14 13:17:23 +02:00
|
|
|
// Public (but explicit) constructor from raw pointer:
|
|
|
|
explicit PointerBase(T* p) noexcept : NullablePointer<T*>(p) { }
|
2017-05-31 14:41:45 +02:00
|
|
|
|
2014-01-29 15:57:35 +01:00
|
|
|
template<typename D, typename U,
|
|
|
|
typename = decltype(static_cast<T*>(std::declval<U*>()))>
|
2019-05-14 13:17:23 +02:00
|
|
|
PointerBase(const PointerBase<D, U>& p)
|
|
|
|
: NullablePointer<T*>(p.operator->()) { }
|
|
|
|
|
|
|
|
T& operator*() const { return *this->value; }
|
|
|
|
T* operator->() const { return this->value; }
|
|
|
|
T& operator[](difference_type n) const { return this->value[n]; }
|
2014-01-29 15:57:35 +01:00
|
|
|
|
2019-05-14 13:17:23 +02:00
|
|
|
Derived& operator++() { ++this->value; return derived(); }
|
|
|
|
Derived& operator--() { --this->value; return derived(); }
|
2014-01-29 15:57:35 +01:00
|
|
|
|
2019-05-14 13:17:23 +02:00
|
|
|
Derived operator++(int) { return Derived(this->value++); }
|
2014-01-29 15:57:35 +01:00
|
|
|
|
2019-05-14 13:17:23 +02:00
|
|
|
Derived operator--(int) { return Derived(this->value--); }
|
2014-01-29 15:57:35 +01:00
|
|
|
|
2019-05-14 13:17:23 +02:00
|
|
|
Derived& operator+=(difference_type n)
|
|
|
|
{
|
|
|
|
this->value += n;
|
|
|
|
return derived();
|
|
|
|
}
|
|
|
|
|
|
|
|
Derived& operator-=(difference_type n)
|
|
|
|
{
|
|
|
|
this->value -= n;
|
|
|
|
return derived();
|
|
|
|
}
|
2014-01-29 15:57:35 +01:00
|
|
|
|
|
|
|
Derived
|
|
|
|
operator+(difference_type n) const
|
|
|
|
{
|
|
|
|
Derived p(derived());
|
|
|
|
return p += n;
|
|
|
|
}
|
|
|
|
|
|
|
|
Derived
|
|
|
|
operator-(difference_type n) const
|
|
|
|
{
|
|
|
|
Derived p(derived());
|
|
|
|
return p -= n;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-05-14 13:17:23 +02:00
|
|
|
friend std::ptrdiff_t operator-(PointerBase l, PointerBase r)
|
|
|
|
{ return l.value - r.value; }
|
|
|
|
|
2017-05-31 14:41:45 +02:00
|
|
|
Derived&
|
|
|
|
derived() { return static_cast<Derived&>(*this); }
|
|
|
|
|
|
|
|
const Derived&
|
|
|
|
derived() const { return static_cast<const Derived&>(*this); }
|
2014-01-29 15:57:35 +01:00
|
|
|
};
|
|
|
|
|
2019-05-14 13:17:23 +02:00
|
|
|
// implementation for pointer-to-void specializations
|
|
|
|
template<typename T>
|
|
|
|
struct PointerBase_void : NullablePointer<T*>
|
2014-01-29 15:57:35 +01:00
|
|
|
{
|
|
|
|
typedef T element_type;
|
|
|
|
|
|
|
|
// typedefs for iterator_traits
|
|
|
|
typedef T value_type;
|
|
|
|
typedef std::ptrdiff_t difference_type;
|
|
|
|
typedef std::random_access_iterator_tag iterator_category;
|
|
|
|
|
2019-05-14 13:17:23 +02:00
|
|
|
using NullablePointer<T*>::NullablePointer;
|
2014-01-29 15:57:35 +01:00
|
|
|
|
2019-05-14 13:17:23 +02:00
|
|
|
T* operator->() const { return this->value; }
|
2014-01-29 15:57:35 +01:00
|
|
|
|
|
|
|
template<typename D, typename U,
|
|
|
|
typename = decltype(static_cast<T*>(std::declval<U*>()))>
|
2019-05-14 13:17:23 +02:00
|
|
|
PointerBase_void(const PointerBase<D, U>& p)
|
|
|
|
: NullablePointer<T*>(p.operator->()) { }
|
2014-01-29 15:57:35 +01:00
|
|
|
};
|
|
|
|
|
2019-05-14 13:17:23 +02:00
|
|
|
template<typename Derived>
|
2014-01-29 15:57:35 +01:00
|
|
|
struct PointerBase<Derived, void> : PointerBase_void<void>
|
|
|
|
{
|
|
|
|
using PointerBase_void::PointerBase_void;
|
|
|
|
typedef Derived pointer;
|
|
|
|
};
|
|
|
|
|
2019-05-14 13:17:23 +02:00
|
|
|
template<typename Derived>
|
2014-01-29 15:57:35 +01:00
|
|
|
struct PointerBase<Derived, const void> : PointerBase_void<const void>
|
|
|
|
{
|
|
|
|
using PointerBase_void::PointerBase_void;
|
|
|
|
typedef Derived pointer;
|
|
|
|
};
|
Add initial version of C++17 <memory_resource> header
This is missing the synchronized_pool_resource and
unsynchronized_pool_resource classes but is otherwise complete.
This is a new implementation, not based on the existing code in
<experimental/memory_resource>, but memory_resource and
polymorphic_allocator ended up looking almost the same anyway.
The constant_init kluge in src/c++17/memory_resource.cc is apparently
due to Richard Smith and ensures that the objects are constructed during
constant initialiation phase and not destroyed (because the
constant_init destructor doesn't destroy the union member and the
storage is not reused).
* config/abi/pre/gnu.ver: Export new symbols.
* configure: Regenerate.
* include/Makefile.am: Add new <memory_resource> header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <memory_resource> for C++17.
* include/std/memory_resource: New header.
(memory_resource, polymorphic_allocator, new_delete_resource)
(null_memory_resource, set_default_resource, get_default_resource)
(pool_options, monotonic_buffer_resource): Define.
* src/Makefile.am: Add c++17 directory.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.am: Fix comment.
* src/c++17/Makefile.am: Add makefile for new sub-directory.
* src/c++17/Makefile.in: Generate.
* src/c++17/memory_resource.cc: New.
(newdel_res_t, null_res_t, constant_init, newdel_res, null_res)
(default_res, new_delete_resource, null_memory_resource)
(set_default_resource, get_default_resource): Define.
* testsuite/20_util/memory_resource/1.cc: New test.
* testsuite/20_util/memory_resource/2.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/1.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/deallocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/release.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/upstream_resource.cc:
New test.
* testsuite/20_util/polymorphic_allocator/1.cc: New test.
* testsuite/20_util/polymorphic_allocator/resource.cc: New test.
* testsuite/20_util/polymorphic_allocator/select.cc: New test.
* testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource):
Define concrete memory resource for testing.
(__gnu_test::default_resource_mgr): Define RAII helper for changing
default resource.
From-SVN: r262953
2018-07-24 23:09:55 +02:00
|
|
|
#endif // C++11
|
|
|
|
|
2018-08-23 21:27:54 +02:00
|
|
|
#if __cplusplus >= 201703L
|
|
|
|
#if __cpp_aligned_new && __cpp_rtti
|
2019-05-14 13:17:27 +02:00
|
|
|
// A concrete memory_resource, with error checking.
|
|
|
|
class memory_resource : public std::pmr::memory_resource
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
memory_resource()
|
|
|
|
: lists(new allocation_lists)
|
|
|
|
{ }
|
Add initial version of C++17 <memory_resource> header
This is missing the synchronized_pool_resource and
unsynchronized_pool_resource classes but is otherwise complete.
This is a new implementation, not based on the existing code in
<experimental/memory_resource>, but memory_resource and
polymorphic_allocator ended up looking almost the same anyway.
The constant_init kluge in src/c++17/memory_resource.cc is apparently
due to Richard Smith and ensures that the objects are constructed during
constant initialiation phase and not destroyed (because the
constant_init destructor doesn't destroy the union member and the
storage is not reused).
* config/abi/pre/gnu.ver: Export new symbols.
* configure: Regenerate.
* include/Makefile.am: Add new <memory_resource> header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <memory_resource> for C++17.
* include/std/memory_resource: New header.
(memory_resource, polymorphic_allocator, new_delete_resource)
(null_memory_resource, set_default_resource, get_default_resource)
(pool_options, monotonic_buffer_resource): Define.
* src/Makefile.am: Add c++17 directory.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.am: Fix comment.
* src/c++17/Makefile.am: Add makefile for new sub-directory.
* src/c++17/Makefile.in: Generate.
* src/c++17/memory_resource.cc: New.
(newdel_res_t, null_res_t, constant_init, newdel_res, null_res)
(default_res, new_delete_resource, null_memory_resource)
(set_default_resource, get_default_resource): Define.
* testsuite/20_util/memory_resource/1.cc: New test.
* testsuite/20_util/memory_resource/2.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/1.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/deallocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/release.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/upstream_resource.cc:
New test.
* testsuite/20_util/polymorphic_allocator/1.cc: New test.
* testsuite/20_util/polymorphic_allocator/resource.cc: New test.
* testsuite/20_util/polymorphic_allocator/select.cc: New test.
* testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource):
Define concrete memory resource for testing.
(__gnu_test::default_resource_mgr): Define RAII helper for changing
default resource.
From-SVN: r262953
2018-07-24 23:09:55 +02:00
|
|
|
|
2019-05-14 13:17:27 +02:00
|
|
|
memory_resource(const memory_resource& r) noexcept
|
|
|
|
: lists(r.lists)
|
|
|
|
{ lists->refcount++; }
|
Add initial version of C++17 <memory_resource> header
This is missing the synchronized_pool_resource and
unsynchronized_pool_resource classes but is otherwise complete.
This is a new implementation, not based on the existing code in
<experimental/memory_resource>, but memory_resource and
polymorphic_allocator ended up looking almost the same anyway.
The constant_init kluge in src/c++17/memory_resource.cc is apparently
due to Richard Smith and ensures that the objects are constructed during
constant initialiation phase and not destroyed (because the
constant_init destructor doesn't destroy the union member and the
storage is not reused).
* config/abi/pre/gnu.ver: Export new symbols.
* configure: Regenerate.
* include/Makefile.am: Add new <memory_resource> header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <memory_resource> for C++17.
* include/std/memory_resource: New header.
(memory_resource, polymorphic_allocator, new_delete_resource)
(null_memory_resource, set_default_resource, get_default_resource)
(pool_options, monotonic_buffer_resource): Define.
* src/Makefile.am: Add c++17 directory.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.am: Fix comment.
* src/c++17/Makefile.am: Add makefile for new sub-directory.
* src/c++17/Makefile.in: Generate.
* src/c++17/memory_resource.cc: New.
(newdel_res_t, null_res_t, constant_init, newdel_res, null_res)
(default_res, new_delete_resource, null_memory_resource)
(set_default_resource, get_default_resource): Define.
* testsuite/20_util/memory_resource/1.cc: New test.
* testsuite/20_util/memory_resource/2.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/1.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/deallocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/release.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/upstream_resource.cc:
New test.
* testsuite/20_util/polymorphic_allocator/1.cc: New test.
* testsuite/20_util/polymorphic_allocator/resource.cc: New test.
* testsuite/20_util/polymorphic_allocator/select.cc: New test.
* testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource):
Define concrete memory resource for testing.
(__gnu_test::default_resource_mgr): Define RAII helper for changing
default resource.
From-SVN: r262953
2018-07-24 23:09:55 +02:00
|
|
|
|
2019-05-14 13:17:27 +02:00
|
|
|
memory_resource& operator=(const memory_resource&) = delete;
|
Add initial version of C++17 <memory_resource> header
This is missing the synchronized_pool_resource and
unsynchronized_pool_resource classes but is otherwise complete.
This is a new implementation, not based on the existing code in
<experimental/memory_resource>, but memory_resource and
polymorphic_allocator ended up looking almost the same anyway.
The constant_init kluge in src/c++17/memory_resource.cc is apparently
due to Richard Smith and ensures that the objects are constructed during
constant initialiation phase and not destroyed (because the
constant_init destructor doesn't destroy the union member and the
storage is not reused).
* config/abi/pre/gnu.ver: Export new symbols.
* configure: Regenerate.
* include/Makefile.am: Add new <memory_resource> header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <memory_resource> for C++17.
* include/std/memory_resource: New header.
(memory_resource, polymorphic_allocator, new_delete_resource)
(null_memory_resource, set_default_resource, get_default_resource)
(pool_options, monotonic_buffer_resource): Define.
* src/Makefile.am: Add c++17 directory.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.am: Fix comment.
* src/c++17/Makefile.am: Add makefile for new sub-directory.
* src/c++17/Makefile.in: Generate.
* src/c++17/memory_resource.cc: New.
(newdel_res_t, null_res_t, constant_init, newdel_res, null_res)
(default_res, new_delete_resource, null_memory_resource)
(set_default_resource, get_default_resource): Define.
* testsuite/20_util/memory_resource/1.cc: New test.
* testsuite/20_util/memory_resource/2.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/1.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/deallocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/release.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/upstream_resource.cc:
New test.
* testsuite/20_util/polymorphic_allocator/1.cc: New test.
* testsuite/20_util/polymorphic_allocator/resource.cc: New test.
* testsuite/20_util/polymorphic_allocator/select.cc: New test.
* testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource):
Define concrete memory resource for testing.
(__gnu_test::default_resource_mgr): Define RAII helper for changing
default resource.
From-SVN: r262953
2018-07-24 23:09:55 +02:00
|
|
|
|
2019-05-14 13:17:27 +02:00
|
|
|
~memory_resource()
|
|
|
|
{
|
|
|
|
if (lists->refcount-- == 1)
|
|
|
|
delete lists; // last one out turns out the lights
|
|
|
|
}
|
Add initial version of C++17 <memory_resource> header
This is missing the synchronized_pool_resource and
unsynchronized_pool_resource classes but is otherwise complete.
This is a new implementation, not based on the existing code in
<experimental/memory_resource>, but memory_resource and
polymorphic_allocator ended up looking almost the same anyway.
The constant_init kluge in src/c++17/memory_resource.cc is apparently
due to Richard Smith and ensures that the objects are constructed during
constant initialiation phase and not destroyed (because the
constant_init destructor doesn't destroy the union member and the
storage is not reused).
* config/abi/pre/gnu.ver: Export new symbols.
* configure: Regenerate.
* include/Makefile.am: Add new <memory_resource> header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <memory_resource> for C++17.
* include/std/memory_resource: New header.
(memory_resource, polymorphic_allocator, new_delete_resource)
(null_memory_resource, set_default_resource, get_default_resource)
(pool_options, monotonic_buffer_resource): Define.
* src/Makefile.am: Add c++17 directory.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.am: Fix comment.
* src/c++17/Makefile.am: Add makefile for new sub-directory.
* src/c++17/Makefile.in: Generate.
* src/c++17/memory_resource.cc: New.
(newdel_res_t, null_res_t, constant_init, newdel_res, null_res)
(default_res, new_delete_resource, null_memory_resource)
(set_default_resource, get_default_resource): Define.
* testsuite/20_util/memory_resource/1.cc: New test.
* testsuite/20_util/memory_resource/2.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/1.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/deallocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/release.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/upstream_resource.cc:
New test.
* testsuite/20_util/polymorphic_allocator/1.cc: New test.
* testsuite/20_util/polymorphic_allocator/resource.cc: New test.
* testsuite/20_util/polymorphic_allocator/select.cc: New test.
* testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource):
Define concrete memory resource for testing.
(__gnu_test::default_resource_mgr): Define RAII helper for changing
default resource.
From-SVN: r262953
2018-07-24 23:09:55 +02:00
|
|
|
|
2019-05-14 13:17:27 +02:00
|
|
|
struct bad_size { };
|
|
|
|
struct bad_alignment { };
|
|
|
|
struct bad_address { };
|
Add initial version of C++17 <memory_resource> header
This is missing the synchronized_pool_resource and
unsynchronized_pool_resource classes but is otherwise complete.
This is a new implementation, not based on the existing code in
<experimental/memory_resource>, but memory_resource and
polymorphic_allocator ended up looking almost the same anyway.
The constant_init kluge in src/c++17/memory_resource.cc is apparently
due to Richard Smith and ensures that the objects are constructed during
constant initialiation phase and not destroyed (because the
constant_init destructor doesn't destroy the union member and the
storage is not reused).
* config/abi/pre/gnu.ver: Export new symbols.
* configure: Regenerate.
* include/Makefile.am: Add new <memory_resource> header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <memory_resource> for C++17.
* include/std/memory_resource: New header.
(memory_resource, polymorphic_allocator, new_delete_resource)
(null_memory_resource, set_default_resource, get_default_resource)
(pool_options, monotonic_buffer_resource): Define.
* src/Makefile.am: Add c++17 directory.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.am: Fix comment.
* src/c++17/Makefile.am: Add makefile for new sub-directory.
* src/c++17/Makefile.in: Generate.
* src/c++17/memory_resource.cc: New.
(newdel_res_t, null_res_t, constant_init, newdel_res, null_res)
(default_res, new_delete_resource, null_memory_resource)
(set_default_resource, get_default_resource): Define.
* testsuite/20_util/memory_resource/1.cc: New test.
* testsuite/20_util/memory_resource/2.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/1.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/deallocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/release.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/upstream_resource.cc:
New test.
* testsuite/20_util/polymorphic_allocator/1.cc: New test.
* testsuite/20_util/polymorphic_allocator/resource.cc: New test.
* testsuite/20_util/polymorphic_allocator/select.cc: New test.
* testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource):
Define concrete memory resource for testing.
(__gnu_test::default_resource_mgr): Define RAII helper for changing
default resource.
From-SVN: r262953
2018-07-24 23:09:55 +02:00
|
|
|
|
2019-05-14 13:17:27 +02:00
|
|
|
// Deallocate everything (moving the tracking info to the freed list)
|
|
|
|
void
|
|
|
|
deallocate_everything()
|
|
|
|
{
|
|
|
|
while (lists->active)
|
|
|
|
{
|
|
|
|
auto a = lists->active;
|
|
|
|
// Intentionally virtual dispatch, to inform derived classes:
|
|
|
|
this->do_deallocate(a->p, a->bytes, a->alignment);
|
|
|
|
}
|
|
|
|
}
|
Add initial version of C++17 <memory_resource> header
This is missing the synchronized_pool_resource and
unsynchronized_pool_resource classes but is otherwise complete.
This is a new implementation, not based on the existing code in
<experimental/memory_resource>, but memory_resource and
polymorphic_allocator ended up looking almost the same anyway.
The constant_init kluge in src/c++17/memory_resource.cc is apparently
due to Richard Smith and ensures that the objects are constructed during
constant initialiation phase and not destroyed (because the
constant_init destructor doesn't destroy the union member and the
storage is not reused).
* config/abi/pre/gnu.ver: Export new symbols.
* configure: Regenerate.
* include/Makefile.am: Add new <memory_resource> header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <memory_resource> for C++17.
* include/std/memory_resource: New header.
(memory_resource, polymorphic_allocator, new_delete_resource)
(null_memory_resource, set_default_resource, get_default_resource)
(pool_options, monotonic_buffer_resource): Define.
* src/Makefile.am: Add c++17 directory.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.am: Fix comment.
* src/c++17/Makefile.am: Add makefile for new sub-directory.
* src/c++17/Makefile.in: Generate.
* src/c++17/memory_resource.cc: New.
(newdel_res_t, null_res_t, constant_init, newdel_res, null_res)
(default_res, new_delete_resource, null_memory_resource)
(set_default_resource, get_default_resource): Define.
* testsuite/20_util/memory_resource/1.cc: New test.
* testsuite/20_util/memory_resource/2.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/1.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/deallocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/release.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/upstream_resource.cc:
New test.
* testsuite/20_util/polymorphic_allocator/1.cc: New test.
* testsuite/20_util/polymorphic_allocator/resource.cc: New test.
* testsuite/20_util/polymorphic_allocator/select.cc: New test.
* testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource):
Define concrete memory resource for testing.
(__gnu_test::default_resource_mgr): Define RAII helper for changing
default resource.
From-SVN: r262953
2018-07-24 23:09:55 +02:00
|
|
|
|
2019-05-14 13:17:27 +02:00
|
|
|
// Clear the freed list
|
|
|
|
void
|
|
|
|
forget_freed_allocations()
|
|
|
|
{ lists->forget_allocations(lists->freed); }
|
Add initial version of C++17 <memory_resource> header
This is missing the synchronized_pool_resource and
unsynchronized_pool_resource classes but is otherwise complete.
This is a new implementation, not based on the existing code in
<experimental/memory_resource>, but memory_resource and
polymorphic_allocator ended up looking almost the same anyway.
The constant_init kluge in src/c++17/memory_resource.cc is apparently
due to Richard Smith and ensures that the objects are constructed during
constant initialiation phase and not destroyed (because the
constant_init destructor doesn't destroy the union member and the
storage is not reused).
* config/abi/pre/gnu.ver: Export new symbols.
* configure: Regenerate.
* include/Makefile.am: Add new <memory_resource> header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <memory_resource> for C++17.
* include/std/memory_resource: New header.
(memory_resource, polymorphic_allocator, new_delete_resource)
(null_memory_resource, set_default_resource, get_default_resource)
(pool_options, monotonic_buffer_resource): Define.
* src/Makefile.am: Add c++17 directory.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.am: Fix comment.
* src/c++17/Makefile.am: Add makefile for new sub-directory.
* src/c++17/Makefile.in: Generate.
* src/c++17/memory_resource.cc: New.
(newdel_res_t, null_res_t, constant_init, newdel_res, null_res)
(default_res, new_delete_resource, null_memory_resource)
(set_default_resource, get_default_resource): Define.
* testsuite/20_util/memory_resource/1.cc: New test.
* testsuite/20_util/memory_resource/2.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/1.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/deallocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/release.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/upstream_resource.cc:
New test.
* testsuite/20_util/polymorphic_allocator/1.cc: New test.
* testsuite/20_util/polymorphic_allocator/resource.cc: New test.
* testsuite/20_util/polymorphic_allocator/select.cc: New test.
* testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource):
Define concrete memory resource for testing.
(__gnu_test::default_resource_mgr): Define RAII helper for changing
default resource.
From-SVN: r262953
2018-07-24 23:09:55 +02:00
|
|
|
|
2019-05-14 13:17:27 +02:00
|
|
|
// Count how many allocations have been done and not freed.
|
|
|
|
std::size_t
|
|
|
|
number_of_active_allocations() const noexcept
|
|
|
|
{
|
|
|
|
std::size_t n = 0;
|
|
|
|
for (auto a = lists->active; a != nullptr; a = a->next)
|
|
|
|
++n;
|
|
|
|
return n;
|
|
|
|
}
|
Add initial version of C++17 <memory_resource> header
This is missing the synchronized_pool_resource and
unsynchronized_pool_resource classes but is otherwise complete.
This is a new implementation, not based on the existing code in
<experimental/memory_resource>, but memory_resource and
polymorphic_allocator ended up looking almost the same anyway.
The constant_init kluge in src/c++17/memory_resource.cc is apparently
due to Richard Smith and ensures that the objects are constructed during
constant initialiation phase and not destroyed (because the
constant_init destructor doesn't destroy the union member and the
storage is not reused).
* config/abi/pre/gnu.ver: Export new symbols.
* configure: Regenerate.
* include/Makefile.am: Add new <memory_resource> header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <memory_resource> for C++17.
* include/std/memory_resource: New header.
(memory_resource, polymorphic_allocator, new_delete_resource)
(null_memory_resource, set_default_resource, get_default_resource)
(pool_options, monotonic_buffer_resource): Define.
* src/Makefile.am: Add c++17 directory.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.am: Fix comment.
* src/c++17/Makefile.am: Add makefile for new sub-directory.
* src/c++17/Makefile.in: Generate.
* src/c++17/memory_resource.cc: New.
(newdel_res_t, null_res_t, constant_init, newdel_res, null_res)
(default_res, new_delete_resource, null_memory_resource)
(set_default_resource, get_default_resource): Define.
* testsuite/20_util/memory_resource/1.cc: New test.
* testsuite/20_util/memory_resource/2.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/1.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/deallocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/release.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/upstream_resource.cc:
New test.
* testsuite/20_util/polymorphic_allocator/1.cc: New test.
* testsuite/20_util/polymorphic_allocator/resource.cc: New test.
* testsuite/20_util/polymorphic_allocator/select.cc: New test.
* testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource):
Define concrete memory resource for testing.
(__gnu_test::default_resource_mgr): Define RAII helper for changing
default resource.
From-SVN: r262953
2018-07-24 23:09:55 +02:00
|
|
|
|
2019-05-14 13:17:27 +02:00
|
|
|
protected:
|
|
|
|
void*
|
|
|
|
do_allocate(std::size_t bytes, std::size_t alignment) override
|
|
|
|
{
|
|
|
|
// TODO perform a single allocation and put the allocation struct
|
|
|
|
// in the buffer using placement new? It means deallocation won't
|
|
|
|
// actually return memory to the OS, as it will stay in lists->freed.
|
|
|
|
//
|
|
|
|
// TODO adjust the returned pointer to be minimally aligned?
|
|
|
|
// e.g. if alignment==1 don't return something aligned to 2 bytes.
|
|
|
|
// Maybe not worth it, at least monotonic_buffer_resource will
|
|
|
|
// never ask upstream for anything with small alignment.
|
|
|
|
void* p = ::operator new(bytes, std::align_val_t(alignment));
|
|
|
|
lists->active = new allocation{p, bytes, alignment, lists->active};
|
|
|
|
return p;
|
|
|
|
}
|
Add initial version of C++17 <memory_resource> header
This is missing the synchronized_pool_resource and
unsynchronized_pool_resource classes but is otherwise complete.
This is a new implementation, not based on the existing code in
<experimental/memory_resource>, but memory_resource and
polymorphic_allocator ended up looking almost the same anyway.
The constant_init kluge in src/c++17/memory_resource.cc is apparently
due to Richard Smith and ensures that the objects are constructed during
constant initialiation phase and not destroyed (because the
constant_init destructor doesn't destroy the union member and the
storage is not reused).
* config/abi/pre/gnu.ver: Export new symbols.
* configure: Regenerate.
* include/Makefile.am: Add new <memory_resource> header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <memory_resource> for C++17.
* include/std/memory_resource: New header.
(memory_resource, polymorphic_allocator, new_delete_resource)
(null_memory_resource, set_default_resource, get_default_resource)
(pool_options, monotonic_buffer_resource): Define.
* src/Makefile.am: Add c++17 directory.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.am: Fix comment.
* src/c++17/Makefile.am: Add makefile for new sub-directory.
* src/c++17/Makefile.in: Generate.
* src/c++17/memory_resource.cc: New.
(newdel_res_t, null_res_t, constant_init, newdel_res, null_res)
(default_res, new_delete_resource, null_memory_resource)
(set_default_resource, get_default_resource): Define.
* testsuite/20_util/memory_resource/1.cc: New test.
* testsuite/20_util/memory_resource/2.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/1.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/deallocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/release.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/upstream_resource.cc:
New test.
* testsuite/20_util/polymorphic_allocator/1.cc: New test.
* testsuite/20_util/polymorphic_allocator/resource.cc: New test.
* testsuite/20_util/polymorphic_allocator/select.cc: New test.
* testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource):
Define concrete memory resource for testing.
(__gnu_test::default_resource_mgr): Define RAII helper for changing
default resource.
From-SVN: r262953
2018-07-24 23:09:55 +02:00
|
|
|
|
2019-05-14 13:17:27 +02:00
|
|
|
void
|
|
|
|
do_deallocate(void* p, std::size_t bytes, std::size_t alignment) override
|
|
|
|
{
|
|
|
|
allocation** aptr = &lists->active;
|
|
|
|
while (*aptr)
|
|
|
|
{
|
|
|
|
allocation* a = *aptr;
|
|
|
|
if (p == a->p)
|
|
|
|
{
|
|
|
|
if (bytes != a->bytes)
|
|
|
|
throw bad_size();
|
|
|
|
if (alignment != a->alignment)
|
|
|
|
throw bad_alignment();
|
2019-03-01 14:50:41 +01:00
|
|
|
#if __cpp_sized_deallocation
|
2019-05-14 13:17:27 +02:00
|
|
|
::operator delete(p, bytes, std::align_val_t(alignment));
|
2019-03-01 14:50:41 +01:00
|
|
|
#else
|
2019-05-14 13:17:27 +02:00
|
|
|
::operator delete(p, std::align_val_t(alignment));
|
2019-03-01 14:50:41 +01:00
|
|
|
#endif
|
2019-05-14 13:17:27 +02:00
|
|
|
*aptr = a->next;
|
|
|
|
a->next = lists->freed;
|
|
|
|
lists->freed = a;
|
|
|
|
return;
|
Add initial version of C++17 <memory_resource> header
This is missing the synchronized_pool_resource and
unsynchronized_pool_resource classes but is otherwise complete.
This is a new implementation, not based on the existing code in
<experimental/memory_resource>, but memory_resource and
polymorphic_allocator ended up looking almost the same anyway.
The constant_init kluge in src/c++17/memory_resource.cc is apparently
due to Richard Smith and ensures that the objects are constructed during
constant initialiation phase and not destroyed (because the
constant_init destructor doesn't destroy the union member and the
storage is not reused).
* config/abi/pre/gnu.ver: Export new symbols.
* configure: Regenerate.
* include/Makefile.am: Add new <memory_resource> header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <memory_resource> for C++17.
* include/std/memory_resource: New header.
(memory_resource, polymorphic_allocator, new_delete_resource)
(null_memory_resource, set_default_resource, get_default_resource)
(pool_options, monotonic_buffer_resource): Define.
* src/Makefile.am: Add c++17 directory.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.am: Fix comment.
* src/c++17/Makefile.am: Add makefile for new sub-directory.
* src/c++17/Makefile.in: Generate.
* src/c++17/memory_resource.cc: New.
(newdel_res_t, null_res_t, constant_init, newdel_res, null_res)
(default_res, new_delete_resource, null_memory_resource)
(set_default_resource, get_default_resource): Define.
* testsuite/20_util/memory_resource/1.cc: New test.
* testsuite/20_util/memory_resource/2.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/1.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/deallocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/release.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/upstream_resource.cc:
New test.
* testsuite/20_util/polymorphic_allocator/1.cc: New test.
* testsuite/20_util/polymorphic_allocator/resource.cc: New test.
* testsuite/20_util/polymorphic_allocator/select.cc: New test.
* testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource):
Define concrete memory resource for testing.
(__gnu_test::default_resource_mgr): Define RAII helper for changing
default resource.
From-SVN: r262953
2018-07-24 23:09:55 +02:00
|
|
|
}
|
2019-05-14 13:17:27 +02:00
|
|
|
aptr = &a->next;
|
Add initial version of C++17 <memory_resource> header
This is missing the synchronized_pool_resource and
unsynchronized_pool_resource classes but is otherwise complete.
This is a new implementation, not based on the existing code in
<experimental/memory_resource>, but memory_resource and
polymorphic_allocator ended up looking almost the same anyway.
The constant_init kluge in src/c++17/memory_resource.cc is apparently
due to Richard Smith and ensures that the objects are constructed during
constant initialiation phase and not destroyed (because the
constant_init destructor doesn't destroy the union member and the
storage is not reused).
* config/abi/pre/gnu.ver: Export new symbols.
* configure: Regenerate.
* include/Makefile.am: Add new <memory_resource> header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <memory_resource> for C++17.
* include/std/memory_resource: New header.
(memory_resource, polymorphic_allocator, new_delete_resource)
(null_memory_resource, set_default_resource, get_default_resource)
(pool_options, monotonic_buffer_resource): Define.
* src/Makefile.am: Add c++17 directory.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.am: Fix comment.
* src/c++17/Makefile.am: Add makefile for new sub-directory.
* src/c++17/Makefile.in: Generate.
* src/c++17/memory_resource.cc: New.
(newdel_res_t, null_res_t, constant_init, newdel_res, null_res)
(default_res, new_delete_resource, null_memory_resource)
(set_default_resource, get_default_resource): Define.
* testsuite/20_util/memory_resource/1.cc: New test.
* testsuite/20_util/memory_resource/2.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/1.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/deallocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/release.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/upstream_resource.cc:
New test.
* testsuite/20_util/polymorphic_allocator/1.cc: New test.
* testsuite/20_util/polymorphic_allocator/resource.cc: New test.
* testsuite/20_util/polymorphic_allocator/select.cc: New test.
* testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource):
Define concrete memory resource for testing.
(__gnu_test::default_resource_mgr): Define RAII helper for changing
default resource.
From-SVN: r262953
2018-07-24 23:09:55 +02:00
|
|
|
}
|
2019-05-14 13:17:27 +02:00
|
|
|
throw bad_address();
|
|
|
|
}
|
Add initial version of C++17 <memory_resource> header
This is missing the synchronized_pool_resource and
unsynchronized_pool_resource classes but is otherwise complete.
This is a new implementation, not based on the existing code in
<experimental/memory_resource>, but memory_resource and
polymorphic_allocator ended up looking almost the same anyway.
The constant_init kluge in src/c++17/memory_resource.cc is apparently
due to Richard Smith and ensures that the objects are constructed during
constant initialiation phase and not destroyed (because the
constant_init destructor doesn't destroy the union member and the
storage is not reused).
* config/abi/pre/gnu.ver: Export new symbols.
* configure: Regenerate.
* include/Makefile.am: Add new <memory_resource> header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <memory_resource> for C++17.
* include/std/memory_resource: New header.
(memory_resource, polymorphic_allocator, new_delete_resource)
(null_memory_resource, set_default_resource, get_default_resource)
(pool_options, monotonic_buffer_resource): Define.
* src/Makefile.am: Add c++17 directory.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.am: Fix comment.
* src/c++17/Makefile.am: Add makefile for new sub-directory.
* src/c++17/Makefile.in: Generate.
* src/c++17/memory_resource.cc: New.
(newdel_res_t, null_res_t, constant_init, newdel_res, null_res)
(default_res, new_delete_resource, null_memory_resource)
(set_default_resource, get_default_resource): Define.
* testsuite/20_util/memory_resource/1.cc: New test.
* testsuite/20_util/memory_resource/2.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/1.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/deallocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/release.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/upstream_resource.cc:
New test.
* testsuite/20_util/polymorphic_allocator/1.cc: New test.
* testsuite/20_util/polymorphic_allocator/resource.cc: New test.
* testsuite/20_util/polymorphic_allocator/select.cc: New test.
* testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource):
Define concrete memory resource for testing.
(__gnu_test::default_resource_mgr): Define RAII helper for changing
default resource.
From-SVN: r262953
2018-07-24 23:09:55 +02:00
|
|
|
|
2019-05-14 13:17:27 +02:00
|
|
|
bool
|
|
|
|
do_is_equal(const std::pmr::memory_resource& r) const noexcept override
|
|
|
|
{
|
|
|
|
// Equality is determined by sharing the same allocation_lists object.
|
|
|
|
if (auto p = dynamic_cast<const memory_resource*>(&r))
|
|
|
|
return p->lists == lists;
|
|
|
|
return false;
|
|
|
|
}
|
Add initial version of C++17 <memory_resource> header
This is missing the synchronized_pool_resource and
unsynchronized_pool_resource classes but is otherwise complete.
This is a new implementation, not based on the existing code in
<experimental/memory_resource>, but memory_resource and
polymorphic_allocator ended up looking almost the same anyway.
The constant_init kluge in src/c++17/memory_resource.cc is apparently
due to Richard Smith and ensures that the objects are constructed during
constant initialiation phase and not destroyed (because the
constant_init destructor doesn't destroy the union member and the
storage is not reused).
* config/abi/pre/gnu.ver: Export new symbols.
* configure: Regenerate.
* include/Makefile.am: Add new <memory_resource> header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <memory_resource> for C++17.
* include/std/memory_resource: New header.
(memory_resource, polymorphic_allocator, new_delete_resource)
(null_memory_resource, set_default_resource, get_default_resource)
(pool_options, monotonic_buffer_resource): Define.
* src/Makefile.am: Add c++17 directory.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.am: Fix comment.
* src/c++17/Makefile.am: Add makefile for new sub-directory.
* src/c++17/Makefile.in: Generate.
* src/c++17/memory_resource.cc: New.
(newdel_res_t, null_res_t, constant_init, newdel_res, null_res)
(default_res, new_delete_resource, null_memory_resource)
(set_default_resource, get_default_resource): Define.
* testsuite/20_util/memory_resource/1.cc: New test.
* testsuite/20_util/memory_resource/2.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/1.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/deallocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/release.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/upstream_resource.cc:
New test.
* testsuite/20_util/polymorphic_allocator/1.cc: New test.
* testsuite/20_util/polymorphic_allocator/resource.cc: New test.
* testsuite/20_util/polymorphic_allocator/select.cc: New test.
* testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource):
Define concrete memory resource for testing.
(__gnu_test::default_resource_mgr): Define RAII helper for changing
default resource.
From-SVN: r262953
2018-07-24 23:09:55 +02:00
|
|
|
|
2019-05-14 13:17:27 +02:00
|
|
|
private:
|
|
|
|
struct allocation
|
|
|
|
{
|
|
|
|
void* p;
|
|
|
|
std::size_t bytes;
|
|
|
|
std::size_t alignment;
|
|
|
|
allocation* next;
|
Add initial version of C++17 <memory_resource> header
This is missing the synchronized_pool_resource and
unsynchronized_pool_resource classes but is otherwise complete.
This is a new implementation, not based on the existing code in
<experimental/memory_resource>, but memory_resource and
polymorphic_allocator ended up looking almost the same anyway.
The constant_init kluge in src/c++17/memory_resource.cc is apparently
due to Richard Smith and ensures that the objects are constructed during
constant initialiation phase and not destroyed (because the
constant_init destructor doesn't destroy the union member and the
storage is not reused).
* config/abi/pre/gnu.ver: Export new symbols.
* configure: Regenerate.
* include/Makefile.am: Add new <memory_resource> header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <memory_resource> for C++17.
* include/std/memory_resource: New header.
(memory_resource, polymorphic_allocator, new_delete_resource)
(null_memory_resource, set_default_resource, get_default_resource)
(pool_options, monotonic_buffer_resource): Define.
* src/Makefile.am: Add c++17 directory.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.am: Fix comment.
* src/c++17/Makefile.am: Add makefile for new sub-directory.
* src/c++17/Makefile.in: Generate.
* src/c++17/memory_resource.cc: New.
(newdel_res_t, null_res_t, constant_init, newdel_res, null_res)
(default_res, new_delete_resource, null_memory_resource)
(set_default_resource, get_default_resource): Define.
* testsuite/20_util/memory_resource/1.cc: New test.
* testsuite/20_util/memory_resource/2.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/1.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/deallocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/release.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/upstream_resource.cc:
New test.
* testsuite/20_util/polymorphic_allocator/1.cc: New test.
* testsuite/20_util/polymorphic_allocator/resource.cc: New test.
* testsuite/20_util/polymorphic_allocator/select.cc: New test.
* testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource):
Define concrete memory resource for testing.
(__gnu_test::default_resource_mgr): Define RAII helper for changing
default resource.
From-SVN: r262953
2018-07-24 23:09:55 +02:00
|
|
|
};
|
|
|
|
|
2019-05-14 13:17:27 +02:00
|
|
|
// Maintain list of allocated blocks and list of freed blocks.
|
|
|
|
// Copies of this memory_resource share the same ref-counted lists.
|
|
|
|
struct allocation_lists
|
Add initial version of C++17 <memory_resource> header
This is missing the synchronized_pool_resource and
unsynchronized_pool_resource classes but is otherwise complete.
This is a new implementation, not based on the existing code in
<experimental/memory_resource>, but memory_resource and
polymorphic_allocator ended up looking almost the same anyway.
The constant_init kluge in src/c++17/memory_resource.cc is apparently
due to Richard Smith and ensures that the objects are constructed during
constant initialiation phase and not destroyed (because the
constant_init destructor doesn't destroy the union member and the
storage is not reused).
* config/abi/pre/gnu.ver: Export new symbols.
* configure: Regenerate.
* include/Makefile.am: Add new <memory_resource> header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <memory_resource> for C++17.
* include/std/memory_resource: New header.
(memory_resource, polymorphic_allocator, new_delete_resource)
(null_memory_resource, set_default_resource, get_default_resource)
(pool_options, monotonic_buffer_resource): Define.
* src/Makefile.am: Add c++17 directory.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.am: Fix comment.
* src/c++17/Makefile.am: Add makefile for new sub-directory.
* src/c++17/Makefile.in: Generate.
* src/c++17/memory_resource.cc: New.
(newdel_res_t, null_res_t, constant_init, newdel_res, null_res)
(default_res, new_delete_resource, null_memory_resource)
(set_default_resource, get_default_resource): Define.
* testsuite/20_util/memory_resource/1.cc: New test.
* testsuite/20_util/memory_resource/2.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/1.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/deallocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/release.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/upstream_resource.cc:
New test.
* testsuite/20_util/polymorphic_allocator/1.cc: New test.
* testsuite/20_util/polymorphic_allocator/resource.cc: New test.
* testsuite/20_util/polymorphic_allocator/select.cc: New test.
* testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource):
Define concrete memory resource for testing.
(__gnu_test::default_resource_mgr): Define RAII helper for changing
default resource.
From-SVN: r262953
2018-07-24 23:09:55 +02:00
|
|
|
{
|
2019-05-14 13:17:27 +02:00
|
|
|
unsigned refcount = 1;
|
|
|
|
allocation* active = nullptr;
|
|
|
|
allocation* freed = nullptr;
|
Add initial version of C++17 <memory_resource> header
This is missing the synchronized_pool_resource and
unsynchronized_pool_resource classes but is otherwise complete.
This is a new implementation, not based on the existing code in
<experimental/memory_resource>, but memory_resource and
polymorphic_allocator ended up looking almost the same anyway.
The constant_init kluge in src/c++17/memory_resource.cc is apparently
due to Richard Smith and ensures that the objects are constructed during
constant initialiation phase and not destroyed (because the
constant_init destructor doesn't destroy the union member and the
storage is not reused).
* config/abi/pre/gnu.ver: Export new symbols.
* configure: Regenerate.
* include/Makefile.am: Add new <memory_resource> header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <memory_resource> for C++17.
* include/std/memory_resource: New header.
(memory_resource, polymorphic_allocator, new_delete_resource)
(null_memory_resource, set_default_resource, get_default_resource)
(pool_options, monotonic_buffer_resource): Define.
* src/Makefile.am: Add c++17 directory.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.am: Fix comment.
* src/c++17/Makefile.am: Add makefile for new sub-directory.
* src/c++17/Makefile.in: Generate.
* src/c++17/memory_resource.cc: New.
(newdel_res_t, null_res_t, constant_init, newdel_res, null_res)
(default_res, new_delete_resource, null_memory_resource)
(set_default_resource, get_default_resource): Define.
* testsuite/20_util/memory_resource/1.cc: New test.
* testsuite/20_util/memory_resource/2.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/1.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/deallocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/release.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/upstream_resource.cc:
New test.
* testsuite/20_util/polymorphic_allocator/1.cc: New test.
* testsuite/20_util/polymorphic_allocator/resource.cc: New test.
* testsuite/20_util/polymorphic_allocator/select.cc: New test.
* testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource):
Define concrete memory resource for testing.
(__gnu_test::default_resource_mgr): Define RAII helper for changing
default resource.
From-SVN: r262953
2018-07-24 23:09:55 +02:00
|
|
|
|
2019-05-14 13:17:27 +02:00
|
|
|
void forget_allocations(allocation*& list)
|
|
|
|
{
|
|
|
|
while (list)
|
|
|
|
{
|
|
|
|
auto p = list;
|
|
|
|
list = list->next;
|
|
|
|
delete p;
|
|
|
|
}
|
|
|
|
}
|
Add initial version of C++17 <memory_resource> header
This is missing the synchronized_pool_resource and
unsynchronized_pool_resource classes but is otherwise complete.
This is a new implementation, not based on the existing code in
<experimental/memory_resource>, but memory_resource and
polymorphic_allocator ended up looking almost the same anyway.
The constant_init kluge in src/c++17/memory_resource.cc is apparently
due to Richard Smith and ensures that the objects are constructed during
constant initialiation phase and not destroyed (because the
constant_init destructor doesn't destroy the union member and the
storage is not reused).
* config/abi/pre/gnu.ver: Export new symbols.
* configure: Regenerate.
* include/Makefile.am: Add new <memory_resource> header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <memory_resource> for C++17.
* include/std/memory_resource: New header.
(memory_resource, polymorphic_allocator, new_delete_resource)
(null_memory_resource, set_default_resource, get_default_resource)
(pool_options, monotonic_buffer_resource): Define.
* src/Makefile.am: Add c++17 directory.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.am: Fix comment.
* src/c++17/Makefile.am: Add makefile for new sub-directory.
* src/c++17/Makefile.in: Generate.
* src/c++17/memory_resource.cc: New.
(newdel_res_t, null_res_t, constant_init, newdel_res, null_res)
(default_res, new_delete_resource, null_memory_resource)
(set_default_resource, get_default_resource): Define.
* testsuite/20_util/memory_resource/1.cc: New test.
* testsuite/20_util/memory_resource/2.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/1.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/deallocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/release.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/upstream_resource.cc:
New test.
* testsuite/20_util/polymorphic_allocator/1.cc: New test.
* testsuite/20_util/polymorphic_allocator/resource.cc: New test.
* testsuite/20_util/polymorphic_allocator/select.cc: New test.
* testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource):
Define concrete memory resource for testing.
(__gnu_test::default_resource_mgr): Define RAII helper for changing
default resource.
From-SVN: r262953
2018-07-24 23:09:55 +02:00
|
|
|
|
2019-05-14 13:17:27 +02:00
|
|
|
~allocation_lists()
|
|
|
|
{
|
|
|
|
forget_allocations(active); // Anything in this list is a leak!
|
|
|
|
forget_allocations(freed);
|
|
|
|
}
|
Add initial version of C++17 <memory_resource> header
This is missing the synchronized_pool_resource and
unsynchronized_pool_resource classes but is otherwise complete.
This is a new implementation, not based on the existing code in
<experimental/memory_resource>, but memory_resource and
polymorphic_allocator ended up looking almost the same anyway.
The constant_init kluge in src/c++17/memory_resource.cc is apparently
due to Richard Smith and ensures that the objects are constructed during
constant initialiation phase and not destroyed (because the
constant_init destructor doesn't destroy the union member and the
storage is not reused).
* config/abi/pre/gnu.ver: Export new symbols.
* configure: Regenerate.
* include/Makefile.am: Add new <memory_resource> header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <memory_resource> for C++17.
* include/std/memory_resource: New header.
(memory_resource, polymorphic_allocator, new_delete_resource)
(null_memory_resource, set_default_resource, get_default_resource)
(pool_options, monotonic_buffer_resource): Define.
* src/Makefile.am: Add c++17 directory.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.am: Fix comment.
* src/c++17/Makefile.am: Add makefile for new sub-directory.
* src/c++17/Makefile.in: Generate.
* src/c++17/memory_resource.cc: New.
(newdel_res_t, null_res_t, constant_init, newdel_res, null_res)
(default_res, new_delete_resource, null_memory_resource)
(set_default_resource, get_default_resource): Define.
* testsuite/20_util/memory_resource/1.cc: New test.
* testsuite/20_util/memory_resource/2.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/1.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/deallocate.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/release.cc: New test.
* testsuite/20_util/monotonic_buffer_resource/upstream_resource.cc:
New test.
* testsuite/20_util/polymorphic_allocator/1.cc: New test.
* testsuite/20_util/polymorphic_allocator/resource.cc: New test.
* testsuite/20_util/polymorphic_allocator/select.cc: New test.
* testsuite/util/testsuite_allocator.h (__gnu_test::memory_resource):
Define concrete memory resource for testing.
(__gnu_test::default_resource_mgr): Define RAII helper for changing
default resource.
From-SVN: r262953
2018-07-24 23:09:55 +02:00
|
|
|
};
|
|
|
|
|
2019-05-14 13:17:27 +02:00
|
|
|
allocation_lists* lists;
|
|
|
|
};
|
|
|
|
#endif // aligned-new && rtti
|
|
|
|
|
|
|
|
// Set the default resource, and restore the previous one on destruction.
|
|
|
|
struct default_resource_mgr
|
|
|
|
{
|
|
|
|
explicit default_resource_mgr(std::pmr::memory_resource* r)
|
|
|
|
: prev(std::pmr::set_default_resource(r))
|
|
|
|
{ }
|
|
|
|
|
|
|
|
~default_resource_mgr()
|
|
|
|
{ std::pmr::set_default_resource(prev); }
|
|
|
|
|
|
|
|
std::pmr::memory_resource* prev;
|
|
|
|
};
|
|
|
|
|
2018-08-23 21:27:54 +02:00
|
|
|
#endif // C++17
|
2013-06-16 19:13:34 +02:00
|
|
|
|
2007-12-09 20:43:49 +01:00
|
|
|
} // namespace __gnu_test
|
2002-11-26 01:53:12 +01:00
|
|
|
|
2003-07-05 06:05:45 +02:00
|
|
|
#endif // _GLIBCXX_TESTSUITE_ALLOCATOR_H
|