[xml] libxml2 IMHO broken on mingw when using as dynamic lib



Hi...

I am using libxml2 on mingw. 2 days ago I found a strange problem in libxml2-2.6.4 resulting from an IMHO broken definition for mingw. I yet don't know whether this is already known or not (and so maybe fixed), I couldn't find anything in the mailinglist archive, and also have just subscribed to this list to report this bug. So please don't mind if this is already known.

What's wrong from my point of view?
include/libxml/xmlexports.h looks like this:
/* Windows platform with GNU compiler (Mingw) */
#if defined(_WIN32) && defined(__MINGW__)
 #if !defined _REENTRANT
   #define _REENTRANT
 #endif
#endif

This is IMHO wrong. First the define for mingw should be __MINGW32__ instead of __MINGW__ and second at least XMLPUBVAR definition is missing so eg. xmlFree() and friends are not really available and when using it on mingw xmlFree() crashes. My suggested fix for this is:
/* Windows platform with GNU compiler (Mingw) */
#if defined(_WIN32) && defined(__MINGW32__)
 #undef XMLPUBFUN
 #undef XMLPUBVAR
 #undef XMLCALL
 #if defined(IN_LIBXML) && !defined(LIBXML_STATIC)
   #define XMLPUBFUN __declspec(dllexport)
   #define XMLPUBVAR __declspec(dllexport)
 #else
   #define XMLPUBFUN
   #if !defined(LIBXML_STATIC)
     #define XMLPUBVAR __declspec(dllimport) extern
   #else
     #define XMLPUBVAR extern
   #endif
 #endif
 #define XMLCALL __cdecl
 #if !defined _REENTRANT
   #define _REENTRANT
 #endif
#endif

It is know looking literally the same as for MSVC and appears to work.

What do you think? Is this acceptable? I don't know the rules for submitting patches to libxml2 (or whether they are welcome at all), so I just added a diff of this change.

Bye,

Roland

--- xmlexports.h        2003-12-30 11:08:35.000000000 +0100
+++ xmlexports.h.new    2004-01-09 10:44:56.000000000 +0100
@@ -85,7 +85,22 @@
 #endif
 
 /* Windows platform with GNU compiler (Mingw) */
-#if defined(_WIN32) && defined(__MINGW__)
+#if defined(_WIN32) && defined(__MINGW32__)
+  #undef XMLPUBFUN
+  #undef XMLPUBVAR
+  #undef XMLCALL
+  #if defined(IN_LIBXML) && !defined(LIBXML_STATIC)
+    #define XMLPUBFUN __declspec(dllexport)
+    #define XMLPUBVAR __declspec(dllexport)
+  #else
+    #define XMLPUBFUN
+    #if !defined(LIBXML_STATIC)
+      #define XMLPUBVAR __declspec(dllimport) extern
+    #else
+      #define XMLPUBVAR extern
+    #endif
+  #endif
+  #define XMLCALL __cdecl
   #if !defined _REENTRANT
     #define _REENTRANT
   #endif


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