port: wrap malloc & co

in case we'll need allocation stats or something later
This commit is contained in:
fgsfds 2023-08-20 14:56:07 +02:00
parent 6fbb7e39ec
commit 7e71450a76
5 changed files with 22 additions and 3 deletions

View File

@ -10,4 +10,8 @@ void sysFatalError(const char *fmt, ...) __attribute__((noreturn));
void sysGetExecutablePath(char *outPath, const u32 outLen);
void *sysMemAlloc(const u32 size);
void *sysMemZeroAlloc(const u32 size);
void sysMemFree(void *ptr);
#endif

View File

@ -78,7 +78,7 @@ void *fsFileLoad(const char *name, u32 *outSize)
void *buf = NULL;
if (size) {
buf = calloc(1, size + 1); // sick hack for a free null terminator
buf = sysMemZeroAlloc(size + 1); // sick hack for a free null terminator
if (!buf) {
fprintf(stderr, "fsFileLoad: could not alloc %d bytes for file: %s\n", size, fullName);
fclose(f);

View File

@ -68,7 +68,7 @@ int main(int argc, const char **argv)
g_OsMemSize = osGetMemSize();
g_MempHeapSize = g_OsMemSize;
g_MempHeap = calloc(1, g_MempHeapSize);
g_MempHeap = sysMemZeroAlloc(g_MempHeapSize);
if (!g_MempHeap) {
sysFatalError("Could not alloc %u bytes for memp heap.", g_MempHeapSize);
}

View File

@ -149,7 +149,7 @@ static inline void romdataLoadRom(void)
sysFatalError("Data segment too small (%u), need at least %u.", dataSegLen, ROMDATA_FILES_OFS);
}
u8 *dataSeg = calloc(1, dataSegLen);
u8 *dataSeg = sysMemAlloc(dataSegLen);
if (!dataSeg) {
sysFatalError("Could not allocate %u bytes for data segment.", dataSegLen);
}

View File

@ -65,3 +65,18 @@ void sysGetExecutablePath(char *outPath, const u32 outLen)
}
SDL_free(sdlPath);
}
void *sysMemAlloc(const u32 size)
{
return malloc(size);
}
void *sysMemZeroAlloc(const u32 size)
{
return calloc(1, size);
}
void sysMemFree(void *ptr)
{
free(ptr);
}