1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-09 04:58:16 +03:00

Remove unnecessary calls to xmlPopInput

It's enough if xmlPopInput is called from xmlSkipBlankChars. Since the
replacement text of a parameter entity is surrounded with space
characters, that's the only place where the replacement can end in a
well-formed document.

This is also required to get rid of the "blanks wrapper" hack.
This commit is contained in:
Nick Wellnhofer 2017-06-19 17:55:20 +02:00
parent aa267cd127
commit 453dff1e3b
2 changed files with 22 additions and 87 deletions

View File

@ -2043,9 +2043,8 @@ static int spacePop(xmlParserCtxtPtr ctxt) {
#define SKIP(val) do { \ #define SKIP(val) do { \
ctxt->nbChars += (val),ctxt->input->cur += (val),ctxt->input->col+=(val); \ ctxt->nbChars += (val),ctxt->input->cur += (val),ctxt->input->col+=(val); \
if ((*ctxt->input->cur == 0) && \ if (*ctxt->input->cur == 0) \
(xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) \ xmlParserInputGrow(ctxt->input, INPUT_CHUNK); \
xmlPopInput(ctxt); \
} while (0) } while (0)
#define SKIPL(val) do { \ #define SKIPL(val) do { \
@ -2057,9 +2056,8 @@ static int spacePop(xmlParserCtxtPtr ctxt) {
ctxt->nbChars++; \ ctxt->nbChars++; \
ctxt->input->cur++; \ ctxt->input->cur++; \
} \ } \
if ((*ctxt->input->cur == 0) && \ if (*ctxt->input->cur == 0) \
(xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) \ xmlParserInputGrow(ctxt->input, INPUT_CHUNK); \
xmlPopInput(ctxt); \
} while (0) } while (0)
#define SHRINK if ((ctxt->progressive == 0) && \ #define SHRINK if ((ctxt->progressive == 0) && \
@ -2069,10 +2067,9 @@ static int spacePop(xmlParserCtxtPtr ctxt) {
static void xmlSHRINK (xmlParserCtxtPtr ctxt) { static void xmlSHRINK (xmlParserCtxtPtr ctxt) {
xmlParserInputShrink(ctxt->input); xmlParserInputShrink(ctxt->input);
if ((*ctxt->input->cur == 0) && if (*ctxt->input->cur == 0)
(xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
xmlPopInput(ctxt); }
}
#define GROW if ((ctxt->progressive == 0) && \ #define GROW if ((ctxt->progressive == 0) && \
(ctxt->input->end - ctxt->input->cur < INPUT_CHUNK)) \ (ctxt->input->end - ctxt->input->cur < INPUT_CHUNK)) \
@ -2097,9 +2094,8 @@ static void xmlGROW (xmlParserCtxtPtr ctxt) {
xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "cur index out of bound"); xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "cur index out of bound");
return; return;
} }
if ((ctxt->input->cur != NULL) && (*ctxt->input->cur == 0) && if ((ctxt->input->cur != NULL) && (*ctxt->input->cur == 0))
(xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
xmlPopInput(ctxt);
} }
#define SKIP_BLANKS xmlSkipBlankChars(ctxt) #define SKIP_BLANKS xmlSkipBlankChars(ctxt)
@ -2219,9 +2215,8 @@ xmlPopInput(xmlParserCtxtPtr ctxt) {
xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
"Unfinished entity outside the DTD"); "Unfinished entity outside the DTD");
xmlFreeInputStream(inputPop(ctxt)); xmlFreeInputStream(inputPop(ctxt));
if ((*ctxt->input->cur == 0) && if (*ctxt->input->cur == 0)
(xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
return(xmlPopInput(ctxt));
return(CUR); return(CUR);
} }
@ -3808,11 +3803,6 @@ xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **orig) {
} }
COPY_BUF(l,buf,len,c); COPY_BUF(l,buf,len,c);
NEXTL(l); NEXTL(l);
/*
* Pop-up of finished entities.
*/
while ((RAW == 0) && (ctxt->inputNr > 1)) /* non input consuming */
xmlPopInput(ctxt);
GROW; GROW;
c = CUR_CHAR(l); c = CUR_CHAR(l);
@ -6602,8 +6592,6 @@ xmlParseElementDecl(xmlParserCtxtPtr ctxt) {
"xmlParseElementDecl: no name for Element\n"); "xmlParseElementDecl: no name for Element\n");
return(-1); return(-1);
} }
while ((RAW == 0) && (ctxt->inputNr > 1))
xmlPopInput(ctxt);
if (!IS_BLANK_CH(CUR)) { if (!IS_BLANK_CH(CUR)) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space required after the element name\n"); "Space required after the element name\n");
@ -6640,12 +6628,6 @@ xmlParseElementDecl(xmlParserCtxtPtr ctxt) {
} }
SKIP_BLANKS; SKIP_BLANKS;
/*
* Pop-up of finished entities.
*/
while ((RAW == 0) && (ctxt->inputNr > 1))
xmlPopInput(ctxt);
SKIP_BLANKS;
if (RAW != '>') { if (RAW != '>') {
xmlFatalErr(ctxt, XML_ERR_GT_REQUIRED, NULL); xmlFatalErr(ctxt, XML_ERR_GT_REQUIRED, NULL);
@ -6724,22 +6706,20 @@ xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
"Entering INCLUDE Conditional Section\n"); "Entering INCLUDE Conditional Section\n");
} }
SKIP_BLANKS;
GROW;
while (((RAW != 0) && ((RAW != ']') || (NXT(1) != ']') || while (((RAW != 0) && ((RAW != ']') || (NXT(1) != ']') ||
(NXT(2) != '>'))) && (ctxt->instate != XML_PARSER_EOF)) { (NXT(2) != '>'))) && (ctxt->instate != XML_PARSER_EOF)) {
const xmlChar *check = CUR_PTR; const xmlChar *check = CUR_PTR;
unsigned int cons = ctxt->input->consumed; unsigned int cons = ctxt->input->consumed;
SKIP_BLANKS;
if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) { if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) {
xmlParseConditionalSections(ctxt); xmlParseConditionalSections(ctxt);
} else } else
xmlParseMarkupDecl(ctxt); xmlParseMarkupDecl(ctxt);
/* SKIP_BLANKS;
* Pop-up of finished entities. GROW;
*/
while ((RAW == 0) && (ctxt->inputNr > 1))
xmlPopInput(ctxt);
if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) { if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) {
xmlFatalErr(ctxt, XML_ERR_EXT_SUBSET_NOT_FINISHED, NULL); xmlFatalErr(ctxt, XML_ERR_EXT_SUBSET_NOT_FINISHED, NULL);
@ -7043,24 +7023,19 @@ xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xmlChar *ExternalID,
ctxt->instate = XML_PARSER_DTD; ctxt->instate = XML_PARSER_DTD;
ctxt->external = 1; ctxt->external = 1;
SKIP_BLANKS;
while (((RAW == '<') && (NXT(1) == '?')) || while (((RAW == '<') && (NXT(1) == '?')) ||
((RAW == '<') && (NXT(1) == '!')) || ((RAW == '<') && (NXT(1) == '!')) ||
(RAW == '%') || IS_BLANK_CH(CUR)) { (RAW == '%')) {
const xmlChar *check = CUR_PTR; const xmlChar *check = CUR_PTR;
unsigned int cons = ctxt->input->consumed; unsigned int cons = ctxt->input->consumed;
SKIP_BLANKS;
GROW; GROW;
if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) { if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) {
xmlParseConditionalSections(ctxt); xmlParseConditionalSections(ctxt);
} else } else
xmlParseMarkupDecl(ctxt); xmlParseMarkupDecl(ctxt);
SKIP_BLANKS;
/*
* Pop-up of finished entities.
*/
while ((RAW == 0) && (ctxt->inputNr > 1))
xmlPopInput(ctxt);
if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) { if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) {
xmlFatalErr(ctxt, XML_ERR_EXT_SUBSET_NOT_FINISHED, NULL); xmlFatalErr(ctxt, XML_ERR_EXT_SUBSET_NOT_FINISHED, NULL);
@ -8368,7 +8343,8 @@ xmlParseInternalSubset(xmlParserCtxtPtr ctxt) {
* PEReferences. * PEReferences.
* Subsequence (markupdecl | PEReference | S)* * Subsequence (markupdecl | PEReference | S)*
*/ */
while ((RAW != ']') && (ctxt->instate != XML_PARSER_EOF)) { while (((RAW != ']') || (ctxt->inputNr > 1)) &&
(ctxt->instate != XML_PARSER_EOF)) {
const xmlChar *check = CUR_PTR; const xmlChar *check = CUR_PTR;
unsigned int cons = ctxt->input->consumed; unsigned int cons = ctxt->input->consumed;
@ -8376,23 +8352,6 @@ xmlParseInternalSubset(xmlParserCtxtPtr ctxt) {
xmlParseMarkupDecl(ctxt); xmlParseMarkupDecl(ctxt);
xmlParsePEReference(ctxt); xmlParsePEReference(ctxt);
/*
* Pop-up of finished entities.
*/
while (ctxt->inputNr > 1) {
if (RAW == 0) {
xmlPopInput(ctxt);
} else if (RAW == ']') {
/*
* Make sure not to return with unfinished entities.
*/
xmlFatalErr(ctxt, XML_ERR_EXT_SUBSET_NOT_FINISHED, NULL);
xmlPopInput(ctxt);
} else {
break;
}
}
if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) { if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) {
xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
"xmlParseInternalSubset: error detected in Markup declaration\n"); "xmlParseInternalSubset: error detected in Markup declaration\n");
@ -9973,11 +9932,6 @@ xmlParseContent(xmlParserCtxtPtr ctxt) {
} }
GROW; GROW;
/*
* Pop-up of finished entities.
*/
while ((RAW == 0) && (ctxt->inputNr > 1))
xmlPopInput(ctxt);
SHRINK; SHRINK;
if ((cons == ctxt->input->consumed) && (test == CUR_PTR)) { if ((cons == ctxt->input->consumed) && (test == CUR_PTR)) {
@ -11272,13 +11226,6 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) {
if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1)) if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1))
return(0); return(0);
/*
* Pop-up of finished entities.
*/
while ((RAW == 0) && (ctxt->inputNr > 1))
xmlPopInput(ctxt);
if (ctxt->input == NULL) break; if (ctxt->input == NULL) break;
if (ctxt->input->buf == NULL) if (ctxt->input->buf == NULL)
avail = ctxt->input->length - avail = ctxt->input->length -
@ -11629,11 +11576,6 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) {
ctxt->checkIndex = 0; ctxt->checkIndex = 0;
xmlParseCharData(ctxt, 0); xmlParseCharData(ctxt, 0);
} }
/*
* Pop-up of finished entities.
*/
while ((RAW == 0) && (ctxt->inputNr > 1))
xmlPopInput(ctxt);
if ((cons == ctxt->input->consumed) && (test == CUR_PTR)) { if ((cons == ctxt->input->consumed) && (test == CUR_PTR)) {
xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
"detected an error in element content\n"); "detected an error in element content\n");

View File

@ -435,8 +435,6 @@ xmlNextChar(xmlParserCtxtPtr ctxt)
if ((*ctxt->input->cur == 0) && if ((*ctxt->input->cur == 0) &&
(xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) { (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) {
if ((ctxt->instate != XML_PARSER_COMMENT))
xmlPopInput(ctxt);
return; return;
} }
@ -523,8 +521,6 @@ xmlNextChar(xmlParserCtxtPtr ctxt)
ctxt->input->cur++; ctxt->input->cur++;
ctxt->nbChars++; ctxt->nbChars++;
if (*ctxt->input->cur == 0)
xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
} else { } else {
/* /*
* Assume it's a fixed length encoding (1) with * Assume it's a fixed length encoding (1) with
@ -538,12 +534,9 @@ xmlNextChar(xmlParserCtxtPtr ctxt)
ctxt->input->col++; ctxt->input->col++;
ctxt->input->cur++; ctxt->input->cur++;
ctxt->nbChars++; ctxt->nbChars++;
if (*ctxt->input->cur == 0)
xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
} }
if ((*ctxt->input->cur == 0) && if (*ctxt->input->cur == 0)
(xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
xmlPopInput(ctxt);
return; return;
encoding_error: encoding_error:
/* /*