make the allocation be per-thread a configure option fixed compilation

* include/libxml/globals.h configure.in global.data: make
  the allocation be per-thread a configure option
* encoding.c include/libxml/parser.h: fixed compilation
  errors
Daniel
diff --git a/ChangeLog b/ChangeLog
index 58618d5..86265f9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Mon Oct 15 14:30:11 CEST 2001 Daniel Veillard <daniel@veillard.com>
+
+	* include/libxml/globals.h configure.in global.data: make
+	  the allocation be per-thread a configure option
+	* encoding.c include/libxml/parser.h: fixed compilation
+	  errors
+
 Mon Oct 15 12:45:03 CEST 2001 Daniel Veillard <daniel@veillard.com>
 
 	* include/libxml/parser.h: Norm reported that a few lines
diff --git a/configure.in b/configure.in
index 9f50db7..45145ef 100644
--- a/configure.in
+++ b/configure.in
@@ -249,6 +249,7 @@
 THREAD_LIBS=""
 WITH_THREADS=0
 THREAD_CFLAGS=""
+
 AC_ARG_WITH(threads, [  --with-threads          Add multithread support(off)])
 if test "$with_threads" = "yes" ; then
     echo Enabling multithreaded support
@@ -264,6 +265,11 @@
         THREAD_CFLAGS="$XML_CFLAGS -D_REENTRANT"
     fi
 fi
+AC_ARG_WITH(thread-alloc, [  --with-thread-alloc     Add per-thread memory(off)])
+if test "$with_threads" = "yes" -a "$WITH_THREADS" = "1" ; then
+    THREAD_CFLAGS="$XML_CFLAGS -DLIBXML_THREAD_ALLOC_ENABLED"
+fi
+
 AC_SUBST(THREAD_LIBS)
 AC_SUBST(WITH_THREADS)
 AC_SUBST(THREAD_CFLAGS)
diff --git a/encoding.c b/encoding.c
index 781d8da..a9495c4 100644
--- a/encoding.c
+++ b/encoding.c
@@ -44,6 +44,7 @@
 #include <libxml/HTMLparser.h>
 #endif
 #include <libxml/xmlerror.h>
+#include <libxml/globals.h>
 
 static xmlCharEncodingHandlerPtr xmlUTF16LEHandler = NULL;
 static xmlCharEncodingHandlerPtr xmlUTF16BEHandler = NULL;
diff --git a/global.data b/global.data
index 45c3b31..2a6a445 100644
--- a/global.data
+++ b/global.data
@@ -6,7 +6,6 @@
 xmlSAXHandler,xmlDefaultSAXHandler
 xmlSAXLocator,xmlDefaultSAXLocator
 int,xmlDoValidityCheckingDefaultValue
-xmlFreeFunc,xmlFree
 xmlGenericErrorFunc,xmlGenericError
 void *,xmlGenericErrorContext
 int,xmlGetWarningsDefaultValue
@@ -14,14 +13,11 @@
 int,xmlKeepBlanksDefaultValue
 int,xmlLineNumbersDefaultValue
 int,xmlLoadExtDtdDefaultValue
-xmlMallocFunc,xmlMalloc
-xmlStrdupFunc,xmlMemStrdup
 int,xmlParserDebugEntities
 const char *,xmlParserVersion
 int,xmlPedanticParserDefaultValue
-xmlReallocFunc,xmlRealloc
 int,xmlSaveNoEmptyTags
 #const xmlChar,xmlStringComment,[]
 #const xmlChar,xmlStringText,[]
 #const xmlChar,xmlStringTextNoenc,[]
-int,xmlSubstituteEntitiesDefaultValue
\ No newline at end of file
+int,xmlSubstituteEntitiesDefaultValue
diff --git a/include/libxml/globals.h b/include/libxml/globals.h
index 499fa58..f1e46a9 100644
--- a/include/libxml/globals.h
+++ b/include/libxml/globals.h
@@ -91,6 +91,54 @@
 void	xmlInitializeGlobalState(xmlGlobalStatePtr gs);
 
 /*
+ * In general the memory allocation entry points are not kept
+ * thread specific but this can be overriden by LIBXML_THREAD_ALLOC_ENABLED
+ *    - xmlMalloc
+ *    - xmlRealloc
+ *    - xmlMemStrdup
+ *    - xmlFree
+ */
+
+#ifdef LIBXML_THREAD_ALLOC_ENABLED
+#ifdef LIBXML_THREAD_ENABLED
+extern xmlMallocFunc *__xmlMalloc(void);
+#define xmlMalloc \
+(*(__xmlMalloc()))
+#else
+LIBXML_DLL_IMPORT extern xmlMallocFunc xmlMalloc;
+#endif
+
+#ifdef LIBXML_THREAD_ENABLED
+extern xmlReallocFunc *__xmlRealloc(void);
+#define xmlRealloc \
+(*(__xmlRealloc()))
+#else
+LIBXML_DLL_IMPORT extern xmlReallocFunc xmlRealloc;
+#endif
+
+#ifdef LIBXML_THREAD_ENABLED
+extern xmlFreeFunc *__xmlFree(void);
+#define xmlFree \
+(*(__xmlFree()))
+#else
+LIBXML_DLL_IMPORT extern xmlFreeFunc xmlFree;
+#endif
+
+#ifdef LIBXML_THREAD_ENABLED
+extern xmlStrdupFunc *__xmlMemStrdup(void);
+#define xmlMemStrdup \
+(*(__xmlMemStrdup()))
+#else
+LIBXML_DLL_IMPORT extern xmlStrdupFunc xmlMemStrdup;
+#endif
+#else /* !LIBXML_THREAD_ALLOC_ENABLED */
+LIBXML_DLL_IMPORT extern xmlMallocFunc xmlMalloc;
+LIBXML_DLL_IMPORT extern xmlReallocFunc xmlRealloc;
+LIBXML_DLL_IMPORT extern xmlFreeFunc xmlFree;
+LIBXML_DLL_IMPORT extern xmlStrdupFunc xmlMemStrdup;
+#endif /* LIBXML_THREAD_ALLOC_ENABLED */
+
+/*
  * Everything starting from the line below is
  * Automatically generated by build_glob.py.
  * Do not modify the previous line.
@@ -162,14 +210,6 @@
 #endif
 
 #ifdef LIBXML_THREAD_ENABLED
-extern xmlFreeFunc *__xmlFree(void);
-#define xmlFree \
-(*(__xmlFree()))
-#else
-LIBXML_DLL_IMPORT extern xmlFreeFunc xmlFree;
-#endif
-
-#ifdef LIBXML_THREAD_ENABLED
 extern xmlGenericErrorFunc *__xmlGenericError(void);
 #define xmlGenericError \
 (*(__xmlGenericError()))
@@ -226,22 +266,6 @@
 #endif
 
 #ifdef LIBXML_THREAD_ENABLED
-extern xmlMallocFunc *__xmlMalloc(void);
-#define xmlMalloc \
-(*(__xmlMalloc()))
-#else
-LIBXML_DLL_IMPORT extern xmlMallocFunc xmlMalloc;
-#endif
-
-#ifdef LIBXML_THREAD_ENABLED
-extern xmlStrdupFunc *__xmlMemStrdup(void);
-#define xmlMemStrdup \
-(*(__xmlMemStrdup()))
-#else
-LIBXML_DLL_IMPORT extern xmlStrdupFunc xmlMemStrdup;
-#endif
-
-#ifdef LIBXML_THREAD_ENABLED
 extern int *__xmlParserDebugEntities(void);
 #define xmlParserDebugEntities \
 (*(__xmlParserDebugEntities()))
@@ -266,14 +290,6 @@
 #endif
 
 #ifdef LIBXML_THREAD_ENABLED
-extern xmlReallocFunc *__xmlRealloc(void);
-#define xmlRealloc \
-(*(__xmlRealloc()))
-#else
-LIBXML_DLL_IMPORT extern xmlReallocFunc xmlRealloc;
-#endif
-
-#ifdef LIBXML_THREAD_ENABLED
 extern int *__xmlSaveNoEmptyTags(void);
 #define xmlSaveNoEmptyTags \
 (*(__xmlSaveNoEmptyTags()))
diff --git a/include/libxml/parser.h b/include/libxml/parser.h
index a3ab956..21244da 100644
--- a/include/libxml/parser.h
+++ b/include/libxml/parser.h
@@ -13,9 +13,6 @@
 #include <libxml/valid.h>
 #include <libxml/xmlIO.h>
 #include <libxml/entities.h>
-#if defined(_REENTRANT) || (_POSIX_C_SOURCE - 0 >= 199506L)
-#include <pthread.h>
-#endif
 
 #ifdef __cplusplus
 extern "C" {
@@ -579,5 +576,7 @@
 }
 #endif
 
+#include <libxml/globals.h>
+
 #endif /* __XML_PARSER_H__ */