diff --git a/HTMLparser.c b/HTMLparser.c
index 3be74648..4add6347 100644
--- a/HTMLparser.c
+++ b/HTMLparser.c
@@ -5817,13 +5817,17 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data,
return(NULL);
encoding = xmlGetCharEncodingName(enc);
- input = xmlNewInputPush(ctxt, filename, chunk, size, encoding);
+ input = xmlInputCreatePush(filename, chunk, size);
if (input == NULL) {
htmlFreeParserCtxt(ctxt);
return(NULL);
}
+
inputPush(ctxt, input);
+ if (encoding != NULL)
+ xmlSwitchEncodingName(ctxt, encoding);
+
return(ctxt);
}
#endif /* LIBXML_PUSH_ENABLED */
diff --git a/include/private/parser.h b/include/private/parser.h
index 494be090..ea2880f1 100644
--- a/include/private/parser.h
+++ b/include/private/parser.h
@@ -108,8 +108,7 @@ xmlNewInputIO(xmlParserCtxtPtr ctxt, const char *url,
void *ioCtxt,
const char *encoding, int flags);
XML_HIDDEN xmlParserInputPtr
-xmlNewInputPush(xmlParserCtxtPtr ctxt, const char *url,
- const char *chunk, int size, const char *encoding);
+xmlInputCreatePush(const char *url, const char *chunk, int size);
XML_HIDDEN xmlChar *
xmlExpandEntitiesInAttValue(xmlParserCtxtPtr ctxt, const xmlChar *str,
diff --git a/parser.c b/parser.c
index ae8f9efa..f4b8baca 100644
--- a/parser.c
+++ b/parser.c
@@ -11633,7 +11633,8 @@ xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk, int size,
* @filename is used as base URI to fetch external entities and for
* error reports.
*
- * Returns the new parser context or NULL in case of error.
+ * Returns the new parser context or NULL if a memory allocation
+ * failed.
*/
xmlParserCtxtPtr
@@ -11649,7 +11650,7 @@ xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
ctxt->options &= ~XML_PARSE_NODICT;
ctxt->dictNames = 1;
- input = xmlNewInputPush(ctxt, filename, chunk, size, NULL);
+ input = xmlInputCreatePush(filename, chunk, size);
if (input == NULL) {
xmlFreeParserCtxt(ctxt);
return(NULL);
@@ -13348,11 +13349,15 @@ xmlCtxtResetPush(xmlParserCtxtPtr ctxt, const char *chunk,
xmlCtxtReset(ctxt);
- input = xmlNewInputPush(ctxt, filename, chunk, size, encoding);
+ input = xmlInputCreatePush(filename, chunk, size);
if (input == NULL)
return(1);
+
inputPush(ctxt, input);
+ if (encoding != NULL)
+ xmlSwitchEncodingName(ctxt, encoding);
+
return(0);
}
diff --git a/parserInternals.c b/parserInternals.c
index 29573c69..c96aac3f 100644
--- a/parserInternals.c
+++ b/parserInternals.c
@@ -1100,7 +1100,7 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)
}
/**
- * xmlSwitchEncodingName:
+ * xmlSwitchInputEncodingName:
* @ctxt: the parser context, only for error reporting
* @input: the input strea,
* @encoding: the encoding name
@@ -1899,37 +1899,27 @@ xmlNewInputIO(xmlParserCtxtPtr ctxt, const char *url,
}
/**
- * xmlNewInputPush:
- * @ctxt: parser context
+ * xmlInputCreatePush:
* @url: base URL (optional)
* @chunk: pointer to char array
* @size: size of array
- * @encoding: character encoding (optional)
*
* Creates a new parser input for a push parser.
*
- * Returns a new parser input.
+ * Returns a new parser input or NULL if a memory allocation failed.
*/
xmlParserInputPtr
-xmlNewInputPush(xmlParserCtxtPtr ctxt, const char *url,
- const char *chunk, int size, const char *encoding) {
+xmlInputCreatePush(const char *url, const char *chunk, int size) {
xmlParserInputBufferPtr buf;
xmlParserInputPtr input;
buf = xmlAllocParserInputBuffer(XML_CHAR_ENCODING_NONE);
- if (buf == NULL) {
- xmlCtxtErrMemory(ctxt);
+ if (buf == NULL)
return(NULL);
- }
input = xmlNewInputInternal(buf, url);
- if (input == NULL) {
- xmlCtxtErrMemory(ctxt);
+ if (input == NULL)
return(NULL);
- }
-
- if (encoding != NULL)
- xmlSwitchInputEncodingName(ctxt, input, encoding);
input->flags |= XML_INPUT_PROGRESSIVE;
@@ -1939,7 +1929,6 @@ xmlNewInputPush(xmlParserCtxtPtr ctxt, const char *url,
res = xmlParserInputBufferPush(input->buf, size, chunk);
xmlBufResetInput(input->buf->buffer, input);
if (res < 0) {
- xmlCtxtErrIO(ctxt, input->buf->error, NULL);
xmlFreeInputStream(input);
return(NULL);
}
@@ -2616,10 +2605,8 @@ xmlInitSAXParserCtxt(xmlParserCtxtPtr ctxt, const xmlSAXHandler *sax,
if (ctxt->nsdb == NULL) {
ctxt->nsdb = xmlParserNsCreate();
- if (ctxt->nsdb == NULL) {
- xmlCtxtErrMemory(ctxt);
+ if (ctxt->nsdb == NULL)
return(-1);
- }
}
return(0);