From 6f37c8e57f21b39d8c1eddef049073c2aeb5a675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Wed, 30 Mar 2022 18:13:08 +0300 Subject: [PATCH] mdbx: resolve all warnings from MinGW. --- mdbx.h | 11 +++++++++-- mdbx.h++ | 1 + src/defs.h | 5 +++++ src/internals.h | 5 +++++ src/lck-windows.c | 9 +++++++++ src/mdbx.c++ | 5 +++++ src/osal.h | 2 +- test/chrono.cc | 11 +++++++++++ test/osal-windows.cc | 2 +- 9 files changed, 47 insertions(+), 4 deletions(-) diff --git a/mdbx.h b/mdbx.h index b5d85921..c793a103 100644 --- a/mdbx.h +++ b/mdbx.h @@ -324,7 +324,8 @@ typedef mode_t mdbx_mode_t; #endif /* MDBX_DEPRECATED */ #ifndef __dll_export -#if defined(_WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) || \ + defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__) #if defined(__GNUC__) || __has_attribute(__dllexport__) #define __dll_export __attribute__((__dllexport__)) #elif defined(_MSC_VER) @@ -340,7 +341,8 @@ typedef mode_t mdbx_mode_t; #endif /* __dll_export */ #ifndef __dll_import -#if defined(_WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) || \ + defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__) #if defined(__GNUC__) || __has_attribute(__dllimport__) #define __dll_import __attribute__((__dllimport__)) #elif defined(_MSC_VER) @@ -457,8 +459,13 @@ typedef mode_t mdbx_mode_t; #ifndef MDBX_PRINTF_ARGS #if defined(__GNUC__) || __has_attribute(__format__) +#if defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__) +#define MDBX_PRINTF_ARGS(format_index, first_arg) \ + __attribute__((__format__(__gnu_printf__, format_index, first_arg))) +#else #define MDBX_PRINTF_ARGS(format_index, first_arg) \ __attribute__((__format__(__printf__, format_index, first_arg))) +#endif /* __MINGW_PRINTF_FORMAT */ #else #define MDBX_PRINTF_ARGS(format_index, first_arg) #endif diff --git a/mdbx.h++ b/mdbx.h++ index 9749debe..903a9f88 100644 --- a/mdbx.h++ +++ b/mdbx.h++ @@ -5463,6 +5463,7 @@ inline size_t txn::put_multiple(map_handle map, const slice &key, if (allow_partial) break; mdbx_txn_break(handle_); + MDBX_CXX17_FALLTHROUGH /* fallthrough */; default: MDBX_CXX20_UNLIKELY error::throw_exception(err); } diff --git a/src/defs.h b/src/defs.h index df6d5247..92c16ed1 100644 --- a/src/defs.h +++ b/src/defs.h @@ -107,6 +107,11 @@ # define __noop(...) do {} while(0) #endif /* __noop */ +#if defined(__fallthrough) && \ + (defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)) +#undef __fallthrough +#endif /* __fallthrough workaround for MinGW */ + #ifndef __fallthrough # if defined(__cplusplus) && (__has_cpp_attribute(fallthrough) && \ (!defined(__clang__) || __clang__ > 4)) || __cplusplus >= 201703L diff --git a/src/internals.h b/src/internals.h index a20230fa..f0335911 100644 --- a/src/internals.h +++ b/src/internals.h @@ -122,6 +122,11 @@ #pragma GCC diagnostic ignored "-Wattributes" #endif /* GCC < 9 */ +#if (defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)) && \ + !defined(__USE_MINGW_ANSI_STDIO) +#define __USE_MINGW_ANSI_STDIO 1 +#endif /* __USE_MINGW_ANSI_STDIO */ + #include "../mdbx.h" #include "defs.h" diff --git a/src/lck-windows.c b/src/lck-windows.c index 7beda553..62500709 100644 --- a/src/lck-windows.c +++ b/src/lck-windows.c @@ -754,6 +754,11 @@ MDBX_GetTickCount64 mdbx_GetTickCount64; MDBX_RegGetValueA mdbx_RegGetValueA; #endif /* xMDBX_ALLOY */ +#if __GNUC_PREREQ(8, 0) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-function-type" +#endif /* GCC/MINGW */ + static void mdbx_winnt_import(void) { const HINSTANCE hNtdll = GetModuleHandleA("ntdll.dll"); @@ -805,4 +810,8 @@ static void mdbx_winnt_import(void) { } } +#if __GNUC_PREREQ(8, 0) +#pragma GCC diagnostic pop +#endif /* GCC/MINGW */ + #endif /* Windows LCK-implementation */ diff --git a/src/mdbx.c++ b/src/mdbx.c++ index 0fe0a2eb..82656151 100644 --- a/src/mdbx.c++ +++ b/src/mdbx.c++ @@ -9,6 +9,11 @@ #define _CRT_SECURE_NO_WARNINGS #endif /* _CRT_SECURE_NO_WARNINGS */ +#if (defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)) && \ + !defined(__USE_MINGW_ANSI_STDIO) +#define __USE_MINGW_ANSI_STDIO 1 +#endif /* __USE_MINGW_ANSI_STDIO */ + #include "../mdbx.h++" #include "defs.h" diff --git a/src/osal.h b/src/osal.h index 061e5033..c4bbd7b7 100644 --- a/src/osal.h +++ b/src/osal.h @@ -474,7 +474,7 @@ typedef union bin128 { #if defined(_WIN32) || defined(_WIN64) typedef union MDBX_srwlock { - struct { + __anonymous_struct_extension__ struct { long volatile readerCount; long volatile writerCount; }; diff --git a/test/chrono.cc b/test/chrono.cc index ffe1067c..c84d603c 100644 --- a/test/chrono.cc +++ b/test/chrono.cc @@ -78,6 +78,12 @@ time from_ms(uint64_t ms) { return result; } +#if __GNUC_PREREQ(8, 0) && \ + (defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-function-type" +#endif /* GCC/MINGW */ + time now_realtime() { #if defined(_WIN32) || defined(_WIN64) || defined(_WINDOWS) static void(WINAPI * query_time)(LPFILETIME); @@ -133,4 +139,9 @@ time now_monotonic() { #endif } +#if __GNUC_PREREQ(8, 0) && \ + (defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)) +#pragma GCC diagnostic pop +#endif /* GCC/MINGW */ + } /* namespace chrono */ diff --git a/test/osal-windows.cc b/test/osal-windows.cc index fbe48899..db42ba2b 100644 --- a/test/osal-windows.cc +++ b/test/osal-windows.cc @@ -75,7 +75,7 @@ void osal_setup(const std::vector &actors) { if (!hEvent) failure_perror("CreateEvent()", GetLastError()); hEvent = make_inheritable(hEvent); - log_trace("osal_setup: event %" PRIuPTR " -> %p", i, hEvent); + log_trace("osal_setup: event %u -> %p", i, hEvent); events[i] = hEvent; }