gh-106869: Use new PyMemberDef constant names#106871
Conversation
|
I created this PR with this #!/usr/bin/python3
import sys
import re
encoding = "utf8"
patterns = (
('T_SHORT', 'Py_T_SHORT'),
('T_INT', 'Py_T_INT'),
('T_LONG', 'Py_T_LONG'),
('T_FLOAT', 'Py_T_FLOAT'),
('T_DOUBLE', 'Py_T_DOUBLE'),
('T_STRING', 'Py_T_STRING'),
('T_OBJECT', '_Py_T_OBJECT'),
('T_CHAR', 'Py_T_CHAR'),
('T_BYTE', 'Py_T_BYTE'),
('T_UBYTE', 'Py_T_UBYTE'),
('T_USHORT', 'Py_T_USHORT'),
('T_UINT', 'Py_T_UINT'),
('T_ULONG', 'Py_T_ULONG'),
('T_STRING_INPLACE', 'Py_T_STRING_INPLACE'),
('T_BOOL', 'Py_T_BOOL'),
('T_OBJECT_EX', 'Py_T_OBJECT_EX'),
('T_LONGLONG', 'Py_T_LONGLONG'),
('T_ULONGLONG', 'Py_T_ULONGLONG'),
('T_PYSSIZET', 'Py_T_PYSSIZET'),
('T_NONE', '_Py_T_NONE'),
('READONLY', 'Py_READONLY'),
('PY_AUDIT_READ', 'Py_AUDIT_READ'),
('READ_RESTRICTED', 'Py_AUDIT_READ'),
('PY_WRITE_RESTRICTED', '_Py_WRITE_RESTRICTED'),
('RESTRICTED', '(Py_AUDIT_READ | _Py_WRITE_RESTRICTED)'),
)
patterns = [(re.compile(fr'\b{pattern}\b'), replace)
for pattern, replace in patterns]
patterns.append((re.compile('#include "structmember.h".*$', re.MULTILINE), ''))
def update(filename):
with open(filename, encoding=encoding) as fp:
content = fp.read()
old_content = content
for pattern, replace in patterns:
content = pattern.sub(replace, content)
if content != old_content:
print(f"Update {filename}")
with open(filename, "w", encoding=encoding) as fp:
fp.write(content)
def main():
if len(sys.argv) < 2:
print("usage: update.py filename [filename2 ...]")
sys.exit(1)
for filename in sys.argv[1:]:
update(filename)
if __name__ == "__main__":
main()And the shell command: |
Sorry, something went wrong.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
If it was created by a script, there is no need to read every line for accepting this PR.
Before committing these changes I have questions:
- Why
_Py_T_OBJECTis underscored? - Why is prefix
Py_used, but notPY_?
Sorry, something went wrong.
@encukou designed this API in Python 3.12. If if needs to be changed, maybe it's not too late to change it. I'm fine with But I'm also curious about the fact that _Py_T_OBJECT is private and the only public constant for object has an I would prefer to not switch from By the way, I'm considering to expose these new |
Sorry, something went wrong.
|
Oh, macOS fails to build: Modules/selectmodule.c:1839:41: error: implicit declaration of function 'offsetof' is invalid in C99 |
Sorry, something went wrong.
I just added stddef.h includes to fix build issues 😁 |
Sorry, something went wrong.
11bef5d to
0c91ecc
Compare
July 25, 2023 12:09
|
PR rebased on the main branch to fix merge conflicts. I also added the missing #include for macOS in the select module. |
Sorry, something went wrong.
* Remove '#include "structmember.h"'. * If needed, add <stddef.h> to get offsetof() function. * Replace: * T_SHORT => Py_T_SHORT * T_INT => Py_T_INT * T_LONG => Py_T_LONG * T_FLOAT => Py_T_FLOAT * T_DOUBLE => Py_T_DOUBLE * T_STRING => Py_T_STRING * T_OBJECT => _Py_T_OBJECT * T_CHAR => Py_T_CHAR * T_BYTE => Py_T_BYTE * T_UBYTE => Py_T_UBYTE * T_USHORT => Py_T_USHORT * T_UINT => Py_T_UINT * T_ULONG => Py_T_ULONG * T_STRING_INPLACE => Py_T_STRING_INPLACE * T_BOOL => Py_T_BOOL * T_OBJECT_EX => Py_T_OBJECT_EX * T_LONGLONG => Py_T_LONGLONG * T_ULONGLONG => Py_T_ULONGLONG * T_PYSSIZET => Py_T_PYSSIZET * T_NONE => _Py_T_NONE * READONLY => Py_READONLY * PY_AUDIT_READ => Py_AUDIT_READ * READ_RESTRICTED => Py_AUDIT_READ * PY_WRITE_RESTRICTED => _Py_WRITE_RESTRICTED * RESTRICTED => (READ_RESTRICTED | _Py_WRITE_RESTRICTED)
0c91ecc to
8d13210
Compare
July 25, 2023 12:22
|
Oops, I reverted my changes on |
Sorry, something went wrong.
|
I also updated Parser/asdl_c.py to update Python/Python-ast.c. |
Sorry, something went wrong.
Remove '#include "structmember.h"'.
If needed, add <stddef.h> to get offsetof() function.
Replace: