more fixes and extending the tests coverage adding a type init interface
* gentest.py testapi.c: more fixes and extending the tests coverage
* relaxng.c include/libxml/relaxng.h: adding a type init interface
* include/libxml/xmlerror.h parser.c xmlreader.c xmlwriter.c: more
cleanups and bug fixes raised by the regression tests
Daniel
diff --git a/xmlwriter.c b/xmlwriter.c
index d4c7176..a11ef25 100644
--- a/xmlwriter.c
+++ b/xmlwriter.c
@@ -96,6 +96,51 @@
xmlTextWriterStackEntry * p);
/**
+ * xmlWriterErrMsg:
+ * @ctxt: a writer context
+ * @error: the error number
+ * @msg: the error message
+ *
+ * Handle a writer error
+ */
+static void
+xmlWriterErrMsg(xmlTextWriterPtr ctxt, xmlParserErrors error,
+ const char *msg)
+{
+ if (ctxt != NULL) {
+ __xmlRaiseError(NULL, NULL, NULL, ctxt->ctxt,
+ NULL, XML_FROM_WRITER, error, XML_ERR_FATAL,
+ NULL, 0, NULL, NULL, NULL, 0, 0, msg);
+ } else {
+ __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_WRITER, error,
+ XML_ERR_FATAL, NULL, 0, NULL, NULL, NULL, 0, 0, msg);
+ }
+}
+
+/**
+ * xmlWriterErrMsgInt:
+ * @ctxt: a writer context
+ * @error: the error number
+ * @msg: the error message
+ * @val: an int
+ *
+ * Handle a writer error
+ */
+static void
+xmlWriterErrMsgInt(xmlTextWriterPtr ctxt, xmlParserErrors error,
+ const char *msg, int val)
+{
+ if (ctxt != NULL) {
+ __xmlRaiseError(NULL, NULL, NULL, ctxt->ctxt,
+ NULL, XML_FROM_WRITER, error, XML_ERR_FATAL,
+ NULL, 0, NULL, NULL, NULL, val, 0, msg, val);
+ } else {
+ __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_WRITER, error,
+ XML_ERR_FATAL, NULL, 0, NULL, NULL, NULL, val, 0, msg, val);
+ }
+}
+
+/**
* xmlNewTextWriter:
* @out: an xmlOutputBufferPtr
*
@@ -110,7 +155,7 @@
ret = (xmlTextWriterPtr) xmlMalloc(sizeof(xmlTextWriter));
if (ret == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
"xmlNewTextWriter : out of memory!\n");
return NULL;
}
@@ -121,7 +166,7 @@
(xmlListDataCompare)
xmlCmpTextWriterStackEntry);
if (ret->nodes == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
"xmlNewTextWriter : out of memory!\n");
xmlFree(ret);
return NULL;
@@ -132,7 +177,7 @@
(xmlListDataCompare)
xmlCmpTextWriterNsStackEntry);
if (ret->nsstack == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
"xmlNewTextWriter : out of memory!\n");
xmlListDelete(ret->nodes);
xmlFree(ret);
@@ -147,7 +192,7 @@
xmlListDelete(ret->nodes);
xmlListDelete(ret->nsstack);
xmlFree(ret);
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
"xmlNewTextWriter : out of memory!\n");
return NULL;
}
@@ -172,14 +217,14 @@
out = xmlOutputBufferCreateFilename(uri, NULL, compression);
if (out == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
"xmlNewTextWriterFilename : out of memory!\n");
return NULL;
}
ret = xmlNewTextWriter(out);
if (ret == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
"xmlNewTextWriterFilename : out of memory!\n");
xmlOutputBufferClose(out);
return NULL;
@@ -213,14 +258,14 @@
xmlTextWriterCloseMemCallback,
(void *) buf, NULL);
if (out == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
"xmlNewTextWriterMemory : out of memory!\n");
return NULL;
}
ret = xmlNewTextWriter(out);
if (ret == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
"xmlNewTextWriterMemory : out of memory!\n");
xmlOutputBufferClose(out);
return NULL;
@@ -247,7 +292,7 @@
xmlOutputBufferPtr out;
if (ctxt == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
"xmlNewTextWriterPushParser : invalid context!\n");
return NULL;
}
@@ -258,14 +303,14 @@
xmlTextWriterCloseDocCallback,
(void *) ctxt, NULL);
if (out == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
"xmlNewTextWriterPushParser : error at xmlOutputBufferCreateIO!\n");
return NULL;
}
ret = xmlNewTextWriter(out);
if (ret == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
"xmlNewTextWriterPushParser : error at xmlNewTextWriter!\n");
xmlOutputBufferClose(out);
return NULL;
@@ -300,7 +345,7 @@
ctxt = xmlCreatePushParserCtxt(&saxHandler, NULL, NULL, 0, NULL);
if (ctxt == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
"xmlNewTextWriterDoc : error at xmlCreatePushParserCtxt!\n");
return NULL;
}
@@ -313,14 +358,14 @@
ctxt->myDoc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION);
if (ctxt->myDoc == NULL) {
xmlFreeParserCtxt(ctxt);
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
"xmlNewTextWriterDoc : error at xmlNewDoc!\n");
return NULL;
}
ret = xmlNewTextWriterPushParser(ctxt, compression);
if (ret == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
"xmlNewTextWriterDoc : error at xmlNewTextWriterPushParser!\n");
return NULL;
}
@@ -352,7 +397,7 @@
xmlParserCtxtPtr ctxt;
if (doc == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
"xmlNewTextWriterTree : invalid document tree!\n");
return NULL;
}
@@ -365,7 +410,7 @@
ctxt = xmlCreatePushParserCtxt(&saxHandler, NULL, NULL, 0, NULL);
if (ctxt == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
"xmlNewTextWriterDoc : error at xmlCreatePushParserCtxt!\n");
return NULL;
}
@@ -378,7 +423,7 @@
ret = xmlNewTextWriterPushParser(ctxt, compression);
if (ret == NULL) {
xmlFreeParserCtxt(ctxt);
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
"xmlNewTextWriterDoc : error at xmlNewTextWriterPushParser!\n");
return NULL;
}
@@ -441,14 +486,14 @@
xmlCharEncodingHandlerPtr encoder;
if ((writer == NULL) || (writer->out == NULL)) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterStartDocument : invalid writer!\n");
return -1;
}
lk = xmlListFront(writer->nodes);
if ((lk != NULL) && (xmlLinkGetData(lk) != NULL)) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterStartDocument : not allowed in this context!\n");
return -1;
}
@@ -457,7 +502,7 @@
if (encoding != NULL) {
encoder = xmlFindCharEncodingHandler(encoding);
if (encoder == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
"xmlTextWriterStartDocument : out of memory!\n");
return -1;
}
@@ -555,7 +600,7 @@
xmlTextWriterStackEntry *p;
if (writer == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterEndDocument : invalid writer!\n");
return -1;
}
@@ -638,7 +683,7 @@
xmlTextWriterStackEntry *p;
if (writer == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterStartComment : invalid writer!\n");
return -1;
}
@@ -675,7 +720,7 @@
p = (xmlTextWriterStackEntry *)
xmlMalloc(sizeof(xmlTextWriterStackEntry));
if (p == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
"xmlTextWriterStartElement : out of memory!\n");
return -1;
}
@@ -717,14 +762,14 @@
xmlTextWriterStackEntry *p;
if (writer == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterEndComment : invalid writer!\n");
return -1;
}
lk = xmlListFront(writer->nodes);
if (lk == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterEndComment : not allowed in this context!\n");
return -1;
}
@@ -799,7 +844,7 @@
xmlChar *buf;
if (writer == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterWriteVFormatComment : invalid writer!\n");
return -1;
}
@@ -896,14 +941,14 @@
p = (xmlTextWriterStackEntry *)
xmlMalloc(sizeof(xmlTextWriterStackEntry));
if (p == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
"xmlTextWriterStartElement : out of memory!\n");
return -1;
}
p->name = xmlStrdup(name);
if (p->name == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
"xmlTextWriterStartElement : out of memory!\n");
xmlFree(p);
return -1;
@@ -1201,13 +1246,13 @@
xmlTextWriterStackEntry *p;
if (writer == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterWriteRawLen : invalid writer!\n");
return -1;
}
if ((content == NULL) || (len < 0)) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterWriteRawLen : invalid content!\n");
return -1;
}
@@ -1704,7 +1749,7 @@
p = (xmlTextWriterNsStackEntry *)
xmlMalloc(sizeof(xmlTextWriterNsStackEntry));
if (p == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
"xmlTextWriterStartAttributeNS : out of memory!\n");
return -1;
}
@@ -1712,7 +1757,7 @@
p->prefix = buf;
p->uri = xmlStrdup(namespaceURI);
if (p->uri == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
"xmlTextWriterStartAttributeNS : out of memory!\n");
xmlFree(p);
return -1;
@@ -2241,7 +2286,7 @@
return -1;
if (xmlStrcasecmp(target, (const xmlChar *) "xml") == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterStartPI : target name [Xx][Mm][Ll] is reserved for xml standardization!\n");
return -1;
}
@@ -2271,7 +2316,7 @@
break;
case XML_TEXTWRITER_PI:
case XML_TEXTWRITER_PI_TEXT:
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterStartPI : nested PI!\n");
return -1;
default:
@@ -2283,14 +2328,14 @@
p = (xmlTextWriterStackEntry *)
xmlMalloc(sizeof(xmlTextWriterStackEntry));
if (p == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
"xmlTextWriterStartPI : out of memory!\n");
return -1;
}
p->name = xmlStrdup(target);
if (p->name == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
"xmlTextWriterStartPI : out of memory!\n");
xmlFree(p);
return -1;
@@ -2493,7 +2538,7 @@
p->state = XML_TEXTWRITER_TEXT;
break;
case XML_TEXTWRITER_CDATA:
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterStartCDATA : CDATA not allowed in this context!\n");
return -1;
default:
@@ -2505,7 +2550,7 @@
p = (xmlTextWriterStackEntry *)
xmlMalloc(sizeof(xmlTextWriterStackEntry));
if (p == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
"xmlTextWriterStartCDATA : out of memory!\n");
return -1;
}
@@ -2682,7 +2727,7 @@
sum = 0;
lk = xmlListFront(writer->nodes);
if ((lk != NULL) && (xmlLinkGetData(lk) != NULL)) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterStartDTD : DTD allowed only in prolog!\n");
return -1;
}
@@ -2690,14 +2735,14 @@
p = (xmlTextWriterStackEntry *)
xmlMalloc(sizeof(xmlTextWriterStackEntry));
if (p == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
"xmlTextWriterStartDTD : out of memory!\n");
return -1;
}
p->name = xmlStrdup(name);
if (p->name == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
"xmlTextWriterStartDTD : out of memory!\n");
xmlFree(p);
return -1;
@@ -2717,7 +2762,7 @@
if (pubid != 0) {
if (sysid == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterStartDTD : system identifier needed!\n");
return -1;
}
@@ -3029,14 +3074,14 @@
p = (xmlTextWriterStackEntry *)
xmlMalloc(sizeof(xmlTextWriterStackEntry));
if (p == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
"xmlTextWriterStartDTDElement : out of memory!\n");
return -1;
}
p->name = xmlStrdup(name);
if (p->name == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
"xmlTextWriterStartDTDElement : out of memory!\n");
xmlFree(p);
return -1;
@@ -3266,14 +3311,14 @@
p = (xmlTextWriterStackEntry *)
xmlMalloc(sizeof(xmlTextWriterStackEntry));
if (p == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
"xmlTextWriterStartDTDAttlist : out of memory!\n");
return -1;
}
p->name = xmlStrdup(name);
if (p->name == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
"xmlTextWriterStartDTDAttlist : out of memory!\n");
xmlFree(p);
return -1;
@@ -3505,14 +3550,14 @@
p = (xmlTextWriterStackEntry *)
xmlMalloc(sizeof(xmlTextWriterStackEntry));
if (p == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
"xmlTextWriterStartDTDElement : out of memory!\n");
return -1;
}
p->name = xmlStrdup(name);
if (p->name == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
"xmlTextWriterStartDTDElement : out of memory!\n");
xmlFree(p);
return -1;
@@ -3824,7 +3869,7 @@
xmlTextWriterStackEntry *p;
if (writer == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterWriteDTDExternalEntityContents: xmlTextWriterPtr invalid!\n");
return -1;
}
@@ -3832,7 +3877,7 @@
sum = 0;
lk = xmlListFront(writer->nodes);
if (lk == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterWriteDTDExternalEntityContents: you must call xmlTextWriterStartDTDEntity before the call to this function!\n");
return -1;
}
@@ -3846,20 +3891,20 @@
break;
case XML_TEXTWRITER_DTD_PENT:
if (ndataid != NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterWriteDTDExternalEntityContents: notation not allowed with parameter entities!\n");
return -1;
}
break;
default:
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterWriteDTDExternalEntityContents: you must call xmlTextWriterStartDTDEntity before the call to this function!\n");
return -1;
}
if (pubid != 0) {
if (sysid == 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterWriteDTDExternalEntityContents: system identifier needed!\n");
return -1;
}
@@ -4248,7 +4293,7 @@
int rc;
if ((rc = xmlParseChunk(ctxt, (const char *) str, len, 0)) != 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsgInt(NULL, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterWriteDocCallback : XML error %d !\n",
rc);
return -1;
@@ -4272,7 +4317,7 @@
int rc;
if ((rc = xmlParseChunk(ctxt, NULL, 0, 1)) != 0) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsgInt(NULL, XML_ERR_INTERNAL_ERROR,
"xmlTextWriterWriteDocCallback : XML error %d !\n",
rc);
return -1;
@@ -4300,7 +4345,7 @@
size = BUFSIZ;
buf = (xmlChar *) xmlMalloc(size);
if (buf == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
"xmlTextWriterVSprintf : out of memory!\n");
return NULL;
}
@@ -4311,7 +4356,7 @@
size += BUFSIZ;
buf = (xmlChar *) xmlMalloc(size);
if (buf == NULL) {
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
"xmlTextWriterVSprintf : out of memory!\n");
return NULL;
}
@@ -4332,9 +4377,6 @@
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlDocPtr doc;
-#ifdef DEBUG_SAX
- xmlGenericError(xmlGenericErrorContext, "SAX.startDocument()\n");
-#endif
if (ctxt->html) {
#ifdef LIBXML_HTML_ENABLED
if (ctxt->myDoc == NULL)
@@ -4349,7 +4391,7 @@
return;
}
#else
- xmlGenericError(xmlGenericErrorContext,
+ xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
"libxml2 built without HTML support\n");
ctxt->errNo = XML_ERR_INTERNAL_ERROR;
ctxt->instate = XML_PARSER_EOF;