[libxml2] Fix the Windows header mess



commit e3890546d798927aeabdb471985b4afd9f74bbec
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Mon Oct 9 00:20:01 2017 +0200

    Fix the Windows header mess
    
    Don't include windows.h and wsockcompat.h from config.h but only when
    needed.
    
    Don't define _WINSOCKAPI_ manually. This was apparently done to stop
    windows.h from including winsock.h which is a problem if winsock2.h
    wasn't included first. But on MinGW, this causes compiler warnings.
    Define WIN32_LEAN_AND_MEAN instead which has the same effect.
    
    Always use the compiler-defined _WIN32 macro instead of WIN32.

 configure.ac             |    1 -
 dict.c                   |    2 +-
 include/libxml/nanoftp.h |    2 +-
 include/win32config.h    |    5 -----
 nanoftp.c                |    8 +-------
 nanohttp.c               |    7 +------
 os400/os400config.h.in   |    3 ---
 parser.c                 |    2 +-
 parserInternals.c        |    2 +-
 runtest.c                |    2 +-
 threads.c                |    1 +
 timsort.h                |    4 ++--
 win32/Makefile.mingw     |    2 --
 win32/Makefile.msvc      |    2 +-
 win32/VC10/config.h      |    5 -----
 xmlIO.c                  |    5 +++--
 xmlmodule.c              |    3 ++-
 17 files changed, 16 insertions(+), 40 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index ff190a5..7aa31fa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1640,7 +1640,6 @@ case "$host" in
  CPPFLAGS="$CPPFLAGS -DWIN32"
  WIN32_EXTRA_LIBADD="-lws2_32"
  WIN32_EXTRA_LDFLAGS="-no-undefined"
- AC_DEFINE([_WINSOCKAPI_],1,[Using the Win32 Socket implementation])
  if test "${PYTHON}" != ""
  then
    WIN32_EXTRA_PYTHON_LIBADD="-L${pythondir}/../../libs -lpython$(echo ${PYTHON_VERSION} | tr -d .)"
diff --git a/dict.c b/dict.c
index 7b005eb..bcfc8bd 100644
--- a/dict.c
+++ b/dict.c
@@ -48,7 +48,7 @@
 #else
 #ifdef HAVE_INTTYPES_H
 #include <inttypes.h>
-#elif defined(WIN32)
+#elif defined(_WIN32)
 typedef unsigned __int32 uint32_t;
 #endif
 #endif
diff --git a/include/libxml/nanoftp.h b/include/libxml/nanoftp.h
index abb4bf7..7335faf 100644
--- a/include/libxml/nanoftp.h
+++ b/include/libxml/nanoftp.h
@@ -16,7 +16,7 @@
 #ifdef LIBXML_FTP_ENABLED
 
 /* Needed for portability to Windows 64 bits */
-#if defined(__MINGW32__) || defined(_WIN32_WCE)
+#if defined(_WIN32) && !defined(__CYGWIN__)
 #include <winsock2.h>
 #else
 /**
diff --git a/include/win32config.h b/include/win32config.h
index 40cf7df..8596755 100644
--- a/include/win32config.h
+++ b/include/win32config.h
@@ -10,7 +10,6 @@
 
 #if defined(_WIN32_WCE)
 #undef HAVE_ERRNO_H
-#include <windows.h>
 #include "wincecompat.h"
 #else
 #define HAVE_SYS_STAT_H
@@ -29,10 +28,6 @@
 #define ICONV_CONST const
 #endif
 
-#ifdef NEED_SOCKETS
-#include <wsockcompat.h>
-#endif
-
 /*
  * Windows platforms may define except 
  */
diff --git a/nanoftp.c b/nanoftp.c
index 9219f47..1624881 100644
--- a/nanoftp.c
+++ b/nanoftp.c
@@ -12,8 +12,6 @@
 #define HAVE_NETINET_IN_H
 #define HAVE_NETDB_H
 #define HAVE_SYS_TIME_H
-#else /* TESTING */
-#define NEED_SOCKETS
 #endif /* TESTING */
 
 #define IN_LIBXML
@@ -77,12 +75,8 @@
 #endif
 
 
-#if defined(__MINGW32__) || defined(_WIN32_WCE)
-#ifndef _WINSOCKAPI_
-#define _WINSOCKAPI_
-#endif
+#if defined(_WIN32) && !defined(__CYGWIN__)
 #include <wsockcompat.h>
-#include <winsock2.h>
 #endif
 
 /**
diff --git a/nanohttp.c b/nanohttp.c
index 667d2ac..3441eca 100644
--- a/nanohttp.c
+++ b/nanohttp.c
@@ -11,7 +11,6 @@
  * daniel veillard com
  */
 
-#define NEED_SOCKETS
 #define IN_LIBXML
 #include "libxml.h"
 
@@ -74,12 +73,8 @@
 #define XML_SOCKLEN_T unsigned int
 #endif
 
-#if defined(__MINGW32__) || defined(_WIN32_WCE)
-#ifndef _WINSOCKAPI_
-#define _WINSOCKAPI_
-#endif
+#if defined(_WIN32) && !defined(__CYGWIN__)
 #include <wsockcompat.h>
-#include <winsock2.h>
 #endif
 
 #include <libxml/globals.h>
diff --git a/os400/os400config.h.in b/os400/os400config.h.in
index 3966ac8..ad5abb7 100644
--- a/os400/os400config.h.in
+++ b/os400/os400config.h.in
@@ -333,9 +333,6 @@
    #define below would cause a syntax error. */
 #undef _UINT32_T
 
-/* Using the Win32 Socket implementation */
-#undef _WINSOCKAPI_
-
 /* ss_family is not defined here, use __ss_family instead */
 #undef ss_family
 
diff --git a/parser.c b/parser.c
index a816db0..1c5e036 100644
--- a/parser.c
+++ b/parser.c
@@ -38,7 +38,7 @@
 #define IN_LIBXML
 #include "libxml.h"
 
-#if defined(WIN32) && !defined (__CYGWIN__)
+#if defined(_WIN32) && !defined (__CYGWIN__)
 #define XML_DIR_SEP '\\'
 #else
 #define XML_DIR_SEP '/'
diff --git a/parserInternals.c b/parserInternals.c
index 43a0f5a..efb2387 100644
--- a/parserInternals.c
+++ b/parserInternals.c
@@ -10,7 +10,7 @@
 #define IN_LIBXML
 #include "libxml.h"
 
-#if defined(WIN32) && !defined (__CYGWIN__)
+#if defined(_WIN32) && !defined (__CYGWIN__)
 #define XML_DIR_SEP '\\'
 #else
 #define XML_DIR_SEP '/'
diff --git a/runtest.c b/runtest.c
index 714de27..0d23701 100644
--- a/runtest.c
+++ b/runtest.c
@@ -4021,7 +4021,7 @@ thread_specific_data(void *private_data)
     return ((void *) Okay);
 }
 
-#if defined WIN32
+#if defined(_WIN32) && !defined(__CYGWIN__)
 #include <windows.h>
 #include <string.h>
 
diff --git a/threads.c b/threads.c
index e52f263..8860697 100644
--- a/threads.c
+++ b/threads.c
@@ -27,6 +27,7 @@
 #ifdef HAVE_PTHREAD_H
 #include <pthread.h>
 #elif defined HAVE_WIN32_THREADS
+#define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #ifndef HAVE_COMPILER_TLS
 #include <process.h>
diff --git a/timsort.h b/timsort.h
index 19aebf2..724e066 100644
--- a/timsort.h
+++ b/timsort.h
@@ -24,14 +24,14 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
 #else
 #ifdef HAVE_INTTYPES_H
 #include <inttypes.h>
-#elif defined(WIN32)
+#elif defined(_WIN32)
 typedef __int64 int64_t;
 typedef unsigned __int64 uint64_t;
 #endif
 #endif
 
 #ifndef MK_UINT64
-#if defined(WIN32) && defined(_MSC_VER) && _MSC_VER < 1300
+#if defined(_MSC_VER) && _MSC_VER < 1300
 #define MK_UINT64(x) ((uint64_t)(x))
 #else
 #define MK_UINT64(x) x##ULL
diff --git a/win32/Makefile.mingw b/win32/Makefile.mingw
index 1889376..f579923 100644
--- a/win32/Makefile.mingw
+++ b/win32/Makefile.mingw
@@ -71,11 +71,9 @@ LDFLAGS += -Wl,--minor-image-version,$(LIBXML_MINOR_VERSION)
 LDFLAGS += -Wl,-L,$(BINDIR) -Wl,-L,$(LIBPREFIX)
 LIBS =
 ifeq ($(WITH_FTP),1)
-CFLAGS += -D_WINSOCKAPI_
 LIBS += -lwsock32 -lws2_32
 endif 
 ifeq ($(WITH_HTTP),1)
-CFLAGS += -D_WINSOCKAPI_
 LIBS += -lwsock32 -lws2_32
 endif 
 ifeq ($(WITH_ICONV),1)
diff --git a/win32/Makefile.msvc b/win32/Makefile.msvc
index d16c1a2..bb7fa4a 100644
--- a/win32/Makefile.msvc
+++ b/win32/Makefile.msvc
@@ -43,7 +43,7 @@ CPPFLAGS = $(CPPFLAGS) /D "_REENTRANT"
 
 # The compiler and its options.
 CC = cl.exe
-CFLAGS = /nologo /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "NOLIBTOOL" /W1 $(CRUNTIME)
+CFLAGS = /nologo /D "_WINDOWS" /D "_MBCS" /D "NOLIBTOOL" /W1 $(CRUNTIME)
 CFLAGS = $(CFLAGS) /I$(XML_SRCDIR) /I$(XML_SRCDIR)\include /I$(INCPREFIX)
 !if "$(WITH_THREADS)" != "no"
 CFLAGS = $(CFLAGS) /D "_REENTRANT"
diff --git a/win32/VC10/config.h b/win32/VC10/config.h
index 891b57e..4e184a3 100644
--- a/win32/VC10/config.h
+++ b/win32/VC10/config.h
@@ -9,7 +9,6 @@
 
 #if defined(_WIN32_WCE)
 #undef HAVE_ERRNO_H
-#include <windows.h>
 #include "wincecompat.h"
 #else
 #define HAVE_SYS_STAT_H
@@ -28,10 +27,6 @@
 #define ICONV_CONST const
 #endif
 
-#ifdef NEED_SOCKETS
-#include <wsockcompat.h>
-#endif
-
 /*
  * Windows platforms may define except 
  */
diff --git a/xmlIO.c b/xmlIO.c
index 5902f62..b15d91d 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -40,7 +40,8 @@
 #include <lzma.h>
 #endif
 
-#if defined(WIN32) || defined(_WIN32)
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #endif
 
@@ -3829,7 +3830,7 @@ xmlParserGetDirectory(const char *filename) {
 
     if (filename == NULL) return(NULL);
 
-#if defined(WIN32) && !defined(__CYGWIN__)
+#if defined(_WIN32) && !defined(__CYGWIN__)
 #   define IS_XMLPGD_SEP(ch) ((ch=='/')||(ch=='\\'))
 #else
 #   define IS_XMLPGD_SEP(ch) (ch=='/')
diff --git a/xmlmodule.c b/xmlmodule.c
index 7f70f9c..e3a8bd6 100644
--- a/xmlmodule.c
+++ b/xmlmodule.c
@@ -301,8 +301,9 @@ xmlModulePlatformSymbol(void *handle, const char *name, void **symbol)
 #endif /* HAVE_SHLLOAD */
 #endif /* ! HAVE_DLOPEN */
 
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(__CYGWIN__)
 
+#define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 
 /*


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]