diff options
author | 2025-03-10 02:37:19 +0000 | |
---|---|---|
committer | 2025-04-06 16:41:13 +0100 | |
commit | 244fea664121acf12871ab5858a5fe95a2606b52 (patch) | |
tree | e42b1990ef97adc0f0ab48b9be7e11de7fee0558 /test | |
parent | d86b7b41453c69b3854baa7cdc05a79a3cdfe092 (diff) | |
download | sst-244fea664121acf12871ab5858a5fe95a2606b52.tar.gz sst-244fea664121acf12871ab5858a5fe95a2606b52.zip |
Rewrite and redesign codegen and feature system
Also switch to somewhat proper C23 flags while we're at it.
This is a huge change. It took me forever, in between being really busy.
Sorry about that. But the good news is I'm now free to start integrating
the various patches that have accumulated since last release. Well, at
least in between still being really busy. Gotta manage expectations.
The main benefit of introducing GAMESPECIFIC() is that features
that don't apply to a particular game no longer show up *at all*, and
less time is wasted on init. It also enables a cool optimisation wherein
unnecessary REQUIRE_GAMEDATA() checks can elided at compile time
whenever the gamedata is known up-front to always exist in supported
games.
The DEF_FEAT_CVAR macro family meanwhile makes it easier to manage the
lifecycle of cvars/ccmds, with less manual registering, unhiding and
such.
Originally I was going to try and just hack these features into the
existing codegen abomination, but it just got too terrible. This rewrite
should make it easier to continue tweaking codegen behaviour in future.
It also has slightly better error messages.
Diffstat (limited to 'test')
-rw-r--r-- | test/hook.test.c | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/test/hook.test.c b/test/hook.test.c index a2447cc..9e7cfa9 100644 --- a/test/hook.test.c +++ b/test/hook.test.c @@ -12,7 +12,7 @@ #include <stdio.h> #include <string.h> -// stubs +// stub void con_warn(const char *msg, ...) { va_list l; va_start(l, msg); @@ -20,43 +20,38 @@ void con_warn(const char *msg, ...) { va_end(l); } -__attribute__((noinline)) -static int some_function(int a, int b) { return a + b; } -static int (*orig_some_function)(int, int); -static int some_hook(int a, int b) { - return orig_some_function(a, b) + 5; -} -__attribute__((noinline)) -static int other_function(int a, int b) { return a - b; } -static int (*orig_other_function)(int, int); -static int other_hook(int a, int b) { - return orig_other_function(a, b) + 5; -} +typedef int (*testfunc)(int, int); + +__attribute__((noinline)) static int func1(int a, int b) { return a + b; } +static int (*orig_func1)(int, int); +static int hook1(int a, int b) { return orig_func1(a, b) + 5; } + +__attribute__((noinline)) static int func2(int a, int b) { return a - b; } +static int (*orig_func2)(int, int); +static int hook2(int a, int b) { return orig_func2(a, b) + 5; } TEST("Inline hooks should be able to wrap the original function") { if (!hook_init()) return false; - orig_some_function = hook_inline(&some_function, &some_hook); - if (!orig_some_function) return false; - return some_function(5, 5) == 15; + orig_func1 = (testfunc)hook_inline((void *)&func1, (void *)&hook1); + if (!orig_func1) return false; + return func1(5, 5) == 15; } TEST("Inline hooks should be removable again") { if (!hook_init()) return false; - orig_some_function = hook_inline(&some_function, &some_hook); - if (!orig_some_function) return false; - unhook_inline(orig_some_function); - return some_function(5, 5) == 10; + orig_func1 = (testfunc)hook_inline((void *)&func1, (void *)&hook1); + if (!orig_func1) return false; + unhook_inline((void *)orig_func1); + return func1(5, 5) == 10; } -TEST("Multiple functions should be able to be inline hooked at once") { +TEST("Multiple functions should be able to be inline-hooked at once") { if (!hook_init()) return false; - orig_some_function = hook_inline(&some_function, &some_hook); - if (!orig_some_function) return false; - - orig_other_function = hook_inline(&other_function, &other_hook); - if (!orig_other_function) return false; - - return other_function(5, 5) == 5; + orig_func1 = (testfunc)hook_inline((void *)&func1, (void *)&hook1); + if (!orig_func1) return false; + orig_func2 = (testfunc)hook_inline((void *)&func2, (void *)&hook2); + if (!orig_func2) return false; + return func2(5, 5) == 5; } #endif |