Files
typthon/Objects/typeslots.py
copilot-swe-agent[bot] b198f511d2 Rename Py_ to Ty_ throughout C API
Massive automated renaming of all Py_/PyObject/etc. prefixes to Ty_/TyObject/etc.
This includes:
- All public API types (TyObject, TyTypeObject, etc.)
- All public API functions (Ty_Initialize, Ty_BuildValue, etc.)
- All internal API (_Ty_ prefixes)
- Reference counting macros (Ty_INCREF, Ty_DECREF, etc.)
- Type flags (Ty_TPFLAGS_*)
- Debug flags (Ty_DEBUG, Ty_TRACE_REFS, etc.)
- All object type APIs (TyList_, TyDict_, TyUnicode_, etc.)

This changes over 60,000 occurrences across 1000+ files.

Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
2025-12-29 17:37:49 +00:00

56 lines
1.9 KiB
Python

#!/usr/bin/python
# Usage: typeslots.py < Include/typeslots.h typeslots.inc
import sys, re
def generate_typeslots(out=sys.stdout):
out.write("/* Generated by typeslots.py */\n")
res = {}
for line in sys.stdin:
m = re.match("#define Ty_([a-z_]+) ([0-9]+)", line)
if not m:
continue
member = m.group(1)
if member == "tp_token":
# The heap type structure (ht_*) is an implementation detail;
# the public slot for it has a familiar `tp_` prefix
member = '{-1, offsetof(PyHeapTypeObject, ht_token)}'
elif member.startswith("tp_"):
member = f'{{-1, offsetof(PyTypeObject, {member})}}'
elif member.startswith("am_"):
member = (f'{{offsetof(PyAsyncMethods, {member}),'+
' offsetof(PyTypeObject, tp_as_async)}')
elif member.startswith("nb_"):
member = (f'{{offsetof(PyNumberMethods, {member}),'+
' offsetof(PyTypeObject, tp_as_number)}')
elif member.startswith("mp_"):
member = (f'{{offsetof(PyMappingMethods, {member}),'+
' offsetof(PyTypeObject, tp_as_mapping)}')
elif member.startswith("sq_"):
member = (f'{{offsetof(PySequenceMethods, {member}),'+
' offsetof(PyTypeObject, tp_as_sequence)}')
elif member.startswith("bf_"):
member = (f'{{offsetof(PyBufferProcs, {member}),'+
' offsetof(PyTypeObject, tp_as_buffer)}')
res[int(m.group(2))] = member
M = max(res.keys())+1
for i in range(1,M):
if i in res:
out.write("%s,\n" % res[i])
else:
out.write("{0, 0},\n")
def main():
if len(sys.argv) == 2:
with open(sys.argv[1], "w") as f:
generate_typeslots(f)
else:
generate_typeslots()
if __name__ == "__main__":
main()