forked from boostorg/beast
allocator_traits::construct is used for user-defined types:
It should only be called when constructing a user-provided type. Close #1332 Signed-off-by: Damian Jarek <damian.jarek93@gmail.com>
This commit is contained in:
4 files changed
+29
-21
No files matched your search
@@ -42,8 +42,9 @@ struct allocate_stable_state final
|
||||
allocate_stable_state>;
|
||||
|
||||
A a(this->get());
|
||||
detail::allocator_traits<A>::destroy(a, this);
|
||||
detail::allocator_traits<A>::deallocate(a, this, 1);
|
||||
auto* p = this;
|
||||
p->~allocate_stable_state();
|
||||
a.deallocate(p, 1);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -118,33 +119,30 @@ allocate_stable(
|
||||
{
|
||||
using allocator_type = typename stable_async_base<
|
||||
Handler, Executor1, Allocator>::allocator_type;
|
||||
|
||||
using state = detail::allocate_stable_state<
|
||||
State, allocator_type>;
|
||||
using A = typename detail::allocator_traits<
|
||||
allocator_type>::template rebind_alloc<
|
||||
detail::allocate_stable_state<
|
||||
State, allocator_type>>;
|
||||
allocator_type>::template rebind_alloc<state>;
|
||||
|
||||
struct deleter
|
||||
{
|
||||
allocator_type alloc;
|
||||
detail::allocate_stable_state<
|
||||
State, allocator_type>* ptr;
|
||||
state* ptr;
|
||||
|
||||
~deleter()
|
||||
{
|
||||
if(ptr)
|
||||
{
|
||||
A a(alloc);
|
||||
detail::allocator_traits<A>::deallocate(a, ptr, 1);
|
||||
a.deallocate(ptr, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
A a(base.get_allocator());
|
||||
deleter d{base.get_allocator(), nullptr};
|
||||
d.ptr = detail::allocator_traits<A>::allocate(a, 1);
|
||||
detail::allocator_traits<A>::construct(a, d.ptr,
|
||||
d.alloc, std::forward<Args>(args)...);
|
||||
deleter d{base.get_allocator(), a.allocate(1)};
|
||||
::new(static_cast<void*>(d.ptr))
|
||||
state(d.alloc, std::forward<Args>(args)...);
|
||||
d.ptr->next_ = base.list_;
|
||||
base.list_ = d.ptr;
|
||||
return boost::exchange(d.ptr, nullptr)->value;
|
||||
|
||||
Reference in new issue
Block a user