ยปCore Development>Code coverage>Objects/typeslots.py

Python code coverage for Objects/typeslots.py

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