diff options
author | 2025-04-17 01:39:10 +0100 | |
---|---|---|
committer | 2025-04-17 20:02:18 +0100 | |
commit | 8a669bc96ffdb9d0f6f54e464da11e3375c80a55 (patch) | |
tree | 569dac0cd082ad25e779a69f0bcceff5ca212bb1 /src/vcall.h | |
parent | 0b40d4d9ea1cbfbb92795e0d6f26cf108f2dec5f (diff) | |
download | sst-8a669bc96ffdb9d0f6f54e464da11e3375c80a55.tar.gz sst-8a669bc96ffdb9d0f6f54e464da11e3375c80a55.zip |
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.
Diffstat (limited to 'src/vcall.h')
-rw-r--r-- | src/vcall.h | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/vcall.h b/src/vcall.h index 55fcfe6..7f230b0 100644 --- a/src/vcall.h +++ b/src/vcall.h @@ -109,32 +109,33 @@ #define _VCALL_UNUSED #endif -#define _DECL_VFUNC_DYN(ret, conv, name, ...) \ - typedef typeof(ret) (*conv name##_func)(void * __VA_OPT__(,) __VA_ARGS__); \ - static inline _VCALL_UNUSED typeof(ret) name(void *this __VA_OPT__(,) \ - _VCALL_ARGLIST(__VA_ARGS__)) { \ +#define _DECL_VFUNC_DYN(class, ret, conv, name, ...) \ + typedef typeof(ret) (*conv name##_func)(typeof(class) * __VA_OPT__(,) \ + __VA_ARGS__); \ + static inline _VCALL_UNUSED typeof(ret) name( \ + typeof(class) *this __VA_OPT__(,) _VCALL_ARGLIST(__VA_ARGS__)) { \ _VCALL_RET(ret) VCALL(this, name __VA_OPT__(,) \ _VCALL_PASSARGS(__VA_ARGS__)); \ } -#define _DECL_VFUNC(ret, conv, name, idx, ...) \ +#define _DECL_VFUNC(class, ret, conv, name, idx, ...) \ enum { vtidx_##name = (idx) }; \ - _DECL_VFUNC_DYN(ret, conv, name __VA_OPT__(,) __VA_ARGS__) + _DECL_VFUNC_DYN(class, ret, conv, name __VA_OPT__(,) __VA_ARGS__) -/* Define a virtual function with a known index */ -#define DECL_VFUNC(ret, name, idx, ...) \ - _DECL_VFUNC(ret, VCALLCONV, name, idx __VA_OPT__(,) __VA_ARGS__) +/* Define a virtual function with a known index. */ +#define DECL_VFUNC(class, ret, name, idx, ...) \ + _DECL_VFUNC(class, ret, VCALLCONV, name, idx __VA_OPT__(,) __VA_ARGS__) /* Define a virtual function with a known index, without thiscall convention */ -#define DECL_VFUNC_CDECL(ret, name, idx, ...) \ - _DECL_VFUNC(ret, , name, idx __VA_OPT__(,) __VA_ARGS__) +#define DECL_VFUNC_CDEFCL(class, ret, name, idx, ...) \ + _DECL_VFUNC(class, ret, , name, idx __VA_OPT__(,) __VA_ARGS__) /* Define a virtual function with an index defined elsewhere (e.g. gamedata) */ -#define DECL_VFUNC_DYN(ret, name, ...) \ - _DECL_VFUNC_DYN(ret, VCALLCONV, name __VA_OPT__(,) __VA_ARGS__) +#define DECL_VFUNC_DYN(class, ret, name, ...) \ + _DECL_VFUNC_DYN(class, ret, VCALLCONV, name __VA_OPT__(,) __VA_ARGS__) /* Define a virtual function with an index defined elsewhere, without thiscall */ -#define DECL_VFUNC_CDECLDYN(ret, name, ...) \ - _DECL_VFUNC_DYN(ret, , name __VA_OPT__(,) __VA_ARGS__) +#define DECL_VFUNC_CDECLDYN(class, ret, name, ...) \ + _DECL_VFUNC_DYN(class, void, ret, , name __VA_OPT__(,) __VA_ARGS__) #endif |