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
Upgrade CPython to the new PyMemberDef API: names starting with Py_ prefix (Py_T_INT instead of T_INT) #106869
The CPython code base was written for the old "structmember.h" API with names like READONLY and T_INT. I propose to upgrade the code base to new public names like Py_READONLY and Py_T_INT.
#include "structmember.h" should be removed, but #include <stddef.h> should maybe be added in exchange to get the standard offsetof() function.
I don't get why 3 constants are private, name starting with _Py prefix:
_Py_T_OBJECT: replace T_OBJECT. It's still documented as T_OBJECT: https://docs.python.org/dev/c-api/structures.html#c.T_OBJECT "This results in surprising behavior in Python: deleting the attribute effectively sets it to None." There is Py_T_OBJECT_EX, but it's a different API: it raises an exception if the pointer is NULL, rather than returning None.
I generated a big PR making all mechanical name changes at once: PR #106871. Maybe this PR is too big (ex: to be reviewed), I can slice it into smaller PRs (ex: 20 files max per PR).
I created this PR to see how it would look, so we can agree on how the change should be done.
About questions on the new API: well, they can be addressed separately.
For now, I replaced T_OBJECT with _Py_T_OBJECT. Maybe some files should be updated to use Py_T_OBJECT_EX and so raise AttributeError if the attribute was deleted (set to None), rather than returning None.
Maybe some files should be updated to use Py_T_OBJECT_EX and so raise AttributeError if the attribute was deleted (set to None), rather than returning None.
I am doing this right now. 😉
The main effect not in deletion, but that these attributes are None by default.
Ah, this is the PR about which I messaged you privately. Thanks for finding it!
The tests are there, in Modules/_testcapi/structmember.c, so this can remain closed.
Activity
vstinner commentedon Jul 18, 2023
I don't get why 3 constants are private, name starting with
_Pyprefix:_Py_T_OBJECT: replaceT_OBJECT. It's still documented asT_OBJECT: https://docs.python.org/dev/c-api/structures.html#c.T_OBJECT "This results in surprising behavior in Python: deleting the attribute effectively sets it to None." There isPy_T_OBJECT_EX, but it's a different API: it raises an exception if the pointer is NULL, rather than returning None._Py_T_NONE: replaceT_NONE-- it's still documented asT_NONE: https://docs.python.org/dev/c-api/structures.html#c.T_NONE_Py_WRITE_RESTRICTED: replace PY_WRITE_RESTRICTEDBy the way,
(Py_AUDIT_READ | _Py_WRITE_RESTRICTED)replacesRESTRICTED, it uses_Py_WRITE_RESTRICTED.vstinner commentedon Jul 18, 2023
_Py_WRITE_RESTRICTEDand its deprecated aliasWRITE_RESTRICTEDdo nothing. Maybe their usage should just be removed in the code.pythongh-106869: Use new PyMemberDef constant names
vstinner commentedon Jul 18, 2023
I generated a big PR making all mechanical name changes at once: PR #106871. Maybe this PR is too big (ex: to be reviewed), I can slice it into smaller PRs (ex: 20 files max per PR).
I created this PR to see how it would look, so we can agree on how the change should be done.
cc @encukou @serhiy-storchaka
pythongh-106869: Use new PyMemberDef constant names
pythongh-106869: Use new PyMemberDef constant names
pythongh-106869: Use new PyMemberDef constant names
gh-106869: Use new PyMemberDef constant names (#106871)
vstinner commentedon Jul 25, 2023
Ok, I updated 78 files to use the new public API rather than "structmember.h" API which doesn't use the
Py_prefix.Thanks @encukou for the new API :-)
About questions on the new API: well, they can be addressed separately.
For now, I replaced T_OBJECT with _Py_T_OBJECT. Maybe some files should be updated to use Py_T_OBJECT_EX and so raise AttributeError if the attribute was deleted (set to None), rather than returning None.
serhiy-storchaka commentedon Jul 25, 2023
I am doing this right now. 😉
The main effect not in deletion, but that these attributes are None by default.
pythongh-106869: Use new PyMemberDef constant names (python#106871)
encukou commentedon Aug 2, 2023
Usage of the old names meant that they were tested, however indirectly. Now the old names have no tests. Could you add tests?
encukou commentedon Aug 2, 2023
They should not be used in new code. Existing code can continue to use
structmember.hand the original names.vstinner commentedon Aug 26, 2023
Why did you reopen this issue?
Ok.
encukou commentedon Aug 31, 2023
Ah, this is the PR about which I messaged you privately. Thanks for finding it!
The tests are there, in
Modules/_testcapi/structmember.c, so this can remain closed.vstinner commentedon Sep 1, 2023
I modified this file twice by mistake, but hopefully, I noticed it and the final merged PR leaves it unchanged.
Part 1, new API:
Part 2, old API:
So it's ok, the new and the old APIs are tested, as expected.
It's good that you also checked :-)