From bc892da992e4a10dc3225e9c1e594ccbbb8fd82b Mon Sep 17 00:00:00 2001 From: IlushaShurupov Date: Sun, 16 Jul 2023 18:28:24 +0300 Subject: [PATCH] Fixes --- Allocators/private/Allocators.cpp | 8 ++++-- Allocators/private/HeapAllocatorGlobal.cpp | 17 ++++++++++--- Allocators/public/Allocators.hpp | 3 ++- Containers/CMakeLists.txt | 2 +- Containers/public/Buffer.hpp | 2 +- Containers/public/Buffer2D.hpp | 23 ++++++++++++++--- Containers/public/Map.hpp | 9 ++++++- Containers/tests/Buffer2DTest.cpp | 5 +--- Containers/tests/BufferTest.cpp | 8 ++---- Containers/tests/ListTest.cpp | 24 +++++++----------- Containers/tests/MapTest.cpp | 29 ++++++++-------------- Containers/tests/Tests.cpp | 21 ++-------------- Containers/tests/Tests.hpp | 10 +------- Containers/tests/TreeTest.cpp | 12 +++------ Math/tests/Tests.cpp | 2 +- Modules/private/Module.cpp | 6 ++--- Modules/public/Module.hpp | 6 ++++- Strings/private/Strings.cpp | 1 - Strings/public/StringLogic.hpp | 1 + Tokenizer/public/RegularExpression.h | 20 ++++++++++++++- Tokenizer/tests/TestTokenizer.cpp | 11 ++++---- Utils/private/Debugging.cpp | 2 +- Utils/public/Debugging.hpp | 2 +- Utils/tests/Tests.cpp | 2 +- 24 files changed, 116 insertions(+), 110 deletions(-) diff --git a/Allocators/private/Allocators.cpp b/Allocators/private/Allocators.cpp index 18bc13c..ad1d935 100644 --- a/Allocators/private/Allocators.cpp +++ b/Allocators/private/Allocators.cpp @@ -3,8 +3,12 @@ #include -static tp::ModuleManifest* sModuleDependencies[] = { &tp::gModuleBase, nullptr }; -tp::ModuleManifest tp::gModuleAllocators = ModuleManifest("Allocators", nullptr, nullptr, sModuleDependencies); +static void deinit(const tp::ModuleManifest* self) { + tp::HeapAllocGlobal::checkLeaks(); +} + +static tp::ModuleManifest* sModuleDependencies[] = { &tp::gModuleUtils, nullptr }; +tp::ModuleManifest tp::gModuleAllocators = ModuleManifest("Allocators", nullptr, deinit, sModuleDependencies); void* operator new(size_t aSize) { return tp::HeapAllocGlobal::allocate(aSize); } diff --git a/Allocators/private/HeapAllocatorGlobal.cpp b/Allocators/private/HeapAllocatorGlobal.cpp index da31e46..f74cd83 100644 --- a/Allocators/private/HeapAllocatorGlobal.cpp +++ b/Allocators/private/HeapAllocatorGlobal.cpp @@ -118,8 +118,15 @@ void HeapAllocGlobal::deallocate(void* aPtr) { } // 3) Check the wrap - ASSERT(!memCompareVal(wrap_top, WRAP_SIZE, WRAP_VAL) && "Allocated Block Wrap Corrupted!") - ASSERT(!memCompareVal(wrap_bottom, WRAP_SIZE, WRAP_VAL) && "Allocated Block Wrap Corrupted!") + if (memCompareVal(wrap_top, WRAP_SIZE, WRAP_VAL)) { + CallStackCapture::printSnapshot(head->mCallStack); + ASSERT(!"Allocated Block Wrap Corrupted!") + } + + if (memCompareVal(wrap_bottom, WRAP_SIZE, WRAP_VAL)) { + CallStackCapture::printSnapshot(head->mCallStack); + ASSERT(!"Allocated Block Wrap Corrupted!") + } // 4) clear data #ifdef MEM_CLEAR_ON_ALLOC @@ -135,10 +142,12 @@ bool HeapAllocGlobal::checkLeaks() { if (mNumAllocations) { #ifdef MEM_STACK_TRACE - gCSCapture->logLeaks(); + for (auto iter = mEntry; iter; iter = iter->mPrev) { + CallStackCapture::printSnapshot(iter->mCallStack); + } #endif - DEBUG_BREAK("Destruction of not freed Allocator") + ASSERT(!"Destruction of not freed Allocator") return true; } return false; diff --git a/Allocators/public/Allocators.hpp b/Allocators/public/Allocators.hpp index da01ede..9cb8b48 100644 --- a/Allocators/public/Allocators.hpp +++ b/Allocators/public/Allocators.hpp @@ -1,6 +1,6 @@ #pragma once -#include "Module.hpp" +#include "Utils.hpp" #include "HeapAllocatorGlobal.hpp" #include "HeapAllocator.hpp" @@ -12,6 +12,7 @@ namespace tp { } inline void* operator new(std::size_t aSize, void* aWhere) noexcept { return aWhere; } +inline void* operator new[](std::size_t aSize, void* aWhere) noexcept { return aWhere; } void* operator new(std::size_t aSize); void* operator new[](std::size_t aSize); diff --git a/Containers/CMakeLists.txt b/Containers/CMakeLists.txt index f63ea2f..add28f5 100644 --- a/Containers/CMakeLists.txt +++ b/Containers/CMakeLists.txt @@ -16,7 +16,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC Modules) enable_testing() file(GLOB TEST_SOURCES "./tests/*.cpp") add_executable(${PROJECT_NAME}Tests ${TEST_SOURCES}) -target_link_libraries(${PROJECT_NAME}Tests ${PROJECT_NAME} Utils) +target_link_libraries(${PROJECT_NAME}Tests ${PROJECT_NAME} Allocators) add_test(NAME ${PROJECT_NAME}Tests COMMAND ${PROJECT_NAME}Tests) install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/lib) \ No newline at end of file diff --git a/Containers/public/Buffer.hpp b/Containers/public/Buffer.hpp index e81abd4..71af4b7 100644 --- a/Containers/public/Buffer.hpp +++ b/Containers/public/Buffer.hpp @@ -80,7 +80,7 @@ namespace tp { } explicit Buffer(ualni size) : mSize(size), mLoad(0) { - mBuff = (tType*) mAllocator.allocate(sizeof(tType) * tMinSize); + mBuff = (tType*) mAllocator.allocate(sizeof(tType) * size); } Buffer(const Buffer& in) : mSize(in.mSize), mLoad(in.mLoad) { diff --git a/Containers/public/Buffer2D.hpp b/Containers/public/Buffer2D.hpp index 0acd229..d8e5205 100644 --- a/Containers/public/Buffer2D.hpp +++ b/Containers/public/Buffer2D.hpp @@ -7,7 +7,10 @@ namespace tp { template< typename tType, ualni tSizeX, ualni tSizeY > using ConstSizeBuffer2D = ConstSizeBuffer, tSizeY>; - template + template < + typename tType, + class tAllocator = DefaultAllocator + > class Buffer2D { public: typedef ualni Index; @@ -15,15 +18,28 @@ namespace tp { typedef SelCopyArg tTypeArg; private: + tAllocator mAlloc; tType* mBuff = nullptr; Index2D mSize = { 0, 0 }; + void deleteBuffer() { + if (!mBuff) return; + for (ualni i = 0; i < mSize.x * mSize.y; i++) mBuff[i].~tType(); + mAlloc.deallocate(mBuff); + } + + void allocateBuffer(Index2D size) { + deleteBuffer(); + mBuff = (tType*) mAlloc.allocate(sizeof(tType) * size.x * size.y); + for (ualni i = 0; i < mSize.x * mSize.y; i++) new (mBuff + i) tType(); + } + public: Buffer2D() = default; ~Buffer2D() { - delete mBuff; + deleteBuffer(); } explicit Buffer2D(Index2D aSize) { @@ -55,8 +71,7 @@ namespace tp { void reserve(const Index2D& newSize) { if (mSize.x != newSize.x || mSize.y != newSize.y) { - delete mBuff; - mBuff = new tType[newSize.x * newSize.y]; + allocateBuffer(newSize); mSize = newSize; } } diff --git a/Containers/public/Map.hpp b/Containers/public/Map.hpp index 2f6fb88..ae91a37 100644 --- a/Containers/public/Map.hpp +++ b/Containers/public/Map.hpp @@ -387,6 +387,13 @@ namespace tp { } } - ~Map() { removeAll(); } + ~Map() { + for (ualni i = 0; i < mNSlots; i++) { + if (mTable[i] && !isDeletedNode(mTable[i])) { + deleteNode(mTable[i]); + } + } + deleteTable(mTable); + } }; } \ No newline at end of file diff --git a/Containers/tests/Buffer2DTest.cpp b/Containers/tests/Buffer2DTest.cpp index 252468d..5a4804a 100644 --- a/Containers/tests/Buffer2DTest.cpp +++ b/Containers/tests/Buffer2DTest.cpp @@ -1,17 +1,14 @@ #include "Tests.hpp" #include "Testing.hpp" - #include "Buffer2D.hpp" -#include - using namespace tp; const ualni size = 1000; TEST_DEF_STATIC(Simple1) { - Buffer2D buff; + Buffer2D buff; buff.reserve({ 4, 4 }); buff.set( { 2, 2 }, 5); TEST(buff.get( { 2, 2 } ) == 5); diff --git a/Containers/tests/BufferTest.cpp b/Containers/tests/BufferTest.cpp index bcca3a8..9c485a2 100644 --- a/Containers/tests/BufferTest.cpp +++ b/Containers/tests/BufferTest.cpp @@ -1,18 +1,14 @@ #include "Tests.hpp" - #include "Buffer.hpp" - #include "Testing.hpp" -#include - using namespace tp; const ualni size = 1000; TEST_DEF_STATIC(Simple1) { - Buffer buff; + Buffer buff; TEST(buff.size() == 0); for (auto i : Range(size * 10)) { buff.append(TestClass(i)); @@ -23,7 +19,7 @@ TEST_DEF_STATIC(Simple1) { } TEST_DEF_STATIC(Simple2) { - Buffer buff(size); + Buffer buff(size); TEST(buff.size() == 0); for (auto i : Range(size * 10)) buff.append(TestClass(i)); TEST(buff.size() == size * 10); diff --git a/Containers/tests/ListTest.cpp b/Containers/tests/ListTest.cpp index 44eddba..69dfc07 100644 --- a/Containers/tests/ListTest.cpp +++ b/Containers/tests/ListTest.cpp @@ -2,12 +2,10 @@ #include "Tests.hpp" #include "Testing.hpp" -#include - using namespace tp; TEST_DEF_STATIC(SimpleReference) { - tp::List list = { TestClass(1), TestClass(2), TestClass(3), TestClass(4) }; + tp::List list = { TestClass(1), TestClass(2), TestClass(3), TestClass(4) }; list.pushBack(TestClass(5)); list.pushFront(TestClass(0)); @@ -21,11 +19,10 @@ TEST_DEF_STATIC(SimpleReference) { TEST(i == 5); list.removeAll(); - TEST(list.getAllocator().getAllocationsCount() == 0); } TEST_DEF_STATIC(SimplePointer) { - tp::List list = { new TestClass(1), new TestClass(2), new TestClass(3), new TestClass(4) }; + tp::List list = { new TestClass(1), new TestClass(2), new TestClass(3), new TestClass(4) }; list.pushBack(new TestClass(5)); list.pushFront(new TestClass(0)); @@ -38,26 +35,25 @@ TEST_DEF_STATIC(SimplePointer) { TEST(i == 5); - list.removeAll(); + for (auto iter : list) { + delete iter.data(); + } - TEST(list.getAllocator().getAllocationsCount() == 0); + list.removeAll(); } TEST_DEF_STATIC(Copy) { - tp::List list = { TestClass(1), TestClass(2), TestClass(3), TestClass(4) }; - tp::List list2 = list; + tp::List list = { TestClass(1), TestClass(2), TestClass(3), TestClass(4) }; + tp::List list2 = list; TEST_EQUAL(list, list2); list.removeAll(); list2.removeAll(); - - TEST(list.getAllocator().getAllocationsCount() == 0); - TEST(list2.getAllocator().getAllocationsCount() == 0); } TEST_DEF_STATIC(SaveLoad) { - tp::List list = { TestClass(1), TestClass(2), TestClass(3), TestClass(4) }; + tp::List list = { TestClass(1), TestClass(2), TestClass(3), TestClass(4) }; TestFile file; @@ -77,8 +73,6 @@ TEST_DEF_STATIC(SaveLoad) { TEST(i == 4); list.removeAll(); - - TEST(list.getAllocator().getAllocationsCount() == 0); } TEST_DEF(List) { diff --git a/Containers/tests/MapTest.cpp b/Containers/tests/MapTest.cpp index 1ce182e..f0cccbb 100644 --- a/Containers/tests/MapTest.cpp +++ b/Containers/tests/MapTest.cpp @@ -1,15 +1,12 @@ #include "Tests.hpp" #include "Testing.hpp" - #include "Map.hpp" -#include - using namespace tp; TEST_DEF_STATIC(SimpleReference) { - tp::Map map; + tp::Map map; for (auto i : Range(1000, 100000)) { map.put(i, TestClass(i)); @@ -40,12 +37,10 @@ TEST_DEF_STATIC(SimpleReference) { } map.removeAll(); - - TEST(map.getAllocator().getAllocationsCount() == 1); } TEST_DEF_STATIC(SimplePointer) { - tp::Map map; + tp::Map map; for (auto i : Range(1000)) { map.put(i, new TestClass(i)); @@ -57,11 +52,14 @@ TEST_DEF_STATIC(SimplePointer) { } for (auto i : Range(1000)) { + auto del = map.get(i); map.put(i, new TestClass(i)); + delete del; } for (auto i : Range(900, 1000)) { TEST(map.presents(i)); + delete map.get(i); map.remove(i); TEST(!map.presents(i)); } @@ -77,30 +75,25 @@ TEST_DEF_STATIC(SimplePointer) { } map.removeAll(); - - TEST(map.getAllocator().getAllocationsCount() == 1); } TEST_DEF_STATIC(Copy) { - tp::Map map; + tp::Map map; for (auto i : Range(10)) { map.put(i, TestClass(i)); } - tp::Map map2 = map; + tp::Map map2 = map; TEST_EQUAL(map, map2); map.removeAll(); map2.removeAll(); - - TEST(map.getAllocator().getAllocationsCount() == 1); - TEST(map2.getAllocator().getAllocationsCount() == 1); } TEST_DEF_STATIC(SaveLoad) { - tp::Map map; + tp::Map map; for (auto i : Range(10)) { map.put(i, TestClass(i)); @@ -112,13 +105,13 @@ TEST_DEF_STATIC(SaveLoad) { map.removeAll(); - TEST(map.getAllocator().getAllocationsCount() == 1); + TEST(map.size() == 0); file.setAddress(0); map.read(file); - TEST(map.getAllocator().getAllocationsCount() == 11); + TEST(map.size() == 10); for (auto i : Range(10)) { TEST(map.presents(i)); @@ -126,8 +119,6 @@ TEST_DEF_STATIC(SaveLoad) { } map.removeAll(); - - TEST(map.getAllocator().getAllocationsCount() == 1); } TEST_DEF(Map) { diff --git a/Containers/tests/Tests.cpp b/Containers/tests/Tests.cpp index a5de12e..529e808 100644 --- a/Containers/tests/Tests.cpp +++ b/Containers/tests/Tests.cpp @@ -1,32 +1,15 @@ #include "Tests.hpp" - #include "Testing.hpp" -#include - static bool init(const tp::ModuleManifest* self) { tp::gTesting.setRootName(self->getName()); return true; } -void* TestAllocator::allocate(tp::ualni size) { - nAllocations++; - return malloc(size); -} - -void TestAllocator::deallocate(void* p) { - nAllocations--; - free(p); -} - -tp::ualni TestAllocator::getAllocationsCount() const { - return nAllocations; -} - int main() { - tp::ModuleManifest* deps[] = { &tp::gModuleContainers, &tp::gModuleUtils, nullptr }; + tp::ModuleManifest* deps[] = { &tp::gModuleUtils, &tp::gModuleAllocators, nullptr }; tp::ModuleManifest testModule("ContainersTest", init, nullptr, deps); if (!testModule.initialize()) { @@ -36,7 +19,7 @@ int main() { testList(); testMap(); testAvl(); - testBuffer(); + testBuffer(); testBuffer2d(); testModule.deinitialize(); diff --git a/Containers/tests/Tests.hpp b/Containers/tests/Tests.hpp index 084d6bc..3e47e0b 100644 --- a/Containers/tests/Tests.hpp +++ b/Containers/tests/Tests.hpp @@ -1,6 +1,7 @@ #pragma once #include "Utils.hpp" +#include "Allocators.hpp" class TestClass { tp::ualni val2 = 0; @@ -27,15 +28,6 @@ public: void setVal(tp::ualni val) { val1 = val; } }; -class TestAllocator { - tp::ualni nAllocations = 0; -public: - TestAllocator() = default; - void* allocate(tp::ualni size); - void deallocate(void* p); - [[nodiscard]] tp::ualni getAllocationsCount() const; -}; - class TestFile { tp::ualni mem[1024] = { 0 }; tp::ualni address = 0; diff --git a/Containers/tests/TreeTest.cpp b/Containers/tests/TreeTest.cpp index 7e39bc3..561e410 100644 --- a/Containers/tests/TreeTest.cpp +++ b/Containers/tests/TreeTest.cpp @@ -1,16 +1,12 @@ #include "Tests.hpp" - #include "Tree.hpp" - #include "Testing.hpp" -#include - using namespace tp; TEST_DEF_STATIC(Simple) { - AvlTree, TestClass, TestAllocator> tree; + AvlTree, TestClass, HeapAlloc> tree; TEST(tree.size() == 0); TEST(tree.head() == nullptr); @@ -27,7 +23,7 @@ TEST_DEF_STATIC(Simple) { } TEST_DEF_STATIC(Persistance) { - AvlTree, TestClass, TestAllocator> tree; + AvlTree, TestClass, HeapAlloc> tree; const auto size = 1000; @@ -46,7 +42,7 @@ TEST_DEF_STATIC(Persistance) { // random load ualni loadSize = 0; while (loadSize < size / 2) { - ualni idx = rand() % (size - 1); + auto idx = ualni(randomFloat() * (size - 1)); DEBUG_ASSERT(idx < size) if (!buff[idx].presents) { tree.insert((alni) buff[idx].data.getVal(), buff[idx].data); @@ -86,7 +82,7 @@ TEST_DEF_STATIC(Persistance) { // random unload ualni unloadSize = 0; while (unloadSize < size / 2) { - ualni idx = rand() % (size - 1); + auto idx = ualni(randomFloat() * (size - 1)); if (buff[idx].presents) { tree.remove((alni) buff[idx].data.getVal()); diff --git a/Math/tests/Tests.cpp b/Math/tests/Tests.cpp index 360c400..d5f8751 100644 --- a/Math/tests/Tests.cpp +++ b/Math/tests/Tests.cpp @@ -14,7 +14,7 @@ void testMath(); int main() { tp::ModuleManifest* deps[] = { &tp::gModuleUtils, nullptr }; - tp::ModuleManifest testModule("ContainersTest", init, nullptr, deps); + tp::ModuleManifest testModule("MathTest", init, nullptr, deps); if (!testModule.initialize()) { return 1; diff --git a/Modules/private/Module.cpp b/Modules/private/Module.cpp index 0a67342..65fcebd 100644 --- a/Modules/private/Module.cpp +++ b/Modules/private/Module.cpp @@ -24,7 +24,7 @@ bool ModuleManifest::isInitialized() const { return mInitialized; } -bool ModuleManifest::initialize() { +bool ModuleManifest::initialize(const ModuleManifest* parent) { mInitCount++; @@ -35,10 +35,10 @@ bool ModuleManifest::initialize() { mInitialized = true; for (auto module = mDependencies; module && *module; module++) { - mInitialized &= (*module)->initialize(); + mInitialized &= (*module)->initialize(this); } - std::cout << "====== Initializing \"" << mModuleName << "\"\n"; + std::cout << "=== Initializing \"" << mModuleName << "\" from \"" << (parent ? parent->mModuleName : mModuleName ) << "\"\n"; if (mInit) mInitialized &= mInit(this); diff --git a/Modules/public/Module.hpp b/Modules/public/Module.hpp index d198af2..7d01e42 100644 --- a/Modules/public/Module.hpp +++ b/Modules/public/Module.hpp @@ -15,9 +15,12 @@ namespace tp { ModuleManifest(const char* aModuleName, ModuleInit aInit, ModuleDeinit aDeinit, ModuleManifest** aDependencies); [[nodiscard]] bool isInitialized() const; - bool initialize(); + bool initialize(const ModuleManifest* parent = nullptr); void deinitialize(); [[nodiscard]] const char* getName() const; + void setCustomData(void* data) { mCustomData = data; } + void* getCustomData(void* data) const { return mCustomData; } + private: const char* mModuleName = nullptr; ModuleManifest** mDependencies; // NULL terminated @@ -25,6 +28,7 @@ namespace tp { ModuleInit mInit = nullptr; ModuleDeinit mDeinit = nullptr; uhalni mInitCount = 0; + void* mCustomData = nullptr; }; extern ModuleManifest gModuleBase; diff --git a/Strings/private/Strings.cpp b/Strings/private/Strings.cpp index 2d59e4d..2e21690 100644 --- a/Strings/private/Strings.cpp +++ b/Strings/private/Strings.cpp @@ -17,7 +17,6 @@ void deinitialize(const ModuleManifest*) { static tp::ModuleManifest* sModuleDependencies[] = { &tp::gModuleContainers, &tp::gModuleAllocators, - &tp::gModuleUtils, nullptr }; diff --git a/Strings/public/StringLogic.hpp b/Strings/public/StringLogic.hpp index 3dc0e18..0abc604 100644 --- a/Strings/public/StringLogic.hpp +++ b/Strings/public/StringLogic.hpp @@ -1,5 +1,6 @@ #pragma once +#include "Allocators.hpp" #include "Utils.hpp" #include "Buffer.hpp" diff --git a/Tokenizer/public/RegularExpression.h b/Tokenizer/public/RegularExpression.h index b0e447b..9294698 100644 --- a/Tokenizer/public/RegularExpression.h +++ b/Tokenizer/public/RegularExpression.h @@ -16,36 +16,53 @@ namespace tp::RegEx { REPEAT, VAL, } mType = NONE; + + AstNode() = default; + virtual ~AstNode() = default; }; template struct AstVal : public AstNode { explicit AstVal(tAlphabetType val) : mVal(val) { mType = VAL; } + ~AstVal() override = default; tAlphabetType mVal; }; struct AstCompound : public AstNode { AstCompound() { mType = COMPOUND; } + ~AstCompound() override { + for (auto iter : mChilds) { + delete iter.data(); + } + mChilds.removeAll(); + } List mChilds; }; struct AstAlternation : public AstNode { AstAlternation() { mType = OR; } + ~AstAlternation() override { + delete mFirst; + delete mSecond; + } AstNode* mFirst = nullptr; AstNode* mSecond = nullptr; }; struct AstIf : public AstNode { AstIf() { mType = IF; } + ~AstIf() override { delete mNode; } AstNode* mNode = nullptr; }; struct AstAny : public AstNode { AstAny() { mType = ANY; } + ~AstAny() override = default; }; struct AstRepetition : public AstNode { AstRepetition() { mType = REPEAT; } + ~AstRepetition() override { delete mNode; } AstNode* mNode = nullptr; bool mPlus = false; }; @@ -53,8 +70,9 @@ namespace tp::RegEx { template struct AstClass : public AstNode { AstClass() { mType = CLASS; } + ~AstClass() override { mRanges.removeAll(); } List> mRanges; - bool mExclude{}; + bool mExclude = false; }; struct ParseError { diff --git a/Tokenizer/tests/TestTokenizer.cpp b/Tokenizer/tests/TestTokenizer.cpp index a25ce49..d6b40a1 100644 --- a/Tokenizer/tests/TestTokenizer.cpp +++ b/Tokenizer/tests/TestTokenizer.cpp @@ -1,10 +1,9 @@ #include "Testing.hpp" #include "Tokenizer.hpp" +#include -#include - -#define LOG(val) std::cout << #val << " " +#define LOG(val) // std::cout << #val << " " using namespace tp; @@ -126,7 +125,7 @@ TEST_DEF_STATIC(Simple) { }); if (!lexer.isBuild()) { - std::cout << lexer.getBuildError().description; + printf("Error : %s", lexer.getBuildError().description); return; } @@ -141,7 +140,7 @@ TEST_DEF_STATIC(Simple) { outputHash += ualni(tok); switch (tok) { - case TokType::SPACE: { std::cout << " "; } break; + case TokType::SPACE: { printf(" "); } break; case TokType::VAR: { LOG(VAR); } break; case TokType::CLASS_DEF: { LOG(CLASS_DEF); } break; case TokType::SELF: { LOG(SELF); } break; @@ -188,7 +187,7 @@ TEST_DEF_STATIC(Simple) { } while (tok != TokType::TOK_SOURCE_END && tok != TokType::FAILED); - std::cout << "\n\nOutputHash : " << outputHash; + printf("\n\nOutputHash : %llu", outputHash); TEST(outputHash == outputHashPassed); } diff --git a/Utils/private/Debugging.cpp b/Utils/private/Debugging.cpp index 38aade8..965da3d 100644 --- a/Utils/private/Debugging.cpp +++ b/Utils/private/Debugging.cpp @@ -208,7 +208,7 @@ void CallStackCapture::printSnapshot(const CallStack* snapshot) { printf("\n"); } -void CallStackCapture::logLeaks() { +void CallStackCapture::logAll() { for (auto cs : *this) { printSnapshot(cs.getCallStack()); } diff --git a/Utils/public/Debugging.hpp b/Utils/public/Debugging.hpp index 26f0cf8..1378c58 100644 --- a/Utils/public/Debugging.hpp +++ b/Utils/public/Debugging.hpp @@ -55,7 +55,7 @@ namespace tp { const DebugSymbols* getSymbols(FramePointer fp); static void printSnapshot(const CallStack* snapshot); - void logLeaks(); + void logAll(); public: diff --git a/Utils/tests/Tests.cpp b/Utils/tests/Tests.cpp index 3ac860a..79c6c18 100644 --- a/Utils/tests/Tests.cpp +++ b/Utils/tests/Tests.cpp @@ -47,7 +47,7 @@ void root() { TEST_DEF(Debugging) { root(); - gCSCapture->logLeaks(); + gCSCapture->logAll(); } int main() {