[Python-checkins] bpo-46656: Remove Py_NO_NAN macro (GH-31160)

vstinner webhook-mailer at python.org
Thu Feb 24 19:33:02 EST 2022


https://github.com/python/cpython/commit/1b2611eb0283055835e5df632a7a735db8c894b8
commit: 1b2611eb0283055835e5df632a7a735db8c894b8
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2022-02-25T01:32:57+01:00
summary:

bpo-46656: Remove Py_NO_NAN macro (GH-31160)

Building Python now requires support for floating point Not-a-Number
(NaN): remove the Py_NO_NAN macro.

files:
A Misc/NEWS.d/next/Build/2022-02-06-14-04-20.bpo-46656.ajJjkh.rst
M Doc/whatsnew/3.11.rst
M Include/floatobject.h
M Include/pymath.h
M Misc/NEWS.d/next/Build/2022-02-04-21-26-50.bpo-46640.HXUmQp.rst
M Modules/cmathmodule.c
M Modules/mathmodule.c
M Objects/floatobject.c
M Python/pystrtod.c

diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst
index c717aad9c87f7..0556a44d4c7d4 100644
--- a/Doc/whatsnew/3.11.rst
+++ b/Doc/whatsnew/3.11.rst
@@ -633,11 +633,13 @@ Build Changes
   (Contributed by Victor Stinner in :issue:`45440`.)
 
 * Building Python now requires a C99 ``<math.h>`` header file providing
-  a ``NAN`` constant, or the ``__builtin_nan()`` built-in function. If a
-  platform does not support Not-a-Number (NaN), the ``Py_NO_NAN`` macro can be
-  defined in the ``pyconfig.h`` file.
+  a ``NAN`` constant, or the ``__builtin_nan()`` built-in function.
   (Contributed by Victor Stinner in :issue:`46640`.)
 
+* Building Python now requires support for floating point Not-a-Number (NaN):
+  remove the ``Py_NO_NAN`` macro.
+  (Contributed by Victor Stinner in :issue:`46656`.)
+
 * Freelists for object structs can now be disabled. A new :program:`configure`
   option :option:`!--without-freelists` can be used to disable all freelists
   except empty tuple singleton.
diff --git a/Include/floatobject.h b/Include/floatobject.h
index 3b6ca478eaef2..9d2fff3097e8e 100644
--- a/Include/floatobject.h
+++ b/Include/floatobject.h
@@ -16,9 +16,7 @@ PyAPI_DATA(PyTypeObject) PyFloat_Type;
 #define PyFloat_Check(op) PyObject_TypeCheck(op, &PyFloat_Type)
 #define PyFloat_CheckExact(op) Py_IS_TYPE(op, &PyFloat_Type)
 
-#ifdef Py_NAN
-#  define Py_RETURN_NAN return PyFloat_FromDouble(Py_NAN)
-#endif
+#define Py_RETURN_NAN return PyFloat_FromDouble(Py_NAN)
 
 #define Py_RETURN_INF(sign)                          \
     do {                                             \
diff --git a/Include/pymath.h b/Include/pymath.h
index edd0841be9259..772b67e497756 100644
--- a/Include/pymath.h
+++ b/Include/pymath.h
@@ -50,11 +50,8 @@
 #  define Py_HUGE_VAL HUGE_VAL
 #endif
 
-/* Py_NAN
- * A value that evaluates to a quiet Not-a-Number (NaN).
- * Define Py_NO_NAN in pyconfig.h if your platform doesn't support NaNs.
- */
-#if !defined(Py_NAN) && !defined(Py_NO_NAN)
+// Py_NAN: Value that evaluates to a quiet Not-a-Number (NaN).
+#if !defined(Py_NAN)
 #  if _Py__has_builtin(__builtin_nan)
      // Built-in implementation of the ISO C99 function nan(): quiet NaN.
 #    define Py_NAN (__builtin_nan(""))
diff --git a/Misc/NEWS.d/next/Build/2022-02-04-21-26-50.bpo-46640.HXUmQp.rst b/Misc/NEWS.d/next/Build/2022-02-04-21-26-50.bpo-46640.HXUmQp.rst
index c7381110ebbcb..9f11c72f131eb 100644
--- a/Misc/NEWS.d/next/Build/2022-02-04-21-26-50.bpo-46640.HXUmQp.rst
+++ b/Misc/NEWS.d/next/Build/2022-02-04-21-26-50.bpo-46640.HXUmQp.rst
@@ -1,4 +1,3 @@
 Building Python now requires a C99 ``<math.h>`` header file providing a ``NAN``
-constant, or the ``__builtin_nan()`` built-in function. If a platform does not
-support Not-a-Number (NaN), the ``Py_NO_NAN`` macro can be defined in the
-``pyconfig.h`` file. Patch by Victor Stinner.
+constant, or the ``__builtin_nan()`` built-in function.
+Patch by Victor Stinner.
diff --git a/Misc/NEWS.d/next/Build/2022-02-06-14-04-20.bpo-46656.ajJjkh.rst b/Misc/NEWS.d/next/Build/2022-02-06-14-04-20.bpo-46656.ajJjkh.rst
new file mode 100644
index 0000000000000..98e37862daea7
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2022-02-06-14-04-20.bpo-46656.ajJjkh.rst
@@ -0,0 +1,2 @@
+Building Python now requires support for floating point Not-a-Number (NaN):
+remove the ``Py_NO_NAN`` macro. Patch by by Victor Stinner.
diff --git a/Modules/cmathmodule.c b/Modules/cmathmodule.c
index c0c0c353d196c..2038ac26e6585 100644
--- a/Modules/cmathmodule.c
+++ b/Modules/cmathmodule.c
@@ -113,7 +113,7 @@ c_infj(void)
     return r;
 }
 
-#if _PY_SHORT_FLOAT_REPR == 1 || defined(Py_NAN)
+#if _PY_SHORT_FLOAT_REPR == 1
 
 static double
 m_nan(void)
@@ -1282,7 +1282,7 @@ cmath_exec(PyObject *mod)
                            PyComplex_FromCComplex(c_infj())) < 0) {
         return -1;
     }
-#if _PY_SHORT_FLOAT_REPR == 1 || defined(Py_NAN)
+#if _PY_SHORT_FLOAT_REPR == 1
     if (PyModule_AddObject(mod, "nan", PyFloat_FromDouble(m_nan())) < 0) {
         return -1;
     }
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 24ae1460e5a89..f0aaf23845f6d 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -283,7 +283,7 @@ m_inf(void)
 /* Constant nan value, generated in the same way as float('nan'). */
 /* We don't currently assume that Py_NAN is defined everywhere. */
 
-#if _PY_SHORT_FLOAT_REPR == 1 || defined(Py_NAN)
+#if _PY_SHORT_FLOAT_REPR == 1
 
 static double
 m_nan(void)
@@ -3838,7 +3838,7 @@ math_exec(PyObject *module)
     if (PyModule_AddObject(module, "inf", PyFloat_FromDouble(m_inf())) < 0) {
         return -1;
     }
-#if _PY_SHORT_FLOAT_REPR == 1 || defined(Py_NAN)
+#if _PY_SHORT_FLOAT_REPR == 1
     if (PyModule_AddObject(module, "nan", PyFloat_FromDouble(m_nan())) < 0) {
         return -1;
     }
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 64d4c3e5a8cef..6d796566c4eb6 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -2486,15 +2486,7 @@ _PyFloat_Unpack2(const unsigned char *p, int le)
         }
         else {
             /* NaN */
-#ifdef Py_NAN
             return sign ? -Py_NAN : Py_NAN;
-#else
-            PyErr_SetString(
-                PyExc_ValueError,
-                "can't unpack IEEE 754 NaN "
-                "on platform that does not support NaNs");
-            return -1;
-#endif  // !defined(Py_NAN)
         }
 #else  // _PY_SHORT_FLOAT_REPR == 1
         if (f == 0) {
diff --git a/Python/pystrtod.c b/Python/pystrtod.c
index 7469d6259d673..1b27f0a3ad36a 100644
--- a/Python/pystrtod.c
+++ b/Python/pystrtod.c
@@ -82,12 +82,10 @@ _Py_parse_inf_or_nan(const char *p, char **endptr)
             s += 5;
         retval = negate ? -Py_HUGE_VAL : Py_HUGE_VAL;
     }
-#ifdef Py_NAN
     else if (case_insensitive_match(s, "nan")) {
         s += 3;
         retval = negate ? -Py_NAN : Py_NAN;
     }
-#endif
     else {
         s = p;
         retval = -1.0;



More information about the Python-checkins mailing list