Skip to content
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

gh-47146: Soft-deprecate structmember.h, expose its contents via Python.h #99014

Merged
merged 14 commits into from Nov 22, 2022

Conversation

encukou
Copy link
Member

@encukou encukou commented Nov 2, 2022

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. (previously T_INT, T_DOUBLE, etc.)
  • The flags PY_READONLY (previously READONLY) and PY_AUDIT_READ (name unchanged)

Several items are not exposed from Python.h:

  • T_OBJECT (use PY_T_OBJECT_EX)
  • T_NONE (previously undocumented, and pretty quirky)
  • The macro WRITE_RESTRICTED which does nothing.
  • The macros RESTRICTED and READ_RESTRICTED, equivalents of PY_AUDIT_READ.
  • In some configurations, <stddef.h> is not included from Python.h.
    It should be included manually when using offsetof().

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

encukou added 4 commits Nov 2, 2022
These docs were ripe for an overhaul, so I did one when touching the code.
@encukou
Copy link
Member Author

encukou commented Nov 7, 2022

Today I noticed the style guide says macros should have the Py_ prefix, not PY_. A minor point, but since this is renaming a bunch of macros, I'll switch to the preferred form.

@encukou encukou marked this pull request as draft Nov 7, 2022
@encukou encukou marked this pull request as ready for review Nov 8, 2022
@encukou encukou marked this pull request as draft Nov 8, 2022
@encukou
Copy link
Member Author

encukou commented Nov 8, 2022

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.

And by the same token, PyMember_GetOne and PyMember_SetOne should be added too.

@encukou encukou marked this pull request as ready for review Nov 10, 2022
@encukou encukou requested a review from a team as a code owner Nov 15, 2022
@encukou
Copy link
Member Author

encukou commented Nov 16, 2022

And here are tests.
I'd appreciate a review, if anyone can spare the time.

@encukou encukou added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 16, 2022
@bedevere-bot
Copy link

bedevere-bot commented Nov 16, 2022

🤖 New build scheduled with the buildbot fleet by @encukou for commit e44b7ca 🤖

If you want to schedule another build, you need to add the "🔨 test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 16, 2022
Copy link
Contributor

@erlend-aasland erlend-aasland left a comment

Looks good. I did some nitpicking.

Doc/c-api/structures.rst Show resolved Hide resolved
Doc/c-api/structures.rst Outdated Show resolved Hide resolved
Doc/c-api/structures.rst Outdated Show resolved Hide resolved
Modules/_testcapi/structmember.c Outdated Show resolved Hide resolved
Modules/_testcapi/structmember.c Outdated Show resolved Hide resolved
Modules/_testcapi/structmember.c Outdated Show resolved Hide resolved
Modules/_testcapi/structmember.c Show resolved Hide resolved
Modules/_testcapi/structmember.c Outdated Show resolved Hide resolved
@encukou
Copy link
Member Author

encukou commented Nov 21, 2022

Thank you! I did the changes, and will merge once everything is green.

@encukou encukou merged commit 4d82f62 into python:main Nov 22, 2022
15 checks passed
@encukou encukou deleted the structmember-public branch Nov 22, 2022
@vstinner
Copy link
Member

vstinner commented Nov 22, 2022

Nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants