New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[C API] Deprecate or remove PyFPE_START_PROTECT() and PyFPE_END_PROTECT() #87416
Comments
In Python 3.6, there was a WANT_SIGFPE_HANDLER macro defined if Python was built with ./configure --with-fpectl. By default, the macro was not defined. The fpectl module installed a SIGFPE signal handler which uses longjmp(). If the WANT_SIGFPE_HANDLER macro was defined, PyFPE_START_PROTECT() and PyFPE_END_PROTECT() macros used setjmp() to catch SIGFPE. All of this machinery was removed by bpo-29137 to fix ABI issues: commit 735ae8d
The PyFPE_START_PROTECT() and PyFPE_END_PROTECT() macros still exist for backward compatibility with Python 3.6 and older. Python/pyfpe.c contains the comment: /* These variables used to be used when Python was built with --with-fpectl,
I'm not convinced that these macros are part of the stable ABI. The PEP-384 doesn't exclude pyfpe.h explicitly, but it's also unclear if it's part of the stable ABI or not. "PyFPE_START_PROTECT" and "PyFPE_END_PROTECT" symbols are not part of the stable ABI at least: they are missing from PC/python3dll.c and Doc/data/stable_abi.dat. Well, these are macros which emitted directly code rather than calling an opaque function. That sounds really bad in term of stable ABI :-( Python 3.6 macros, when WANT_SIGFPE_HANDLER macro is defined: --- #include <signal.h>
#include <setjmp.h>
#include <math.h>
extern jmp_buf PyFPE_jbuf;
extern int PyFPE_counter;
extern double PyFPE_dummy(void *);
#define PyFPE_START_PROTECT(err_string, leave_stmt) \
if (!PyFPE_counter++ && setjmp(PyFPE_jbuf)) { \
PyErr_SetString(PyExc_FloatingPointError, err_string); \
PyFPE_counter = 0; \
leave_stmt; \
}
#define PyFPE_END_PROTECT(v) PyFPE_counter -= (int)PyFPE_dummy(&(v)); I propose to either deprecate these macros or remove them. These macros are not documented. In Python 3.6, the PyFPE macros were used in the Python stdlib, by files: Doc/library/fpectl.rst But it doesn't seem to be used outside Python. Note: In master, they are not used anywhere, they are only defined by Include/pyfpe.h. |
Latest commit related to these macros: commit be143ec
|
Another related change from bpo-37474: commit 5e0ea75
|
I explicitly excluded the PyFPE macros from the limited C API in Python 3.9: commit 488d02a
|
See also bpo-38835: "pyfpe.h: Exclude PyFPE_START_PROTECT and PyFPE_END_PROTECT from the Py_LIMITED_API". |
Using INADA-san recipe https://github.com/methane/notes/tree/master/2020/wchar-cache I found the 62 projects on the PyPI top 4000 which contain "PyFPE" pattern: asyncpg-0.22.0.tar.gz Example with asyncpg: $ rg PyFPE
asyncpg/pgproto/pgproto.c
39841: PyFPE_START_PROTECT("add", return NULL)
39843: PyFPE_END_PROTECT(result) asyncpg/protocol/protocol.c So it doesn't sound like a good idea to immediately remove these two macros. |
MAYBE we can update the annotation in pyfpe.h to address that we will remove those macros in python 4.0. The fpe have been removed, so those macros will be removed finally. |
If I remember correctly, cython-generated C code calls those macros at On Thu, Feb 18, 2021, 04:16 STINNER Victor <report@bugs.python.org> wrote:
|
I don't have the bandwidth to update Cython and mark the macro as deprecated. So I just close the issue. |
I'm about to kill them off in Cython - cython/cython#5841. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: