From 9a2efd9db7becdcb5c55f9abc6c70b835a5352be Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Thu, 6 Sep 2018 19:53:13 +0200 Subject: [PATCH] nt: squelch novelty GCC 8 cast-function-type warnings --- src/nt.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/nt.c b/src/nt.c index 2b5fd44..408d0d4 100644 --- a/src/nt.c +++ b/src/nt.c @@ -3,6 +3,18 @@ #include "nt.h" #include "win.h" +/* Set up a workaround for the following problem: + * FARPROC addr = GetProcAddress(...); + * MY_FUNC func = (MY_FUNC) addr; <-- GCC 8 warning/error. + * MY_FUNC func = (MY_FUNC) (void*) addr; <-- MSVC warning/error. + * To compile cleanly with either compiler, do casts with this "bridge" type: + * MY_FUNC func = (MY_FUNC) (nt__fn_ptr_cast_t) addr; */ +#ifdef __GNUC__ +typedef void* nt__fn_ptr_cast_t; +#else +typedef FARPROC nt__fn_ptr_cast_t; +#endif + #define X(return_type, attributes, name, parameters) \ WEPOLL_INTERNAL return_type(attributes* name) parameters = NULL; NT_NTDLL_IMPORT_LIST(X) @@ -10,15 +22,17 @@ NT_NTDLL_IMPORT_LIST(X) int nt_global_init(void) { HMODULE ntdll; + FARPROC fn_ptr; ntdll = GetModuleHandleW(L"ntdll.dll"); if (ntdll == NULL) return -1; -#define X(return_type, attributes, name, parameters) \ - name = (return_type(attributes*) parameters) GetProcAddress(ntdll, #name); \ - if (name == NULL) \ - return -1; +#define X(return_type, attributes, name, parameters) \ + fn_ptr = GetProcAddress(ntdll, #name); \ + if (fn_ptr == NULL) \ + return -1; \ + name = (return_type(attributes*) parameters)(nt__fn_ptr_cast_t) fn_ptr; NT_NTDLL_IMPORT_LIST(X) #undef X