This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: [C API] Py_IS_INFINITY() macro doesn't work in the limited C API if isinf() is not defined
Type: Stage: resolved
Components: C API Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: vstinner
Priority: normal Keywords: patch

Created on 2021-10-11 23:51 by vstinner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 28894 merged vstinner, 2021-10-12 00:22
PR 28977 merged vstinner, 2021-10-15 13:10
Messages (5)
msg403704 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-11 23:51
If the HAVE_DECL_ISINF macro is not defined in pyconfig.h, the Py_IS_INFINITY macro is defined as:

#define Py_IS_INFINITY(X) \
    ((X) && (Py_FORCE_DOUBLE(X)*0.5 == Py_FORCE_DOUBLE(X)))

Problem: Py_FORCE_DOUBLE() is excluded from the limited C API (and the stable ABI).

I see different options:

* Implement Py_IS_INFINITY() as an opaque function if the HAVE_DECL_ISINF macro is not defined. I did something similar in Py_INCREF() to support the limited C API with a debug build of Python: call _Py_IncRef() opaque function.

* Make Py_FORCE_DOUBLE() private and add it to the limited C API as an implementation detail.

* Add Py_FORCE_DOUBLE() macro to the limited C API: the current implementation is fragile, it depends on how Python.h is included. Also, I dislike macros in the limited C API.

I would prefer to *remove* Py_FORCE_DOUBLE() to all APIs, than adding it to the limited C API.
msg403706 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-12 00:15
The Py_FORCE_DOUBLE() macro was added in bpo-5724 by the change:

commit e05e8409e1b47a2c018ad8a67016546217165c60
Author: Mark Dickinson <dickinsm@gmail.com>
Date:   Mon May 4 13:30:43 2009 +0000

    Issue #5724: Fix cmath failures on Solaris 10.
msg403873 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-13 21:27
New changeset 194a9526d8ee6abbbe58ef48520ec87a7e83f327 by Victor Stinner in branch 'main':
bpo-45440: Require math.h isinf() to build (GH-28894)
https://github.com/python/cpython/commit/194a9526d8ee6abbbe58ef48520ec87a7e83f327
msg403874 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-13 21:30
> [C API] Py_IS_INFINITY() macro doesn't work in the limited C API if isinf() is not defined

Well, the final fix is to remove the code path when isinf() is not available and require it to build Python ;-)
msg404041 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-15 17:45
New changeset 00ffc4513df7b89a168e88da4d1e3ac367f7682f by Victor Stinner in branch 'main':
bpo-45440: Remove pymath.c fallbacks (GH-28977)
https://github.com/python/cpython/commit/00ffc4513df7b89a168e88da4d1e3ac367f7682f
History
Date User Action Args
2022-04-11 14:59:51adminsetgithub: 89603
2021-10-15 17:45:37vstinnersetmessages: + msg404041
2021-10-15 13:10:22vstinnersetpull_requests: + pull_request27265
2021-10-13 21:30:01vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg403874

stage: patch review -> resolved
2021-10-13 21:27:57vstinnersetmessages: + msg403873
2021-10-12 00:22:16vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request27189
2021-10-12 00:15:12vstinnersetmessages: + msg403706
2021-10-11 23:51:20vstinnercreate