From ef7507727be75c4da98971e395b941249a579e88 Mon Sep 17 00:00:00 2001 From: superp00t Date: Fri, 4 Aug 2023 20:44:16 -0400 Subject: [PATCH] chore(memory): rely on external dependency for allocation functions --- .gitmodules | 3 +++ lib/mem | 1 + storm/Memory.cpp | 66 ------------------------------------------------ storm/Memory.hpp | 11 +------- 4 files changed, 5 insertions(+), 76 deletions(-) create mode 160000 lib/mem delete mode 100644 storm/Memory.cpp diff --git a/.gitmodules b/.gitmodules index b8836d9..c3d199c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "lib/system"] path = lib/system url = https://github.com/thunderbrewhq/system.git +[submodule "lib/mem"] + path = lib/mem + url = https://github.com/thunderbrewhq/mem.git diff --git a/lib/mem b/lib/mem new file mode 160000 index 0000000..8a8fa79 --- /dev/null +++ b/lib/mem @@ -0,0 +1 @@ +Subproject commit 8a8fa7918cebc8fdf23061d4501e49079af9a312 diff --git a/storm/Memory.cpp b/storm/Memory.cpp deleted file mode 100644 index bf04ef3..0000000 --- a/storm/Memory.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "storm/Memory.hpp" - -constexpr size_t ALIGNMENT = 8; - -void* SMemAlloc(size_t bytes, const char* filename, int32_t linenumber, uint32_t flags) { - size_t alignedBytes = (bytes + (ALIGNMENT - 1)) & ~(ALIGNMENT - 1); - - void* result; - - if (flags & 0x8) { - result = calloc(1, alignedBytes); - } else { - result = malloc(alignedBytes); - } - - if (result) { - return result; - } else { - // TODO handle errors - return nullptr; - } -} - -void SMemFree(void* ptr) { - if (ptr) { - free(ptr); - } -} - -void SMemFree(void* ptr, const char* filename, int32_t linenumber, uint32_t flags) { - if (ptr) { - free(ptr); - } -} - -void* SMemReAlloc(void* ptr, size_t bytes, const char* filename, int32_t linenumber, uint32_t flags) { - if (flags == 0xB00BEEE5) { - return nullptr; - } - - if (!ptr) { - return SMemAlloc(bytes, filename, linenumber, flags); - } - - if (flags & 0x10) { - return nullptr; - } - - size_t alignedBytes = (bytes + (ALIGNMENT - 1)) & ~(ALIGNMENT - 1); - - void* result = realloc(ptr, alignedBytes); - - if (result) { - if (flags & 0x8) { - // TODO zero out expanded portion - } - - return result; - } else { - if (alignedBytes) { - // TODO handle errors - } - - return nullptr; - } -} diff --git a/storm/Memory.hpp b/storm/Memory.hpp index 07c8186..2e2ee6e 100644 --- a/storm/Memory.hpp +++ b/storm/Memory.hpp @@ -1,15 +1,6 @@ #ifndef STORM_MEMORY_HPP #define STORM_MEMORY_HPP -#include -#include - -void* SMemAlloc(size_t bytes, const char* filename, int32_t linenumber, uint32_t flags); - -void SMemFree(void* ptr); - -void SMemFree(void* ptr, const char* filename, int32_t linenumber, uint32_t flags); - -void* SMemReAlloc(void* ptr, size_t bytes, const char* filename, int32_t linenumber, uint32_t flags); +#include #endif