1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-21 14:53:44 +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'/> <arg name='nargs' type='int' info='the number of arguments'/>
</function> </function>
<function name='xmlXPathInit' file='xpath' module='xpath'> <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> <info>DEPRECATED: Alias for xmlInitParser.</info>
<return type='void'/> <return type='void'/>
</function> </function>
@@ -17567,13 +17567,13 @@ Could we use @subtypes for this?'/>
<arg name='nodes2' type='xmlNodeSetPtr' info='a node-set'/> <arg name='nodes2' type='xmlNodeSetPtr' info='a node-set'/>
</function> </function>
<function name='xmlXPathIsInf' file='xpath' module='xpath'> <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> <info>Checks whether a double is an infinity.</info>
<return type='int' info='1 if the value is +Infinite, -1 if -Infinite, 0 otherwise'/> <return type='int' info='1 if the value is +Infinite, -1 if -Infinite, 0 otherwise'/>
<arg name='val' type='double' info='a double value'/> <arg name='val' type='double' info='a double value'/>
</function> </function>
<function name='xmlXPathIsNaN' file='xpath' module='xpath'> <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> <info>Checks whether a double is a NaN.</info>
<return type='int' info='1 if the value is a NaN, 0 otherwise'/> <return type='int' info='1 if the value is a NaN, 0 otherwise'/>
<arg name='val' type='double' info='a double value'/> <arg name='val' type='double' info='a double value'/>

View File

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

View File

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

View File

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

View File

@@ -36,10 +36,8 @@
#include "private/error.h" #include "private/error.h"
#ifndef LIBXML_XPATH_ENABLED #ifndef isnan
extern double xmlXPathNAN; #define isnan(x) (!((x) == (x)))
extern double xmlXPathPINF;
extern double xmlXPathNINF;
#endif #endif
#define XML_SCHEMAS_NAMESPACE_NAME \ #define XML_SCHEMAS_NAMESPACE_NAME \
@@ -124,6 +122,11 @@ struct _xmlSchemaVal {
}; };
static int xmlSchemaTypesInitialized = 0; static int xmlSchemaTypesInitialized = 0;
static double xmlSchemaNAN = 0.0;
static double xmlSchemaPINF = 0.0;
static double xmlSchemaNINF = 0.0;
static xmlHashTablePtr xmlSchemaTypesBank = NULL; static xmlHashTablePtr xmlSchemaTypesBank = NULL;
/* /*
@@ -521,6 +524,19 @@ xmlSchemaInitTypes(void)
{ {
if (xmlSchemaTypesInitialized != 0) if (xmlSchemaTypesInitialized != 0)
return (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); xmlSchemaTypesBank = xmlHashCreate(40);
if (xmlSchemaTypesBank == NULL) { if (xmlSchemaTypesBank == NULL) {
xmlSchemaTypeErrMemory(); xmlSchemaTypeErrMemory();
@@ -2709,7 +2725,7 @@ xmlSchemaValAtomicType(xmlSchemaTypePtr type, const xmlChar * value,
if (type == xmlSchemaTypeFloatDef) { if (type == xmlSchemaTypeFloatDef) {
v = xmlSchemaNewValue(XML_SCHEMAS_FLOAT); v = xmlSchemaNewValue(XML_SCHEMAS_FLOAT);
if (v != NULL) { if (v != NULL) {
v->value.f = (float) xmlXPathNAN; v->value.f = (float) xmlSchemaNAN;
} else { } else {
xmlSchemaFreeValue(v); xmlSchemaFreeValue(v);
goto error; goto error;
@@ -2717,7 +2733,7 @@ xmlSchemaValAtomicType(xmlSchemaTypePtr type, const xmlChar * value,
} else { } else {
v = xmlSchemaNewValue(XML_SCHEMAS_DOUBLE); v = xmlSchemaNewValue(XML_SCHEMAS_DOUBLE);
if (v != NULL) { if (v != NULL) {
v->value.d = xmlXPathNAN; v->value.d = xmlSchemaNAN;
} else { } else {
xmlSchemaFreeValue(v); xmlSchemaFreeValue(v);
goto error; goto error;
@@ -2740,9 +2756,9 @@ xmlSchemaValAtomicType(xmlSchemaTypePtr type, const xmlChar * value,
v = xmlSchemaNewValue(XML_SCHEMAS_FLOAT); v = xmlSchemaNewValue(XML_SCHEMAS_FLOAT);
if (v != NULL) { if (v != NULL) {
if (neg) if (neg)
v->value.f = (float) xmlXPathNINF; v->value.f = (float) xmlSchemaNINF;
else else
v->value.f = (float) xmlXPathPINF; v->value.f = (float) xmlSchemaPINF;
} else { } else {
xmlSchemaFreeValue(v); xmlSchemaFreeValue(v);
goto error; goto error;
@@ -2751,9 +2767,9 @@ xmlSchemaValAtomicType(xmlSchemaTypePtr type, const xmlChar * value,
v = xmlSchemaNewValue(XML_SCHEMAS_DOUBLE); v = xmlSchemaNewValue(XML_SCHEMAS_DOUBLE);
if (v != NULL) { if (v != NULL) {
if (neg) if (neg)
v->value.d = xmlXPathNINF; v->value.d = xmlSchemaNINF;
else else
v->value.d = xmlXPathPINF; v->value.d = xmlSchemaPINF;
} else { } else {
xmlSchemaFreeValue(v); xmlSchemaFreeValue(v);
goto error; goto error;
@@ -4818,27 +4834,13 @@ xmlSchemaCompareFloats(xmlSchemaValPtr x, xmlSchemaValPtr y) {
/* /*
* Check for special cases. * Check for special cases.
*/ */
if (xmlXPathIsNaN(d1)) { if (isnan(d1)) {
if (xmlXPathIsNaN(d2)) if (isnan(d2))
return(0); return(0);
return(1); return(1);
} }
if (xmlXPathIsNaN(d2)) if (isnan(d2))
return(-1); 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 * basic tests, the last one we should have equality, but
@@ -5777,86 +5779,6 @@ xmlSchemaValidateFacetWhtsp(xmlSchemaFacetPtr facet,
value, val, ws)); 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: * xmlSchemaGetCanonValue:
* @val: the precomputed value * @val: the precomputed value

View File

@@ -131,7 +131,7 @@
* any use of the macros IS_ASCII_CHARACTER and IS_ASCII_DIGIT) * 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
} }
#endif /* SCHEMAS or XPATH */
#ifdef LIBXML_XPATH_ENABLED
/* /*
* TODO: when compatibility allows remove all "fake node libxslt" strings * TODO: when compatibility allows remove all "fake node libxslt" strings
* the test should just be name[0] = ' ' * the test should just be name[0] = ' '