From 855ba85bd04700388d3728a39b7f313a349a2743 Mon Sep 17 00:00:00 2001 From: Andrej Redeky Date: Sun, 12 Jan 2025 00:12:03 +0100 Subject: [PATCH] Fix Allocator issues reported by ReSharper - missing template keyword calling dependent function name - missing default initialization for AllocationResult - disable ReSharper virtual destructor check - reformat - remove deprecated structs --- include/RED4ext/Memory/Allocators.hpp | 44 ++++++++++++--------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/include/RED4ext/Memory/Allocators.hpp b/include/RED4ext/Memory/Allocators.hpp index b2be47430..49b36f580 100644 --- a/include/RED4ext/Memory/Allocators.hpp +++ b/include/RED4ext/Memory/Allocators.hpp @@ -1,13 +1,17 @@ -#pragma once +// Disable ReSharper virtual destructor check, as the Allocators are just structs with pointers to functions which are +// copied around. +// ReSharper disable CppPolymorphicClassWithNonVirtualPublicDestructor -#include -#include +#pragma once -#include #include +#include #include #include +#include +#include + namespace RED4ext { namespace Memory @@ -28,7 +32,7 @@ struct IAllocator uint32_t aAlignment) const = 0; // 16 virtual void Free(AllocationResult& aAllocation) const = 0; // 20 virtual void sub_28(void* a1) const = 0; // 28 - virtual const uint32_t GetHandle() const = 0; // 30 + virtual const uint32_t GetHandle() const = 0; // 30 [[deprecated("Use 'GetHandle()' instead.")]] const uint32_t GetId() const { @@ -81,9 +85,9 @@ struct Allocator : IAllocator static UniversalRelocFunc alloc(Detail::AddressHashes::Memory_Vault_Alloc); auto pool = T::Get(); - auto storage = pool->storage->GetAllocatorStorage(); + auto storage = pool->storage->template GetAllocatorStorage(); - AllocationResult result; + AllocationResult result = {}; alloc(storage, &result, aSize); if (!result.memory) { @@ -99,9 +103,9 @@ struct Allocator : IAllocator static UniversalRelocFunc alloc(Detail::AddressHashes::Memory_Vault_AllocAligned); auto pool = T::Get(); - auto storage = pool->storage->GetAllocatorStorage(); + auto storage = pool->storage->template GetAllocatorStorage(); - AllocationResult result; + AllocationResult result = {}; alloc(storage, &result, aSize, aAlignment); if (!result.memory) { @@ -117,9 +121,9 @@ struct Allocator : IAllocator static UniversalRelocFunc realloc(Detail::AddressHashes::Memory_Vault_Realloc); auto pool = T::Get(); - auto storage = pool->storage->GetAllocatorStorage(); + auto storage = pool->storage->template GetAllocatorStorage(); - AllocationResult result; + AllocationResult result = {}; realloc(storage, &result, aAllocation, aSize); if (!result.memory && aSize) { @@ -136,9 +140,9 @@ struct Allocator : IAllocator static UniversalRelocFunc realloc(Detail::AddressHashes::Memory_Vault_ReallocAligned); auto pool = T::Get(); - auto storage = pool->storage->GetAllocatorStorage(); + auto storage = pool->storage->template GetAllocatorStorage(); - AllocationResult result; + AllocationResult result = {}; realloc(storage, &result, aAllocation, aSize, aAlignment); if (!result.memory && aSize) { @@ -154,7 +158,7 @@ struct Allocator : IAllocator static UniversalRelocFunc func(Detail::AddressHashes::Memory_Vault_Free); auto pool = T::Get(); - auto storage = pool->storage->GetAllocatorStorage(); + auto storage = pool->storage->template GetAllocatorStorage(); func(storage, aAllocation); } @@ -164,7 +168,7 @@ struct Allocator : IAllocator static UniversalRelocFunc func(Detail::AddressHashes::Memory_Vault_Unk1); auto pool = T::Get(); - auto storage = pool->storage->GetAllocatorStorage(); + auto storage = pool->storage->template GetAllocatorStorage(); func(storage, a2); } @@ -2712,14 +2716,4 @@ struct GPUM_Buffer_MorphTargetsAllocator : Allocator { }; } // namespace Memory - -struct [[deprecated("Use 'Memory::IAllocator' instead.")]] IMemoryAllocator : Memory::IAllocator -{ - struct [[deprecated("Use 'Memory::AllocationResult' instead.")]] Result : Memory::AllocationResult{}; -}; - -struct [[deprecated("Use 'Memory::EngineAllocator' instead.")]] EngineAllocator : Memory::EngineAllocator{}; -struct [[deprecated("Use 'Memory::RTTIAllocator' instead.")]] RTTIAllocator : Memory::RTTIAllocator{}; -struct [[deprecated("Use 'Memory::RTTIFunctionAllocator' instead.")]] RTTIFunctionAllocator - : Memory::RTTIFunctionAllocator{}; } // namespace RED4ext