[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

STINNER Victor report at bugs.python.org
Fri Oct 8 09:39:11 EDT 2021


New submission from STINNER Victor <vstinner at python.org>:

I propose to remove the following macros from the Python C API:

* Py_OVERFLOWED()
* _Py_SET_EDOM_FOR_NAN()
* Py_SET_ERRNO_ON_MATH_ERROR()
* Py_SET_ERANGE_IF_OVERFLOW()
* Py_ADJUST_ERANGE1()
* Py_ADJUST_ERANGE2()

Only Py_ADJUST_ERANGE1() and Py_ADJUST_ERANGE2() are still used by Python itself, other macros are no longer used since Python 2.7:

* Py_OVERFLOWED(): no longer used since Python 2.7
* _Py_SET_EDOM_FOR_NAN(): used by Py_SET_ERRNO_ON_MATH_ERROR() which is no longer used
* Py_SET_ERRNO_ON_MATH_ERROR(): no longer used since Python 2.6
* Py_SET_ERANGE_IF_OVERFLOW(): no longer used since Python 2.4
* Py_ADJUST_ERANGE1(): used by Objects/floatobject.c
* Py_ADJUST_ERANGE2(): used by Objects/complexobject.c

I searched for these macros in the PyPI top 5000 modules: none of these macros are used. There is a single match: frozendict-2.0.6 which contains a Include/pyport.h copy, but it doesn't use these macros.

--

Py_OVERFLOWED() was used by long_true_divide() and PyLong_AsDouble() in Python 2.6, but Python 2.7 no longer used them.


(1) Py_OVERFLOWED() call in long_true_divide() was removed in Python 2.7 by bpo-1811:

commit 465728364749e903fb4293b2f7a266b58de6bde4
Author: Mark Dickinson <dickinsm at gmail.com>
Date:   Sun Dec 27 14:55:57 2009 +0000

    Issue #1811:  Improve accuracy and consistency of true division for integers.


(2) Py_OVERFLOWED() call in PyLong_AsDouble() was removed in Python 2.7 by bpo-3166:

commit 6736cf8d20b67b74e8e959622132963285156242
Author: Mark Dickinson <dickinsm at gmail.com>
Date:   Mon Apr 20 21:13:33 2009 +0000

    Issue #3166: Make long -> float (and int -> float) conversions
    correctly rounded, using round-half-to-even.  This ensures that the
    value of float(n) doesn't depend on whether we're using 15-bit digits
    or 30-bit digits for Python longs.

--

Py_SET_ERRNO_ON_MATH_ERROR() and Py_SET_ERANGE_IF_OVERFLOW() were used in Objects/mathmodule.c in Python 2.5.


(1) The last call to Py_SET_ERRNO_ON_MATH_ERROR() was removed by in Python 2.6 by:

commit 6f34109384f3a78d5f4f8bdd418a89caca19631e
Author: Christian Heimes <christian at cheimes.de>
Date:   Fri Apr 18 23:13:07 2008 +0000

    I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
    
    The patch also adds acosh, asinh, atanh, log1p and copysign to all platforms. Finally it fixes differences between platforms like different results or exceptions for edge cases. Have fun :)


(2) The last call to Py_SET_ERANGE_IF_OVERFLOW() was removed in Python 2.4 by:

commit 77d9a3effa21b8987ceac26d67ad676e1c5afb49
Author: Hye-Shik Chang <hyeshik at gmail.com>
Date:   Mon Mar 22 08:43:55 2004 +0000

    Patch #871657: Set EDOM for `nan' return values on FreeBSD and OpenBSD.
    This fixes a problem that math.sqrt(-1) doesn't raise math.error.

----------
components: C API
messages: 403473
nosy: vstinner
priority: normal
severity: normal
status: open
title: [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()
versions: Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45412>
_______________________________________


More information about the Python-bugs-list mailing list