gh-47146: Soft-deprecate structmember.h, expose its contents via Python.h by encukou · Pull Request #99014 · python/cpython (original) (raw)
The structmember.h
header is deprecated, though it continues to be available and there are no plans to remove it. There are no deprecation warnings. Old code can stay unchanged (unless the extra include and non-namespaced macros bother you greatly). Specifically, no uses in CPython are updated -- that would just be unnecessary churn.
The header's contents are now available just by including Python.h
, with a PY_
prefix added if it was missing:
PyMemberDef
,PyMember_GetOne
,PyMember_SetOne
- Type macros like
PY_T_INT
,PY_T_DOUBLE
, etc. (previouslyT_INT
,T_DOUBLE
, etc.) - The flags
PY_READONLY
(previouslyREADONLY
) andPY_AUDIT_READ
(name unchanged)
Several items are not exposed from Python.h
:
T_OBJECT
(usePY_T_OBJECT_EX
)T_NONE
(previously undocumented, and pretty quirky)- The macro
WRITE_RESTRICTED
which does nothing. - The macros
RESTRICTED
andREAD_RESTRICTED
, equivalents ofPY_AUDIT_READ
. - In some configurations,
<stddef.h>
is not included fromPython.h
.
It should be included manually when usingoffsetof()
.
The PY_T_*
, PY_READONLY
and PY_AUDIT_READ
macros are added to the stable API manifest. This is just a clerical change, really -- Stable ABI extensions in the wild use structmember.h
, and PyMemberDef
& Py_tp_members
are already listed.
There is discussion on the issue to rename T_PYSSIZET
to PY_T_SSIZE
or similar. I chose not to do that -- users will probably copy/paste that with any spelling, and not renaming it makes migration docs simpler.
Co-Authored-By: Alexander Belopolsky abalkin@users.noreply.github.com
Co-Authored-By: Matthias Braun MatzeB@users.noreply.github.com