From 2ad3bddc173907075773d57ddf38d33d9cb9f103 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Fri, 8 Mar 2024 16:37:37 -0500 Subject: [PATCH] fix allocator issue --- CMakeLists.txt | 2 +- libs/BLT | 2 +- tests/src/main.cpp | 2 +- tests/src/tests3.cpp | 47 +++++++++++++++++++++++++++++++++----------- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 27229bc..1770d85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ 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_UBSAN "Enable the ub sanitizer" OFF) diff --git a/libs/BLT b/libs/BLT index b4be727..55bae67 160000 --- a/libs/BLT +++ b/libs/BLT @@ -1 +1 @@ -Subproject commit b4be72795d7deee0e2bbbb54f6e84424d3a1092f +Subproject commit 55bae674077139b78eeeb6c94361662ec2b2a8be diff --git a/tests/src/main.cpp b/tests/src/main.cpp index ad701da..9049759 100644 --- a/tests/src/main.cpp +++ b/tests/src/main.cpp @@ -47,7 +47,7 @@ int main(int argc, const char** argv) if (args.contains("--tests")) { - //fb::test2(); + fb::test2(); fb::test3(); BLT_PRINT_PROFILE("Tree Construction"); diff --git a/tests/src/tests3.cpp b/tests/src/tests3.cpp index 3949146..0473e22 100644 --- a/tests/src/tests3.cpp +++ b/tests/src/tests3.cpp @@ -255,12 +255,21 @@ namespace fb { base_t* type = 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) throw std::bad_alloc(); + else if (reinterpret_cast(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(this->type) % alignof(base_t*)); children = alloc.emplace_many(this->type->argc()); + for (blt::size_t i = 0; i < this->type->argc(); i++) + children[i] = nullptr; + if (reinterpret_cast(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(this->children) % alignof(node_t**)); } void evaluate() const @@ -301,17 +310,11 @@ namespace fb ~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]); - } - } else - if (type->argc() != 0) - BLT_WARN("Hey wtf is up %ld", type->argc()); - alloc.destroy(children); + alloc.destroy(children[i]); + alloc.deallocate(children[i]); + } alloc.deallocate(children); alloc.destroy(type); alloc.deallocate(type); @@ -432,7 +435,27 @@ namespace fb delete[] cum; - //run(); + run(); 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(); +// *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; } } \ No newline at end of file