[PATCH xproto] Adjust wrapping to work with MinGW-w64 headers

Yaakov (Cygwin/X) yselkowitz at users.sourceforge.net
Mon Oct 22 13:21:34 PDT 2012


From: Yaakov Selkowitz <yselkowitz at users.sourceforge.net>

Adjust <windows.h> wrapping to work with MinGW-w64 as well MinGW.org headers,
which define BOOL in a different way.
Add some more comments on what we doing here.
v2: Make similar changes to Xwinsock.h, used for MinGW but not Cygwin.
v3: Also add wrappers for conflicting 64-bit types.

Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
Signed-off-by: Yaakov Selkowitz <yselkowitz at users.sourceforge.net>
---
X11 on Win64 has other issues (as discussed today on IRC), but I think 
this takes care of the conflicting types.

 Xwindows.h |   43 ++++++++++++++++++++++++++++++++-----------
 Xwinsock.h |   18 +++++++++++++++++-
 2 files changed, 49 insertions(+), 12 deletions(-)

diff --git a/Xwindows.h b/Xwindows.h
index 6318155..888df2d 100644
--- a/Xwindows.h
+++ b/Xwindows.h
@@ -29,29 +29,42 @@ The Open Group.
 /*
  * This header file has the sole purpose of allowing the inclusion of
  * windows.h without getting any name conflicts with X headers code, by
- * renaming the conflicting definitions from windows.h
- *
- * Some (non-Microsoft) versions of the Windows API headers actually avoid
+ * renaming or disabling the conflicting definitions from windows.h
+ */
+
+/*
+ * Mingw.org versions of the Windows API headers actually avoid
  * making the conflicting definitions if XFree86Server is defined, so we
  * need to remember if that was defined and undefine it during including
  * windows.h (so the conflicting definitions get wrapped correctly), and
- * then redefine it afterwards...
- *
- * There doesn't seem to be a good way to wrap the min/max macros from
- * windows.h, so we simply avoid defining them completely, allowing any
- * pre-existing definition to stand.
- *
+ * then redefine it afterwards. (This was never the correct thing to
+ * do as it's no help at all to X11 clients which also need to use the
+ * Win32 API)
  */
-
 #undef _XFree86Server
 #ifdef XFree86Server
 # define _XFree86Server
 # undef XFree86Server
 #endif
 
+/*
+ * There doesn't seem to be a good way to wrap the min/max macros from
+ * windows.h, so we simply avoid defining them completely, allowing any
+ * pre-existing definition to stand.
+ *
+ */
 #define NOMINMAX
-#define BOOL wBOOL
+
+/*
+ * mingw-w64 headers define BOOL as a typedef, protecting against macros
+ * mingw.org headers define BOOL in terms of WINBOOL
+ * ... so try to come up with something which works with both :-)
+ */
+#define _NO_BOOL_TYPEDEF
+#define BOOL WINBOOL
 #define INT32 wINT32
+#define INT64 wINT64
+#define LONG64 wLONG64
 #undef Status
 #define Status wStatus
 #define ATOM wATOM
@@ -64,10 +77,18 @@ The Open Group.
 #undef BYTE
 #undef BOOL
 #undef INT32
+#undef INT64
+#undef LONG64
 #undef ATOM
 #undef FreeResource
 #undef CreateWindowA
 
+/*
+ * Older version of this header used to name the windows API bool type wBOOL,
+ * rather than more standard name WINBOOL
+ */
+#define wBOOL WINBOOL
+
 #ifdef RESOURCE_H
 # undef RT_FONT
 # undef RT_CURSOR
diff --git a/Xwinsock.h b/Xwinsock.h
index e6ca7b5..e846785 100644
--- a/Xwinsock.h
+++ b/Xwinsock.h
@@ -39,8 +39,16 @@ The Open Group.
 # undef XFree86Server
 #endif
 
-#define BOOL wBOOL
+/*
+ * mingw-w64 headers define BOOL as a typedef, protecting against macros
+ * mingw.org headers define BOOL in terms of WINBOOL
+ * ... so try to come up with something which works with both :-)
+ */
+#define _NO_BOOL_TYPEDEF
+#define BOOL WINBOOL
 #define INT32 wINT32
+#define INT64 wINT64
+#define LONG64 wLONG64
 #undef Status
 #define Status wStatus
 #define ATOM wATOM
@@ -52,12 +60,20 @@ The Open Group.
 #undef BYTE
 #undef BOOL
 #undef INT32
+#undef INT64
+#undef LONG64
 #undef ATOM
 #undef FreeResource
 #undef CreateWindowA
 #undef RT_FONT
 #undef RT_CURSOR
 
+/*
+ * Older version of this header used to name the windows API bool type wBOOL,
+ * rather than more standard name WINBOOL
+ */
+#define wBOOL WINBOOL
+
 #ifdef _XFree86Server
 # define XFree86Server
 # undef _XFree86Server
-- 
1.7.9



More information about the xorg-devel mailing list