From 8a669bc96ffdb9d0f6f54e464da11e3375c80a55 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Thu, 17 Apr 2025 01:39:10 +0100 Subject: Add type-safety to virtual calls and accessors This probably should have been the design from the start. It's still possible to use void pointers, and this is done in a couple of places for simplicity, but wherever possible, we have actual structs for things now. Additionally, in places where vtables are fiddled with, e.g. vtable hooks, we have actual struct definitions with vtable pointers so there's need for pointer-casting horror. --- src/extmalloc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/extmalloc.c') diff --git a/src/extmalloc.c b/src/extmalloc.c index e3f40b8..08538ea 100644 --- a/src/extmalloc.c +++ b/src/extmalloc.c @@ -25,15 +25,15 @@ #ifdef _WIN32 -__declspec(dllimport) void *g_pMemAlloc; +__declspec(dllimport) struct IMemAlloc *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. // 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 *) +DECL_VFUNC(struct IMemAlloc, void *, Alloc, 1, usize) +DECL_VFUNC(struct IMemAlloc, void *, Realloc, 3, void *, usize) +DECL_VFUNC(struct IMemAlloc, void, Free, 5, void *) void *extmalloc(usize sz) { return Alloc(g_pMemAlloc, sz); } void *extrealloc(void *mem, usize sz) { return Realloc(g_pMemAlloc, mem, sz); } -- cgit v1.2.3-54-g00ecf