summaryrefslogtreecommitdiffhomepage
path: root/src/extmalloc.c
diff options
context:
space:
mode:
authorMichael Smith <mikesmiffy128@gmail.com>2023-08-20 16:20:03 +0100
committerMichael Smith <mikesmiffy128@gmail.com>2023-08-27 00:46:09 +0100
commita1998f2f7ce4153d670e2e5cb5018366517cc1ca (patch)
tree4d899fbad24c728c0b51f183c61ed6a7fb213c04 /src/extmalloc.c
parent38fa6c52a8a26ac178a3e1f80a8317740b8e82b3 (diff)
Get things at least compiling under Linux
Nothing really works yet, but at least test.h and fastspin are fixed and some of the issues with RTTI and libdl and stuff are maybe kind of sorted, subject to more testing later. The main issue now seems to be the cvar interface not quite lining up and crashing pretty much immediately. That'll probably take a lot more debugging to figure out, which likely still won't be a priority for quite a while.
Diffstat (limited to 'src/extmalloc.c')
-rw-r--r--src/extmalloc.c50
1 files changed, 30 insertions, 20 deletions
diff --git a/src/extmalloc.c b/src/extmalloc.c
index 3e14e0d..a23dc2a 100644
--- a/src/extmalloc.c
+++ b/src/extmalloc.c
@@ -1,5 +1,5 @@
/*
- * Copyright © 2021 Michael Smith <mikesmiffy128@gmail.com>
+ * Copyright © 2023 Michael Smith <mikesmiffy128@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -14,39 +14,49 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
+#ifndef _WIN32
+#include <stdlib.h>
+#endif
+
#include "intdefs.h"
#include "vcall.h"
-// XXX: this is duped from os.h because I don't want to pull in Windows.h,
-// consider splitting out the IMPORT/EXPORT defs to some other thing?
-#ifdef _WIN32
-#define IMPORT __declspec(dllimport) // only needed for variables
-#else
-#define IMPORT
-#endif
-
// XXX: not sure if "ext" is the best naming convention? use brain later
-IMPORT void *g_pMemAlloc;
+#ifdef _WIN32
+
+__declspec(dllimport) void *g_pMemAlloc;
// this interface has changed a bit between versions but thankfully the basic
// functions we care about have always been at the start - nice and easy.
-// unfortunately though, because the debug and non-debug versions are overloads
-// and Microsoft are a bunch of crazies who decided vtable order should be
-// affected by naming (overloads are grouped, and *reversed* inside of a
-// group!?), we get this amusing ABI difference between platforms:
-#ifdef _WIN32
+// note that since Microsoft are a bunch of crazies, overloads are grouped and
+// reversed so the vtable order here is maybe not what you'd expect otherwise.
DECL_VFUNC(void *, Alloc, 1, usize)
DECL_VFUNC(void *, Realloc, 3, void *, usize)
DECL_VFUNC(void, Free, 5, void *)
-#else
-DECL_VFUNC(void *, Alloc, 0, usize)
-DECL_VFUNC(void *, Realloc, 1, void *, usize)
-DECL_VFUNC(void, Free, 2, void *)
-#endif
void *extmalloc(usize sz) { return Alloc(g_pMemAlloc, sz); }
void *extrealloc(void *mem, usize sz) { return Realloc(g_pMemAlloc, mem, sz); }
void extfree(void *mem) { Free(g_pMemAlloc, mem); }
+#else
+
+void Error(const char *fmt, ...); // stub left out of con_.h (not that useful)
+
+// Linux Source doesn't seem to bother with the custom allocator stuff at all.
+// We still want to check for OoM though, because turning off overcommit is a
+// right, not a privilege. Like func_vehicle.
+void *extmalloc(usize sz) {
+ void *ret = malloc(sz);
+ if (!ret) Error("sst: out of memory");
+ return ret;
+}
+void *extrealloc(void *mem, usize sz) {
+ void *ret = realloc(mem, sz);
+ if (!ret) Error("sst: out of memory");
+ return ret;
+}
+// note: extfree is #defined to free in the header
+#endif
+
// vi: sw=4 ts=4 noet tw=80 cc=80