https://github.com/python/cpython/commit/df349036b3f912e539643d91b84cbce32e4a1051
commit: df349036b3f912e539643d91b84cbce32e4a1051
branch: 3.13
author: Bénédikt Tran <[email protected]>
committer: Yhg1s <[email protected]>
date: 2025-09-18T12:47:12+01:00
summary:

[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 7a3b03509e5e3e72d8c47137579cccb52548a318.
(cherry picked from commit d54b1091d43b9d8f0da0ba081565bccca3f138fd)

files:
A Misc/NEWS.d/next/C API/2025-07-08-22-07-54.gh-issue-136006.XRU5w4.rst
M Include/pymath.h

diff --git a/Include/pymath.h b/Include/pymath.h
index 4c1e3d9984894b..cfae2477d7fce3 100644
--- a/Include/pymath.h
+++ b/Include/pymath.h
@@ -54,9 +54,24 @@
 
 /* Py_NAN: Value that evaluates to a quiet Not-a-Number (NaN).  The sign is
  * undefined and normally not relevant, but e.g. fixed for float("nan").
+ *
+ * Note: On Solaris, NAN is a function address, hence arithmetic is impossible.
+ * For that reason, we instead use the built-in call if available or fallback
+ * to a generic NaN computed from strtod() as a last resort.
+ *
+ * See https://github.com/python/cpython/issues/136006 for details.
  */
 #if !defined(Py_NAN)
-#    define Py_NAN ((double)NAN)
+#  if defined(__sun)
+#    if _Py__has_builtin(__builtin_nanf)
+#       define Py_NAN   ((double)__builtin_nanf(""))
+#    else
+#       include <stdlib.h>
+#       define Py_NAN   (strtod("NAN", NULL))
+#    endif
+#  else
+#    define Py_NAN      ((double)NAN)
+#  endif
 #endif
 
 #endif /* Py_PYMATH_H */
diff --git a/Misc/NEWS.d/next/C 
API/2025-07-08-22-07-54.gh-issue-136006.XRU5w4.rst b/Misc/NEWS.d/next/C 
API/2025-07-08-22-07-54.gh-issue-136006.XRU5w4.rst
new file mode 100644
index 00000000000000..2165e535b12245
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2025-07-08-22-07-54.gh-issue-136006.XRU5w4.rst     
@@ -0,0 +1,2 @@
+On Solaris, the :c:macro:`!Py_NAN` macro now expands to a :c:type:`!double`
+instead of a function address. Patch by Bénédikt Tran.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to