trying to cleanup the not thread safe parts of the library. Daniel

* catalog.c xpath.c: trying to cleanup the not thread safe
  parts of the library.
Daniel
diff --git a/xpath.c b/xpath.c
index b63f8b7..f8966d1 100644
--- a/xpath.c
+++ b/xpath.c
@@ -51,6 +51,7 @@
 #include <libxml/debugXML.h>
 #endif
 #include <libxml/xmlerror.h>
+#include <libxml/threads.h>
 
 /* #define DEBUG */
 /* #define DEBUG_STEP */
@@ -69,6 +70,13 @@
     BAD_CAST "xml"
 };
 static xmlNsPtr xmlXPathXMLNamespace = &xmlXPathXMLNamespaceStruct;
+#ifndef LIBXML_THREADS_ENABLED
+/* 
+ * Optimizer is disabled only when threaded apps are detected while
+ * the library ain't compiled for thread safety.
+ */
+static int xmlXPathDisableOptimizer = 0;
+#endif
 
 /************************************************************************
  * 									*
@@ -361,14 +369,21 @@
  * @op: operation index
  *
  * Swaps 2 operations in the compiled expression
- * TODO: not thread safe, disable for multi-thread operations
- *
- * Returns -1 in case of failure, the index otherwise
  */
 static void
 xmlXPathCompSwap(xmlXPathStepOpPtr op) {
     int tmp;
 
+#ifdef LIBXML_THREADS_ENABLED
+    /*
+     * Since this manipulates possibly shared variables, this is
+     * disable if one detects that the library is used in a multithreaded
+     * application
+     */
+    if (xmlXPathDisableOptimizer)
+	return;
+#endif
+
     tmp = op->ch1;
     op->ch1 = op->ch2;
     op->ch2 = tmp;
@@ -9819,6 +9834,9 @@
     xmlXPathParserContextPtr ctxt;
     xmlXPathObjectPtr res, tmp, init = NULL;
     int stack = 0;
+#ifndef LIBXML_THREAD_ENABLED
+    static int reentance = 0;
+#endif
 
     if ((comp == NULL) || (ctx == NULL))
 	return(NULL);
@@ -9826,6 +9844,12 @@
 
     CHECK_CONTEXT(ctx)
 
+#ifndef LIBXML_THREAD_ENABLED
+    reentance++;
+    if (reentance > 1)
+	xmlXPathDisableOptimizer = 1;
+#endif
+
 #ifdef DEBUG_EVAL_COUNTS
     comp->nb++;
     if ((comp->string != NULL) && (comp->nb > 100)) {
@@ -9866,6 +9890,9 @@
 
     ctxt->comp = NULL;
     xmlXPathFreeParserContext(ctxt);
+#ifndef LIBXML_THREAD_ENABLED
+    reentance--;
+#endif
     return(res);
 }