cpython-withatomic / Objects / typeslots.py

#!/usr/bin/python
# Usage: typeslots.py < Include/typeslots.h > typeslots.inc

import sys, re

print("/* Generated by typeslots.py */")
res = {}
for line in sys.stdin:
    m = re.match("#define Py_([a-z_]+) ([0-9]+)", line)
    if not m:
        continue
    member = m.group(1)
    if member.startswith("tp_"):
        member = "ht_type."+member
    elif member.startswith("nb_"):
        member = "as_number."+member
    elif member.startswith("mp_"):
        member = "as_mapping."+member
    elif member.startswith("sq_"):
        member = "as_sequence."+member
    elif member.startswith("bf_"):
        member = "as_buffer."+member
    res[int(m.group(2))] = member

M = max(res.keys())+1
for i in range(1,M):
    if i in res:
        print("offsetof(PyHeapTypeObject, %s)," % res[i])
    else:
        print("0,")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.