1 | n/a | #!/usr/bin/python |
---|
2 | n/a | # Usage: typeslots.py < Include/typeslots.h typeslots.inc |
---|
3 | n/a | |
---|
4 | n/a | import sys, re |
---|
5 | n/a | |
---|
6 | n/a | def generate_typeslots(out=sys.stdout): |
---|
7 | n/a | out.write("/* Generated by typeslots.py */\n") |
---|
8 | n/a | res = {} |
---|
9 | n/a | for line in sys.stdin: |
---|
10 | n/a | m = re.match("#define Py_([a-z_]+) ([0-9]+)", line) |
---|
11 | n/a | if not m: |
---|
12 | n/a | continue |
---|
13 | n/a | member = m.group(1) |
---|
14 | n/a | if member.startswith("tp_"): |
---|
15 | n/a | member = "ht_type."+member |
---|
16 | n/a | elif member.startswith("am_"): |
---|
17 | n/a | member = "as_async."+member |
---|
18 | n/a | elif member.startswith("nb_"): |
---|
19 | n/a | member = "as_number."+member |
---|
20 | n/a | elif member.startswith("mp_"): |
---|
21 | n/a | member = "as_mapping."+member |
---|
22 | n/a | elif member.startswith("sq_"): |
---|
23 | n/a | member = "as_sequence."+member |
---|
24 | n/a | elif member.startswith("bf_"): |
---|
25 | n/a | member = "as_buffer."+member |
---|
26 | n/a | res[int(m.group(2))] = member |
---|
27 | n/a | |
---|
28 | n/a | M = max(res.keys())+1 |
---|
29 | n/a | for i in range(1,M): |
---|
30 | n/a | if i in res: |
---|
31 | n/a | out.write("offsetof(PyHeapTypeObject, %s),\n" % res[i]) |
---|
32 | n/a | else: |
---|
33 | n/a | out.write("0,\n") |
---|
34 | n/a | |
---|
35 | n/a | def main(): |
---|
36 | n/a | if len(sys.argv) == 2: |
---|
37 | n/a | with open(sys.argv[1], "w") as f: |
---|
38 | n/a | generate_typeslots(f) |
---|
39 | n/a | else: |
---|
40 | n/a | generate_typeslots() |
---|
41 | n/a | |
---|
42 | n/a | if __name__ == "__main__": |
---|
43 | n/a | main() |
---|