better handling of conditional features more testing on parser contexts

* gentest.py testapi.c: better handling of conditional features
* HTMLparser.c SAX2.c parserInternals.c xmlwriter.c: more testing
  on parser contexts closed leaks, error messages
Daniel
diff --git a/ChangeLog b/ChangeLog
index 5c56a49..9d4224e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Tue Nov  9 15:59:50 CET 2004 Daniel Veillard <daniel@veillard.com>
+
+	* gentest.py testapi.c: better handling of conditional features
+	* HTMLparser.c SAX2.c parserInternals.c xmlwriter.c: more testing
+	  on parser contexts closed leaks, error messages
+
 Tue Nov  9 10:21:37 GMT 2004 William Brack <wbrack@mmm.com.hk>
 
 	* xpath.c: fixed problem concerning XPath context corruption
diff --git a/HTMLparser.c b/HTMLparser.c
index 864cd56..4f84d7c 100644
--- a/HTMLparser.c
+++ b/HTMLparser.c
@@ -5675,8 +5675,12 @@
     ctxt->input = NULL;
 
     ctxt->spaceNr = 0;
-    ctxt->spaceTab[0] = -1;
-    ctxt->space = &ctxt->spaceTab[0];
+    if (ctxt->spaceTab != NULL) {
+	ctxt->spaceTab[0] = -1;
+	ctxt->space = &ctxt->spaceTab[0];
+    } else {
+	ctxt->space = NULL;
+    }
 
 
     ctxt->nodeNr = 0;
diff --git a/SAX2.c b/SAX2.c
index b95e555..cf8a615 100644
--- a/SAX2.c
+++ b/SAX2.c
@@ -1421,7 +1421,7 @@
     const xmlChar *value;
     int i;
 
-    if ((ctx == NULL) || (fullname == NULL)) return;
+    if ((ctx == NULL) || (fullname == NULL) || (ctxt->myDoc == NULL)) return;
     parent = ctxt->node;
 #ifdef DEBUG_SAX
     xmlGenericError(xmlGenericErrorContext,
diff --git a/gentest.py b/gentest.py
index b77b885..d66b50a 100755
--- a/gentest.py
+++ b/gentest.py
@@ -21,6 +21,80 @@
 ]
 
 #
+# defines for each module
+#
+modules_defines = {
+    "HTMLparser": "LIBXML_HTML_ENABLED",
+    "catalog": "LIBXML_CATALOG_ENABLED",
+    "xmlreader": "LIBXML_READER_ENABLED",
+    "relaxng": "LIBXML_SCHEMAS_ENABLED",
+    "schemasInternals": "LIBXML_SCHEMAS_ENABLED",
+    "xmlschemas": "LIBXML_SCHEMAS_ENABLED",
+    "xmlschemastypes": "LIBXML_SCHEMAS_ENABLED",
+    "xpath": "LIBXML_XPATH_ENABLED",
+    "xpathInternals": "LIBXML_XPATH_ENABLED",
+    "xinclude": "LIBXML_XINCLUDE_ENABLED",
+    "xpointer": "LIBXML_XPTR_ENABLED",
+    "xmlregexp" : "LIBXML_REGEXP_ENABLED",
+    "xmlautomata" : "LIBXML_AUTOMATA_ENABLED",
+    "xmlsave" : "LIBXML_OUTPUT_ENABLED",
+    "DOCBparser" : "LIBXML_DOCB_ENABLED",
+}
+
+#
+# defines for specific functions
+#
+function_defines = {
+    "htmlDefaultSAXHandlerInit": "LIBXML_HTML_ENABLED",
+    "xmlSAX2EndElement" : "LIBXML_SAX1_ENABLED",
+    "xmlSAX2StartElement" : "LIBXML_SAX1_ENABLED",
+    "xmlSAXDefaultVersion" : "LIBXML_SAX1_ENABLED",
+    "UTF8Toisolat1" : "LIBXML_OUTPUT_ENABLED",
+    "xmlCleanupPredefinedEntities": "LIBXML_LEGACY_ENABLED",
+    "xmlInitializePredefinedEntities": "LIBXML_LEGACY_ENABLED",
+    "xmlSetFeature": "LIBXML_LEGACY_ENABLED",
+    "xmlGetFeature": "LIBXML_LEGACY_ENABLED",
+    "xmlGetFeaturesList": "LIBXML_LEGACY_ENABLED",
+    "xmlIOParseDTD": "LIBXML_VALID_ENABLED",
+    "xmlParseDTD": "LIBXML_VALID_ENABLED",
+    "xmlParseDoc": "LIBXML_SAX1_ENABLED",
+    "xmlParseMemory": "LIBXML_SAX1_ENABLED",
+    "xmlRecoverDoc": "LIBXML_SAX1_ENABLED",
+    "xmlParseFile": "LIBXML_SAX1_ENABLED",
+    "xmlRecoverFile": "LIBXML_SAX1_ENABLED",
+    "xmlRecoverMemory": "LIBXML_SAX1_ENABLED",
+    "xmlSAXParseFileWithData": "LIBXML_SAX1_ENABLED",
+    "xmlSAXParseMemory": "LIBXML_SAX1_ENABLED",
+    "xmlSAXUserParseMemory": "LIBXML_SAX1_ENABLED",
+    "xmlSAXParseDoc": "LIBXML_SAX1_ENABLED",
+    "xmlSAXParseDTD": "LIBXML_SAX1_ENABLED",
+    "xmlSAXUserParseFile": "LIBXML_SAX1_ENABLED",
+    "xmlParseEntity": "LIBXML_SAX1_ENABLED",
+    "xmlParseExternalEntity": "LIBXML_SAX1_ENABLED",
+    "xmlSAXParseMemoryWithData": "LIBXML_SAX1_ENABLED",
+    "xmlParseBalancedChunkMemory": "LIBXML_SAX1_ENABLED",
+    "xmlParseBalancedChunkMemoryRecover": "LIBXML_SAX1_ENABLED",
+    "xmlSetupParserForBuffer": "LIBXML_SAX1_ENABLED",
+    "xmlStopParser": "LIBXML_PUSH_ENABLED",
+    "xmlAttrSerializeTxtContent": "LIBXML_OUTPUT_ENABLED",
+    "xmlSAXParseFile": "LIBXML_SAX1_ENABLED",
+    "xmlSAXParseEntity": "LIBXML_SAX1_ENABLED",
+    "xmlNewTextChild": "LIBXML_TREE_ENABLED",
+    "xmlNewDocRawNode": "LIBXML_TREE_ENABLED",
+    "xmlNewProp": "LIBXML_TREE_ENABLED",
+    "xmlReconciliateNs": "LIBXML_TREE_ENABLED",
+    "xmlValidateNCName": "LIBXML_TREE_ENABLED",
+    "xmlValidateNMToken": "LIBXML_TREE_ENABLED",
+    "xmlValidateName": "LIBXML_TREE_ENABLED",
+    "xmlNewChild": "LIBXML_TREE_ENABLED",
+    "xmlValidateQName": "LIBXML_TREE_ENABLED",
+    "xmlSprintfElementContent": "LIBXML_OUTPUT_ENABLED",
+    "xmlValidGetPotentialChildren" : "LIBXML_VALID_ENABLED",
+    "xmlValidGetValidElements" : "LIBXML_VALID_ENABLED",
+    "docbDefaultSAXHandlerInit" : "LIBXML_DOCB_ENABLED",
+}
+
+#
 # Some function really need to be skipped for the tests.
 #
 skipped_functions = [
@@ -97,14 +171,26 @@
 # Extra code needed for some test cases
 #
 extra_pre_call = {
-   "xmlSAXUserParseFile":
-       "if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL;",
-   "xmlSAXUserParseMemory":
-       "if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL;",
-   "xmlParseBalancedChunkMemory":
-       "if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL;",
-   "xmlParseBalancedChunkMemoryRecover":
-       "if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL;",
+   "xmlSAXUserParseFile": """
+#ifdef LIBXML_SAX1_ENABLED
+        if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL;
+#endif
+""",
+   "xmlSAXUserParseMemory": """
+#ifdef LIBXML_SAX1_ENABLED
+        if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL;
+#endif
+""",
+   "xmlParseBalancedChunkMemory": """
+#ifdef LIBXML_SAX1_ENABLED
+        if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL;
+#endif
+""",
+   "xmlParseBalancedChunkMemoryRecover": """
+#ifdef LIBXML_SAX1_ENABLED
+        if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL;
+#endif
+""",
    "xmlParserInputBufferCreateFd":
        "if (fd >= 0) fd = -1;",
 }
@@ -151,8 +237,13 @@
    "xmlCopyNamespace": "if (ret_val != NULL) xmlFreeNs(ret_val);",
    "xmlCopyNamespaceList": "if (ret_val != NULL) xmlFreeNsList(ret_val);",
    "xmlNewTextWriter": "if (ret_val != NULL) out = NULL;",
-   "xmlNewTextWriterPushParser": "if (ret_val != NULL) ctxt = NULL;",
+   "xmlNewTextWriterPushParser": "if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;} if (ret_val != NULL) ctxt = NULL;",
    "xmlNewIOInputStream": "if (ret_val != NULL) input = NULL;",
+   "htmlParseChunk": "if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;}",
+   "htmlParseDocument": "if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;}",
+   "xmlParseDocument": "if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;}",
+   "xmlParseChunk": "if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;}",
+   "xmlParseExtParsedEnt": "if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;}",
 }
 
 modules = []
@@ -217,9 +308,6 @@
     res = string.replace(str, " *", "_ptr")
 #    res = string.replace(str, "*", "_ptr")
     res = string.replace(res, " ", "_")
-    res = string.replace(res, "htmlNode", "xmlNode")
-    res = string.replace(res, "htmlDoc", "xmlDoc")
-    res = string.replace(res, "htmlParser", "xmlParser")
     if res == 'const_char_ptr':
         if string.find(name, "file") != -1 or \
            string.find(name, "uri") != -1 or \
@@ -301,6 +389,10 @@
 	else:
 	    crtype = rtype
 
+        define = 0
+	if modules_defines.has_key(module):
+	    test.write("#ifdef %s\n" % (modules_defines[module]))
+	    define = 1
         test.write("""
 #define gen_nb_%s 1
 static %s gen_%s(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -309,6 +401,8 @@
 static void des_%s(int no ATTRIBUTE_UNUSED, %s val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
 """ % (name, crtype, name, name, rtype))
+        if define == 1:
+	    test.write("#endif\n\n")
         add_generated_param_type(name)
         return 1
 
@@ -386,6 +480,8 @@
     name = enum.xpathEval('string(@name)')
     if name == None:
         continue;
+    module = enum.xpathEval('string(@file)')
+    define = 0
 
     if is_known_param_type(name, name) == 0:
 	values = ctxt.xpathEval("/api/symbols/enum[@type='%s']" % name)
@@ -402,6 +498,9 @@
 	if vals == []:
 	    print "Didn't found any value for enum %s" % (name)
 	    continue
+	if modules_defines.has_key(module):
+	    test.write("#ifdef %s\n" % (modules_defines[module]))
+	    define = 1
 	test.write("#define gen_nb_%s %d\n" % (name, len(vals)))
 	test.write("""static %s gen_%s(int no, int nr ATTRIBUTE_UNUSED) {\n""" %
 	           (name, name))
@@ -415,6 +514,9 @@
 	known_param_types.append(name)
 
     if is_known_return_type(name) == 0:
+	if define == 0 and modules_defines.has_key(module):
+	    test.write("#ifdef %s\n" % (modules_defines[module]))
+	    define = 1
         test.write("""static void des_%s(int no ATTRIBUTE_UNUSED, %s val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
 static void desret_%s(%s val ATTRIBUTE_UNUSED) {
@@ -422,6 +524,8 @@
 
 """ % (name, name, name, name))
 	known_return_types.append(name)
+    if define == 1:
+        test.write("#endif\n\n")
 
 #
 # Load the interfaces
@@ -566,6 +670,11 @@
 	    nb_cond = nb_cond + 1
     except:
         pass
+
+    define = 0
+    if function_defines.has_key(name):
+        test.write("#ifdef %s\n" % (function_defines[name]))
+	define = 1
     
     # Declare the memory usage counter
     no_mem = is_skipped_memcheck(name)
@@ -672,6 +781,8 @@
     while nb_cond > 0:
         test.write("#endif\n")
 	nb_cond = nb_cond -1
+    if define == 1:
+        test.write("#endif\n")
 
     nb_tests = nb_tests + 1;
 
diff --git a/parserInternals.c b/parserInternals.c
index 3fffcd1..994aaa2 100644
--- a/parserInternals.c
+++ b/parserInternals.c
@@ -574,15 +574,20 @@
      * to ISO-Latin-1 (if you don't like this policy, just declare the
      * encoding !)
      */
-    __xmlErrEncoding(ctxt, XML_ERR_INVALID_CHAR,
-		   "Input is not proper UTF-8, indicate encoding !\n",
-		   NULL, NULL);
-    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL) &&
-        (ctxt->input != NULL)) {
-        ctxt->sax->error(ctxt->userData,
-                         "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
-                         ctxt->input->cur[0], ctxt->input->cur[1],
-                         ctxt->input->cur[2], ctxt->input->cur[3]);
+    if ((ctxt == NULL) || (ctxt->input == NULL) ||
+        (ctxt->input->end - ctxt->input->cur < 4)) {
+	__xmlErrEncoding(ctxt, XML_ERR_INVALID_CHAR,
+		     "Input is not proper UTF-8, indicate encoding !\n",
+		     NULL, NULL);
+    } else {
+        char buffer[150];
+
+	snprintf(buffer, 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
+			ctxt->input->cur[0], ctxt->input->cur[1],
+			ctxt->input->cur[2], ctxt->input->cur[3]);
+	__xmlErrEncoding(ctxt, XML_ERR_INVALID_CHAR,
+		     "Input is not proper UTF-8, indicate encoding !\n%s",
+		     BAD_CAST buffer, NULL);
     }
     ctxt->charset = XML_CHAR_ENCODING_8859_1;
     ctxt->input->cur++;
@@ -722,14 +727,15 @@
      * to ISO-Latin-1 (if you don't like this policy, just declare the
      * encoding !)
      */
-    __xmlErrEncoding(ctxt, XML_ERR_INVALID_CHAR,
-		   "Input is not proper UTF-8, indicate encoding !\n",
-		   NULL, NULL);
-    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL) &&
-        (ctxt->input != NULL)) {
-	ctxt->sax->error(ctxt->userData, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
+    {
+        char buffer[150];
+
+	snprintf(buffer, 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
 			ctxt->input->cur[0], ctxt->input->cur[1],
 			ctxt->input->cur[2], ctxt->input->cur[3]);
+	__xmlErrEncoding(ctxt, XML_ERR_INVALID_CHAR,
+		     "Input is not proper UTF-8, indicate encoding !\n%s",
+		     BAD_CAST buffer, NULL);
     }
     ctxt->charset = XML_CHAR_ENCODING_8859_1; 
     *len = 1;
@@ -818,21 +824,31 @@
 encoding_error:
 
     /*
+     * An encoding problem may arise from a truncated input buffer
+     * splitting a character in the middle. In that case do not raise
+     * an error but return 0 to endicate an end of stream problem
+     */
+    if ((ctxt == NULL) || (ctxt->input == NULL) ||
+        (ctxt->input->end - ctxt->input->cur < 4)) {
+	*len = 0;
+	return(0);
+    }
+    /*
      * If we detect an UTF8 error that probably mean that the
      * input encoding didn't get properly advertised in the
      * declaration header. Report the error and switch the encoding
      * to ISO-Latin-1 (if you don't like this policy, just declare the
      * encoding !)
      */
-    __xmlErrEncoding(ctxt, XML_ERR_INVALID_CHAR,
-		   "Input is not proper UTF-8, indicate encoding !\n",
-		   NULL, NULL);
-    if ((ctxt != NULL) && (ctxt->sax != NULL) && (ctxt->sax->error != NULL) &&
-        (ctxt->input != NULL)) {
-	ctxt->sax->error(ctxt->userData,
-			 "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
-			 ctxt->input->cur[0], ctxt->input->cur[1],
-			 ctxt->input->cur[2], ctxt->input->cur[3]);
+    {
+        char buffer[150];
+
+	snprintf(buffer, 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
+			ctxt->input->cur[0], ctxt->input->cur[1],
+			ctxt->input->cur[2], ctxt->input->cur[3]);
+	__xmlErrEncoding(ctxt, XML_ERR_INVALID_CHAR,
+		     "Input is not proper UTF-8, indicate encoding !\n%s",
+		     BAD_CAST buffer, NULL);
     }
     *len = 1;
     return ((int) *cur);
@@ -1526,6 +1542,8 @@
 int
 xmlInitParserCtxt(xmlParserCtxtPtr ctxt)
 {
+    xmlParserInputPtr input;
+
     if(ctxt==NULL) {
         xmlErrInternal(NULL, "Got NULL parser context\n", NULL);
         return(-1);
@@ -1563,6 +1581,9 @@
 	ctxt->input = NULL;
 	return(-1);
     }
+    while ((input = inputPop(ctxt)) != NULL) { /* Non consuming */
+        xmlFreeInputStream(input);
+    }
     ctxt->inputNr = 0;
     ctxt->input = NULL;
 
diff --git a/testapi.c b/testapi.c
index ea7b40c..610e8fc 100644
--- a/testapi.c
+++ b/testapi.c
@@ -175,6 +175,7 @@
 #include <libxml/xmlwriter.h>
 #include <libxml/xpath.h>
 #include <libxml/xpointer.h>
+#include <libxml/debugXML.h>
 
 #define gen_nb_void_ptr 2
 
@@ -404,9 +405,10 @@
 static void des_fileoutput(int no ATTRIBUTE_UNUSED, const char *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
 
-#define gen_nb_xmlParserCtxtPtr 2
+#define gen_nb_xmlParserCtxtPtr 3
 static xmlParserCtxtPtr gen_xmlParserCtxtPtr(int no, int nr ATTRIBUTE_UNUSED) {
     if (no == 0) return(xmlNewParserCtxt());
+    if (no == 1) return(xmlCreateMemoryParserCtxt("<doc/>", 6));
     return(NULL);
 }
 static void des_xmlParserCtxtPtr(int no ATTRIBUTE_UNUSED, xmlParserCtxtPtr val, int nr ATTRIBUTE_UNUSED) {
@@ -416,7 +418,9 @@
 
 #define gen_nb_xmlSAXHandlerPtr 2
 static xmlSAXHandlerPtr gen_xmlSAXHandlerPtr(int no, int nr ATTRIBUTE_UNUSED) {
+#ifdef LIBXML_SAX1_ENABLED
     if (no == 0) return((xmlSAXHandlerPtr) &xmlDefaultSAXHandler);
+#endif
     return(NULL);
 }
 static void des_xmlSAXHandlerPtr(int no ATTRIBUTE_UNUSED, xmlSAXHandlerPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -424,12 +428,16 @@
 
 #define gen_nb_xmlValidCtxtPtr 2
 static xmlValidCtxtPtr gen_xmlValidCtxtPtr(int no, int nr ATTRIBUTE_UNUSED) {
+#ifdef LIBXML_VALID_ENABLED
     if (no == 0) return(xmlNewValidCtxt());
+#endif
     return(NULL);
 }
 static void des_xmlValidCtxtPtr(int no ATTRIBUTE_UNUSED, xmlValidCtxtPtr val, int nr ATTRIBUTE_UNUSED) {
+#ifdef LIBXML_VALID_ENABLED
     if (val != NULL)
         xmlFreeValidCtxt(val);
+#endif
 }
 
 #define gen_nb_xmlParserInputBufferPtr 8
@@ -777,6 +785,95 @@
 }
 #endif
 
+/* cut and pasted from autogenerated to avoid troubles */
+#define gen_nb_const_xmlChar_ptr_ptr 1
+static xmlChar ** gen_const_xmlChar_ptr_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    return(NULL);
+}
+static void des_const_xmlChar_ptr_ptr(int no ATTRIBUTE_UNUSED, const xmlChar ** val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+}
+
+#define gen_nb_unsigned_char_ptr 1
+static unsigned char * gen_unsigned_char_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    return(NULL);
+}
+static void des_unsigned_char_ptr(int no ATTRIBUTE_UNUSED, unsigned char * val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+}
+
+#define gen_nb_const_unsigned_char_ptr 1
+static unsigned char * gen_const_unsigned_char_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    return(NULL);
+}
+static void des_const_unsigned_char_ptr(int no ATTRIBUTE_UNUSED, const unsigned char * val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+}
+
+#ifdef LIBXML_HTML_ENABLED
+#define gen_nb_const_htmlNodePtr 1
+static htmlNodePtr gen_const_htmlNodePtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    return(NULL);
+}
+static void des_const_htmlNodePtr(int no ATTRIBUTE_UNUSED, const htmlNodePtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+}
+#endif
+
+#ifdef LIBXML_HTML_ENABLED
+#define gen_nb_htmlDocPtr 3
+static htmlDocPtr gen_htmlDocPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    if (no == 0) return(htmlNewDoc(NULL, NULL));
+    if (no == 1) return(htmlReadMemory("<html/>", 7, "test", NULL, 0));
+    return(NULL);
+}
+static void des_htmlDocPtr(int no ATTRIBUTE_UNUSED, htmlDocPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    if ((val != NULL) && (val != api_doc) && (val->doc != api_doc))
+        xmlFreeDoc(val);
+}
+static void desret_htmlDocPtr(htmlDocPtr val) {
+    if ((val != NULL) && (val != api_doc) && (val->doc != api_doc))
+        xmlFreeDoc(val);
+}
+#define gen_nb_htmlParserCtxtPtr 3
+static htmlParserCtxtPtr gen_htmlParserCtxtPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    if (no == 0) return(xmlNewParserCtxt());
+    if (no == 1) return(htmlCreateMemoryParserCtxt("<html/>", 7));
+    return(NULL);
+}
+static void des_htmlParserCtxtPtr(int no ATTRIBUTE_UNUSED, htmlParserCtxtPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    if (val != NULL)
+        htmlFreeParserCtxt(val);
+}
+static void desret_htmlParserCtxtPtr(htmlParserCtxtPtr val) {
+    if (val != NULL)
+        htmlFreeParserCtxt(val);
+}
+#endif
+
+#ifdef LIBXML_XPATH_ENABLED
+#define gen_nb_xmlNodeSetPtr 1
+static xmlNodeSetPtr gen_xmlNodeSetPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    return(NULL);
+}
+static void des_xmlNodeSetPtr(int no ATTRIBUTE_UNUSED, xmlNodeSetPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+}
+#endif
+
+#ifdef LIBXML_DEBUG_ENABLED
+#define gen_nb_xmlShellCtxtPtr 1
+static xmlShellCtxtPtr gen_xmlShellCtxtPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    return(NULL);
+}
+static void des_xmlShellCtxtPtr(int no ATTRIBUTE_UNUSED, xmlShellCtxtPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+}
+#endif
+
+#ifdef LIBXML_PATTERN_ENABLED
+#define gen_nb_xmlPatternPtr 1
+static xmlPatternPtr gen_xmlPatternPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    return(NULL);
+}
+static void des_xmlPatternPtr(int no ATTRIBUTE_UNUSED, xmlPatternPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+}
+#endif
+
 /************************************************************************
  *									*
  *   WARNING: end of the manually maintained part of the test code	*
@@ -785,6 +882,7 @@
  ************************************************************************/
 
 /* CUT HERE: everything below that line is generated */
+#ifdef LIBXML_HTML_ENABLED
 #define gen_nb_htmlParserOption 4
 static htmlParserOption gen_htmlParserOption(int no, int nr ATTRIBUTE_UNUSED) {
     if (no == 1) return(HTML_PARSE_NOBLANKS);
@@ -798,6 +896,9 @@
 static void desret_htmlParserOption(htmlParserOption val ATTRIBUTE_UNUSED) {
 }
 
+#endif
+
+#ifdef LIBXML_HTML_ENABLED
 #define gen_nb_htmlStatus 4
 static htmlStatus gen_htmlStatus(int no, int nr ATTRIBUTE_UNUSED) {
     if (no == 1) return(HTML_DEPRECATED);
@@ -811,6 +912,8 @@
 static void desret_htmlStatus(htmlStatus val ATTRIBUTE_UNUSED) {
 }
 
+#endif
+
 #define gen_nb_xlinkActuate 3
 static xlinkActuate gen_xlinkActuate(int no, int nr ATTRIBUTE_UNUSED) {
     if (no == 1) return(XLINK_ACTUATE_AUTO);
@@ -887,6 +990,7 @@
 static void desret_xmlBufferAllocationScheme(xmlBufferAllocationScheme val ATTRIBUTE_UNUSED) {
 }
 
+#ifdef LIBXML_CATALOG_ENABLED
 #define gen_nb_xmlCatalogAllow 4
 static xmlCatalogAllow gen_xmlCatalogAllow(int no, int nr ATTRIBUTE_UNUSED) {
     if (no == 1) return(XML_CATA_ALLOW_ALL);
@@ -900,6 +1004,9 @@
 static void desret_xmlCatalogAllow(xmlCatalogAllow val ATTRIBUTE_UNUSED) {
 }
 
+#endif
+
+#ifdef LIBXML_CATALOG_ENABLED
 #define gen_nb_xmlCatalogPrefer 3
 static xmlCatalogPrefer gen_xmlCatalogPrefer(int no, int nr ATTRIBUTE_UNUSED) {
     if (no == 1) return(XML_CATA_PREFER_NONE);
@@ -912,6 +1019,8 @@
 static void desret_xmlCatalogPrefer(xmlCatalogPrefer val ATTRIBUTE_UNUSED) {
 }
 
+#endif
+
 #define gen_nb_xmlElementContentOccur 4
 static xmlElementContentOccur gen_xmlElementContentOccur(int no, int nr ATTRIBUTE_UNUSED) {
     if (no == 1) return(XML_ELEMENT_CONTENT_MULT);
@@ -1055,6 +1164,7 @@
 static void desret_xmlParserOption(xmlParserOption val ATTRIBUTE_UNUSED) {
 }
 
+#ifdef LIBXML_READER_ENABLED
 #define gen_nb_xmlParserProperties 4
 static xmlParserProperties gen_xmlParserProperties(int no, int nr ATTRIBUTE_UNUSED) {
     if (no == 1) return(XML_PARSER_DEFAULTATTRS);
@@ -1068,6 +1178,9 @@
 static void desret_xmlParserProperties(xmlParserProperties val ATTRIBUTE_UNUSED) {
 }
 
+#endif
+
+#ifdef LIBXML_READER_ENABLED
 #define gen_nb_xmlParserSeverities 4
 static xmlParserSeverities gen_xmlParserSeverities(int no, int nr ATTRIBUTE_UNUSED) {
     if (no == 1) return(XML_PARSER_SEVERITY_ERROR);
@@ -1081,6 +1194,9 @@
 static void desret_xmlParserSeverities(xmlParserSeverities val ATTRIBUTE_UNUSED) {
 }
 
+#endif
+
+#ifdef LIBXML_READER_ENABLED
 #define gen_nb_xmlReaderTypes 4
 static xmlReaderTypes gen_xmlReaderTypes(int no, int nr ATTRIBUTE_UNUSED) {
     if (no == 1) return(XML_READER_TYPE_ATTRIBUTE);
@@ -1094,6 +1210,9 @@
 static void desret_xmlReaderTypes(xmlReaderTypes val ATTRIBUTE_UNUSED) {
 }
 
+#endif
+
+#ifdef LIBXML_SCHEMAS_ENABLED
 #define gen_nb_xmlRelaxNGParserFlag 3
 static xmlRelaxNGParserFlag gen_xmlRelaxNGParserFlag(int no, int nr ATTRIBUTE_UNUSED) {
     if (no == 1) return(XML_RELAXNGP_CRNG);
@@ -1106,6 +1225,9 @@
 static void desret_xmlRelaxNGParserFlag(xmlRelaxNGParserFlag val ATTRIBUTE_UNUSED) {
 }
 
+#endif
+
+#ifdef LIBXML_SCHEMAS_ENABLED
 #define gen_nb_xmlRelaxNGValidErr 4
 static xmlRelaxNGValidErr gen_xmlRelaxNGValidErr(int no, int nr ATTRIBUTE_UNUSED) {
     if (no == 1) return(XML_RELAXNG_ERR_ATTREXTRANS);
@@ -1119,6 +1241,9 @@
 static void desret_xmlRelaxNGValidErr(xmlRelaxNGValidErr val ATTRIBUTE_UNUSED) {
 }
 
+#endif
+
+#ifdef LIBXML_SCHEMAS_ENABLED
 #define gen_nb_xmlSchemaContentType 4
 static xmlSchemaContentType gen_xmlSchemaContentType(int no, int nr ATTRIBUTE_UNUSED) {
     if (no == 1) return(XML_SCHEMA_CONTENT_ANY);
@@ -1132,6 +1257,9 @@
 static void desret_xmlSchemaContentType(xmlSchemaContentType val ATTRIBUTE_UNUSED) {
 }
 
+#endif
+
+#ifdef LIBXML_SCHEMAS_ENABLED
 #define gen_nb_xmlSchemaTypeType 4
 static xmlSchemaTypeType gen_xmlSchemaTypeType(int no, int nr ATTRIBUTE_UNUSED) {
     if (no == 1) return(XML_SCHEMA_FACET_ENUMERATION);
@@ -1145,6 +1273,9 @@
 static void desret_xmlSchemaTypeType(xmlSchemaTypeType val ATTRIBUTE_UNUSED) {
 }
 
+#endif
+
+#ifdef LIBXML_SCHEMAS_ENABLED
 #define gen_nb_xmlSchemaValType 4
 static xmlSchemaValType gen_xmlSchemaValType(int no, int nr ATTRIBUTE_UNUSED) {
     if (no == 1) return(XML_SCHEMAS_ANYSIMPLETYPE);
@@ -1158,6 +1289,9 @@
 static void desret_xmlSchemaValType(xmlSchemaValType val ATTRIBUTE_UNUSED) {
 }
 
+#endif
+
+#ifdef LIBXML_SCHEMAS_ENABLED
 #define gen_nb_xmlSchemaValidError 4
 static xmlSchemaValidError gen_xmlSchemaValidError(int no, int nr ATTRIBUTE_UNUSED) {
     if (no == 1) return(XML_SCHEMAS_ERR_);
@@ -1171,6 +1305,9 @@
 static void desret_xmlSchemaValidError(xmlSchemaValidError val ATTRIBUTE_UNUSED) {
 }
 
+#endif
+
+#ifdef LIBXML_SCHEMAS_ENABLED
 #define gen_nb_xmlSchemaValidOption 1
 static xmlSchemaValidOption gen_xmlSchemaValidOption(int no, int nr ATTRIBUTE_UNUSED) {
     if (no == 1) return(XML_SCHEMA_VAL_VC_I_CREATE);
@@ -1181,6 +1318,9 @@
 static void desret_xmlSchemaValidOption(xmlSchemaValidOption val ATTRIBUTE_UNUSED) {
 }
 
+#endif
+
+#ifdef LIBXML_READER_ENABLED
 #define gen_nb_xmlTextReaderMode 4
 static xmlTextReaderMode gen_xmlTextReaderMode(int no, int nr ATTRIBUTE_UNUSED) {
     if (no == 1) return(XML_TEXTREADER_MODE_CLOSED);
@@ -1194,6 +1334,9 @@
 static void desret_xmlTextReaderMode(xmlTextReaderMode val ATTRIBUTE_UNUSED) {
 }
 
+#endif
+
+#ifdef LIBXML_XPATH_ENABLED
 #define gen_nb_xmlXPathError 4
 static xmlXPathError gen_xmlXPathError(int no, int nr ATTRIBUTE_UNUSED) {
     if (no == 1) return(XPATH_ENCODING_ERROR);
@@ -1207,6 +1350,9 @@
 static void desret_xmlXPathError(xmlXPathError val ATTRIBUTE_UNUSED) {
 }
 
+#endif
+
+#ifdef LIBXML_XPATH_ENABLED
 #define gen_nb_xmlXPathObjectType 4
 static xmlXPathObjectType gen_xmlXPathObjectType(int no, int nr ATTRIBUTE_UNUSED) {
     if (no == 1) return(XPATH_BOOLEAN);
@@ -1220,6 +1366,8 @@
 static void desret_xmlXPathObjectType(xmlXPathObjectType val ATTRIBUTE_UNUSED) {
 }
 
+#endif
+
 #include <libxml/HTMLparser.h>
 #include <libxml/HTMLtree.h>
 #include <libxml/SAX2.h>
@@ -1352,20 +1500,6 @@
 }
 
 
-#define gen_nb_unsigned_char_ptr 1
-static unsigned char * gen_unsigned_char_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-    return(NULL);
-}
-static void des_unsigned_char_ptr(int no ATTRIBUTE_UNUSED, unsigned char * val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-}
-
-#define gen_nb_const_unsigned_char_ptr 1
-static unsigned char * gen_const_unsigned_char_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-    return(NULL);
-}
-static void des_const_unsigned_char_ptr(int no ATTRIBUTE_UNUSED, const unsigned char * val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-}
-
 static int
 test_UTF8ToHtml(void) {
     int test_ret = 0;
@@ -1420,6 +1554,7 @@
     return(test_ret);
 }
 
+#ifdef LIBXML_HTML_ENABLED
 
 #define gen_nb_const_htmlElemDesc_ptr 1
 static htmlElemDesc * gen_const_htmlElemDesc_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -1427,6 +1562,8 @@
 }
 static void des_const_htmlElemDesc_ptr(int no ATTRIBUTE_UNUSED, const htmlElemDesc * val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_htmlAttrAllowed(void) {
@@ -1475,6 +1612,16 @@
     return(test_ret);
 }
 
+#ifdef LIBXML_HTML_ENABLED
+
+#define gen_nb_htmlNodePtr 1
+static htmlNodePtr gen_htmlNodePtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    return(NULL);
+}
+static void des_htmlNodePtr(int no ATTRIBUTE_UNUSED, htmlNodePtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+}
+#endif
+
 
 static int
 test_htmlAutoCloseTag(void) {
@@ -1490,20 +1637,20 @@
     htmlNodePtr elem; /* the HTML element */
     int n_elem;
 
-    for (n_doc = 0;n_doc < gen_nb_xmlDocPtr;n_doc++) {
+    for (n_doc = 0;n_doc < gen_nb_htmlDocPtr;n_doc++) {
     for (n_name = 0;n_name < gen_nb_const_xmlChar_ptr;n_name++) {
-    for (n_elem = 0;n_elem < gen_nb_xmlNodePtr;n_elem++) {
+    for (n_elem = 0;n_elem < gen_nb_htmlNodePtr;n_elem++) {
         mem_base = xmlMemBlocks();
-        doc = gen_xmlDocPtr(n_doc, 0);
+        doc = gen_htmlDocPtr(n_doc, 0);
         name = gen_const_xmlChar_ptr(n_name, 1);
-        elem = gen_xmlNodePtr(n_elem, 2);
+        elem = gen_htmlNodePtr(n_elem, 2);
 
         ret_val = htmlAutoCloseTag(doc, name, elem);
         desret_int(ret_val);
         call_tests++;
-        des_xmlDocPtr(n_doc, doc, 0);
+        des_htmlDocPtr(n_doc, doc, 0);
         des_const_xmlChar_ptr(n_name, name, 1);
-        des_xmlNodePtr(n_elem, elem, 2);
+        des_htmlNodePtr(n_elem, elem, 2);
         xmlResetLastError();
         if (mem_base != xmlMemBlocks()) {
             printf("Leak of %d blocks found in htmlAutoCloseTag",
@@ -1543,7 +1690,7 @@
         size = gen_int(n_size, 1);
 
         ret_val = htmlCreateMemoryParserCtxt(buffer, size);
-        desret_xmlParserCtxtPtr(ret_val);
+        desret_htmlParserCtxtPtr(ret_val);
         call_tests++;
         des_const_char_ptr(n_buffer, buffer, 0);
         des_int(n_size, size, 1);
@@ -1564,6 +1711,7 @@
     return(test_ret);
 }
 
+#ifdef LIBXML_HTML_ENABLED
 
 #define gen_nb_htmlSAXHandlerPtr 1
 static htmlSAXHandlerPtr gen_htmlSAXHandlerPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -1571,6 +1719,8 @@
 }
 static void des_htmlSAXHandlerPtr(int no ATTRIBUTE_UNUSED, htmlSAXHandlerPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_htmlCreatePushParserCtxt(void) {
@@ -1608,7 +1758,7 @@
         enc = gen_xmlCharEncoding(n_enc, 5);
 
         ret_val = htmlCreatePushParserCtxt(sax, user_data, chunk, size, filename, enc);
-        desret_xmlParserCtxtPtr(ret_val);
+        desret_htmlParserCtxtPtr(ret_val);
         call_tests++;
         des_htmlSAXHandlerPtr(n_sax, sax, 0);
         des_userdata(n_user_data, user_data, 1);
@@ -1661,22 +1811,22 @@
     int options; /* a combination of htmlParserOption(s) */
     int n_options;
 
-    for (n_ctxt = 0;n_ctxt < gen_nb_xmlParserCtxtPtr;n_ctxt++) {
+    for (n_ctxt = 0;n_ctxt < gen_nb_htmlParserCtxtPtr;n_ctxt++) {
     for (n_cur = 0;n_cur < gen_nb_const_xmlChar_ptr;n_cur++) {
     for (n_URL = 0;n_URL < gen_nb_filepath;n_URL++) {
     for (n_encoding = 0;n_encoding < gen_nb_const_char_ptr;n_encoding++) {
     for (n_options = 0;n_options < gen_nb_int;n_options++) {
         mem_base = xmlMemBlocks();
-        ctxt = gen_xmlParserCtxtPtr(n_ctxt, 0);
+        ctxt = gen_htmlParserCtxtPtr(n_ctxt, 0);
         cur = gen_const_xmlChar_ptr(n_cur, 1);
         URL = gen_filepath(n_URL, 2);
         encoding = gen_const_char_ptr(n_encoding, 3);
         options = gen_int(n_options, 4);
 
         ret_val = htmlCtxtReadDoc(ctxt, cur, URL, encoding, options);
-        desret_xmlDocPtr(ret_val);
+        desret_htmlDocPtr(ret_val);
         call_tests++;
-        des_xmlParserCtxtPtr(n_ctxt, ctxt, 0);
+        des_htmlParserCtxtPtr(n_ctxt, ctxt, 0);
         des_const_xmlChar_ptr(n_cur, cur, 1);
         des_filepath(n_URL, URL, 2);
         des_const_char_ptr(n_encoding, encoding, 3);
@@ -1721,20 +1871,20 @@
     int options; /* a combination of htmlParserOption(s) */
     int n_options;
 
-    for (n_ctxt = 0;n_ctxt < gen_nb_xmlParserCtxtPtr;n_ctxt++) {
+    for (n_ctxt = 0;n_ctxt < gen_nb_htmlParserCtxtPtr;n_ctxt++) {
     for (n_filename = 0;n_filename < gen_nb_filepath;n_filename++) {
     for (n_encoding = 0;n_encoding < gen_nb_const_char_ptr;n_encoding++) {
     for (n_options = 0;n_options < gen_nb_int;n_options++) {
         mem_base = xmlMemBlocks();
-        ctxt = gen_xmlParserCtxtPtr(n_ctxt, 0);
+        ctxt = gen_htmlParserCtxtPtr(n_ctxt, 0);
         filename = gen_filepath(n_filename, 1);
         encoding = gen_const_char_ptr(n_encoding, 2);
         options = gen_int(n_options, 3);
 
         ret_val = htmlCtxtReadFile(ctxt, filename, encoding, options);
-        desret_xmlDocPtr(ret_val);
+        desret_htmlDocPtr(ret_val);
         call_tests++;
-        des_xmlParserCtxtPtr(n_ctxt, ctxt, 0);
+        des_htmlParserCtxtPtr(n_ctxt, ctxt, 0);
         des_filepath(n_filename, filename, 1);
         des_const_char_ptr(n_encoding, encoding, 2);
         des_int(n_options, options, 3);
@@ -1780,14 +1930,14 @@
     int options; /* a combination of htmlParserOption(s) */
     int n_options;
 
-    for (n_ctxt = 0;n_ctxt < gen_nb_xmlParserCtxtPtr;n_ctxt++) {
+    for (n_ctxt = 0;n_ctxt < gen_nb_htmlParserCtxtPtr;n_ctxt++) {
     for (n_buffer = 0;n_buffer < gen_nb_const_char_ptr;n_buffer++) {
     for (n_size = 0;n_size < gen_nb_int;n_size++) {
     for (n_URL = 0;n_URL < gen_nb_filepath;n_URL++) {
     for (n_encoding = 0;n_encoding < gen_nb_const_char_ptr;n_encoding++) {
     for (n_options = 0;n_options < gen_nb_int;n_options++) {
         mem_base = xmlMemBlocks();
-        ctxt = gen_xmlParserCtxtPtr(n_ctxt, 0);
+        ctxt = gen_htmlParserCtxtPtr(n_ctxt, 0);
         buffer = gen_const_char_ptr(n_buffer, 1);
         size = gen_int(n_size, 2);
         URL = gen_filepath(n_URL, 3);
@@ -1795,9 +1945,9 @@
         options = gen_int(n_options, 5);
 
         ret_val = htmlCtxtReadMemory(ctxt, buffer, size, URL, encoding, options);
-        desret_xmlDocPtr(ret_val);
+        desret_htmlDocPtr(ret_val);
         call_tests++;
-        des_xmlParserCtxtPtr(n_ctxt, ctxt, 0);
+        des_htmlParserCtxtPtr(n_ctxt, ctxt, 0);
         des_const_char_ptr(n_buffer, buffer, 1);
         des_int(n_size, size, 2);
         des_filepath(n_URL, URL, 3);
@@ -1838,13 +1988,13 @@
     htmlParserCtxtPtr ctxt; /* an HTML parser context */
     int n_ctxt;
 
-    for (n_ctxt = 0;n_ctxt < gen_nb_xmlParserCtxtPtr;n_ctxt++) {
+    for (n_ctxt = 0;n_ctxt < gen_nb_htmlParserCtxtPtr;n_ctxt++) {
         mem_base = xmlMemBlocks();
-        ctxt = gen_xmlParserCtxtPtr(n_ctxt, 0);
+        ctxt = gen_htmlParserCtxtPtr(n_ctxt, 0);
 
         htmlCtxtReset(ctxt);
         call_tests++;
-        des_xmlParserCtxtPtr(n_ctxt, ctxt, 0);
+        des_htmlParserCtxtPtr(n_ctxt, ctxt, 0);
         xmlResetLastError();
         if (mem_base != xmlMemBlocks()) {
             printf("Leak of %d blocks found in htmlCtxtReset",
@@ -1873,16 +2023,16 @@
     int options; /* a combination of htmlParserOption(s) */
     int n_options;
 
-    for (n_ctxt = 0;n_ctxt < gen_nb_xmlParserCtxtPtr;n_ctxt++) {
+    for (n_ctxt = 0;n_ctxt < gen_nb_htmlParserCtxtPtr;n_ctxt++) {
     for (n_options = 0;n_options < gen_nb_int;n_options++) {
         mem_base = xmlMemBlocks();
-        ctxt = gen_xmlParserCtxtPtr(n_ctxt, 0);
+        ctxt = gen_htmlParserCtxtPtr(n_ctxt, 0);
         options = gen_int(n_options, 1);
 
         ret_val = htmlCtxtUseOptions(ctxt, options);
         desret_int(ret_val);
         call_tests++;
-        des_xmlParserCtxtPtr(n_ctxt, ctxt, 0);
+        des_htmlParserCtxtPtr(n_ctxt, ctxt, 0);
         des_int(n_options, options, 1);
         xmlResetLastError();
         if (mem_base != xmlMemBlocks()) {
@@ -2160,17 +2310,17 @@
     htmlNodePtr elem; /* the HTML element */
     int n_elem;
 
-    for (n_doc = 0;n_doc < gen_nb_xmlDocPtr;n_doc++) {
-    for (n_elem = 0;n_elem < gen_nb_xmlNodePtr;n_elem++) {
+    for (n_doc = 0;n_doc < gen_nb_htmlDocPtr;n_doc++) {
+    for (n_elem = 0;n_elem < gen_nb_htmlNodePtr;n_elem++) {
         mem_base = xmlMemBlocks();
-        doc = gen_xmlDocPtr(n_doc, 0);
-        elem = gen_xmlNodePtr(n_elem, 1);
+        doc = gen_htmlDocPtr(n_doc, 0);
+        elem = gen_htmlNodePtr(n_elem, 1);
 
         ret_val = htmlIsAutoClosed(doc, elem);
         desret_int(ret_val);
         call_tests++;
-        des_xmlDocPtr(n_doc, doc, 0);
-        des_xmlNodePtr(n_elem, elem, 1);
+        des_htmlDocPtr(n_doc, doc, 0);
+        des_htmlNodePtr(n_elem, elem, 1);
         xmlResetLastError();
         if (mem_base != xmlMemBlocks()) {
             printf("Leak of %d blocks found in htmlIsAutoClosed",
@@ -2223,13 +2373,6 @@
 }
 
 
-#define gen_nb_const_xmlNodePtr 1
-static htmlNodePtr gen_const_xmlNodePtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-    return(NULL);
-}
-static void des_const_xmlNodePtr(int no ATTRIBUTE_UNUSED, const htmlNodePtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-}
-
 static int
 test_htmlNodeStatus(void) {
     int test_ret = 0;
@@ -2242,16 +2385,16 @@
     int legacy; /* whether to allow deprecated elements (YES is faster here for Element nodes) */
     int n_legacy;
 
-    for (n_node = 0;n_node < gen_nb_const_xmlNodePtr;n_node++) {
+    for (n_node = 0;n_node < gen_nb_const_htmlNodePtr;n_node++) {
     for (n_legacy = 0;n_legacy < gen_nb_int;n_legacy++) {
         mem_base = xmlMemBlocks();
-        node = gen_const_xmlNodePtr(n_node, 0);
+        node = gen_const_htmlNodePtr(n_node, 0);
         legacy = gen_int(n_legacy, 1);
 
         ret_val = htmlNodeStatus(node, legacy);
         desret_htmlStatus(ret_val);
         call_tests++;
-        des_const_xmlNodePtr(n_node, node, 0);
+        des_const_htmlNodePtr(n_node, node, 0);
         des_int(n_legacy, legacy, 1);
         xmlResetLastError();
         if (mem_base != xmlMemBlocks()) {
@@ -2281,14 +2424,14 @@
     htmlParserCtxtPtr ctxt; /* an HTML parser context */
     int n_ctxt;
 
-    for (n_ctxt = 0;n_ctxt < gen_nb_xmlParserCtxtPtr;n_ctxt++) {
+    for (n_ctxt = 0;n_ctxt < gen_nb_htmlParserCtxtPtr;n_ctxt++) {
         mem_base = xmlMemBlocks();
-        ctxt = gen_xmlParserCtxtPtr(n_ctxt, 0);
+        ctxt = gen_htmlParserCtxtPtr(n_ctxt, 0);
 
         ret_val = htmlParseCharRef(ctxt);
         desret_int(ret_val);
         call_tests++;
-        des_xmlParserCtxtPtr(n_ctxt, ctxt, 0);
+        des_htmlParserCtxtPtr(n_ctxt, ctxt, 0);
         xmlResetLastError();
         if (mem_base != xmlMemBlocks()) {
             printf("Leak of %d blocks found in htmlParseCharRef",
@@ -2322,20 +2465,21 @@
     int terminate; /* last chunk indicator */
     int n_terminate;
 
-    for (n_ctxt = 0;n_ctxt < gen_nb_xmlParserCtxtPtr;n_ctxt++) {
+    for (n_ctxt = 0;n_ctxt < gen_nb_htmlParserCtxtPtr;n_ctxt++) {
     for (n_chunk = 0;n_chunk < gen_nb_const_char_ptr;n_chunk++) {
     for (n_size = 0;n_size < gen_nb_int;n_size++) {
     for (n_terminate = 0;n_terminate < gen_nb_int;n_terminate++) {
         mem_base = xmlMemBlocks();
-        ctxt = gen_xmlParserCtxtPtr(n_ctxt, 0);
+        ctxt = gen_htmlParserCtxtPtr(n_ctxt, 0);
         chunk = gen_const_char_ptr(n_chunk, 1);
         size = gen_int(n_size, 2);
         terminate = gen_int(n_terminate, 3);
 
         ret_val = htmlParseChunk(ctxt, chunk, size, terminate);
+        if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;}
         desret_int(ret_val);
         call_tests++;
-        des_xmlParserCtxtPtr(n_ctxt, ctxt, 0);
+        des_htmlParserCtxtPtr(n_ctxt, ctxt, 0);
         des_const_char_ptr(n_chunk, chunk, 1);
         des_int(n_size, size, 2);
         des_int(n_terminate, terminate, 3);
@@ -2381,7 +2525,7 @@
         encoding = gen_const_char_ptr(n_encoding, 1);
 
         ret_val = htmlParseDoc(cur, encoding);
-        desret_xmlDocPtr(ret_val);
+        desret_htmlDocPtr(ret_val);
         call_tests++;
         des_xmlChar_ptr(n_cur, cur, 0);
         des_const_char_ptr(n_encoding, encoding, 1);
@@ -2413,14 +2557,15 @@
     htmlParserCtxtPtr ctxt; /* an HTML parser context */
     int n_ctxt;
 
-    for (n_ctxt = 0;n_ctxt < gen_nb_xmlParserCtxtPtr;n_ctxt++) {
+    for (n_ctxt = 0;n_ctxt < gen_nb_htmlParserCtxtPtr;n_ctxt++) {
         mem_base = xmlMemBlocks();
-        ctxt = gen_xmlParserCtxtPtr(n_ctxt, 0);
+        ctxt = gen_htmlParserCtxtPtr(n_ctxt, 0);
 
         ret_val = htmlParseDocument(ctxt);
+        if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;}
         desret_int(ret_val);
         call_tests++;
-        des_xmlParserCtxtPtr(n_ctxt, ctxt, 0);
+        des_htmlParserCtxtPtr(n_ctxt, ctxt, 0);
         xmlResetLastError();
         if (mem_base != xmlMemBlocks()) {
             printf("Leak of %d blocks found in htmlParseDocument",
@@ -2446,13 +2591,13 @@
     htmlParserCtxtPtr ctxt; /* an HTML parser context */
     int n_ctxt;
 
-    for (n_ctxt = 0;n_ctxt < gen_nb_xmlParserCtxtPtr;n_ctxt++) {
+    for (n_ctxt = 0;n_ctxt < gen_nb_htmlParserCtxtPtr;n_ctxt++) {
         mem_base = xmlMemBlocks();
-        ctxt = gen_xmlParserCtxtPtr(n_ctxt, 0);
+        ctxt = gen_htmlParserCtxtPtr(n_ctxt, 0);
 
         htmlParseElement(ctxt);
         call_tests++;
-        des_xmlParserCtxtPtr(n_ctxt, ctxt, 0);
+        des_htmlParserCtxtPtr(n_ctxt, ctxt, 0);
         xmlResetLastError();
         if (mem_base != xmlMemBlocks()) {
             printf("Leak of %d blocks found in htmlParseElement",
@@ -2469,13 +2614,6 @@
 }
 
 
-#define gen_nb_const_xmlChar_ptr_ptr 1
-static xmlChar ** gen_const_xmlChar_ptr_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-    return(NULL);
-}
-static void des_const_xmlChar_ptr_ptr(int no ATTRIBUTE_UNUSED, const xmlChar ** val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-}
-
 static int
 test_htmlParseEntityRef(void) {
     int test_ret = 0;
@@ -2488,16 +2626,16 @@
     xmlChar ** str; /* location to store the entity name */
     int n_str;
 
-    for (n_ctxt = 0;n_ctxt < gen_nb_xmlParserCtxtPtr;n_ctxt++) {
+    for (n_ctxt = 0;n_ctxt < gen_nb_htmlParserCtxtPtr;n_ctxt++) {
     for (n_str = 0;n_str < gen_nb_const_xmlChar_ptr_ptr;n_str++) {
         mem_base = xmlMemBlocks();
-        ctxt = gen_xmlParserCtxtPtr(n_ctxt, 0);
+        ctxt = gen_htmlParserCtxtPtr(n_ctxt, 0);
         str = gen_const_xmlChar_ptr_ptr(n_str, 1);
 
         ret_val = htmlParseEntityRef(ctxt, str);
         desret_const_htmlEntityDesc_ptr(ret_val);
         call_tests++;
-        des_xmlParserCtxtPtr(n_ctxt, ctxt, 0);
+        des_htmlParserCtxtPtr(n_ctxt, ctxt, 0);
         des_const_xmlChar_ptr_ptr(n_str, str, 1);
         xmlResetLastError();
         if (mem_base != xmlMemBlocks()) {
@@ -2534,7 +2672,7 @@
         encoding = gen_const_char_ptr(n_encoding, 1);
 
         ret_val = htmlParseFile(filename, encoding);
-        desret_xmlDocPtr(ret_val);
+        desret_htmlDocPtr(ret_val);
         call_tests++;
         des_filepath(n_filename, filename, 0);
         des_const_char_ptr(n_encoding, encoding, 1);
@@ -2575,7 +2713,7 @@
         options = gen_int(n_options, 3);
 
         ret_val = htmlReadDoc(cur, URL, encoding, options);
-        desret_xmlDocPtr(ret_val);
+        desret_htmlDocPtr(ret_val);
         call_tests++;
         des_const_xmlChar_ptr(n_cur, cur, 0);
         des_filepath(n_URL, URL, 1);
@@ -2626,7 +2764,7 @@
         options = gen_int(n_options, 2);
 
         ret_val = htmlReadFile(filename, encoding, options);
-        desret_xmlDocPtr(ret_val);
+        desret_htmlDocPtr(ret_val);
         call_tests++;
         des_filepath(n_filename, filename, 0);
         des_const_char_ptr(n_encoding, encoding, 1);
@@ -2682,7 +2820,7 @@
         options = gen_int(n_options, 4);
 
         ret_val = htmlReadMemory(buffer, size, URL, encoding, options);
-        desret_xmlDocPtr(ret_val);
+        desret_htmlDocPtr(ret_val);
         call_tests++;
         des_const_char_ptr(n_buffer, buffer, 0);
         des_int(n_size, size, 1);
@@ -2740,7 +2878,7 @@
         userData = gen_userdata(n_userData, 3);
 
         ret_val = htmlSAXParseDoc(cur, encoding, sax, userData);
-        desret_xmlDocPtr(ret_val);
+        desret_htmlDocPtr(ret_val);
         call_tests++;
         des_xmlChar_ptr(n_cur, cur, 0);
         des_const_char_ptr(n_encoding, encoding, 1);
@@ -2795,7 +2933,7 @@
         userData = gen_userdata(n_userData, 3);
 
         ret_val = htmlSAXParseFile(filename, encoding, sax, userData);
-        desret_xmlDocPtr(ret_val);
+        desret_htmlDocPtr(ret_val);
         call_tests++;
         des_filepath(n_filename, filename, 0);
         des_const_char_ptr(n_encoding, encoding, 1);
@@ -3086,14 +3224,14 @@
     htmlDocPtr doc; /* the document */
     int n_doc;
 
-    for (n_doc = 0;n_doc < gen_nb_xmlDocPtr;n_doc++) {
+    for (n_doc = 0;n_doc < gen_nb_htmlDocPtr;n_doc++) {
         mem_base = xmlMemBlocks();
-        doc = gen_xmlDocPtr(n_doc, 0);
+        doc = gen_htmlDocPtr(n_doc, 0);
 
         ret_val = htmlGetMetaEncoding(doc);
         desret_const_xmlChar_ptr(ret_val);
         call_tests++;
-        des_xmlDocPtr(n_doc, doc, 0);
+        des_htmlDocPtr(n_doc, doc, 0);
         xmlResetLastError();
         if (mem_base != xmlMemBlocks()) {
             printf("Leak of %d blocks found in htmlGetMetaEncoding",
@@ -3163,7 +3301,7 @@
         ExternalID = gen_const_xmlChar_ptr(n_ExternalID, 1);
 
         ret_val = htmlNewDoc(URI, ExternalID);
-        desret_xmlDocPtr(ret_val);
+        desret_htmlDocPtr(ret_val);
         call_tests++;
         des_const_xmlChar_ptr(n_URI, URI, 0);
         des_const_xmlChar_ptr(n_ExternalID, ExternalID, 1);
@@ -3204,7 +3342,7 @@
         ExternalID = gen_const_xmlChar_ptr(n_ExternalID, 1);
 
         ret_val = htmlNewDocNoDtD(URI, ExternalID);
-        desret_xmlDocPtr(ret_val);
+        desret_htmlDocPtr(ret_val);
         call_tests++;
         des_const_xmlChar_ptr(n_URI, URI, 0);
         des_const_xmlChar_ptr(n_ExternalID, ExternalID, 1);
@@ -3667,16 +3805,16 @@
     xmlChar * encoding; /* the encoding string */
     int n_encoding;
 
-    for (n_doc = 0;n_doc < gen_nb_xmlDocPtr;n_doc++) {
+    for (n_doc = 0;n_doc < gen_nb_htmlDocPtr;n_doc++) {
     for (n_encoding = 0;n_encoding < gen_nb_const_xmlChar_ptr;n_encoding++) {
         mem_base = xmlMemBlocks();
-        doc = gen_xmlDocPtr(n_doc, 0);
+        doc = gen_htmlDocPtr(n_doc, 0);
         encoding = gen_const_xmlChar_ptr(n_encoding, 1);
 
         ret_val = htmlSetMetaEncoding(doc, encoding);
         desret_int(ret_val);
         call_tests++;
-        des_xmlDocPtr(n_doc, doc, 0);
+        des_htmlDocPtr(n_doc, doc, 0);
         des_const_xmlChar_ptr(n_encoding, encoding, 1);
         xmlResetLastError();
         if (mem_base != xmlMemBlocks()) {
@@ -3727,6 +3865,7 @@
 test_docbDefaultSAXHandlerInit(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_DOCB_ENABLED
     int mem_base;
 
         mem_base = xmlMemBlocks();
@@ -3740,6 +3879,7 @@
 	    test_ret++;
             printf("\n");
         }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -3750,6 +3890,7 @@
 test_htmlDefaultSAXHandlerInit(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_HTML_ENABLED
     int mem_base;
 
         mem_base = xmlMemBlocks();
@@ -3763,6 +3904,7 @@
 	    test_ret++;
             printf("\n");
         }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -4088,6 +4230,7 @@
 test_xmlSAX2EndElement(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     void * ctx; /* the user data (XML parser context) */
     int n_ctx;
@@ -4115,6 +4258,7 @@
         }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -5049,6 +5193,7 @@
 test_xmlSAX2StartElement(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     void * ctx; /* the user data (XML parser context) */
     int n_ctx;
@@ -5083,6 +5228,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -5237,6 +5383,7 @@
 test_xmlSAXDefaultVersion(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     int ret_val;
     int version; /* the version, 1 or 2 */
@@ -5259,6 +5406,7 @@
             printf("\n");
         }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -5352,13 +5500,6 @@
     return(test_ret);
 }
 
-#define gen_nb_xmlNodeSetPtr 1
-static xmlNodeSetPtr gen_xmlNodeSetPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-    return(NULL);
-}
-static void des_xmlNodeSetPtr(int no ATTRIBUTE_UNUSED, xmlNodeSetPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-}
-
 static int
 test_xmlC14NDocDumpMemory(void) {
     int test_ret = 0;
@@ -5602,6 +5743,7 @@
 	printf("Module c14n: %d errors\n", test_ret);
     return(test_ret);
 }
+#ifdef LIBXML_CATALOG_ENABLED
 
 #define gen_nb_xmlCatalogPtr 1
 static xmlCatalogPtr gen_xmlCatalogPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -5609,6 +5751,8 @@
 }
 static void des_xmlCatalogPtr(int no ATTRIBUTE_UNUSED, xmlCatalogPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_xmlACatalogAdd(void) {
@@ -7542,13 +7686,6 @@
 }
 
 
-#define gen_nb_xmlShellCtxtPtr 1
-static xmlShellCtxtPtr gen_xmlShellCtxtPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-    return(NULL);
-}
-static void des_xmlShellCtxtPtr(int no ATTRIBUTE_UNUSED, xmlShellCtxtPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-}
-
 static int
 test_xmlShellBase(void) {
     int test_ret = 0;
@@ -8445,6 +8582,7 @@
 test_UTF8Toisolat1(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_OUTPUT_ENABLED
     int mem_base;
     int ret_val;
     unsigned char * out; /* a pointer to an array of bytes to store the result */
@@ -8488,6 +8626,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -9207,6 +9346,7 @@
 test_xmlCleanupPredefinedEntities(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_LEGACY_ENABLED
     int mem_base;
 
         mem_base = xmlMemBlocks();
@@ -9220,6 +9360,7 @@
 	    test_ret++;
             printf("\n");
         }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -9569,6 +9710,7 @@
 test_xmlInitializePredefinedEntities(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_LEGACY_ENABLED
     int mem_base;
 
         mem_base = xmlMemBlocks();
@@ -9582,6 +9724,7 @@
 	    test_ret++;
             printf("\n");
         }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -13136,6 +13279,7 @@
 test_xmlGetFeature(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_LEGACY_ENABLED
     int mem_base;
     int ret_val;
     xmlParserCtxtPtr ctxt; /* an XML/HTML parser context */
@@ -13172,6 +13316,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -13189,6 +13334,7 @@
 test_xmlGetFeaturesList(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_LEGACY_ENABLED
     int mem_base;
     int ret_val;
     int * len; /* the length of the features name array (input/output) */
@@ -13218,6 +13364,7 @@
         }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -13228,6 +13375,7 @@
 test_xmlIOParseDTD(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_VALID_ENABLED
     int mem_base;
     xmlDtdPtr ret_val;
     xmlSAXHandlerPtr sax; /* the SAX handler block or NULL */
@@ -13265,6 +13413,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -13549,6 +13698,7 @@
 test_xmlParseBalancedChunkMemory(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     int ret_val;
     xmlDocPtr doc; /* the document the chunk pertains to */
@@ -13577,7 +13727,11 @@
         depth = gen_int(n_depth, 3);
         string = gen_const_xmlChar_ptr(n_string, 4);
         lst = gen_xmlNodePtr_ptr(n_lst, 5);
+        
+#ifdef LIBXML_SAX1_ENABLED
         if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL;
+#endif
+
 
         ret_val = xmlParseBalancedChunkMemory(doc, sax, user_data, depth, string, lst);
         desret_int(ret_val);
@@ -13607,6 +13761,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -13617,6 +13772,7 @@
 test_xmlParseBalancedChunkMemoryRecover(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     int ret_val;
     xmlDocPtr doc; /* the document the chunk pertains to */
@@ -13649,7 +13805,11 @@
         string = gen_const_xmlChar_ptr(n_string, 4);
         lst = gen_xmlNodePtr_ptr(n_lst, 5);
         recover = gen_int(n_recover, 6);
+        
+#ifdef LIBXML_SAX1_ENABLED
         if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL;
+#endif
+
 
         ret_val = xmlParseBalancedChunkMemoryRecover(doc, sax, user_data, depth, string, lst, recover);
         desret_int(ret_val);
@@ -13682,6 +13842,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -13715,6 +13876,7 @@
         terminate = gen_int(n_terminate, 3);
 
         ret_val = xmlParseChunk(ctxt, chunk, size, terminate);
+        if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;}
         desret_int(ret_val);
         call_tests++;
         des_xmlParserCtxtPtr(n_ctxt, ctxt, 0);
@@ -13800,6 +13962,7 @@
 test_xmlParseDTD(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_VALID_ENABLED
     int mem_base;
     xmlDtdPtr ret_val;
     xmlChar * ExternalID; /* a NAME* containing the External ID of the DTD */
@@ -13829,6 +13992,7 @@
         }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -13839,6 +14003,7 @@
 test_xmlParseDoc(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     xmlDocPtr ret_val;
     xmlChar * cur; /* a pointer to an array of xmlChar */
@@ -13861,6 +14026,7 @@
             printf("\n");
         }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -13881,6 +14047,7 @@
         ctxt = gen_xmlParserCtxtPtr(n_ctxt, 0);
 
         ret_val = xmlParseDocument(ctxt);
+        if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;}
         desret_int(ret_val);
         call_tests++;
         des_xmlParserCtxtPtr(n_ctxt, ctxt, 0);
@@ -13903,6 +14070,7 @@
 test_xmlParseEntity(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     xmlDocPtr ret_val;
     const char * filename; /* the filename */
@@ -13925,6 +14093,7 @@
             printf("\n");
         }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -13945,6 +14114,7 @@
         ctxt = gen_xmlParserCtxtPtr(n_ctxt, 0);
 
         ret_val = xmlParseExtParsedEnt(ctxt);
+        if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;}
         desret_int(ret_val);
         call_tests++;
         des_xmlParserCtxtPtr(n_ctxt, ctxt, 0);
@@ -13967,6 +14137,7 @@
 test_xmlParseExternalEntity(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     int ret_val;
     xmlDocPtr doc; /* the document the chunk pertains to */
@@ -14031,6 +14202,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -14041,6 +14213,7 @@
 test_xmlParseFile(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     xmlDocPtr ret_val;
     const char * filename; /* the filename */
@@ -14063,6 +14236,7 @@
             printf("\n");
         }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -14133,6 +14307,7 @@
 test_xmlParseMemory(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     xmlDocPtr ret_val;
     char * buffer; /* an pointer to a char array */
@@ -14162,6 +14337,7 @@
         }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -14219,6 +14395,13 @@
 static void des_const_xmlParserCtxtPtr(int no ATTRIBUTE_UNUSED, const xmlParserCtxtPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
 
+#define gen_nb_const_xmlNodePtr 1
+static xmlNodePtr gen_const_xmlNodePtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    return(NULL);
+}
+static void des_const_xmlNodePtr(int no ATTRIBUTE_UNUSED, const xmlNodePtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+}
+
 static int
 test_xmlParserFindNodeInfo(void) {
     int test_ret = 0;
@@ -14526,6 +14709,7 @@
 test_xmlRecoverDoc(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     xmlDocPtr ret_val;
     xmlChar * cur; /* a pointer to an array of xmlChar */
@@ -14548,6 +14732,7 @@
             printf("\n");
         }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -14558,6 +14743,7 @@
 test_xmlRecoverFile(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     xmlDocPtr ret_val;
     const char * filename; /* the filename */
@@ -14580,6 +14766,7 @@
             printf("\n");
         }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -14590,6 +14777,7 @@
 test_xmlRecoverMemory(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     xmlDocPtr ret_val;
     char * buffer; /* an pointer to a char array */
@@ -14619,6 +14807,7 @@
         }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -14629,6 +14818,7 @@
 test_xmlSAXParseDTD(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     xmlDtdPtr ret_val;
     xmlSAXHandlerPtr sax; /* the SAX handler block */
@@ -14665,6 +14855,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -14675,6 +14866,7 @@
 test_xmlSAXParseDoc(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     xmlDocPtr ret_val;
     xmlSAXHandlerPtr sax; /* the SAX handler block */
@@ -14711,6 +14903,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -14721,6 +14914,7 @@
 test_xmlSAXParseEntity(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     xmlDocPtr ret_val;
     xmlSAXHandlerPtr sax; /* the SAX handler block */
@@ -14750,6 +14944,7 @@
         }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -14760,6 +14955,7 @@
 test_xmlSAXParseFile(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     xmlDocPtr ret_val;
     xmlSAXHandlerPtr sax; /* the SAX handler block */
@@ -14796,6 +14992,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -14806,6 +15003,7 @@
 test_xmlSAXParseFileWithData(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     xmlDocPtr ret_val;
     xmlSAXHandlerPtr sax; /* the SAX handler block */
@@ -14849,6 +15047,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -14859,6 +15058,7 @@
 test_xmlSAXParseMemory(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     xmlDocPtr ret_val;
     xmlSAXHandlerPtr sax; /* the SAX handler block */
@@ -14902,6 +15102,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -14912,6 +15113,7 @@
 test_xmlSAXParseMemoryWithData(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     xmlDocPtr ret_val;
     xmlSAXHandlerPtr sax; /* the SAX handler block */
@@ -14962,6 +15164,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -14972,6 +15175,7 @@
 test_xmlSAXUserParseFile(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     int ret_val;
     xmlSAXHandlerPtr sax; /* a SAX handler */
@@ -14988,7 +15192,11 @@
         sax = gen_xmlSAXHandlerPtr(n_sax, 0);
         user_data = gen_userdata(n_user_data, 1);
         filename = gen_filepath(n_filename, 2);
+        
+#ifdef LIBXML_SAX1_ENABLED
         if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL;
+#endif
+
 
         ret_val = xmlSAXUserParseFile(sax, user_data, filename);
         desret_int(ret_val);
@@ -15009,6 +15217,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -15019,6 +15228,7 @@
 test_xmlSAXUserParseMemory(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     int ret_val;
     xmlSAXHandlerPtr sax; /* a SAX handler */
@@ -15039,7 +15249,11 @@
         user_data = gen_userdata(n_user_data, 1);
         buffer = gen_const_char_ptr(n_buffer, 2);
         size = gen_int(n_size, 3);
+        
+#ifdef LIBXML_SAX1_ENABLED
         if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL;
+#endif
+
 
         ret_val = xmlSAXUserParseMemory(sax, user_data, buffer, size);
         desret_int(ret_val);
@@ -15063,6 +15277,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -15083,6 +15298,7 @@
 test_xmlSetFeature(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_LEGACY_ENABLED
     int mem_base;
     int ret_val;
     xmlParserCtxtPtr ctxt; /* an XML/HTML parser context */
@@ -15119,6 +15335,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -15129,6 +15346,7 @@
 test_xmlSetupParserForBuffer(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_SAX1_ENABLED
     int mem_base;
     xmlParserCtxtPtr ctxt; /* an XML parser context */
     int n_ctxt;
@@ -15163,6 +15381,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -15173,6 +15392,7 @@
 test_xmlStopParser(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_PUSH_ENABLED
     int mem_base;
     xmlParserCtxtPtr ctxt; /* an XML parser context */
     int n_ctxt;
@@ -15193,6 +15413,7 @@
             printf("\n");
         }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -15322,7 +15543,7 @@
         encoding = gen_const_char_ptr(n_encoding, 1);
 
         ret_val = htmlCreateFileParserCtxt(filename, encoding);
-        desret_xmlParserCtxtPtr(ret_val);
+        desret_htmlParserCtxtPtr(ret_val);
         call_tests++;
         des_fileoutput(n_filename, filename, 0);
         des_const_char_ptr(n_encoding, encoding, 1);
@@ -16652,13 +16873,6 @@
     return(test_ret);
 }
 
-#define gen_nb_xmlPatternPtr 1
-static xmlPatternPtr gen_xmlPatternPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-    return(NULL);
-}
-static void des_xmlPatternPtr(int no ATTRIBUTE_UNUSED, xmlPatternPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-}
-
 static int
 test_xmlPatternMatch(void) {
     int test_ret = 0;
@@ -16721,6 +16935,7 @@
 	printf("Module pattern: %d errors\n", test_ret);
     return(test_ret);
 }
+#ifdef LIBXML_SCHEMAS_ENABLED
 
 #define gen_nb_xmlRelaxNGPtr 1
 static xmlRelaxNGPtr gen_xmlRelaxNGPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -16728,6 +16943,8 @@
 }
 static void des_xmlRelaxNGPtr(int no ATTRIBUTE_UNUSED, xmlRelaxNGPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_xmlRelaxNGDump(void) {
@@ -16810,6 +17027,7 @@
     return(test_ret);
 }
 
+#ifdef LIBXML_SCHEMAS_ENABLED
 
 #define gen_nb_xmlRelaxNGParserCtxtPtr 1
 static xmlRelaxNGParserCtxtPtr gen_xmlRelaxNGParserCtxtPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -16817,6 +17035,9 @@
 }
 static void des_xmlRelaxNGParserCtxtPtr(int no ATTRIBUTE_UNUSED, xmlRelaxNGParserCtxtPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
+#ifdef LIBXML_SCHEMAS_ENABLED
 
 #define gen_nb_xmlRelaxNGValidityErrorFunc_ptr 1
 static xmlRelaxNGValidityErrorFunc * gen_xmlRelaxNGValidityErrorFunc_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -16824,6 +17045,9 @@
 }
 static void des_xmlRelaxNGValidityErrorFunc_ptr(int no ATTRIBUTE_UNUSED, xmlRelaxNGValidityErrorFunc * val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
+#ifdef LIBXML_SCHEMAS_ENABLED
 
 #define gen_nb_xmlRelaxNGValidityWarningFunc_ptr 1
 static xmlRelaxNGValidityWarningFunc * gen_xmlRelaxNGValidityWarningFunc_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -16831,6 +17055,9 @@
 }
 static void des_xmlRelaxNGValidityWarningFunc_ptr(int no ATTRIBUTE_UNUSED, xmlRelaxNGValidityWarningFunc * val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
+#ifdef LIBXML_SCHEMAS_ENABLED
 
 #define gen_nb_void_ptr_ptr 1
 static void ** gen_void_ptr_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -16838,6 +17065,8 @@
 }
 static void des_void_ptr_ptr(int no ATTRIBUTE_UNUSED, void ** val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_xmlRelaxNGGetParserErrors(void) {
@@ -16893,6 +17122,7 @@
     return(test_ret);
 }
 
+#ifdef LIBXML_SCHEMAS_ENABLED
 
 #define gen_nb_xmlRelaxNGValidCtxtPtr 1
 static xmlRelaxNGValidCtxtPtr gen_xmlRelaxNGValidCtxtPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -16900,6 +17130,8 @@
 }
 static void des_xmlRelaxNGValidCtxtPtr(int no ATTRIBUTE_UNUSED, xmlRelaxNGValidCtxtPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_xmlRelaxNGGetValidErrors(void) {
@@ -17650,6 +17882,7 @@
 test_xmlAttrSerializeTxtContent(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_OUTPUT_ENABLED
     int mem_base;
     xmlBufferPtr buf; /* the XML buffer output */
     int n_buf;
@@ -17691,6 +17924,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -19775,6 +20009,7 @@
 test_xmlNewChild(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_TREE_ENABLED
     int mem_base;
     xmlNodePtr ret_val;
     xmlNodePtr parent; /* the parent node */
@@ -19818,6 +20053,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -20163,6 +20399,7 @@
 test_xmlNewDocRawNode(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_TREE_ENABLED
     int mem_base;
     xmlNodePtr ret_val;
     xmlDocPtr doc; /* the document */
@@ -20206,6 +20443,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -20624,6 +20862,7 @@
 test_xmlNewProp(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_TREE_ENABLED
     int mem_base;
     xmlAttrPtr ret_val;
     xmlNodePtr node; /* the holding node */
@@ -20660,6 +20899,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -20741,6 +20981,7 @@
 test_xmlNewTextChild(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_TREE_ENABLED
     int mem_base;
     xmlNodePtr ret_val;
     xmlNodePtr parent; /* the parent node */
@@ -20784,6 +21025,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -21582,6 +21824,7 @@
 test_xmlReconciliateNs(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_TREE_ENABLED
     int mem_base;
     int ret_val;
     xmlDocPtr doc; /* the document */
@@ -21611,6 +21854,7 @@
         }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -22670,6 +22914,7 @@
 test_xmlValidateNCName(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_TREE_ENABLED
     int mem_base;
     int ret_val;
     xmlChar * value; /* the value to check */
@@ -22699,6 +22944,7 @@
         }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -22709,6 +22955,7 @@
 test_xmlValidateNMToken(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_TREE_ENABLED
     int mem_base;
     int ret_val;
     xmlChar * value; /* the value to check */
@@ -22738,6 +22985,7 @@
         }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -22748,6 +22996,7 @@
 test_xmlValidateName(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_TREE_ENABLED
     int mem_base;
     int ret_val;
     xmlChar * value; /* the value to check */
@@ -22777,6 +23026,7 @@
         }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -22787,6 +23037,7 @@
 test_xmlValidateQName(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_TREE_ENABLED
     int mem_base;
     int ret_val;
     xmlChar * value; /* the value to check */
@@ -22816,6 +23067,7 @@
         }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -24385,6 +24637,7 @@
 test_xmlSprintfElementContent(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_OUTPUT_ENABLED
     int mem_base;
     char * buf; /* an output buffer */
     int n_buf;
@@ -24419,6 +24672,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -24539,6 +24793,7 @@
 test_xmlValidGetPotentialChildren(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_VALID_ENABLED
     int mem_base;
     int ret_val;
     xmlElementContent * ctree; /* an element content tree */
@@ -24582,6 +24837,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -24592,6 +24848,7 @@
 test_xmlValidGetValidElements(void) {
     int test_ret = 0;
 
+#ifdef LIBXML_VALID_ENABLED
     int mem_base;
     int ret_val;
     xmlNode * prev; /* an element to insert after */
@@ -24635,6 +24892,7 @@
     }
     }
     }
+#endif
 
     function_tests++;
     return(test_ret);
@@ -25815,6 +26073,7 @@
     return(test_ret);
 }
 
+#ifdef LIBXML_XINCLUDE_ENABLED
 
 #define gen_nb_xmlXIncludeCtxtPtr 1
 static xmlXIncludeCtxtPtr gen_xmlXIncludeCtxtPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -25822,6 +26081,8 @@
 }
 static void des_xmlXIncludeCtxtPtr(int no ATTRIBUTE_UNUSED, xmlXIncludeCtxtPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_xmlXIncludeProcessNode(void) {
@@ -27467,6 +27728,7 @@
 	printf("Module xmlIO: %d errors\n", test_ret);
     return(test_ret);
 }
+#ifdef LIBXML_AUTOMATA_ENABLED
 
 #define gen_nb_xmlAutomataPtr 1
 static xmlAutomataPtr gen_xmlAutomataPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -27474,6 +27736,8 @@
 }
 static void des_xmlAutomataPtr(int no ATTRIBUTE_UNUSED, xmlAutomataPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_xmlAutomataCompile(void) {
@@ -27528,6 +27792,7 @@
     return(test_ret);
 }
 
+#ifdef LIBXML_AUTOMATA_ENABLED
 
 #define gen_nb_xmlAutomataStatePtr 1
 static xmlAutomataStatePtr gen_xmlAutomataStatePtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -27535,6 +27800,8 @@
 }
 static void des_xmlAutomataStatePtr(int no ATTRIBUTE_UNUSED, xmlAutomataStatePtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_xmlAutomataNewAllTrans(void) {
@@ -29310,6 +29577,7 @@
     return(test_ret);
 }
 
+#ifdef LIBXML_READER_ENABLED
 
 #define gen_nb_xmlTextReaderErrorFunc_ptr 1
 static xmlTextReaderErrorFunc * gen_xmlTextReaderErrorFunc_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -29317,6 +29585,8 @@
 }
 static void des_xmlTextReaderErrorFunc_ptr(int no ATTRIBUTE_UNUSED, xmlTextReaderErrorFunc * val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_xmlTextReaderGetErrorHandler(void) {
@@ -29676,6 +29946,7 @@
     return(test_ret);
 }
 
+#ifdef LIBXML_READER_ENABLED
 
 #define gen_nb_xmlTextReaderLocatorPtr 1
 static xmlTextReaderLocatorPtr gen_xmlTextReaderLocatorPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -29683,6 +29954,8 @@
 }
 static void des_xmlTextReaderLocatorPtr(int no ATTRIBUTE_UNUSED, xmlTextReaderLocatorPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_xmlTextReaderLocatorBaseURI(void) {
@@ -30816,6 +31089,7 @@
 	printf("Module xmlreader: %d errors\n", test_ret);
     return(test_ret);
 }
+#ifdef LIBXML_REGEXP_ENABLED
 
 #define gen_nb_xmlRegExecCtxtPtr 1
 static xmlRegExecCtxtPtr gen_xmlRegExecCtxtPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -30823,6 +31097,8 @@
 }
 static void des_xmlRegExecCtxtPtr(int no ATTRIBUTE_UNUSED, xmlRegExecCtxtPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_xmlRegExecPushString(void) {
@@ -30926,6 +31202,7 @@
     return(test_ret);
 }
 
+#ifdef LIBXML_REGEXP_ENABLED
 
 #define gen_nb_xmlRegexpPtr 1
 static xmlRegexpPtr gen_xmlRegexpPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -30933,6 +31210,8 @@
 }
 static void des_xmlRegexpPtr(int no ATTRIBUTE_UNUSED, xmlRegexpPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_xmlRegNewExecCtxt(void) {
@@ -31084,6 +31363,7 @@
 	printf("Module xmlregexp: %d errors\n", test_ret);
     return(test_ret);
 }
+#ifdef LIBXML_OUTPUT_ENABLED
 
 #define gen_nb_xmlSaveCtxtPtr 1
 static xmlSaveCtxtPtr gen_xmlSaveCtxtPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -31091,6 +31371,8 @@
 }
 static void des_xmlSaveCtxtPtr(int no ATTRIBUTE_UNUSED, xmlSaveCtxtPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_xmlSaveClose(void) {
@@ -31299,6 +31581,7 @@
 	printf("Module xmlsave: %d errors\n", test_ret);
     return(test_ret);
 }
+#ifdef LIBXML_SCHEMAS_ENABLED
 
 #define gen_nb_xmlSchemaPtr 1
 static xmlSchemaPtr gen_xmlSchemaPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -31306,6 +31589,8 @@
 }
 static void des_xmlSchemaPtr(int no ATTRIBUTE_UNUSED, xmlSchemaPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_xmlSchemaDump(void) {
@@ -31347,6 +31632,7 @@
     return(test_ret);
 }
 
+#ifdef LIBXML_SCHEMAS_ENABLED
 
 #define gen_nb_xmlSchemaParserCtxtPtr 1
 static xmlSchemaParserCtxtPtr gen_xmlSchemaParserCtxtPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -31354,6 +31640,9 @@
 }
 static void des_xmlSchemaParserCtxtPtr(int no ATTRIBUTE_UNUSED, xmlSchemaParserCtxtPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
+#ifdef LIBXML_SCHEMAS_ENABLED
 
 #define gen_nb_xmlSchemaValidityErrorFunc_ptr 1
 static xmlSchemaValidityErrorFunc * gen_xmlSchemaValidityErrorFunc_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -31361,6 +31650,9 @@
 }
 static void des_xmlSchemaValidityErrorFunc_ptr(int no ATTRIBUTE_UNUSED, xmlSchemaValidityErrorFunc * val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
+#ifdef LIBXML_SCHEMAS_ENABLED
 
 #define gen_nb_xmlSchemaValidityWarningFunc_ptr 1
 static xmlSchemaValidityWarningFunc * gen_xmlSchemaValidityWarningFunc_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -31368,6 +31660,8 @@
 }
 static void des_xmlSchemaValidityWarningFunc_ptr(int no ATTRIBUTE_UNUSED, xmlSchemaValidityWarningFunc * val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_xmlSchemaGetParserErrors(void) {
@@ -31423,6 +31717,7 @@
     return(test_ret);
 }
 
+#ifdef LIBXML_SCHEMAS_ENABLED
 
 #define gen_nb_xmlSchemaValidCtxtPtr 1
 static xmlSchemaValidCtxtPtr gen_xmlSchemaValidCtxtPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -31430,6 +31725,8 @@
 }
 static void des_xmlSchemaValidCtxtPtr(int no ATTRIBUTE_UNUSED, xmlSchemaValidCtxtPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_xmlSchemaGetValidErrors(void) {
@@ -31878,6 +32175,7 @@
 	printf("Module xmlschemas: %d errors\n", test_ret);
     return(test_ret);
 }
+#ifdef LIBXML_SCHEMAS_ENABLED
 
 #define gen_nb_xmlSchemaFacetPtr 1
 static xmlSchemaFacetPtr gen_xmlSchemaFacetPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -31885,6 +32183,9 @@
 }
 static void des_xmlSchemaFacetPtr(int no ATTRIBUTE_UNUSED, xmlSchemaFacetPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
+#ifdef LIBXML_SCHEMAS_ENABLED
 
 #define gen_nb_xmlSchemaTypePtr 1
 static xmlSchemaTypePtr gen_xmlSchemaTypePtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -31892,6 +32193,8 @@
 }
 static void des_xmlSchemaTypePtr(int no ATTRIBUTE_UNUSED, xmlSchemaTypePtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_xmlSchemaCheckFacet(void) {
@@ -32006,6 +32309,7 @@
     return(test_ret);
 }
 
+#ifdef LIBXML_SCHEMAS_ENABLED
 
 #define gen_nb_xmlSchemaValPtr 1
 static xmlSchemaValPtr gen_xmlSchemaValPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -32013,6 +32317,8 @@
 }
 static void des_xmlSchemaValPtr(int no ATTRIBUTE_UNUSED, xmlSchemaValPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_xmlSchemaCompareValues(void) {
@@ -32232,6 +32538,7 @@
     return(test_ret);
 }
 
+#ifdef LIBXML_SCHEMAS_ENABLED
 
 #define gen_nb_xmlSchemaValPtr_ptr 1
 static xmlSchemaValPtr * gen_xmlSchemaValPtr_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -32239,6 +32546,8 @@
 }
 static void des_xmlSchemaValPtr_ptr(int no ATTRIBUTE_UNUSED, xmlSchemaValPtr * val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_xmlSchemaValPredefTypeNode(void) {
@@ -39639,7 +39948,7 @@
         compression = gen_int(n_compression, 1);
 
         ret_val = xmlNewTextWriterPushParser(ctxt, compression);
-        if (ret_val != NULL) ctxt = NULL;
+        if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;} if (ret_val != NULL) ctxt = NULL;
         desret_xmlTextWriterPtr(ret_val);
         call_tests++;
         des_xmlParserCtxtPtr(n_ctxt, ctxt, 0);
@@ -42672,6 +42981,7 @@
     return(test_ret);
 }
 
+#ifdef LIBXML_XPATH_ENABLED
 
 #define gen_nb_xmlXPathCompExprPtr 1
 static xmlXPathCompExprPtr gen_xmlXPathCompExprPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -42679,6 +42989,9 @@
 }
 static void des_xmlXPathCompExprPtr(int no ATTRIBUTE_UNUSED, xmlXPathCompExprPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
+#ifdef LIBXML_XPATH_ENABLED
 
 #define gen_nb_xmlXPathContextPtr 1
 static xmlXPathContextPtr gen_xmlXPathContextPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -42686,6 +42999,8 @@
 }
 static void des_xmlXPathContextPtr(int no ATTRIBUTE_UNUSED, xmlXPathContextPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_xmlXPathCompiledEval(void) {
@@ -43211,6 +43526,7 @@
 	printf("Module xpath: %d errors\n", test_ret);
     return(test_ret);
 }
+#ifdef LIBXML_XPATH_ENABLED
 
 #define gen_nb_xmlXPathParserContextPtr 1
 static xmlXPathParserContextPtr gen_xmlXPathParserContextPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -43218,6 +43534,8 @@
 }
 static void des_xmlXPathParserContextPtr(int no ATTRIBUTE_UNUSED, xmlXPathParserContextPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_valuePop(void) {
@@ -47597,6 +47915,7 @@
     return(test_ret);
 }
 
+#ifdef LIBXML_XPTR_ENABLED
 
 #define gen_nb_xmlLocationSetPtr 1
 static xmlLocationSetPtr gen_xmlLocationSetPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -47604,6 +47923,8 @@
 }
 static void des_xmlLocationSetPtr(int no ATTRIBUTE_UNUSED, xmlLocationSetPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
+
 
 static int
 test_xmlXPtrLocationSetAdd(void) {
diff --git a/xmlwriter.c b/xmlwriter.c
index 4b2c3e1..3255c67 100644
--- a/xmlwriter.c
+++ b/xmlwriter.c
@@ -71,6 +71,7 @@
     xmlChar *ichar;             /* indent character */
     char qchar;                 /* character used for quoting attribute values */
     xmlParserCtxtPtr ctxt;
+    int no_doc_free;
 };
 
 static void xmlFreeTextWriterStackEntry(xmlLinkPtr lk);
@@ -198,6 +199,7 @@
                         "xmlNewTextWriter : out of memory!\n");
         return NULL;
     }
+    ret->no_doc_free = 0;
 
     return ret;
 }
@@ -376,8 +378,10 @@
 
     xmlSetDocCompressMode(ctxt->myDoc, compression);
 
-    if (doc != NULL)
+    if (doc != NULL) {
         *doc = ctxt->myDoc;
+	ret->no_doc_free = 1;
+    }
 
     return ret;
 }
@@ -434,6 +438,7 @@
 
     ctxt->myDoc = doc;
     ctxt->node = node;
+    ret->no_doc_free = 1;
 
     xmlSetDocCompressMode(doc, compression);
 
@@ -461,8 +466,13 @@
     if (writer->nsstack != NULL)
         xmlListDelete(writer->nsstack);
 
-    if (writer->ctxt != NULL)
+    if (writer->ctxt != NULL) {
+        if ((writer->ctxt->myDoc != NULL) && (writer->no_doc_free == 0)) {
+	    xmlFreeDoc(writer->ctxt->myDoc);
+	    writer->ctxt->myDoc = NULL;
+	}
         xmlFreeParserCtxt(writer->ctxt);
+    }
 
     if (writer->ichar != NULL)
         xmlFree(writer->ichar);