attempt to work around what seemed a gcc optimizer bug when handling
* xpath.c: attempt to work around what seemed a gcc optimizer
bug when handling floats on i386 http://veillard.com/gcc.bug
* tree.c entities.c encoding.c: doing some cleanups while
chasing it
Daniel
diff --git a/ChangeLog b/ChangeLog
index 8f2d2a9..894f489 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Fri Jun 22 00:04:36 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
+
+ * xpath.c: attempt to work around what seemed a gcc optimizer
+ bug when handling floats on i386 http://veillard.com/gcc.bug
+ * tree.c entities.c encoding.c: doing some cleanups while
+ chasing it
+
Thu Jun 21 13:13:36 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* Makefile.am: cleanup when --without-debug is specified
diff --git a/encoding.c b/encoding.c
index df760f7..b7611c2 100644
--- a/encoding.c
+++ b/encoding.c
@@ -2016,7 +2016,7 @@
default:
xmlGenericError(xmlGenericErrorContext,"Unknown input conversion failed %d\n", ret);
}
-#endif
+#endif /* DEBUG_ENCODING */
/*
* Ignore when input buffer is not on a boundary
*/
@@ -2039,70 +2039,82 @@
* the result of transformation can't fit into the encoding we want), or
*/
int
-xmlCharEncInFunc(xmlCharEncodingHandler *handler, xmlBufferPtr out,
- xmlBufferPtr in) {
+xmlCharEncInFunc(xmlCharEncodingHandler * handler, xmlBufferPtr out,
+ xmlBufferPtr in)
+{
int ret = -2;
int written;
int toconv;
- if (handler == NULL) return(-1);
- if (out == NULL) return(-1);
- if (in == NULL) return(-1);
+ if (handler == NULL)
+ return (-1);
+ if (out == NULL)
+ return (-1);
+ if (in == NULL)
+ return (-1);
toconv = in->use;
if (toconv == 0)
- return(0);
+ return (0);
written = out->size - out->use;
if (toconv * 2 >= written) {
xmlBufferGrow(out, out->size + toconv * 2);
- written = out->size - out->use - 1;
+ written = out->size - out->use - 1;
}
if (handler->input != NULL) {
- ret = handler->input(&out->content[out->use], &written,
- in->content, &toconv);
- xmlBufferShrink(in, toconv);
- out->use += written;
- out->content[out->use] = 0;
+ ret = handler->input(&out->content[out->use], &written,
+ in->content, &toconv);
+ xmlBufferShrink(in, toconv);
+ out->use += written;
+ out->content[out->use] = 0;
}
#ifdef LIBXML_ICONV_ENABLED
else if (handler->iconv_in != NULL) {
- ret = xmlIconvWrapper(handler->iconv_in, &out->content[out->use],
- &written, in->content, &toconv);
- xmlBufferShrink(in, toconv);
- out->use += written;
- out->content[out->use] = 0;
- if (ret == -1) ret = -3;
+ ret = xmlIconvWrapper(handler->iconv_in, &out->content[out->use],
+ &written, in->content, &toconv);
+ xmlBufferShrink(in, toconv);
+ out->use += written;
+ out->content[out->use] = 0;
+ if (ret == -1)
+ ret = -3;
}
#endif /* LIBXML_ICONV_ENABLED */
switch (ret) {
-#ifdef DEBUG_ENCODING
case 0:
- xmlGenericError(xmlGenericErrorContext,
- "converted %d bytes to %d bytes of input\n",
- toconv, written);
- break;
- case -1:
- xmlGenericError(xmlGenericErrorContext,"converted %d bytes to %d bytes of input, %d left\n",
- toconv, written, in->use);
- break;
- case -3:
- xmlGenericError(xmlGenericErrorContext,"converted %d bytes to %d bytes of input, %d left\n",
- toconv, written, in->use);
- break;
+#ifdef DEBUG_ENCODING
+ xmlGenericError(xmlGenericErrorContext,
+ "converted %d bytes to %d bytes of input\n",
+ toconv, written);
#endif
+ break;
+ case -1:
+#ifdef DEBUG_ENCODING
+ xmlGenericError(xmlGenericErrorContext,
+ "converted %d bytes to %d bytes of input, %d left\n",
+ toconv, written, in->use);
+#endif
+ break;
+ case -3:
+#ifdef DEBUG_ENCODING
+ xmlGenericError(xmlGenericErrorContext,
+ "converted %d bytes to %d bytes of input, %d left\n",
+ toconv, written, in->use);
+#endif
+ break;
case -2:
- xmlGenericError(xmlGenericErrorContext,
- "input conversion failed due to input error\n");
- xmlGenericError(xmlGenericErrorContext,
- "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
- in->content[0], in->content[1],
- in->content[2], in->content[3]);
+ xmlGenericError(xmlGenericErrorContext,
+ "input conversion failed due to input error\n");
+ xmlGenericError(xmlGenericErrorContext,
+ "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
+ in->content[0], in->content[1],
+ in->content[2], in->content[3]);
}
/*
* Ignore when input buffer is not on a boundary
*/
- if (ret == -3) ret = 0;
- return(ret);
+ if (ret == -3)
+ ret = 0;
+ return (ret);
}
/**
@@ -2214,17 +2226,19 @@
* Attempt to handle error cases
*/
switch (ret) {
-#ifdef DEBUG_ENCODING
case 0:
+#ifdef DEBUG_ENCODING
xmlGenericError(xmlGenericErrorContext,
"converted %d bytes to %d bytes of output\n",
toconv, written);
+#endif
break;
case -1:
+#ifdef DEBUG_ENCODING
xmlGenericError(xmlGenericErrorContext,
"output conversion failed by lack of space\n");
- break;
#endif
+ break;
case -3:
xmlGenericError(xmlGenericErrorContext,"converted %d bytes to %d bytes of output %d left\n",
toconv, written, in->use);
@@ -2313,8 +2327,8 @@
else
xmlGenericError(xmlGenericErrorContext,
"closed the encoding handler\n");
-
#endif
+
return(ret);
}
diff --git a/entities.c b/entities.c
index 3e6b581..23a9de1 100644
--- a/entities.c
+++ b/entities.c
@@ -18,8 +18,6 @@
#include <libxml/parser.h>
#include <libxml/xmlerror.h>
-#define DEBUG_ENT_REF /* debugging of cross entities dependancies */
-
/*
* The XML predefined entities.
*/
@@ -37,8 +35,8 @@
};
/*
- * TODO: !!!!!!! This is GROSS, allocation of a 256 entry hash for
- * a fixed number of 4 elements !
+ * TODO: This is GROSS, allocation of a 256 entry hash for
+ * a fixed number of 4 elements !
*/
xmlHashTablePtr xmlPredefinedEntities = NULL;
diff --git a/tree.c b/tree.c
index ae97e7c..3316d25 100644
--- a/tree.c
+++ b/tree.c
@@ -5645,12 +5645,12 @@
#endif
return;
}
- if (doc == NULL) {
#ifdef DEBUG_TREE
+ if (doc == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlElemDump : doc == NULL\n");
-#endif
}
+#endif
buf = xmlBufferCreate();
if (buf == NULL) return;
if ((doc != NULL) &&
diff --git a/xpath.c b/xpath.c
index 9d18ee7..e59c12c 100644
--- a/xpath.c
+++ b/xpath.c
@@ -5731,7 +5731,7 @@
const xmlChar *cur = str;
double ret = 0.0;
double mult = 1;
- int ok = 0;
+ int ok = 0, tmp = 0;
int isneg = 0;
int exponent = 0;
int is_exponent_negative = 0;
@@ -5744,11 +5744,16 @@
isneg = 1;
cur++;
}
+ /*
+ * tmp is a workaroudn against a gcc compiler bug
+ */
while ((*cur >= '0') && (*cur <= '9')) {
- ret = ret * 10 + (*cur - '0');
+ tmp = tmp * 10 + (*cur - '0');
ok = 1;
cur++;
}
+ ret = (double) tmp;
+
if (*cur == '.') {
cur++;
if (((*cur < '0') || (*cur > '9')) && (!ok)) {
@@ -5791,10 +5796,11 @@
*
*/
static void
-xmlXPathCompNumber(xmlXPathParserContextPtr ctxt) {
+xmlXPathCompNumber(xmlXPathParserContextPtr ctxt)
+{
double ret = 0.0;
double mult = 1;
- int ok = 0;
+ int ok = 0, tmp = 0;
int exponent = 0;
int is_exponent_negative = 0;
@@ -5802,38 +5808,42 @@
if ((CUR != '.') && ((CUR < '0') || (CUR > '9'))) {
XP_ERROR(XPATH_NUMBER_ERROR);
}
+ /*
+ * Try to work around a gcc optimizer bug
+ */
while ((CUR >= '0') && (CUR <= '9')) {
- ret = ret * 10 + (CUR - '0');
- ok = 1;
- NEXT;
+ tmp = tmp * 10 + (CUR - '0');
+ ok = 1;
+ NEXT;
}
+ ret = (double) tmp;
if (CUR == '.') {
NEXT;
- if (((CUR < '0') || (CUR > '9')) && (!ok)) {
- XP_ERROR(XPATH_NUMBER_ERROR);
- }
- while ((CUR >= '0') && (CUR <= '9')) {
- mult /= 10;
- ret = ret + (CUR - '0') * mult;
- NEXT;
- }
+ if (((CUR < '0') || (CUR > '9')) && (!ok)) {
+ XP_ERROR(XPATH_NUMBER_ERROR);
+ }
+ while ((CUR >= '0') && (CUR <= '9')) {
+ mult /= 10;
+ ret = ret + (CUR - '0') * mult;
+ NEXT;
+ }
}
if ((CUR == 'e') || (CUR == 'E')) {
- NEXT;
- if (CUR == '-') {
- is_exponent_negative = 1;
- NEXT;
- }
- while ((CUR >= '0') && (CUR <= '9')) {
- exponent = exponent * 10 + (CUR - '0');
- NEXT;
- }
+ NEXT;
+ if (CUR == '-') {
+ is_exponent_negative = 1;
+ NEXT;
+ }
+ while ((CUR >= '0') && (CUR <= '9')) {
+ exponent = exponent * 10 + (CUR - '0');
+ NEXT;
+ }
+ if (is_exponent_negative)
+ exponent = -exponent;
+ ret *= pow(10.0, (double) exponent);
}
- if (is_exponent_negative)
- exponent = -exponent;
- ret *= pow(10.0, (double)exponent);
PUSH_LONG_EXPR(XPATH_OP_VALUE, XPATH_NUMBER, 0, 0,
- xmlXPathNewFloat(ret), NULL);
+ xmlXPathNewFloat(ret), NULL);
}
/**