{"thread":{"id":"21547","subject":"[PATCH v3 4/4] Add explicit Cygwin check to guard WIN32 header inclusion","startedAt":"2009-11-09T19:31:24Z","lastAt":"2009-11-09T22:25:09Z","messageCount":2,"participants":["Ramsay Jones","Junio C Hamano"],"isPatch":true,"patchVersion":3,"patchTotal":4},"messages":[{"id":"127190","messageId":"4AF86E0C.4080001@ramsay1.demon.co.uk","threadId":"21547","inReplyTo":null,"subject":"[PATCH v3 4/4] Add explicit Cygwin check to guard WIN32 header inclusion","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsay1.demon.co.uk","sentAt":"2009-11-09T19:31:24Z","receivedAt":"2009-11-09T19:31:24Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"Since commit 435bdf8c (\"Make usage of windows.h lean and mean\",\n16-9-2009), the amount of code potentially including the WIN32\nAPI header files has greatly increased. In particular, the Cygwin\nbuild is at greater risk of inadvertently including WIN32 code\nwithin preprocessor sections protected by the WIN32 or _WIN32\nmacros.\n\nThe previous commit message, along with comments elsewhere, assert\nthat the WIN32 macro is not defined on Cygwin. Currently, this is\ntrue for the cygwin build. However, the cygwin platform can be\nused to develop WIN32 GUI, WIN32 console, and POSIX applications.\nIndeed it is possible to create applications which use a mix of\nthe WIN32 API and POSIX code (eg git!).\n\nUnlike native WIN32 compilers, gcc on cygwin does not automatically\ndefine the _WIN32 macro. However, as soon as you include the\n<windows.h> header file, the _WIN32 and WIN32 macros are defined.\n\nIn order to reduce the risk of problems in the future, we protect\nthe inclusion of the windows header with an explicit check for\n__CYGWIN__. Also, we move the other use of the <windows.h> header\nfrom compat/win32.h to compat/cygwin.c\n\nSigned-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n---\n\nChanges since v2:\n    - removed indentation from the #if-#endif block\n\nI hope you don't mind, but I've only sent this patch, rather than\nre-send the whole series. If you would like a complete re-send, just\nlet me know.\n\nATB,\nRamsay Jones\n\n compat/cygwin.c   |    1 +\n compat/win32.h    |    3 ---\n git-compat-util.h |    2 +-\n 3 files changed, 2 insertions(+), 4 deletions(-)\n\ndiff --git a/compat/cygwin.c b/compat/cygwin.c\nindex b4a51b9..6695515 100644\n--- a/compat/cygwin.c\n+++ b/compat/cygwin.c\n@@ -1,5 +1,6 @@\n #define WIN32_LEAN_AND_MEAN\n #include \"../git-compat-util.h\"\n+#include <windows.h>\n #include \"win32.h\"\n #include \"../cache.h\" /* to read configuration */\n \ndiff --git a/compat/win32.h b/compat/win32.h\nindex 8ce9104..a7ed72b 100644\n--- a/compat/win32.h\n+++ b/compat/win32.h\n@@ -2,9 +2,6 @@\n #define WIN32_H\n \n /* common Win32 functions for MinGW and Cygwin */\n-#ifndef WIN32         /* Not defined by Cygwin */\n-#include <windows.h>\n-#endif\n \n static inline int file_attr_to_st_mode (DWORD attr)\n {\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex ef60803..0cd2693 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -65,7 +65,7 @@\n #define _NETBSD_SOURCE 1\n #define _SGI_SOURCE 1\n \n-#ifdef WIN32 /* Both MinGW and MSVC */\n+#if defined(_WIN32) && !defined(__CYGWIN__) /* Both MinGW and MSVC */\n #define WIN32_LEAN_AND_MEAN  /* stops windows.h including winsock.h */\n #include <winsock2.h>\n #include <windows.h>\n-- \n1.6.5\n"},{"id":"127202","messageId":"7vd43rpc8q.fsf@alter.siamese.dyndns.org","threadId":"21547","inReplyTo":"4AF86E0C.4080001@ramsay1.demon.co.uk","subject":"Re: [PATCH v3 4/4] Add explicit Cygwin check to guard WIN32 header inclusion","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-11-09T22:25:09Z","receivedAt":"2009-11-09T22:25:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramsay Jones <ramsay@ramsay1.demon.co.uk> writes:\n\n> Changes since v2:\n>     - removed indentation from the #if-#endif block\n>\n> I hope you don't mind, but I've only sent this patch, rather than\n> re-send the whole series. If you would like a complete re-send, just\n> let me know.\n\nNo, I don't mind \"replace only this one out of the four-patch series\" at\nall as long as what's being replaced is marked clearly enough (which you\ndid in this case).\n\nBut I thought J6t had problems with what this particular patch does, not\nhow the patch was indented?  So I'd wait for more comments and hopefully\nan Ack from him before touching this one.\n"}]}