From da0dab99a76e22c6be36fa7174b2b34c60eea0d7 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 14 Jul 2022 20:57:13 +0200 Subject: [PATCH] kernel: avoid compiler warnings in some kernel extensions Kernel extensions which don't use compiler options to turn off certain warnings may see a bunch of them caused by conversion between different kinds of function pointers, which in general can indeed indicate a bug, but here is *really* correct. We silence these for good by first casting to `void *` which is always legal. Also, when compiling with C++, disable a `#pragma` we use to temporarily silence the warning issued by `-Wstrict-prototypes`, as this warning is not supported in C++ and so trying to disable it can cause a warning by itself. --- src/calls.h | 16 ++++++++-------- src/common.h | 2 ++ src/modules.h | 16 ++++++++-------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/calls.h b/src/calls.h index dcd7f559a2..3338f1cbb3 100644 --- a/src/calls.h +++ b/src/calls.h @@ -228,42 +228,42 @@ BOOL IsKernelFunction(Obj func); EXPORT_INLINE ObjFunc_0ARGS HDLR_0ARGS(Obj func) { - return (ObjFunc_0ARGS)HDLR_FUNC(func, 0); + return (ObjFunc_0ARGS)(void *)HDLR_FUNC(func, 0); } EXPORT_INLINE ObjFunc_1ARGS HDLR_1ARGS(Obj func) { - return (ObjFunc_1ARGS)HDLR_FUNC(func, 1); + return (ObjFunc_1ARGS)(void *)HDLR_FUNC(func, 1); } EXPORT_INLINE ObjFunc_2ARGS HDLR_2ARGS(Obj func) { - return (ObjFunc_2ARGS)HDLR_FUNC(func, 2); + return (ObjFunc_2ARGS)(void *)HDLR_FUNC(func, 2); } EXPORT_INLINE ObjFunc_3ARGS HDLR_3ARGS(Obj func) { - return (ObjFunc_3ARGS)HDLR_FUNC(func, 3); + return (ObjFunc_3ARGS)(void *)HDLR_FUNC(func, 3); } EXPORT_INLINE ObjFunc_4ARGS HDLR_4ARGS(Obj func) { - return (ObjFunc_4ARGS)HDLR_FUNC(func, 4); + return (ObjFunc_4ARGS)(void *)HDLR_FUNC(func, 4); } EXPORT_INLINE ObjFunc_5ARGS HDLR_5ARGS(Obj func) { - return (ObjFunc_5ARGS)HDLR_FUNC(func, 5); + return (ObjFunc_5ARGS)(void *)HDLR_FUNC(func, 5); } EXPORT_INLINE ObjFunc_6ARGS HDLR_6ARGS(Obj func) { - return (ObjFunc_6ARGS)HDLR_FUNC(func, 6); + return (ObjFunc_6ARGS)(void *)HDLR_FUNC(func, 6); } EXPORT_INLINE ObjFunc_1ARGS HDLR_XARGS(Obj func) { - return (ObjFunc_1ARGS)HDLR_FUNC(func, 7); + return (ObjFunc_1ARGS)(void *)HDLR_FUNC(func, 7); } diff --git a/src/common.h b/src/common.h index 28de6334de..e7c10b8d0b 100644 --- a/src/common.h +++ b/src/common.h @@ -163,7 +163,9 @@ typedef Bag Obj; ** 'ObjFunc' is the type of a function returning an object. */ #pragma GCC diagnostic push +#ifndef __cplusplus #pragma GCC diagnostic ignored "-Wstrict-prototypes" +#endif typedef Obj (* ObjFunc) (/*arguments*/); #pragma GCC diagnostic pop diff --git a/src/modules.h b/src/modules.h index 0a6f3641b4..f36b1a4cb5 100644 --- a/src/modules.h +++ b/src/modules.h @@ -154,19 +154,19 @@ static inline ObjFunc VALIDATE_FUNC_HELPER_6(ObjFunc_6ARGS f) } #define VALIDATE_FUNC_0ARGS(func) \ - (0 ? VALIDATE_FUNC_HELPER_0(func) : (ObjFunc)func) + (0 ? VALIDATE_FUNC_HELPER_0(func) : (ObjFunc)(void *)func) #define VALIDATE_FUNC_1ARGS(func) \ - (0 ? VALIDATE_FUNC_HELPER_1(func) : (ObjFunc)func) + (0 ? VALIDATE_FUNC_HELPER_1(func) : (ObjFunc)(void *)func) #define VALIDATE_FUNC_2ARGS(func) \ - (0 ? VALIDATE_FUNC_HELPER_2(func) : (ObjFunc)func) + (0 ? VALIDATE_FUNC_HELPER_2(func) : (ObjFunc)(void *)func) #define VALIDATE_FUNC_3ARGS(func) \ - (0 ? VALIDATE_FUNC_HELPER_3(func) : (ObjFunc)func) + (0 ? VALIDATE_FUNC_HELPER_3(func) : (ObjFunc)(void *)func) #define VALIDATE_FUNC_4ARGS(func) \ - (0 ? VALIDATE_FUNC_HELPER_4(func) : (ObjFunc)func) + (0 ? VALIDATE_FUNC_HELPER_4(func) : (ObjFunc)(void *)func) #define VALIDATE_FUNC_5ARGS(func) \ - (0 ? VALIDATE_FUNC_HELPER_5(func) : (ObjFunc)func) + (0 ? VALIDATE_FUNC_HELPER_5(func) : (ObjFunc)(void *)func) #define VALIDATE_FUNC_6ARGS(func) \ - (0 ? VALIDATE_FUNC_HELPER_6(func) : (ObjFunc)func) + (0 ? VALIDATE_FUNC_HELPER_6(func) : (ObjFunc)(void *)func) /**************************************************************************** @@ -322,7 +322,7 @@ typedef struct { // StructGVarFunc arrays #define GVAR_FUNC(name, nargs, args) \ { \ - #name, nargs, args, (ObjFunc)Func##name, __FILE__ ":" #name \ + #name, nargs, args, (ObjFunc)(void *)Func##name, __FILE__ ":" #name \ } // The following helper macros are similar to GVAR_FUNC, but perform stricter