Skip to content

Commit df34903

Browse files
authored
[3.13] gh-136006: fix Py_NAN expansion on Solaris systems (GH-136575) (#138734)
On Solaris, `Py_NAN` may expand as a function address instead of a floating-point number. This amends commit 7a3b035. (cherry picked from commit d54b109)
1 parent 135198d commit df34903

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Include/pymath.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,24 @@
5454

5555
/* Py_NAN: Value that evaluates to a quiet Not-a-Number (NaN). The sign is
5656
* undefined and normally not relevant, but e.g. fixed for float("nan").
57+
*
58+
* Note: On Solaris, NAN is a function address, hence arithmetic is impossible.
59+
* For that reason, we instead use the built-in call if available or fallback
60+
* to a generic NaN computed from strtod() as a last resort.
61+
*
62+
* See https://github.com/python/cpython/issues/136006 for details.
5763
*/
5864
#if !defined(Py_NAN)
59-
# define Py_NAN ((double)NAN)
65+
# if defined(__sun)
66+
# if _Py__has_builtin(__builtin_nanf)
67+
# define Py_NAN ((double)__builtin_nanf(""))
68+
# else
69+
# include <stdlib.h>
70+
# define Py_NAN (strtod("NAN", NULL))
71+
# endif
72+
# else
73+
# define Py_NAN ((double)NAN)
74+
# endif
6075
#endif
6176

6277
#endif /* Py_PYMATH_H */
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
On Solaris, the :c:macro:`!Py_NAN` macro now expands to a :c:type:`!double`
2+
instead of a function address. Patch by Bénédikt Tran.

0 commit comments

Comments
 (0)