1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-12-23 17:33:50 +03:00

schemas: Use private copy of global NaN and Inf

Simplify symbol availability logic.
This commit is contained in:
Nick Wellnhofer 2024-06-15 23:53:04 +02:00
parent b0fc67aa22
commit f307237e14
6 changed files with 39 additions and 127 deletions

View File

@ -17555,7 +17555,7 @@ Could we use @subtypes for this?'/>
<arg name='nargs' type='int' info='the number of arguments'/>
</function>
<function name='xmlXPathInit' file='xpath' module='xpath'>
<cond>defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)</cond>
<cond>defined(LIBXML_XPATH_ENABLED)</cond>
<info>DEPRECATED: Alias for xmlInitParser.</info>
<return type='void'/>
</function>
@ -17567,13 +17567,13 @@ Could we use @subtypes for this?'/>
<arg name='nodes2' type='xmlNodeSetPtr' info='a node-set'/>
</function>
<function name='xmlXPathIsInf' file='xpath' module='xpath'>
<cond>defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)</cond>
<cond>defined(LIBXML_XPATH_ENABLED)</cond>
<info>Checks whether a double is an infinity.</info>
<return type='int' info='1 if the value is +Infinite, -1 if -Infinite, 0 otherwise'/>
<arg name='val' type='double' info='a double value'/>
</function>
<function name='xmlXPathIsNaN' file='xpath' module='xpath'>
<cond>defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)</cond>
<cond>defined(LIBXML_XPATH_ENABLED)</cond>
<info>Checks whether a double is a NaN.</info>
<return type='int' info='1 if the value is a NaN, 0 otherwise'/>
<arg name='val' type='double' info='a double value'/>

View File

@ -26,15 +26,10 @@
#include <libxml/xmlerror.h>
#include <libxml/tree.h>
#include <libxml/hash.h>
#endif /* LIBXML_XPATH_ENABLED */
#if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
#ifdef __cplusplus
extern "C" {
#endif
#endif /* LIBXML_XPATH_ENABLED or LIBXML_SCHEMAS_ENABLED */
#ifdef LIBXML_XPATH_ENABLED
typedef struct _xmlXPathContext xmlXPathContext;
typedef xmlXPathContext *xmlXPathContextPtr;
@ -554,8 +549,7 @@ XMLPUBFUN int
xmlXPathContextPtr ctxt);
XMLPUBFUN void
xmlXPathFreeCompExpr (xmlXPathCompExprPtr comp);
#endif /* LIBXML_XPATH_ENABLED */
#if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
XML_DEPRECATED
XMLPUBFUN void
xmlXPathInit (void);
@ -568,5 +562,5 @@ XMLPUBFUN int
}
#endif
#endif /* LIBXML_XPATH_ENABLED or LIBXML_SCHEMAS_ENABLED*/
#endif /* LIBXML_XPATH_ENABLED */
#endif /* ! __XML_XPATH_H__ */

View File

@ -47629,7 +47629,7 @@ static int
test_xmlXPathInit(void) {
int test_ret = 0;
#if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
#if defined(LIBXML_XPATH_ENABLED)
int mem_base;
mem_base = xmlMemBlocks();
@ -47654,7 +47654,7 @@ static int
test_xmlXPathIsInf(void) {
int test_ret = 0;
#if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
#if defined(LIBXML_XPATH_ENABLED)
int mem_base;
int ret_val;
double val; /* a double value */
@ -47688,7 +47688,7 @@ static int
test_xmlXPathIsNaN(void) {
int test_ret = 0;
#if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
#if defined(LIBXML_XPATH_ENABLED)
int mem_base;
int ret_val;
double val; /* a double value */

View File

@ -589,7 +589,7 @@ xmlInitParser(void) {
xmlInitGlobalsInternal();
xmlInitDictInternal();
xmlInitEncodingInternal();
#if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
#if defined(LIBXML_XPATH_ENABLED)
xmlInitXPathInternal();
#endif
xmlInitIOCallbacks();

View File

@ -36,10 +36,8 @@
#include "private/error.h"
#ifndef LIBXML_XPATH_ENABLED
extern double xmlXPathNAN;
extern double xmlXPathPINF;
extern double xmlXPathNINF;
#ifndef isnan
#define isnan(x) (!((x) == (x)))
#endif
#define XML_SCHEMAS_NAMESPACE_NAME \
@ -124,6 +122,11 @@ struct _xmlSchemaVal {
};
static int xmlSchemaTypesInitialized = 0;
static double xmlSchemaNAN = 0.0;
static double xmlSchemaPINF = 0.0;
static double xmlSchemaNINF = 0.0;
static xmlHashTablePtr xmlSchemaTypesBank = NULL;
/*
@ -521,6 +524,19 @@ xmlSchemaInitTypes(void)
{
if (xmlSchemaTypesInitialized != 0)
return (0);
#if defined(NAN) && defined(INFINITY)
xmlSchemaNAN = NAN;
xmlSchemaPINF = INFINITY;
xmlSchemaNINF = -INFINITY;
#else
/* MSVC doesn't allow division by zero in constant expressions. */
double zero = 0.0;
xmlSchemaNAN = 0.0 / zero;
xmlSchemaPINF = 1.0 / zero;
xmlSchemaNINF = -xmlSchemaPINF;
#endif
xmlSchemaTypesBank = xmlHashCreate(40);
if (xmlSchemaTypesBank == NULL) {
xmlSchemaTypeErrMemory();
@ -2709,7 +2725,7 @@ xmlSchemaValAtomicType(xmlSchemaTypePtr type, const xmlChar * value,
if (type == xmlSchemaTypeFloatDef) {
v = xmlSchemaNewValue(XML_SCHEMAS_FLOAT);
if (v != NULL) {
v->value.f = (float) xmlXPathNAN;
v->value.f = (float) xmlSchemaNAN;
} else {
xmlSchemaFreeValue(v);
goto error;
@ -2717,7 +2733,7 @@ xmlSchemaValAtomicType(xmlSchemaTypePtr type, const xmlChar * value,
} else {
v = xmlSchemaNewValue(XML_SCHEMAS_DOUBLE);
if (v != NULL) {
v->value.d = xmlXPathNAN;
v->value.d = xmlSchemaNAN;
} else {
xmlSchemaFreeValue(v);
goto error;
@ -2740,9 +2756,9 @@ xmlSchemaValAtomicType(xmlSchemaTypePtr type, const xmlChar * value,
v = xmlSchemaNewValue(XML_SCHEMAS_FLOAT);
if (v != NULL) {
if (neg)
v->value.f = (float) xmlXPathNINF;
v->value.f = (float) xmlSchemaNINF;
else
v->value.f = (float) xmlXPathPINF;
v->value.f = (float) xmlSchemaPINF;
} else {
xmlSchemaFreeValue(v);
goto error;
@ -2751,9 +2767,9 @@ xmlSchemaValAtomicType(xmlSchemaTypePtr type, const xmlChar * value,
v = xmlSchemaNewValue(XML_SCHEMAS_DOUBLE);
if (v != NULL) {
if (neg)
v->value.d = xmlXPathNINF;
v->value.d = xmlSchemaNINF;
else
v->value.d = xmlXPathPINF;
v->value.d = xmlSchemaPINF;
} else {
xmlSchemaFreeValue(v);
goto error;
@ -4818,27 +4834,13 @@ xmlSchemaCompareFloats(xmlSchemaValPtr x, xmlSchemaValPtr y) {
/*
* Check for special cases.
*/
if (xmlXPathIsNaN(d1)) {
if (xmlXPathIsNaN(d2))
if (isnan(d1)) {
if (isnan(d2))
return(0);
return(1);
}
if (xmlXPathIsNaN(d2))
if (isnan(d2))
return(-1);
if (d1 == xmlXPathPINF) {
if (d2 == xmlXPathPINF)
return(0);
return(1);
}
if (d2 == xmlXPathPINF)
return(-1);
if (d1 == xmlXPathNINF) {
if (d2 == xmlXPathNINF)
return(0);
return(-1);
}
if (d2 == xmlXPathNINF)
return(1);
/*
* basic tests, the last one we should have equality, but
@ -5777,86 +5779,6 @@ xmlSchemaValidateFacetWhtsp(xmlSchemaFacetPtr facet,
value, val, ws));
}
#if 0
#ifndef DBL_DIG
#define DBL_DIG 16
#endif
#ifndef DBL_EPSILON
#define DBL_EPSILON 1E-9
#endif
#define INTEGER_DIGITS DBL_DIG
#define FRACTION_DIGITS (DBL_DIG + 1)
#define EXPONENT_DIGITS (3 + 2)
/**
* xmlXPathFormatNumber:
* @number: number to format
* @buffer: output buffer
* @buffersize: size of output buffer
*
* Convert the number into a string representation.
*/
static void
xmlSchemaFormatFloat(double number, char buffer[], int buffersize)
{
switch (xmlXPathIsInf(number)) {
case 1:
if (buffersize > (int)sizeof("INF"))
snprintf(buffer, buffersize, "INF");
break;
case -1:
if (buffersize > (int)sizeof("-INF"))
snprintf(buffer, buffersize, "-INF");
break;
default:
if (xmlXPathIsNaN(number)) {
if (buffersize > (int)sizeof("NaN"))
snprintf(buffer, buffersize, "NaN");
} else if (number == 0) {
snprintf(buffer, buffersize, "0.0E0");
} else {
/* 3 is sign, decimal point, and terminating zero */
char work[DBL_DIG + EXPONENT_DIGITS + 3];
int integer_place, fraction_place;
char *ptr;
char *after_fraction;
double absolute_value;
int size;
absolute_value = fabs(number);
/*
* Result is in work, and after_fraction points
* just past the fractional part.
* Use scientific notation
*/
integer_place = DBL_DIG + EXPONENT_DIGITS + 1;
fraction_place = DBL_DIG - 1;
snprintf(work, sizeof(work),"%*.*e",
integer_place, fraction_place, number);
after_fraction = strchr(work + DBL_DIG, 'e');
/* Remove fractional trailing zeroes */
ptr = after_fraction;
while (*(--ptr) == '0')
;
if (*ptr != '.')
ptr++;
while ((*ptr++ = *after_fraction++) != 0);
/* Finally copy result back to caller */
size = strlen(work) + 1;
if (size > buffersize) {
work[buffersize - 1] = 0;
size = buffersize;
}
memmove(buffer, work, size);
}
break;
}
}
#endif
/**
* xmlSchemaGetCanonValue:
* @val: the precomputed value

View File

@ -131,7 +131,7 @@
* any use of the macros IS_ASCII_CHARACTER and IS_ASCII_DIGIT)
*/
#if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
#if defined(LIBXML_XPATH_ENABLED)
/************************************************************************
* *
@ -212,10 +212,6 @@ xmlXPathIsInf(double val) {
#endif
}
#endif /* SCHEMAS or XPATH */
#ifdef LIBXML_XPATH_ENABLED
/*
* TODO: when compatibility allows remove all "fake node libxslt" strings
* the test should just be name[0] = ' '