[Python-checkins] Remove unused internal macros (#102415)

mdickinson webhook-mailer at python.org
Sat Mar 4 07:20:30 EST 2023


https://github.com/python/cpython/commit/b022250e67449e0bc49a3c982fe9e6a2d6a7b71a
commit: b022250e67449e0bc49a3c982fe9e6a2d6a7b71a
branch: main
author: Mark Dickinson <dickinsm at gmail.com>
committer: mdickinson <dickinsm at gmail.com>
date: 2023-03-04T12:20:14Z
summary:

Remove unused internal macros (#102415)

Since #101826 was merged, the internal macro `_Py_InIntegralTypeRange` is unused, as are its supporting macros `_Py_IntegralTypeMax` and `_Py_IntegralTypeMin`. This PR removes them.

Note that `_Py_InIntegralTypeRange` doesn't actually work as advertised - it's not a safe way to avoid undefined behaviour in an integer to double conversion.

files:
M Include/internal/pycore_pymath.h

diff --git a/Include/internal/pycore_pymath.h b/Include/internal/pycore_pymath.h
index 5f3afe4df686..7a4e1c1eb714 100644
--- a/Include/internal/pycore_pymath.h
+++ b/Include/internal/pycore_pymath.h
@@ -56,21 +56,6 @@ static inline void _Py_ADJUST_ERANGE2(double x, double y)
     }
 }
 
-// Return the maximum value of integral type *type*.
-#define _Py_IntegralTypeMax(type) \
-    (_Py_IS_TYPE_SIGNED(type) ? (((((type)1 << (sizeof(type)*CHAR_BIT - 2)) - 1) << 1) + 1) : ~(type)0)
-
-// Return the minimum value of integral type *type*.
-#define _Py_IntegralTypeMin(type) \
-    (_Py_IS_TYPE_SIGNED(type) ? -_Py_IntegralTypeMax(type) - 1 : 0)
-
-// Check whether *v* is in the range of integral type *type*. This is most
-// useful if *v* is floating-point, since demoting a floating-point *v* to an
-// integral type that cannot represent *v*'s integral part is undefined
-// behavior.
-#define _Py_InIntegralTypeRange(type, v) \
-    (_Py_IntegralTypeMin(type) <= v && v <= _Py_IntegralTypeMax(type))
-
 
 //--- HAVE_PY_SET_53BIT_PRECISION macro ------------------------------------
 //



More information about the Python-checkins mailing list