mirror of
https://github.com/matrix-construct/construct
synced 2024-06-18 09:58:22 +02:00
ircd::util: Fix unsafe instance_list emplace; assert for allocator state.
This commit is contained in:
parent
5d71d848a7
commit
b271007fd2
|
@ -57,29 +57,50 @@ struct ircd::util::instance_list
|
|||
template<class T>
|
||||
ircd::util::instance_list<T>::instance_list()
|
||||
{
|
||||
const auto &alloc(list.get_allocator().s);
|
||||
const auto &address(reinterpret_cast<uint8_t *>(&node));
|
||||
list.get_allocator().s->next = reinterpret_cast<T **>(address);
|
||||
|
||||
assert(alloc);
|
||||
assert(!alloc->next);
|
||||
const scope_restore next
|
||||
{
|
||||
alloc->next, reinterpret_cast<T **>(address)
|
||||
};
|
||||
|
||||
it = list.emplace(end(list), static_cast<T *>(this));
|
||||
list.get_allocator().s->next = nullptr;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ircd::util::instance_list<T>::instance_list(instance_list &&other)
|
||||
noexcept
|
||||
{
|
||||
const auto &alloc(list.get_allocator().s);
|
||||
const auto &address(reinterpret_cast<uint8_t *>(&node));
|
||||
list.get_allocator().s->next = reinterpret_cast<T **>(address);
|
||||
|
||||
assert(alloc);
|
||||
assert(!alloc->next);
|
||||
const scope_restore next
|
||||
{
|
||||
alloc->next, reinterpret_cast<T **>(address)
|
||||
};
|
||||
|
||||
it = list.emplace(end(list), static_cast<T *>(this));
|
||||
list.get_allocator().s->next = nullptr;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ircd::util::instance_list<T>::instance_list(const instance_list &other)
|
||||
{
|
||||
const auto &alloc(list.get_allocator().s);
|
||||
const auto &address(reinterpret_cast<uint8_t *>(&node));
|
||||
list.get_allocator().s->next = reinterpret_cast<T **>(address);
|
||||
|
||||
assert(alloc);
|
||||
assert(!alloc->next);
|
||||
const scope_restore next
|
||||
{
|
||||
alloc->next, reinterpret_cast<T **>(address)
|
||||
};
|
||||
|
||||
it = list.emplace(end(list), static_cast<T *>(this));
|
||||
list.get_allocator().s->next = nullptr;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
|
|
|
@ -41,6 +41,8 @@ namespace ircd
|
|||
#include "env.h"
|
||||
#include "va_rtti.h"
|
||||
#include "unique_iterator.h"
|
||||
#include "scope_count.h"
|
||||
#include "scope_restore.h"
|
||||
#include "instance_list.h"
|
||||
#include "instance_multimap.h"
|
||||
#include "instance_map.h"
|
||||
|
@ -48,8 +50,6 @@ namespace ircd
|
|||
#include "bswap.h"
|
||||
#include "tuple.h"
|
||||
#include "timer.h"
|
||||
#include "scope_count.h"
|
||||
#include "scope_restore.h"
|
||||
#include "life_guard.h"
|
||||
#include "pubsetbuf.h"
|
||||
#include "string.h"
|
||||
|
|
Loading…
Reference in a new issue