You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The Python C API should only define macros with a name starting wit Py #157695
Currently, the Python C API defines 472 macros with a name which doesn't start with Py, PY, _Py or _PY prefix.
I propose adding a check to prevent adding new macros which doesn't respect this convention. Existing invalid names will be added to an ignore list for now.
The following Include/ header files are not included by Python.h and defines many macros which don't start with Py prefix:
opcode.h
opcode_ids.h
errcode.h
osdefs.h
structmember.h
To clean up the C API, a simple move would be to move these header files to the internal C API. Problem: they are actually used in the wild (well, as usual ;-)).
I checked PyPI top 15,000 projects (at 2026-09-17) to find projects including these header files.
Projects (10) including opcode.h:
coverage (7.16.1)
crosshair_tool (0.0.110)
ddtrace (4.15.0)
nuitka (4.2.1)
pygments (2.21.0)
pyobjc_core (12.2.2)
pywinpty (3.0.5)
rook (0.1.209)
slipcover (1.1.0)
yappi (1.7.6)
I found no project including errcode.h.
Projects (4) including osdefs.h:
freeze_core (0.7.5)
mod_wsgi (6.0.6)
nuitka (4.2.1)
scandir (1.10.0)
Projects (169) including structmember.h:
MySQL-python (1.2.5)
PyICU-binary (2.7.4)
PyQt5 (5.15.11)
... the list is quite long, I prefer to truncate it! :-)
For example, I searched for include\s+["<]errcode\.h[">] for errcode.h include.
structmember.h has been deprecated in docs (which we now call soft deprectation) since 3.12. See also the comment in the header.
IMO, exposing legacy non-Py_-prefixed names via an opt-in #include is perfectly fine.
I replacedAC_CHECK_FUNCS_ONCE(acospi asinpi atanpi atan2pi cospi sinpi tanpi) with PY_CHECK_FUNC_PRIVATE([acospi]) (and similar call for the other functions) where PY_CHECK_FUNC_PRIVATE() is a new function based on PY_CHECK_FUNC().
I expected PY_CHECK_FUNC() to be the same as AC_CHECK_FUNC(), but it works differently. AC_CHECK_FUNC() doesn't need to include the system header file declaring the function. It only checks if the C library has a symbol with the expected name (it doesn't check the API). PY_CHECK_FUNC() requires to include the right header file, otherwise the function is not detected.
I had to fix configure.ac to use PY_CHECK_FUNC_PRIVATE([acospi], [@%:@include <math.h>]) instead.
The problem is that it's not always easy to pick the right header file to get a function, or different operating systems can use different header files.
It would be nice to have a function similar to AC_CHECK_FUNC() (only check if the function exists, don't check its API), but define _Py_HAVE_xxx macro instead of HAVE_xxx.
For now, I put my #157939 PR on hold until I better understand this issue.
Activity
vstinner commentedon Sep 17, 2026
The following Include/ header files are not included by Python.h and defines many macros which don't start with
Pyprefix:To clean up the C API, a simple move would be to move these header files to the internal C API. Problem: they are actually used in the wild (well, as usual ;-)).
I checked PyPI top 15,000 projects (at 2026-09-17) to find projects including these header files.
Projects (10) including opcode.h:
I found no project including errcode.h.
Projects (4) including osdefs.h:
Projects (169) including structmember.h:
For example, I searched for
include\s+["<]errcode\.h[">]for errcode.h include.vstinner commentedon Sep 17, 2026
This check is similar to "make smelly" which fails if libpython exports symbols with a name which doesn't start with "Py".
vstinner commentedon Sep 17, 2026
cc @encukou
vstinner commentedon Sep 17, 2026
See issue gh-149685 "Use _Py prefix for private C API added in 3.15" for a recent change (last May) about a similar issue.
gh-157695: Rename HAVE_FLOAT16 macro to _Py_HAVE_FLOAT16 (#157752)
gh-157695: Check that C API macros start with "Py" (#157696)
gh-157695: Rename HAVE_ICONV to _Py_HAVE_ICONV (#157821)
gh-157695: Rename HAVE_ACOSPI to _Py_HAVE_ACOSPI (#157858)
Locked-chess-official commentedon Sep 22, 2026
I have an immature idea: For configures, we can move the private configure macros into a new file named
pycore_pyconfig.hencukou commentedon Sep 22, 2026
structmember.hhas been deprecated in docs (which we now call soft deprectation) since 3.12. See also the comment in the header.IMO, exposing legacy non-
Py_-prefixed names via an opt-in#includeis perfectly fine.vstinner commentedon Sep 22, 2026
I'm not sure that autotools support multiple output files where some macros are defined in a file, and other macros are defined in another file.
configure.acusesAC_CONFIG_HEADERS([pyconfig.h]).gh-157695: Fix acospi() detection in configure.ac (#157948)
Locked-chess-official commentedon Sep 23, 2026
According to #141488 , the list of macros should be renamed anyway (it may has mistakes):
Details
HAVE_SYS_TYPES_HMS_WINDOWS
_POSIX_THREADS
WITH_PYMALLOC
WITH_MIMALLOC
HAVE_PTHREAD_H
DYNAMIC_ANNOTATIONS_ENABLED
HAVE_SYS_STAT_H
S_IFMT
S_IFLNK
S_ISREG
S_ISDIR
S_ISCHR
S_ISLNK
HAVE_FORK
STACKLESS
SEP
MAXPATHLEN
DELIM
_BSD_WCHAR_T_DEFINED_
NCURSES_VERSION
MVWDELCH_IS_EXPRESSION
CURSES_MODULE
WITH_DTRACE
WITH_DOC_STRINGS
UCHAR_MAX
HAVE_LONG_LONG
HAVE_PY_SSIZE_T
SIGNED_RIGHT_SHIFT_ZERO_FILLS
INT_MAX
LONG_MAX
LONG_MIN
LONG_BIT
WORDS_BIGENDIAN
WITH_THREAD
USE_STACKCHECK
SIZEOF_WCHAR_T
HAVE_USABLE_WCHAR_T
HAVE_WCHAR_H
vstinner commentedon Sep 23, 2026
I replaced
AC_CHECK_FUNCS_ONCE(acospi asinpi atanpi atan2pi cospi sinpi tanpi)withPY_CHECK_FUNC_PRIVATE([acospi])(and similar call for the other functions) wherePY_CHECK_FUNC_PRIVATE()is a new function based onPY_CHECK_FUNC().I expected
PY_CHECK_FUNC()to be the same asAC_CHECK_FUNC(), but it works differently.AC_CHECK_FUNC()doesn't need to include the system header file declaring the function. It only checks if the C library has a symbol with the expected name (it doesn't check the API).PY_CHECK_FUNC()requires to include the right header file, otherwise the function is not detected.I had to fix configure.ac to use
PY_CHECK_FUNC_PRIVATE([acospi], [@%:@include <math.h>])instead.The problem is that it's not always easy to pick the right header file to get a function, or different operating systems can use different header files.
It would be nice to have a function similar to
AC_CHECK_FUNC()(only check if the function exists, don't check its API), but define_Py_HAVE_xxxmacro instead ofHAVE_xxx.For now, I put my #157939 PR on hold until I better understand this issue.
Merge branch 'main' into fix-iconv-stateful-incremental
gh-157695: Parse also _Py_HAVE_xxx variables in sysconfig (#158926)
[3.15] gh-158893: Make os.strerror() thread-safe (#159120)
[3.15] pythongh-158893: Make os.strerror() thread-safe (python#159120)
[3.14] gh-158893: Make os.strerror() thread-safe (#159120) (#159145)