From a14ff91254f40cf36e0fee199e26fb11260fab49 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Tue, 25 Jul 2023 10:52:10 -0700 Subject: [PATCH] move _WIN32_WINNT defintions before first #include _WIN32_WINNT and WIN32_LEAN_AND_MEAN need to be defined before the windows.h is included for the first time. Avoid the confusion of indirect #include by defining before any. --- event_iocp.c | 4 +++- evthread_win32.c | 11 +++++++---- evutil.c | 13 ++++++++----- listener.c | 11 +++++++---- wepoll.c | 16 ++++++---------- 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/event_iocp.c b/event_iocp.c index 6b2a2e15..4955e426 100644 --- a/event_iocp.c +++ b/event_iocp.c @@ -23,12 +23,14 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "evconfig-private.h" #ifndef _WIN32_WINNT /* Minimum required for InitializeCriticalSectionAndSpinCount */ #define _WIN32_WINNT 0x0403 #endif + +#include "evconfig-private.h" + #include #include #include diff --git a/evthread_win32.c b/evthread_win32.c index 2ec80560..8647f72b 100644 --- a/evthread_win32.c +++ b/evthread_win32.c @@ -23,18 +23,21 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "event2/event-config.h" -#include "evconfig-private.h" #ifdef _WIN32 #ifndef _WIN32_WINNT /* Minimum required for InitializeCriticalSectionAndSpinCount */ #define _WIN32_WINNT 0x0403 #endif -#include #define WIN32_LEAN_AND_MEAN +#endif + +#include "event2/event-config.h" +#include "evconfig-private.h" + +#ifdef _WIN32 +#include #include -#undef WIN32_LEAN_AND_MEAN #include #endif diff --git a/evutil.c b/evutil.c index 4308bf2e..5be307d4 100644 --- a/evutil.c +++ b/evutil.c @@ -24,6 +24,14 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifdef _WIN32 +#ifndef _WIN32_WINNT +/* For structs needed by GetAdaptersAddresses */ +#define _WIN32_WINNT 0x0501 +#endif +#define WIN32_LEAN_AND_MEAN +#endif + #include "event2/event-config.h" #include "evconfig-private.h" @@ -34,15 +42,10 @@ #ifdef EVENT__HAVE_AFUNIX_H #include #endif -#define WIN32_LEAN_AND_MEAN #include -#undef WIN32_LEAN_AND_MEAN #include #include #include -#undef _WIN32_WINNT -/* For structs needed by GetAdaptersAddresses */ -#define _WIN32_WINNT 0x0501 #include #include #endif diff --git a/listener.c b/listener.c index ffbc4186..f2fa0d1b 100644 --- a/listener.c +++ b/listener.c @@ -24,16 +24,19 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifdef _WIN32 +#ifndef _WIN32_WINNT +/* Minimum required for InitializeCriticalSectionAndSpinCount */ +#define _WIN32_WINNT 0x0403 +#endif +#endif + #include "event2/event-config.h" #include "evconfig-private.h" #include #ifdef _WIN32 -#ifndef _WIN32_WINNT -/* Minimum required for InitializeCriticalSectionAndSpinCount */ -#define _WIN32_WINNT 0x0403 -#endif #include #include #include diff --git a/wepoll.c b/wepoll.c index 5ea75507..514deffe 100644 --- a/wepoll.c +++ b/wepoll.c @@ -31,6 +31,12 @@ #define WEPOLL_EXPORT +#ifndef _WIN32_WINNT +/* Minimum required for SetFileCompletionNotificationModes() */ +#define _WIN32_WINNT 0x0600 +#endif +#define WIN32_LEAN_AND_MEAN + #include #include "event-internal.h" @@ -113,21 +119,11 @@ WEPOLL_EXPORT int epoll_wait(HANDLE ephnd, #define WEPOLL_INTERNAL static #define WEPOLL_INTERNAL_VAR static -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif - #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wreserved-id-macro" #endif -#ifdef _WIN32_WINNT -#undef _WIN32_WINNT -#endif - -#define _WIN32_WINNT 0x0600 - #ifdef __clang__ #pragma clang diagnostic pop #endif