Add explicit Cygwin check to guard WIN32 header inclusion
PATCH v3 4/4 Add explicit Cygwin check to guard WIN32 header inclusion
Since commit 435bdf8c ("Make usage of windows.h lean and mean", 16-9-2009), the amount of code potentially including the WIN32 API header files has greatly increased. In particular, the Cygwin build is at greater risk of inadvertently including WIN32 code within preprocessor sections protected by the WIN32 or _WIN32 macros.
The previous commit message, along with comments elsewhere, assert that the WIN32 macro is not defined on Cygwin. Currently, this is true for the cygwin build. However, the cygwin platform can be used to develop WIN32 GUI, WIN32 console, and POSIX applications. Indeed it is possible to create applications which use a mix of the WIN32 API and POSIX code (eg git!).
Unlike native WIN32 compilers, gcc on cygwin does not automatically define the _WIN32 macro. However, as soon as you include the <windows.h> header file, the _WIN32 and WIN32 macros are defined.
In order to reduce the risk of problems in the future, we protect the inclusion of the windows header with an explicit check for __CYGWIN__. Also, we move the other use of the <windows.h> header from compat/win32.h to compat/cygwin.c
---
Changes since v2:
- removed indentation from the #if-#endif block
I hope you don't mind, but I've only sent this patch, rather than re-send the whole series. If you would like a complete re-send, just let me know.
ATB,
Ramsay Jones
compat/cygwin.c | 1 + compat/win32.h | 3 --- git-compat-util.h | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-)
compat/cygwin.c +1 -0
@@ -1,5 +1,6 @@#define WIN32_LEAN_AND_MEAN #include "../git-compat-util.h" +#include <windows.h> #include "win32.h" #include "../cache.h" /* to read configuration */
compat/win32.h +0 -3
@@ -2,9 +2,6 @@#define WIN32_H /* common Win32 functions for MinGW and Cygwin */ -#ifndef WIN32 /* Not defined by Cygwin */ -#include <windows.h> -#endif static inline int file_attr_to_st_mode (DWORD attr) {
git-compat-util.h +1 -1
@@ -65,7 +65,7 @@#define _NETBSD_SOURCE 1#define _SGI_SOURCE 1 -#ifdef WIN32 /* Both MinGW and MSVC */ +#if defined(_WIN32) && !defined(__CYGWIN__)/* Both MinGW and MSVC */ #define WIN32_LEAN_AND_MEAN /* stops windows.h including winsock.h */ #include <winsock2.h> #include <windows.h>
Signature · 1 line
1.6.5
Quoted 6 lines · Ramsay Jones
Changes since v2:
- removed indentation from the #if-#endif blockI hope you don't mind, but I've only sent this patch, rather than re-send the whole series. If you would like a complete re-send, just let me know.
No, I don't mind "replace only this one out of the four-patch series" at all as long as what's being replaced is marked clearly enough (which you did in this case).
But I thought J6t had problems with what this particular patch does, not how the patch was indented? So I'd wait for more comments and hopefully an Ack from him before touching this one.