-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrefcounts_borrowed.py
More file actions
executable file
·43 lines (36 loc) · 1008 Bytes
/
refcounts_borrowed.py
File metadata and controls
executable file
·43 lines (36 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
"""
Script parsing CPython Doc/data/refcounts.dat to list functions which
return a borrow PyObject* reference.
"""
import sys
def parse_refcounts(filename):
total = 0
header = True
for line in open(filename, encoding="utf8"):
pos = line.find('#')
if pos >= 0:
line = line[pos:]
line = line.strip()
if not line:
header = True
continue
if not header:
continue
if ':PyObject*:' in line:
parts = line.split(':')
if parts[3] == '0':
func = parts[0]
print("Borrowed reference: %s()" % func)
total += 1
header = False
print()
print("Total: %s functions" % total)
def main():
if len(sys.argv) != 2:
print("usage: %s cpython/Doc/data/refcounts.dat" % sys.argv[0])
sys.exit(1)
filename = sys.argv[1]
parse_refcounts(filename)
if __name__ == "__main__":
main()