summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJia Tan <jiat0218@gmail.com>2023-01-19 20:35:09 +0800
committerLasse Collin <lasse.collin@tukaani.org>2023-03-11 21:45:26 +0200
commit8daaac8e10f68289b44f68d0925e169176ce8a5c (patch)
tree794f5e2002caedd32eeb4f5ee1f625f636ff0dc2
parent6c9a2c2e465a80aa079cf3c8b3fdd382b396d21f (diff)
downloadxz-8daaac8e10f68289b44f68d0925e169176ce8a5c.tar.gz
tuklib_physmem: Silence warning from -Wcast-function-type on MinGW-w64.
tuklib_physmem depends on GetProcAddress() for both MSVC and MinGW-w64 to retrieve a function address. The proper way to do this is to cast the return value to the type of function pointer retrieved. Unfortunately, this causes a cast-function-type warning, so the best solution is to simply ignore the warning.
-rw-r--r--src/common/tuklib_physmem.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/common/tuklib_physmem.c b/src/common/tuklib_physmem.c
index a1bccb2..69f6fd4 100644
--- a/src/common/tuklib_physmem.c
+++ b/src/common/tuklib_physmem.c
@@ -73,6 +73,17 @@
#endif
+// With GCC >= 8.1 with -Wextra and Clang >= 13 with -Wcast-function-type
+// will warn about the Windows-specific code.
+#if defined(__has_warning)
+# if __has_warning("-Wcast-function-type")
+# define CAN_DISABLE_WCAST_FUNCTION_TYPE 1
+# endif
+#elif TUKLIB_GNUC_REQ(8,1)
+# define CAN_DISABLE_WCAST_FUNCTION_TYPE 1
+#endif
+
+
extern uint64_t
tuklib_physmem(void)
{
@@ -87,8 +98,15 @@ tuklib_physmem(void)
HMODULE kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
if (kernel32 != NULL) {
typedef BOOL (WINAPI *gmse_type)(LPMEMORYSTATUSEX);
+#ifdef CAN_DISABLE_WCAST_FUNCTION_TYPE
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wcast-function-type"
+#endif
gmse_type gmse = (gmse_type)GetProcAddress(
kernel32, "GlobalMemoryStatusEx");
+#ifdef CAN_DISABLE_WCAST_FUNCTION_TYPE
+# pragma GCC diagnostic pop
+#endif
if (gmse != NULL) {
MEMORYSTATUSEX meminfo;
meminfo.dwLength = sizeof(meminfo);