diff options
author | Haru <haru@dotalux.com> | 2016-02-28 02:17:21 +0100 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2016-04-30 15:57:46 +0200 |
commit | 5db7c799055c6ae9c4463f6cf4c88a35597d5d31 (patch) | |
tree | e3cdf52436dc322aaab69babc6021af911bf7b9e /src/plugins/HPMHooking.h | |
parent | 1ec93281b66061f7f7cff509450299bdcbf813b4 (diff) | |
download | hercules-5db7c799055c6ae9c4463f6cf4c88a35597d5d31.tar.gz hercules-5db7c799055c6ae9c4463f6cf4c88a35597d5d31.tar.bz2 hercules-5db7c799055c6ae9c4463f6cf4c88a35597d5d31.tar.xz hercules-5db7c799055c6ae9c4463f6cf4c88a35597d5d31.zip |
Added type-checking for the addHookPre() and addHookPost() macros
- The macros will now throw a warning at compile time if a plugin is
using a wrong function type for a pre or post hook. This avoids some
very subtle, hard to detect, issues.
- The macros now require 3 arguments instead of 2. Example:
old code: addHookPre("ifname->function" my_hook);
becomes: addHookPre(ifname, function, my_hook);
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/plugins/HPMHooking.h')
-rw-r--r-- | src/plugins/HPMHooking.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/plugins/HPMHooking.h b/src/plugins/HPMHooking.h index b2d95dd8d..44970863c 100644 --- a/src/plugins/HPMHooking.h +++ b/src/plugins/HPMHooking.h @@ -43,8 +43,18 @@ struct HPMHooking_core_interface { #else // ! HERCULES_CORE HPExport struct HPMHooking_interface HPMHooking_s; -#define addHookPre(tname,hook) (HPMi->hooking->AddHook(HOOK_TYPE_PRE,(tname),(hook),HPMi->pid)) -#define addHookPost(tname,hook) (HPMi->hooking->AddHook(HOOK_TYPE_POST,(tname),(hook),HPMi->pid)) +#include "HPMHooking/HPMHooking.Defs.inc" + +#define addHookPre(ifname, funcname, hook) ( \ + (void)((HPMHOOK_pre_ ## ifname ## _ ## funcname)0 == (hook)), \ + HPMi->hooking->AddHook(HOOK_TYPE_PRE, #ifname "->" #funcname, (hook), HPMi->pid) \ + ) + +#define addHookPost(ifname, funcname, hook) ( \ + (void)((HPMHOOK_post_ ## ifname ## _ ## funcname)0 == (hook)), \ + HPMi->hooking->AddHook(HOOK_TYPE_POST, #ifname "->" #funcname, (hook), HPMi->pid) \ + ) + /* need better names ;/ */ /* will not run the original function after pre-hook processing is complete (other hooks will run) */ #define hookStop() (HPMi->hooking->HookStop(__func__,HPMi->pid)) |