From ae65f1a212d1de208ed70ca0aa48be7bbc2d0ae5 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 1 Jul 2015 11:23:59 -0700 Subject: [PATCH] Remove random includes of windows.h Instead, include a stanza in port_platform.h that: - gets windows.h included - defines things that we needs to define - tries to respect applications configurations by leaving things as untouched as possible --- include/grpc/support/atm_win32.h | 2 -- include/grpc/support/log_win32.h | 2 -- include/grpc/support/port_platform.h | 32 ++++++++++++++++++++++++++++ include/grpc/support/sync_win32.h | 2 -- src/core/iomgr/iocp_windows.h | 1 - src/core/iomgr/pollset_windows.h | 1 - src/core/iomgr/sockaddr_win32.h | 2 +- src/core/iomgr/socket_windows.h | 3 ++- src/core/support/cpu_windows.c | 1 - src/core/support/string_win32.c | 1 - src/core/support/string_win32.h | 2 -- src/core/support/sync_win32.c | 3 --- src/core/support/thd_win32.c | 1 - src/core/support/time_win32.c | 1 - 14 files changed, 35 insertions(+), 19 deletions(-) diff --git a/include/grpc/support/atm_win32.h b/include/grpc/support/atm_win32.h index dcba4d433d5..da99021c24b 100644 --- a/include/grpc/support/atm_win32.h +++ b/include/grpc/support/atm_win32.h @@ -37,8 +37,6 @@ /* Win32 variant of atm_platform.h */ #include -#include - typedef gpr_intptr gpr_atm; #define gpr_atm_full_barrier MemoryBarrier diff --git a/include/grpc/support/log_win32.h b/include/grpc/support/log_win32.h index ad0edcdb89f..595a81a5af9 100644 --- a/include/grpc/support/log_win32.h +++ b/include/grpc/support/log_win32.h @@ -34,8 +34,6 @@ #ifndef GRPC_SUPPORT_LOG_WIN32_H #define GRPC_SUPPORT_LOG_WIN32_H -#include - #ifdef __cplusplus extern "C" { #endif diff --git a/include/grpc/support/port_platform.h b/include/grpc/support/port_platform.h index 4fbce9c8d9b..d3cfee113d1 100644 --- a/include/grpc/support/port_platform.h +++ b/include/grpc/support/port_platform.h @@ -34,6 +34,38 @@ #ifndef GRPC_SUPPORT_PORT_PLATFORM_H #define GRPC_SUPPORT_PORT_PLATFORM_H +/* Get windows.h included everywhere (we need it) */ +#if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32) +#ifndef WIN32_LEAN_AND_MEAN +#define GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED +#define WIN32_LEAN_AND_MEAN +#endif /* WIN32_LEAN_AND_MEAN */ + +#ifndef NOMINMAX +#define GRPC_NOMINMX_WAS_NOT_DEFINED +#define NOMINMAX +#endif /* NOMINMAX */ + +#if defined(_WIN32_WINNT) +#if _WIN32_WINNT < 0x0600 +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x0600 +#endif /* _WIN32_WINNT < 0x0600 */ +#endif /* defined(_WIN32_WINNT) */ + +#include + +#ifdef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED +#undef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED +#undef WIN32_LEAN_AND_MEAN +#endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */ + +#ifdef GRPC_NOMINMAX_WAS_NOT_DEFINED +#undef GRPC_NOMINMAX_WAS_NOT_DEFINED +#undef NOMINMAX +#endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */ +#endif /* defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32) */ + /* Override this file with one for your platform if you need to redefine things. */ diff --git a/include/grpc/support/sync_win32.h b/include/grpc/support/sync_win32.h index cb2a8663a05..66b9af9074b 100644 --- a/include/grpc/support/sync_win32.h +++ b/include/grpc/support/sync_win32.h @@ -36,8 +36,6 @@ #include -#include - typedef struct { CRITICAL_SECTION cs; /* Not an SRWLock until Vista is unsupported */ int locked; diff --git a/src/core/iomgr/iocp_windows.h b/src/core/iomgr/iocp_windows.h index 4503fdd55ee..9df6476917f 100644 --- a/src/core/iomgr/iocp_windows.h +++ b/src/core/iomgr/iocp_windows.h @@ -34,7 +34,6 @@ #ifndef GRPC_INTERNAL_CORE_IOMGR_IOCP_WINDOWS_H #define GRPC_INTERNAL_CORE_IOMGR_IOCP_WINDOWS_H -#include #include #include "src/core/iomgr/socket_windows.h" diff --git a/src/core/iomgr/pollset_windows.h b/src/core/iomgr/pollset_windows.h index 57a29079266..c9b8d3f3749 100644 --- a/src/core/iomgr/pollset_windows.h +++ b/src/core/iomgr/pollset_windows.h @@ -34,7 +34,6 @@ #ifndef GRPC_INTERNAL_CORE_IOMGR_POLLSET_WINDOWS_H #define GRPC_INTERNAL_CORE_IOMGR_POLLSET_WINDOWS_H -#include #include #include "src/core/iomgr/socket_windows.h" diff --git a/src/core/iomgr/sockaddr_win32.h b/src/core/iomgr/sockaddr_win32.h index c0385ea6148..be55db805aa 100644 --- a/src/core/iomgr/sockaddr_win32.h +++ b/src/core/iomgr/sockaddr_win32.h @@ -34,8 +34,8 @@ #ifndef GRPC_INTERNAL_CORE_IOMGR_SOCKADDR_WIN32_H #define GRPC_INTERNAL_CORE_IOMGR_SOCKADDR_WIN32_H -#include #include +#include #include #ifdef __MINGW32__ diff --git a/src/core/iomgr/socket_windows.h b/src/core/iomgr/socket_windows.h index 7080919af09..f7b969eb5ea 100644 --- a/src/core/iomgr/socket_windows.h +++ b/src/core/iomgr/socket_windows.h @@ -34,7 +34,8 @@ #ifndef GRPC_INTERNAL_CORE_IOMGR_SOCKET_WINDOWS_H #define GRPC_INTERNAL_CORE_IOMGR_SOCKET_WINDOWS_H -#include +#include +#include #include #include diff --git a/src/core/support/cpu_windows.c b/src/core/support/cpu_windows.c index 107a7b85f00..ce32eb0a9d6 100644 --- a/src/core/support/cpu_windows.c +++ b/src/core/support/cpu_windows.c @@ -34,7 +34,6 @@ #include #ifdef GPR_WIN32 -#include #include unsigned gpr_cpu_num_cores(void) { diff --git a/src/core/support/string_win32.c b/src/core/support/string_win32.c index 6d1d6337a93..27b9f3637a6 100644 --- a/src/core/support/string_win32.c +++ b/src/core/support/string_win32.c @@ -37,7 +37,6 @@ #ifdef GPR_WIN32 -#include #include #include #include diff --git a/src/core/support/string_win32.h b/src/core/support/string_win32.h index 0bc3247d9da..1260aa55c16 100644 --- a/src/core/support/string_win32.h +++ b/src/core/support/string_win32.h @@ -38,8 +38,6 @@ #ifdef GPR_WIN32 -#include - /* These allocate new strings using gpr_malloc to convert from and to utf-8. */ LPTSTR gpr_char_to_tchar(LPCSTR input); LPSTR gpr_tchar_to_char(LPCTSTR input); diff --git a/src/core/support/sync_win32.c b/src/core/support/sync_win32.c index cc31d9b052d..72f39f8d464 100644 --- a/src/core/support/sync_win32.c +++ b/src/core/support/sync_win32.c @@ -37,9 +37,6 @@ #ifdef GPR_WIN32 -#undef _WIN32_WINNT -#define _WIN32_WINNT 0x0600 -#include #include #include #include diff --git a/src/core/support/thd_win32.c b/src/core/support/thd_win32.c index 3cc798293ac..4fa3907444f 100644 --- a/src/core/support/thd_win32.c +++ b/src/core/support/thd_win32.c @@ -37,7 +37,6 @@ #ifdef GPR_WIN32 -#include #include #include #include diff --git a/src/core/support/time_win32.c b/src/core/support/time_win32.c index f4443b5c2d7..9db267c01b0 100644 --- a/src/core/support/time_win32.c +++ b/src/core/support/time_win32.c @@ -39,7 +39,6 @@ #include #include -#include gpr_timespec gpr_now(void) { gpr_timespec now_tv;