cleaning up XPath error reporting that time. applied the two patches for

* error.c include/libxml/xmlerror.h include/libxml/xpath.h
  include/libxml/xpathInternals.h xpath.c: cleaning up XPath
  error reporting that time.
* threads.c: applied the two patches for TLS threads
  on Windows from Jesse Pelton
* parser.c: tiny safety patch for xmlStrPrintf() make sure the
  return is always zero terminated. Should also help detecting
  passing wrong buffer size easilly.
* result/VC/* result/valid/rss.xml.err result/valid/xlink.xml.err:
  updated the results to follow the errors string generated by
  last commit.
Daniel
diff --git a/include/libxml/xmlerror.h b/include/libxml/xmlerror.h
index 2d65360..7c21aec 100644
--- a/include/libxml/xmlerror.h
+++ b/include/libxml/xmlerror.h
@@ -375,7 +375,29 @@
     XML_RNGP_VALUE_EMPTY,
     XML_RNGP_VALUE_NO_CONTENT,
     XML_RNGP_XMLNS_NAME,
-    XML_RNGP_XML_NS
+    XML_RNGP_XML_NS,
+    XML_XPATH_EXPRESSION_OK = 1200,
+    XML_XPATH_NUMBER_ERROR,
+    XML_XPATH_UNFINISHED_LITERAL_ERROR,
+    XML_XPATH_START_LITERAL_ERROR,
+    XML_XPATH_VARIABLE_REF_ERROR,
+    XML_XPATH_UNDEF_VARIABLE_ERROR,
+    XML_XPATH_INVALID_PREDICATE_ERROR,
+    XML_XPATH_EXPR_ERROR,
+    XML_XPATH_UNCLOSED_ERROR,
+    XML_XPATH_UNKNOWN_FUNC_ERROR,
+    XML_XPATH_INVALID_OPERAND,
+    XML_XPATH_INVALID_TYPE,
+    XML_XPATH_INVALID_ARITY,
+    XML_XPATH_INVALID_CTXT_SIZE,
+    XML_XPATH_INVALID_CTXT_POSITION,
+    XML_XPATH_MEMORY_ERROR,
+    XML_XPTR_SYNTAX_ERROR,
+    XML_XPTR_RESOURCE_ERROR,
+    XML_XPTR_SUB_RESOURCE_ERROR,
+    XML_XPATH_UNDEF_PREFIX_ERROR,
+    XML_XPATH_ENCODING_ERROR,
+    XML_XPATH_INVALID_CHAR_ERROR
 } xmlParserErrors;
 
 /**
@@ -389,7 +411,16 @@
  */
 typedef void (*xmlGenericErrorFunc) (void *ctx,
 				 const char *msg,
-				 ...);
+	 			 ...);
+/**
+ * xmlStructuredErrorFunc:
+ * @userData:  user provided data for the error callback
+ * @error:  the error being raised.
+ *
+ * Signature of the function to use when there is an error and
+ * the module handles the new error reporting mechanism.
+ */
+typedef void (*xmlStructuredErrorFunc) (void *userData, xmlErrorPtr error);
 
 /*
  * Use the following function to reset the two global variables
diff --git a/include/libxml/xpath.h b/include/libxml/xpath.h
index d7471df..dbd1b77 100644
--- a/include/libxml/xpath.h
+++ b/include/libxml/xpath.h
@@ -13,6 +13,7 @@
 #define __XML_XPATH_H__
 
 #include <libxml/xmlversion.h>
+#include <libxml/xmlerror.h>
 #include <libxml/tree.h>
 #include <libxml/hash.h>
 
@@ -253,6 +254,12 @@
     /* temporary namespace lists kept for walking the namespace axis */
     xmlNsPtr *tmpNsList;		/* Array of namespaces */
     int tmpNsNr;			/* number of namespace in scope */
+
+    /* error reporting mechanism */
+    void *userData;                     /* user specific data block */
+    xmlStructuredErrorFunc error;       /* the callback in case of errors */
+    xmlError lastError;			/* the last error */
+    xmlNodePtr debugNode;		/* the source node XSLT */
 };
 
 /*
diff --git a/include/libxml/xpathInternals.h b/include/libxml/xpathInternals.h
index 6b9e996..269edb8 100644
--- a/include/libxml/xpathInternals.h
+++ b/include/libxml/xpathInternals.h
@@ -250,8 +250,7 @@
  * Macro to raise an XPath error and return.
  */
 #define XP_ERROR(X)							\
-    { xmlXPatherror(ctxt, __FILE__, __LINE__, X);			\
-      ctxt->error = (X); return; }
+    { xmlXPathErr(ctxt, X); return; }
 
 /**
  * XP_ERROR0:
@@ -260,8 +259,7 @@
  * Macro to raise an XPath error and return 0.
  */
 #define XP_ERROR0(X)							\
-    { xmlXPatherror(ctxt, __FILE__, __LINE__, X);			\
-      ctxt->error = (X); return(0); }
+    { xmlXPathErr(ctxt, X); return(0); }
 
 /**
  * CHECK_TYPE:
@@ -377,6 +375,10 @@
 				 int line,
 				 int no);
 
+XMLPUBFUN void XMLCALL
+		xmlXPathErr	(xmlXPathParserContextPtr ctxt,
+				 int error);
+
 #ifdef LIBXML_DEBUG_ENABLED
 XMLPUBFUN void XMLCALL		
 		xmlXPathDebugDumpObject	(FILE *output,