fix allocator issue

main
Brett 2024-03-08 16:37:37 -05:00
parent 2a8734f0c0
commit 2ad3bddc17
4 changed files with 38 additions and 15 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25) cmake_minimum_required(VERSION 3.25)
project(lilfbtf5 VERSION 0.1.4) project(lilfbtf5 VERSION 0.1.5)
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)

@ -1 +1 @@
Subproject commit b4be72795d7deee0e2bbbb54f6e84424d3a1092f Subproject commit 55bae674077139b78eeeb6c94361662ec2b2a8be

View File

@ -47,7 +47,7 @@ int main(int argc, const char** argv)
if (args.contains("--tests")) if (args.contains("--tests"))
{ {
//fb::test2(); fb::test2();
fb::test3(); fb::test3();
BLT_PRINT_PROFILE("Tree Construction"); BLT_PRINT_PROFILE("Tree Construction");

View File

@ -255,12 +255,21 @@ namespace fb
{ {
base_t* type = nullptr; base_t* type = nullptr;
node_t** children = nullptr; node_t** children = nullptr;
type_t type_value;
explicit node_t(type_t type): type(create_node_type(type)) explicit node_t(type_t type): type(create_node_type(type)), type_value(type)
{ {
if (this->type == nullptr) if (this->type == nullptr)
throw std::bad_alloc(); throw std::bad_alloc();
else if (reinterpret_cast<blt::size_t>(this->type) % alignof(base_t*) != 0)
BLT_WARN("type pointer %p is misaligned, expecting alignment of %ld reminder %ld", this->type, alignof(base_t*),
reinterpret_cast<blt::size_t>(this->type) % alignof(base_t*));
children = alloc.emplace_many<node_t*>(this->type->argc()); children = alloc.emplace_many<node_t*>(this->type->argc());
for (blt::size_t i = 0; i < this->type->argc(); i++)
children[i] = nullptr;
if (reinterpret_cast<blt::size_t>(this->children) % alignof(node_t**) != 0)
BLT_WARN("children pointer is misaligned, expecting alignment of %ld remainder %ld", this->children, alignof(node_t**),
reinterpret_cast<blt::size_t>(this->children) % alignof(node_t**));
} }
void evaluate() const void evaluate() const
@ -301,17 +310,11 @@ namespace fb
~node_t() ~node_t()
{ {
if (children != nullptr) for (blt::size_t i = 0; i < type->argc(); i++)
{ {
for (blt::size_t i = 0; i < type->argc(); i++) alloc.destroy(children[i]);
{ alloc.deallocate(children[i]);
alloc.destroy(children[i]); }
alloc.deallocate(children[i]);
}
} else
if (type->argc() != 0)
BLT_WARN("Hey wtf is up %ld", type->argc());
alloc.destroy(children);
alloc.deallocate(children); alloc.deallocate(children);
alloc.destroy(type); alloc.destroy(type);
alloc.deallocate(type); alloc.deallocate(type);
@ -432,7 +435,27 @@ namespace fb
delete[] cum; delete[] cum;
//run(); run();
run2(); run2();
// using testing = blt::size_t;
// constexpr blt::size_t INT_SIZE = blt::BLT_2MB_SIZE * 8 / sizeof(testing);
// auto** data = new testing*[INT_SIZE];
//
// for (blt::size_t i = 0; i < INT_SIZE; i++)
// {
// data[i] = alloc.emplace<testing>();
// *data[i] = 256;
// }
//
// for (blt::size_t i = 0; i < INT_SIZE; i++)
// {
// alloc.deallocate(data[i]);
// auto* blk = alloc.blk(data[i]);
// if (*data[i] != 256)
// BLT_WARN("Data is not 256 (%d)! %ld || %ld || 0x%lx || 0x%lx pointer %p part of block %p", *data[i], i % blt::BLT_2MB_SIZE, i, i, i % blt::BLT_2MB_SIZE, data[i], blk);
// }
// delete[] data;
} }
} }