-
-
Notifications
You must be signed in to change notification settings - Fork 897
/
0009-avoid-isnan-isinf.patch
81 lines (63 loc) · 2.67 KB
/
0009-avoid-isnan-isinf.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
This patch is a result of rake-compiler-dock using centos 7 (manylinux2014) to cross-compile.
Centos, for reasons I have not been able to discern, implements `isnan` and `isinf` as a function
and not as a macro. Debian knows how to resolve that function at dynamic-link time (despite using a
macro at compile time), but musl-based systems (like alpine) do not. Running `nm` on nokogiri.so
created on such a centos system shows:
```
U __isinf@@GLIBC_2.2.5
U __isnan@@GLIBC_2.2.5
```
(see https://github.com/sparklemotion/nokogiri/pull/2142 for more info)
This patch avoids using glibc's `isnan` and `isinf` calls, instead using libxml2's fallback
implementation. There's history here, see libxml2 commit 8813f39:
commit 8813f39
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Date: 2017-09-21 00:11:26 +0200
Simplify XPath NaN, inf and -0 handling
Use C99 macros NAN, INFINITY, isnan, isinf. If they're not available:
- Assume that (0.0 / 0.0) generates a NaN and !(x == x) tests for NaN.
- Use C89's HUGE_VAL for INFINITY.
Remove manual handling of NaN, infinity and negative zero in functions
xmlXPathValueFlipSign and xmlXPathDivValues.
Remove xmlXPathGetSign. All the tests for negative zero can be replaced
with a test for negative or positive zero.
Simplify xmlXPathRoundFunction.
Remove Trio dependency.
This should work on IEEE 754 compliant implementations even if the C99
macros aren't available, but will likely break some ancient platforms.
If problems arise, my plan is to port the relevant trionan.c solution
to xpath.c. Note that non-compliant implementations are impossible
to fully support, anyway, since XPath requires IEEE 754.
This patch would be unnecessary if any of the following was true:
* centos implements these as macros, and doesn't generate an unresolved symbol for either in the shared library
* we had a way to ensure `__isinf` and `__isnan` resolve on musl (e.g., we implement them locally)
diff --git a/xpath.c b/xpath.c
index 9f64ab9..5b6d999 100644
--- a/xpath.c
+++ b/xpath.c
@@ -509,11 +509,7 @@ xmlXPathInit(void) {
*/
int
xmlXPathIsNaN(double val) {
-#ifdef isnan
- return isnan(val);
-#else
return !(val == val);
-#endif
}
/**
@@ -524,15 +520,11 @@ xmlXPathIsNaN(double val) {
*/
int
xmlXPathIsInf(double val) {
-#ifdef isinf
- return isinf(val) ? (val > 0 ? 1 : -1) : 0;
-#else
if (val >= INFINITY)
return 1;
if (val <= -INFINITY)
return -1;
return 0;
-#endif
}
#endif /* SCHEMAS or XPATH */