dohh I really didn't intended to commit this test version :-( Daniel
* HTMLparser.c error.c parser.c parserInternals.c tree.c xmlIO.c
include/libxml/tree.h: dohh I really didn't intended to commit
this test version :-(
Daniel
diff --git a/ChangeLog b/ChangeLog
index 5f6be58..04c3f1e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Mar 20 22:42:42 CET 2002 Daniel Veillard <daniel@veillard.com>
+
+ * HTMLparser.c error.c parser.c parserInternals.c tree.c xmlIO.c
+ include/libxml/tree.h: dohh I really didn't intended to commit
+ this test version :-(
+
Wed Mar 20 20:20:57 CET 2002 Daniel Veillard <daniel@veillard.com>
* testSAX.c: I wanted to see the real speed at the SAX interface
diff --git a/HTMLparser.c b/HTMLparser.c
index f5da298..4c819d1 100644
--- a/HTMLparser.c
+++ b/HTMLparser.c
@@ -147,12 +147,11 @@
/* Inported from XML */
-#define CUR ((ctxt->input->cur < ctxt->input->end) ? (*ctxt->input->cur) : 0)
+/* #define CUR (ctxt->token ? ctxt->token : (int) (*ctxt->input->cur)) */
+#define CUR ((int) (*ctxt->input->cur))
#define NEXT xmlNextChar(ctxt),ctxt->nbChars++
-#define AVAIL (ctxt->input->end - ctxt->input->cur)
-#define RAW (ctxt->token ? -1 : \
- (ctxt->input->cur < ctxt->input->end) ? (*ctxt->input->cur) : 0)
+#define RAW (ctxt->token ? -1 : (*ctxt->input->cur))
#define NXT(val) ctxt->input->cur[(val)]
#define CUR_PTR ctxt->input->cur
@@ -3048,8 +3047,8 @@
else {
/* Dump the bogus attribute string up to the next blank or
* the end of the tag. */
- while ((AVAIL > 0) && (IS_CHAR(CUR)) && !(IS_BLANK(CUR)) &&
- (CUR != '>') && ((CUR != '/') || (NXT(1) != '>')))
+ while ((IS_CHAR(CUR)) && !(IS_BLANK(CUR)) && (CUR != '>')
+ && ((CUR != '/') || (NXT(1) != '>')))
NEXT;
}
@@ -4671,8 +4670,6 @@
xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
ctxt->input->base = ctxt->input->buf->buffer->content + base;
ctxt->input->cur = ctxt->input->base + cur;
- ctxt->input->end = ctxt->input->buf->buffer->content +
- ctxt->input->buf->buffer->use;
#ifdef DEBUG_PUSH
xmlGenericError(xmlGenericErrorContext, "HPP: pushed %d\n", size);
#endif
diff --git a/error.c b/error.c
index 6a4a69f..14d91f3 100644
--- a/error.c
+++ b/error.c
@@ -146,63 +146,103 @@
*/
void
-xmlParserPrintFileContext(xmlParserInputPtr input)
-{
- const xmlChar *cur, *base, *end;
+xmlParserPrintFileContext(xmlParserInputPtr input) {
+ const xmlChar *cur, *base;
int n;
- xmlChar content[81];
+ xmlChar content[81];
xmlChar *ctnt;
- if (input == NULL)
- return;
+ if (input == NULL) return;
cur = input->cur;
base = input->base;
- end = input->end;
/* skip backwards over any end-of-lines */
- while ((cur > base) && (cur < end)
- && ((*cur == '\n') || (*cur == '\r'))) {
- cur--;
+ while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) {
+ cur--;
}
n = 0;
/* search backwards for beginning-of-line maximum 80 characters */
- while ((n++ < 80) && (cur > base) && (cur < end) && (*cur != '\n')
- && (*cur != '\r'))
+ while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r'))
cur--;
- if ((cur > base) && (cur < end) && ((*cur == '\n') || (*cur == '\r')))
- cur++;
- /* search forward for end-of-line maximum 80 characters */
+ if ((*cur == '\n') || (*cur == '\r')) cur++;
+ /* search forward for end-of-line maximum 80 characters */
n = 0;
ctnt = content;
- while ((cur < end) && (*cur != 0) && (*cur != '\n') && (*cur != '\r')
- && (n < 79)) {
- *ctnt++ = *cur++;
- n++;
+ while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) {
+ *ctnt++ = *cur++;
+ n++;
}
*ctnt = 0;
- xmlGenericError(xmlGenericErrorContext, "%s\n", content);
+ xmlGenericError(xmlGenericErrorContext,"%s\n", content);
/* create blank line with problem pointer */
cur = input->cur;
- while ((cur > base) && (cur < end)
- && ((*cur == '\n') || (*cur == '\r'))) {
- cur--;
- }
+ while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) {
+ cur--;
+ }
n = 0;
ctnt = content;
- while ((n++ < 79) && (cur > base) && (cur < end) && (*cur != '\n')
- && (*cur != '\r')) {
- *ctnt++ = ' ';
- cur--;
+ while ((n++ < 79) && (cur > base) && (*cur != '\n') && (*cur != '\r')) {
+ *ctnt++ = ' ';
+ cur--;
}
if (ctnt > content) {
- *(--ctnt) = '^';
- *(++ctnt) = 0;
+ *(--ctnt) = '^';
+ *(++ctnt) = 0;
} else {
- *ctnt = '^';
- *(++ctnt) = 0;
+ *ctnt = '^';
+ *(++ctnt) = 0;
}
- xmlGenericError(xmlGenericErrorContext, "%s\n", content);
+ xmlGenericError(xmlGenericErrorContext,"%s\n", content);
}
+#if 0
+/**
+ * xmlGetVarStr:
+ * @msg: the message format
+ * @args: a va_list argument list
+ *
+ * SGS contribution
+ * Get an arbitrary-sized string for an error argument
+ * The caller must free() the returned string
+ */
+static char *
+xmlGetVarStr(const char * msg, va_list args) {
+ int size;
+ int length;
+ int chars, left;
+ char *str, *larger;
+ va_list ap;
+
+ str = (char *) xmlMalloc(150);
+ if (str == NULL)
+ return(NULL);
+
+ size = 150;
+ length = 0;
+
+ while (1) {
+ left = size - length;
+ /* Try to print in the allocated space. */
+ va_start(msg, ap);
+ chars = vsnprintf(str + length, left, msg, ap);
+ va_end(ap);
+ /* If that worked, we're done. */
+ if ((chars > -1) && (chars < left ))
+ break;
+ /* Else try again with more space. */
+ if (chars > -1) /* glibc 2.1 */
+ size += chars + 1; /* precisely what is needed */
+ else /* glibc 2.0 */
+ size += 100;
+ if ((larger = (char *) xmlRealloc(str, size)) == NULL) {
+ xmlFree(str);
+ return(NULL);
+ }
+ str = larger;
+ }
+ return(str);
+}
+#endif
+
/**
* xmlParserError:
* @ctx: an XML parser context
diff --git a/include/libxml/tree.h b/include/libxml/tree.h
index 448a599..940426d 100644
--- a/include/libxml/tree.h
+++ b/include/libxml/tree.h
@@ -402,8 +402,7 @@
typedef enum {
XML_BUFFER_ALLOC_DOUBLEIT,
- XML_BUFFER_ALLOC_EXACT,
- XML_BUFFER_ALLOC_UNMUTABLE
+ XML_BUFFER_ALLOC_EXACT
} xmlBufferAllocationScheme;
/**
diff --git a/parser.c b/parser.c
index 13e9d50..a14cdbd 100644
--- a/parser.c
+++ b/parser.c
@@ -268,32 +268,29 @@
* GROW, SHRINK handling of input buffers
*/
-#define AVAIL (ctxt->input->end - ctxt->input->cur)
-#define RAW (ctxt->token ? -1 : \
- (ctxt->input->cur < ctxt->input->end) ? (*ctxt->input->cur) : 0)
-#define CUR (ctxt->token ? ctxt->token : \
- (ctxt->input->cur < ctxt->input->end) ? (*ctxt->input->cur) : 0)
+#define RAW (ctxt->token ? -1 : (*ctxt->input->cur))
+#define CUR (ctxt->token ? ctxt->token : (*ctxt->input->cur))
#define NXT(val) ctxt->input->cur[(val)]
#define CUR_PTR ctxt->input->cur
#define SKIP(val) do { \
ctxt->nbChars += (val),ctxt->input->cur += (val); \
if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); \
- if ((ctxt->input->cur >= ctxt->input->end) && \
+ if ((*ctxt->input->cur == 0) && \
(xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) \
xmlPopInput(ctxt); \
} while (0)
#define SHRINK if (ctxt->input->cur - ctxt->input->base > INPUT_CHUNK) {\
xmlParserInputShrink(ctxt->input); \
- if ((ctxt->input->cur >= ctxt->input->end) && \
+ if ((*ctxt->input->cur == 0) && \
(xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) \
xmlPopInput(ctxt); \
}
#define GROW if (ctxt->input->end - ctxt->input->cur < INPUT_CHUNK) { \
xmlParserInputGrow(ctxt->input, INPUT_CHUNK); \
- if ((ctxt->input->cur >= ctxt->input->end) && \
+ if ((*ctxt->input->cur == 0) && \
(xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) \
xmlPopInput(ctxt); \
}
@@ -305,7 +302,7 @@
#define NEXT1 { \
ctxt->input->cur++; \
ctxt->nbChars++; \
- if (ctxt->input->cur >= ctxt->input->end) \
+ if (*ctxt->input->cur == 0) \
xmlParserInputGrow(ctxt->input, INPUT_CHUNK); \
}
@@ -412,7 +409,7 @@
xmlGenericError(xmlGenericErrorContext,
"Popping input %d\n", ctxt->inputNr);
xmlFreeInputStream(inputPop(ctxt));
- if ((ctxt->input->cur >= ctxt->input->end) &&
+ if ((*ctxt->input->cur == 0) &&
(xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0))
return(xmlPopInput(ctxt));
return(CUR);
@@ -470,8 +467,7 @@
/*
* Using RAW/CUR/NEXT is okay since we are working on ASCII range here
*/
- GROW;
- if ((AVAIL >= 5) && (RAW == '&') && (NXT(1) == '#') &&
+ if ((RAW == '&') && (NXT(1) == '#') &&
(NXT(2) == 'x')) {
SKIP(3);
GROW;
@@ -504,7 +500,7 @@
ctxt->nbChars ++;
ctxt->input->cur++;
}
- } else if ((AVAIL >= 4) && (RAW == '&') && (NXT(1) == '#')) {
+ } else if ((RAW == '&') && (NXT(1) == '#')) {
SKIP(2);
GROW;
while (RAW != ';') { /* loop blocked by count */
@@ -840,19 +836,16 @@
* plug some encoding conversion routines.
*/
GROW
- if (AVAIL > 4) {
- start[0] = RAW;
- start[1] = NXT(1);
- start[2] = NXT(2);
- start[3] = NXT(3);
- enc = xmlDetectCharEncoding(start, 4);
- if (enc != XML_CHAR_ENCODING_NONE) {
- xmlSwitchEncoding(ctxt, enc);
- }
+ start[0] = RAW;
+ start[1] = NXT(1);
+ start[2] = NXT(2);
+ start[3] = NXT(3);
+ enc = xmlDetectCharEncoding(start, 4);
+ if (enc != XML_CHAR_ENCODING_NONE) {
+ xmlSwitchEncoding(ctxt, enc);
}
if ((entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) &&
- (AVAIL >= 6) &&
(RAW == '<') && (NXT(1) == '?') &&
(NXT(2) == 'x') && (NXT(3) == 'm') &&
(NXT(4) == 'l') && (IS_BLANK(NXT(5)))) {
@@ -1533,7 +1526,7 @@
/*
* Otherwise, heuristic :-\
*/
- if ((AVAIL < 2) || (RAW != '<')) return(0);
+ if (RAW != '<') return(0);
if ((ctxt->node->children == NULL) &&
(RAW == '<') && (NXT(1) == '/')) return(0);
@@ -2562,7 +2555,7 @@
void
xmlParseCharData(xmlParserCtxtPtr ctxt, int cdata) {
- const xmlChar *in, *end;
+ const xmlChar *in;
int nbchar = 0;
int line = ctxt->input->line;
int col = ctxt->input->col;
@@ -2575,24 +2568,21 @@
*/
if ((ctxt->token == 0) && (!cdata)) {
in = ctxt->input->cur;
- end = ctxt->input->end;
do {
get_more:
- while ((in < end) &&
- (((*in >= 0x20) && (*in != '<') && (*in != ']') &&
- (*in != '&') && (*in <= 0x7F)) || (*in == 0x09)))
+ while (((*in >= 0x20) && (*in != '<') && (*in != ']') &&
+ (*in != '&') && (*in <= 0x7F)) || (*in == 0x09))
in++;
- if (in >= end) {
- end = ctxt->input->end;
- } else if (*in == 0xA) {
+ if (*in == 0xA) {
ctxt->input->line++;
in++;
- while ((in < end) && (*in == 0xA)) {
+ while (*in == 0xA) {
ctxt->input->line++;
in++;
}
goto get_more;
- } else if (*in == ']') {
+ }
+ if (*in == ']') {
if ((in[1] == ']') && (in[2] == '>')) {
ctxt->errNo = XML_ERR_MISPLACED_CDATA_END;
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
@@ -2631,29 +2621,26 @@
}
}
ctxt->input->cur = in;
- if (in < ctxt->input->end) {
- if (*in == 0xD) {
+ if (*in == 0xD) {
+ in++;
+ if (*in == 0xA) {
+ ctxt->input->cur = in;
in++;
- if (*in == 0xA) {
- ctxt->input->cur = in;
- in++;
- ctxt->input->line++;
- continue; /* while */
- }
- in--;
+ ctxt->input->line++;
+ continue; /* while */
}
- if (*in == '<') {
- return;
- }
- if (*in == '&') {
- return;
- }
+ in--;
+ }
+ if (*in == '<') {
+ return;
+ }
+ if (*in == '&') {
+ return;
}
SHRINK;
GROW;
in = ctxt->input->cur;
- end = ctxt->input->end;
- } while ((in < end) && (*in >= 0x20) && (*in <= 0x7F));
+ } while ((*in >= 0x20) && (*in <= 0x7F));
nbchar = 0;
}
ctxt->input->line = line;
@@ -6759,7 +6746,7 @@
void
xmlParseContent(xmlParserCtxtPtr ctxt) {
GROW;
- while ((AVAIL > 0) && ((RAW != 0) || (ctxt->token != 0)) &&
+ while (((RAW != 0) || (ctxt->token != 0)) &&
((RAW != '<') || (NXT(1) != '/'))) {
const xmlChar *test = CUR_PTR;
int cons = ctxt->input->consumed;
@@ -6826,7 +6813,7 @@
/*
* Pop-up of finished entities.
*/
- while (((AVAIL == 0) || (RAW == 0)) && (ctxt->inputNr > 1))
+ while ((RAW == 0) && (ctxt->inputNr > 1))
xmlPopInput(ctxt);
SHRINK;
@@ -7540,16 +7527,13 @@
void
xmlParseMisc(xmlParserCtxtPtr ctxt) {
- if (AVAIL < 4) {
- GROW;
- }
- while (((AVAIL >= 2) && ((RAW == '<') && (NXT(1) == '?'))) ||
- ((AVAIL >= 4) && ((RAW == '<') && (NXT(1) == '!') &&
- (NXT(2) == '-') && (NXT(3) == '-'))) ||
- ((AVAIL > 0) && (IS_BLANK(CUR)))) {
- if ((AVAIL >= 2) && (RAW == '<') && (NXT(1) == '?')) {
+ while (((RAW == '<') && (NXT(1) == '?')) ||
+ ((RAW == '<') && (NXT(1) == '!') &&
+ (NXT(2) == '-') && (NXT(3) == '-')) ||
+ IS_BLANK(CUR)) {
+ if ((RAW == '<') && (NXT(1) == '?')) {
xmlParsePI(ctxt);
- } else if ((AVAIL > 0) && (IS_BLANK(CUR))) {
+ } else if (IS_BLANK(CUR)) {
NEXT;
} else
xmlParseComment(ctxt);
@@ -7699,7 +7683,7 @@
*/
xmlParseMisc(ctxt);
- if ((AVAIL > 0) && (RAW != 0)) {
+ if (RAW != 0) {
ctxt->errNo = XML_ERR_DOCUMENT_END;
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
ctxt->sax->error(ctxt->userData,
@@ -9541,14 +9525,14 @@
xmlParseContent(ctxt);
- if ((AVAIL > 2) && (RAW == '<') && (NXT(1) == '/')) {
+ if ((RAW == '<') && (NXT(1) == '/')) {
ctxt->errNo = XML_ERR_NOT_WELL_BALANCED;
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
ctxt->sax->error(ctxt->userData,
"chunk is not well balanced\n");
ctxt->wellFormed = 0;
ctxt->disableSAX = 1;
- } else if ((AVAIL > 0) && (RAW != 0)) {
+ } else if (RAW != 0) {
ctxt->errNo = XML_ERR_EXTRA_CONTENT;
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
ctxt->sax->error(ctxt->userData,
diff --git a/parserInternals.c b/parserInternals.c
index ca84b19..68ac538 100644
--- a/parserInternals.c
+++ b/parserInternals.c
@@ -993,7 +993,6 @@
if (in->base == NULL) return(-1);
if (in->cur == NULL) return(-1);
if (in->buf->buffer == NULL) return(-1);
- if (in->buf->buffer->alloc == XML_BUFFER_ALLOC_UNMUTABLE) return(-1);
CHECK_BUFFER(in);
@@ -1049,7 +1048,6 @@
if (in->base == NULL) return;
if (in->cur == NULL) return;
if (in->buf->buffer == NULL) return;
- if (in->buf->buffer->alloc == XML_BUFFER_ALLOC_UNMUTABLE) return;
CHECK_BUFFER(in);
@@ -1103,13 +1101,9 @@
void
xmlNextChar(xmlParserCtxtPtr ctxt) {
- int avail;
-
if (ctxt->instate == XML_PARSER_EOF)
return;
- avail = ctxt->input->end - ctxt->input->cur;
-
/*
* 2.11 End-of-Line Handling
* the literal two-character sequence "#xD#xA" or a standalone
@@ -1118,8 +1112,7 @@
*/
if (ctxt->token != 0) ctxt->token = 0;
else if (ctxt->charset == XML_CHAR_ENCODING_UTF8) {
- if (((ctxt->input->cur >= ctxt->input->end) ||
- (*ctxt->input->cur == 0)) &&
+ if ((*ctxt->input->cur == 0) &&
(xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0) &&
(ctxt->instate != XML_PARSER_COMMENT)) {
/*
@@ -1133,14 +1126,6 @@
if (*(ctxt->input->cur) == '\n') {
ctxt->input->line++; ctxt->input->col = 1;
} else ctxt->input->col++;
-
- if (avail < 4) {
- xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
- avail = ctxt->input->end - ctxt->input->cur;
- }
- if (avail < 1)
- return;
-
if (ctxt->charset == XML_CHAR_ENCODING_UTF8) {
/*
* We are supposed to handle UTF8, check it's valid
@@ -1158,15 +1143,21 @@
c = *cur;
if (c & 0x80) {
- if ((avail < 2) || (cur[1] & 0xc0) != 0x80)
+ if (cur[1] == 0)
+ xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
+ if ((cur[1] & 0xc0) != 0x80)
goto encoding_error;
if ((c & 0xe0) == 0xe0) {
unsigned int val;
- if ((avail < 3) || ((cur[2] & 0xc0) != 0x80))
+ if (cur[2] == 0)
+ xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
+ if ((cur[2] & 0xc0) != 0x80)
goto encoding_error;
if ((c & 0xf0) == 0xf0) {
- if ((avail < 4) || ((c & 0xf8) != 0xf0) ||
+ if (cur[3] == 0)
+ xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
+ if (((c & 0xf8) != 0xf0) ||
((cur[3] & 0xc0) != 0x80))
goto encoding_error;
/* 4-byte code */
@@ -1208,18 +1199,18 @@
ctxt->input->cur++;
}
ctxt->nbChars++;
+ if (*ctxt->input->cur == 0)
+ xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
}
} else {
ctxt->input->cur++;
ctxt->nbChars++;
- if (avail < 1) {
+ if (*ctxt->input->cur == 0)
xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
- avail = ctxt->input->end - ctxt->input->cur;
- }
}
- if ((avail > 1) && (*ctxt->input->cur == '%') && (!ctxt->html))
+ if ((*ctxt->input->cur == '%') && (!ctxt->html))
xmlParserHandlePEReference(ctxt);
- if ((avail < 1) &&
+ if ((*ctxt->input->cur == 0) &&
(xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0))
xmlPopInput(ctxt);
return;
@@ -1232,34 +1223,17 @@
* encoding !)
*/
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) {
- xmlChar bytes[4];
- if (avail > 3)
- bytes[3] = ctxt->input->cur[3];
- else
- bytes[3] = 0;
- if (avail > 2)
- bytes[2] = ctxt->input->cur[2];
- else
- bytes[2] = 0;
- if (avail > 1)
- bytes[1] = ctxt->input->cur[1];
- else
- bytes[1] = 0;
- if (avail > 0)
- bytes[0] = ctxt->input->cur[0];
- else
- bytes[0] = 0;
ctxt->sax->error(ctxt->userData,
"Input is not proper UTF-8, indicate encoding !\n");
ctxt->sax->error(ctxt->userData, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
- bytes[0], bytes[1],bytes[2],bytes[3]);
+ ctxt->input->cur[0], ctxt->input->cur[1],
+ ctxt->input->cur[2], ctxt->input->cur[3]);
}
ctxt->wellFormed = 0;
ctxt->errNo = XML_ERR_INVALID_ENCODING;
ctxt->charset = XML_CHAR_ENCODING_8859_1;
- if (avail > 1)
- ctxt->input->cur++;
+ ctxt->input->cur++;
return;
}
@@ -1283,8 +1257,6 @@
int
xmlCurrentChar(xmlParserCtxtPtr ctxt, int *len) {
- int avail;
-
if (ctxt->instate == XML_PARSER_EOF)
return(0);
@@ -1292,18 +1264,9 @@
*len = 0;
return(ctxt->token);
}
- avail = ctxt->input->end - ctxt->input->cur;
- if (avail < 4) {
- xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
- avail = ctxt->input->end - ctxt->input->cur;
- }
- if (avail < 1)
- return(0);
-
- if ((avail > 1) &&
- (*ctxt->input->cur >= 0x20) && (*ctxt->input->cur <= 0x7F)) {
- *len = 1;
- return((int) *ctxt->input->cur);
+ if ((*ctxt->input->cur >= 0x20) && (*ctxt->input->cur <= 0x7F)) {
+ *len = 1;
+ return((int) *ctxt->input->cur);
}
if (ctxt->charset == XML_CHAR_ENCODING_UTF8) {
/*
@@ -1323,15 +1286,20 @@
c = *cur;
if (c & 0x80) {
- if ((avail < 2) || (cur[1] & 0xc0) != 0x80)
+ if (cur[1] == 0)
+ xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
+ if ((cur[1] & 0xc0) != 0x80)
goto encoding_error;
if ((c & 0xe0) == 0xe0) {
- if ((avail < 3) || ((cur[2] & 0xc0) != 0x80))
+
+ if (cur[2] == 0)
+ xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
+ if ((cur[2] & 0xc0) != 0x80)
goto encoding_error;
if ((c & 0xf0) == 0xf0) {
if (cur[3] == 0)
xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
- if ((avail < 4) || ((c & 0xf8) != 0xf0) ||
+ if (((c & 0xf8) != 0xf0) ||
((cur[3] & 0xc0) != 0x80))
goto encoding_error;
/* 4-byte code */
@@ -1367,7 +1335,7 @@
/* 1-byte code */
*len = 1;
if (*ctxt->input->cur == 0xD) {
- if ((avail > 1) && (ctxt->input->cur[1] == 0xA)) {
+ if (ctxt->input->cur[1] == 0xA) {
ctxt->nbChars++;
ctxt->input->cur++;
}
@@ -1383,7 +1351,7 @@
*/
*len = 1;
if (*ctxt->input->cur == 0xD) {
- if ((avail > 1) && (ctxt->input->cur[1] == 0xA)) {
+ if (ctxt->input->cur[1] == 0xA) {
ctxt->nbChars++;
ctxt->input->cur++;
}
@@ -1399,36 +1367,16 @@
* encoding !)
*/
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) {
- xmlChar bytes[4];
- if (avail > 3)
- bytes[3] = ctxt->input->cur[3];
- else
- bytes[3] = 0;
- if (avail > 2)
- bytes[2] = ctxt->input->cur[2];
- else
- bytes[2] = 0;
- if (avail > 1)
- bytes[1] = ctxt->input->cur[1];
- else
- bytes[1] = 0;
- if (avail > 0)
- bytes[0] = ctxt->input->cur[0];
- else
- bytes[0] = 0;
ctxt->sax->error(ctxt->userData,
"Input is not proper UTF-8, indicate encoding !\n");
ctxt->sax->error(ctxt->userData, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
- bytes[0], bytes[1],bytes[2],bytes[3]);
+ ctxt->input->cur[0], ctxt->input->cur[1],
+ ctxt->input->cur[2], ctxt->input->cur[3]);
}
ctxt->wellFormed = 0;
ctxt->errNo = XML_ERR_INVALID_ENCODING;
ctxt->charset = XML_CHAR_ENCODING_8859_1;
- if (avail < 1) {
- *len = 0;
- return(0);
- }
*len = 1;
return((int) *ctxt->input->cur);
}
diff --git a/tree.c b/tree.c
index bbae85b..0d36ca9 100644
--- a/tree.c
+++ b/tree.c
@@ -5159,8 +5159,6 @@
void
xmlBufferSetAllocationScheme(xmlBufferPtr buf,
xmlBufferAllocationScheme scheme) {
- if (buf->alloc == XML_BUFFER_ALLOC_UNMUTABLE)
- return;
if (buf == NULL) {
#ifdef DEBUG_BUFFER
xmlGenericError(xmlGenericErrorContext,
@@ -5188,8 +5186,7 @@
#endif
return;
}
- if ((buf->content != NULL) &&
- (buf->alloc != XML_BUFFER_ALLOC_UNMUTABLE)) {
+ if (buf->content != NULL) {
xmlFree(buf->content);
}
xmlFree(buf);
@@ -5203,9 +5200,6 @@
*/
void
xmlBufferEmpty(xmlBufferPtr buf) {
- if (buf->alloc == XML_BUFFER_ALLOC_UNMUTABLE)
- return;
-
if (buf->content == NULL) return;
buf->use = 0;
memset(buf->content, 0, buf->size);
@@ -5225,12 +5219,6 @@
if (len == 0) return(0);
if (len > buf->use) return(-1);
- if (buf->alloc == XML_BUFFER_ALLOC_UNMUTABLE) {
- buf->content = &buf->content[len];
- buf->use -= len;
- return(len);
- }
-
buf->use -= len;
memmove(buf->content, &buf->content[len], buf->use * sizeof(xmlChar));
@@ -5252,9 +5240,6 @@
int size;
xmlChar *newbuf;
- if (buf->alloc == XML_BUFFER_ALLOC_UNMUTABLE)
- return(-1);
-
if (len + buf->use < buf->size) return(0);
size = buf->use + len + 100;
@@ -5349,9 +5334,6 @@
unsigned int newSize;
xmlChar* rebuf = NULL;
- if (buf->alloc == XML_BUFFER_ALLOC_UNMUTABLE)
- return 0;
-
/*take care of empty case*/
newSize = (buf->size ? buf->size*2 : size);
@@ -5401,9 +5383,6 @@
xmlBufferAdd(xmlBufferPtr buf, const xmlChar *str, int len) {
unsigned int needSize;
- if (buf->alloc == XML_BUFFER_ALLOC_UNMUTABLE)
- return;
-
if (str == NULL) {
#ifdef DEBUG_BUFFER
xmlGenericError(xmlGenericErrorContext,
@@ -5452,9 +5431,6 @@
xmlBufferAddHead(xmlBufferPtr buf, const xmlChar *str, int len) {
unsigned int needSize;
- if (buf->alloc == XML_BUFFER_ALLOC_UNMUTABLE)
- return;
-
if (str == NULL) {
#ifdef DEBUG_BUFFER
xmlGenericError(xmlGenericErrorContext,
@@ -5515,9 +5491,6 @@
xmlBufferCCat(xmlBufferPtr buf, const char *str) {
const char *cur;
- if (buf->alloc == XML_BUFFER_ALLOC_UNMUTABLE)
- return;
-
if (str == NULL) {
#ifdef DEBUG_BUFFER
xmlGenericError(xmlGenericErrorContext,
@@ -5590,9 +5563,6 @@
*/
void
xmlBufferWriteQuotedString(xmlBufferPtr buf, const xmlChar *string) {
- if (buf->alloc == XML_BUFFER_ALLOC_UNMUTABLE)
- return;
-
if (xmlStrchr(string, '"')) {
if (xmlStrchr(string, '\'')) {
#ifdef DEBUG_BUFFER
diff --git a/xmlIO.c b/xmlIO.c
index 2811058..e3c16fb 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -33,14 +33,6 @@
#include <zlib.h>
#endif
-#ifdef HAVE_SYS_MMAN_H
-#include <sys/mman.h>
-/* seems needed for Solaris */
-#ifndef MAP_FAILED
-#define MAP_FAILED ((void *) -1)
-#endif
-#endif
-
/* Figure a portable way to know if a file is a directory. */
#ifndef HAVE_STAT
# ifdef HAVE__STAT
@@ -1955,84 +1947,6 @@
return(ret);
}
-#ifdef HAVE_SYS_MMAN_H
-typedef struct _xmlMMapContext xmlMMapContext;
-typedef xmlMMapContext *xmlMMapContextPtr;
-struct _xmlMMapContext {
- int fd;
- const char *mem;
- size_t size;
-};
-
-/**
- * xmlParserInputBufferCloseMMapFile:
- * @ctxt: the mmaped context
- *
- * Free up the resources associated to the mmaped file
- */
-static void
-xmlParserInputBufferCloseMMapFile(xmlMMapContextPtr ctxt) {
- if (ctxt == NULL)
- return;
- if (ctxt->mem != (void *) MAP_FAILED)
- munmap((char *) ctxt->mem, ctxt->size);
- if (ctxt->fd >= 0)
- close(ctxt->fd);
- xmlFree(ctxt);
-}
-
-/**
- * xmlParserInputBufferCreateMMapFile:
- * @fd: the descriptor associated to the mmaped file.
- * @base: the mmaped start
- * @size: the length of the memory block
- * @enc: the charset encoding if known
- *
- * Create a buffered parser input for the progressive parsing for the input
- * from a memory area.
- *
- * Returns the new parser input or NULL
- */
-static xmlParserInputBufferPtr
-xmlParserInputBufferCreateMMapFile(int fd, const char *mem, size_t size,
- xmlCharEncoding enc) {
- xmlParserInputBufferPtr ret;
- xmlMMapContextPtr ctxt;
-
- if (fd < 0) return(NULL);
- if (size <= 0) return(NULL);
- if (mem == NULL) return(NULL);
-
- ctxt = (xmlMMapContextPtr) xmlMalloc(sizeof(xmlMMapContext));
- if (ctxt == NULL)
- return(NULL);
- ctxt->fd = fd;
- ctxt->mem = mem;
- ctxt->size = size;
-
-
- ret = xmlAllocParserInputBuffer(enc);
- if (ret != NULL) {
- ret->context = (void *) ctxt;
- ret->readcallback = (xmlInputReadCallback) xmlNop;
- ret->closecallback = (xmlInputCloseCallback)
- xmlParserInputBufferCloseMMapFile;
- if (ret->buffer->content != NULL) {
- xmlFree(ret->buffer->content);
- }
- ret->buffer->alloc = XML_BUFFER_ALLOC_UNMUTABLE;
- ret->buffer->content = (xmlChar *) mem;
- ret->buffer->size = size;
- ret->buffer->use = size;
- } else {
- xmlFree(ctxt);
- return(NULL);
- }
-
- return(ret);
-}
-#endif
-
/**
* xmlOutputBufferCreateFd:
* @fd: a file descriptor number
@@ -2519,7 +2433,8 @@
* *
****************************************************************/
-static const char * xmlSysIDExists(const char *URL, size_t *size) {
+#ifdef LIBXML_CATALOG_ENABLED
+static int xmlSysIDExists(const char *URL) {
#ifdef HAVE_STAT
int ret;
struct stat info;
@@ -2539,16 +2454,12 @@
} else
path = URL;
ret = stat(path, &info);
- if (ret == 0) {
- if (size)
- *size = info.st_size;
- return(path);
- }
+ if (ret == 0)
+ return(1);
#endif
- if (size)
- *size = -1;
- return(NULL);
+ return(0);
}
+#endif
/**
* xmlDefaultExternalEntityLoader:
@@ -2569,57 +2480,7 @@
#ifdef LIBXML_CATALOG_ENABLED
xmlCatalogAllow pref;
#endif
- const char *exist;
- size_t length;
- exist = xmlSysIDExists(URL, &length);
-#ifdef HAVE_SYS_MMAN_H
- /*
- * Shortcut, if asked for a file, the file is present, mmap it !
- */
- if ((exist != NULL) && (length > 0)) {
- int fd = -1;
- const char *base = NULL;
- xmlParserInputBufferPtr buf = NULL;
-
- if ((fd = open(exist, O_RDONLY)) >= 0) {
- /*
- * Magic test: don't drop back native compressed content support
- */
- char tmpbuf[2];
- if (read(fd, tmpbuf, 2) != 2)
- goto failed;
- if ((tmpbuf[0] == 0x1F) && (tmpbuf[1] == 0x8B))
- goto failed;
-
- base = mmap(NULL, length, PROT_READ, MAP_SHARED, fd, 0);
- if (base != (void *) MAP_FAILED) {
- buf = xmlParserInputBufferCreateMMapFile(fd, base, length,
- XML_CHAR_ENCODING_NONE);
- if (buf != NULL) {
- ret = xmlNewInputStream(ctxt);
- if (ret != NULL) {
- ret->filename = (const char *) xmlCharStrdup(exist);
- ret->directory = (const char *)
- xmlParserGetDirectory(exist);
- ret->buf = buf;
- ret->base = ret->buf->buffer->content;
- ret->cur = ret->buf->buffer->content;
- ret->end = &ret->base[ret->buf->buffer->use];
- return(ret);
- }
- }
- }
- }
-failed:
- if (buf != NULL)
- xmlFreeParserInputBuffer(buf);
- if (base != (void *) MAP_FAILED)
- munmap((char *) base, length);
- if (fd >= 0)
- close(fd);
- }
-#endif
#ifdef DEBUG_EXTERNAL_ENTITIES
xmlGenericError(xmlGenericErrorContext,
"xmlDefaultExternalEntityLoader(%s, xxx)\n", URL);
@@ -2631,7 +2492,7 @@
*/
pref = xmlCatalogGetDefaults();
- if ((pref != XML_CATA_ALLOW_NONE) && (exist == NULL)) {
+ if ((pref != XML_CATA_ALLOW_NONE) && (!xmlSysIDExists(URL))) {
/*
* Do a local lookup
*/
@@ -2657,8 +2518,7 @@
/*
* TODO: do an URI lookup on the reference
*/
- exist = xmlSysIDExists(URL, &length);
- if ((resource != NULL) && (exist == NULL)) {
+ if ((resource != NULL) && (!xmlSysIDExists((const char *)resource))) {
xmlChar *tmp = NULL;
if ((ctxt->catalogs != NULL) &&