mirror of
https://github.com/thunderbrewhq/bc.git
synced 2025-12-12 01:52:30 +00:00
chore(build): remove mem dependency
This commit is contained in:
parent
3acd26453d
commit
f42a37ddd7
5 changed files with 85 additions and 7 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
#include "bc/Memory.hpp"
|
#include "bc/Memory.hpp"
|
||||||
#include <mem/Memory.hpp>
|
#include "bc/memory/Storm.hpp"
|
||||||
|
|
||||||
void* Blizzard::Memory::Allocate(uint32_t bytes) {
|
void* Blizzard::Memory::Allocate(uint32_t bytes) {
|
||||||
return SMemAlloc(bytes, __FILE__, __LINE__, 0x0);
|
return SMemAlloc(bytes, __FILE__, __LINE__, 0x0);
|
||||||
|
|
|
||||||
68
bc/memory/Storm.cpp
Normal file
68
bc/memory/Storm.cpp
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
#include "bc/memory/Storm.hpp"
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
14
bc/memory/Storm.hpp
Normal file
14
bc/memory/Storm.hpp
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef BC_MEMORY_STORM_HPP
|
||||||
|
#define BC_MEMORY_STORM_HPP
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -16,10 +16,6 @@ pub fn build(b: *std.Build) void {
|
||||||
// Add system detection defines
|
// Add system detection defines
|
||||||
system.add_defines(bc);
|
system.add_defines(bc);
|
||||||
|
|
||||||
// Publicly link mem
|
|
||||||
const mem = b.dependency("mem", .{});
|
|
||||||
bc.linkLibrary(mem.artifact("mem"));
|
|
||||||
|
|
||||||
bc.addIncludePath(b.path("."));
|
bc.addIncludePath(b.path("."));
|
||||||
|
|
||||||
bc.addCSourceFiles(.{
|
bc.addCSourceFiles(.{
|
||||||
|
|
@ -48,6 +44,8 @@ pub fn build(b: *std.Build) void {
|
||||||
|
|
||||||
"bc/time/Time.cpp",
|
"bc/time/Time.cpp",
|
||||||
|
|
||||||
|
"bc/memory/Storm.cpp",
|
||||||
|
|
||||||
"bc/Debug.cpp",
|
"bc/Debug.cpp",
|
||||||
"bc/Lock.cpp",
|
"bc/Lock.cpp",
|
||||||
"bc/Memory.cpp",
|
"bc/Memory.cpp",
|
||||||
|
|
@ -72,7 +70,6 @@ pub fn build(b: *std.Build) void {
|
||||||
// Add system detection defines
|
// Add system detection defines
|
||||||
system.add_defines(bc_test_exe);
|
system.add_defines(bc_test_exe);
|
||||||
|
|
||||||
bc_test_exe.linkLibrary(mem.artifact("mem"));
|
|
||||||
bc_test_exe.linkLibrary(bc);
|
bc_test_exe.linkLibrary(bc);
|
||||||
|
|
||||||
bc_test_exe.addIncludePath(b.path("."));
|
bc_test_exe.addIncludePath(b.path("."));
|
||||||
|
|
|
||||||
1
lib/mem
1
lib/mem
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit 515378839ec59155ef2b8df141f588f3f12f89d2
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue