port: wrap malloc & co
in case we'll need allocation stats or something later
This commit is contained in:
parent
6fbb7e39ec
commit
7e71450a76
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue