Skip to content

Commit 77bab59

Browse files
authoredFeb 9, 2022
bpo-36876: Update the c-analyzer whitelist. (gh-31225)
This change adds variables that had been added since the last time the whitelist was updated. It also cleans up the list a little. https://bugs.python.org/issue36876
1 parent 06e1701 commit 77bab59

File tree

4 files changed

+2364
-2010
lines changed

4 files changed

+2364
-2010
lines changed
 

‎Tools/c-analyzer/cpython/_analyzer.py

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
_DATA_DIR = os.path.dirname(__file__)
3333
KNOWN_FILE = os.path.join(_DATA_DIR, 'known.tsv')
3434
IGNORED_FILE = os.path.join(_DATA_DIR, 'ignored.tsv')
35+
NEED_FIX_FILE = os.path.join(_DATA_DIR, 'globals-to-fix.tsv')
3536
KNOWN_IN_DOT_C = {
3637
'struct _odictobject': False,
3738
'PyTupleObject': False,
@@ -85,6 +86,7 @@ def write_known():
8586
def read_ignored():
8687
if not _IGNORED:
8788
_IGNORED.update(_datafiles.read_ignored(IGNORED_FILE, relroot=REPO_ROOT))
89+
_IGNORED.update(_datafiles.read_ignored(NEED_FIX_FILE, relroot=REPO_ROOT))
8890
return dict(_IGNORED)
8991

9092

‎Tools/c-analyzer/cpython/globals-to-fix.tsv

+1,646
Large diffs are not rendered by default.

‎Tools/c-analyzer/cpython/ignored.tsv

+583-2,010
Large diffs are not rendered by default.

‎Tools/c-analyzer/table-file.py

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
2+
def iter_clean_lines(lines):
3+
lines = iter(lines)
4+
for line in lines:
5+
line = line.strip()
6+
if line.startswith('# XXX'):
7+
continue
8+
yield line
9+
10+
11+
def parse_table_lines(lines):
12+
lines = iter_clean_lines(lines)
13+
14+
for line in lines:
15+
if line.startswith(('####', '#----')):
16+
kind = 0 if line[1] == '#' else 1
17+
try:
18+
line = next(lines).strip()
19+
except StopIteration:
20+
line = ''
21+
if not line.startswith('# '):
22+
raise NotImplementedError(line)
23+
yield kind, line[2:].lstrip()
24+
continue
25+
26+
maybe = None
27+
while line.startswith('#'):
28+
if line != '#' and line[1] == ' ':
29+
maybe = line[2:].lstrip()
30+
try:
31+
line = next(lines).strip()
32+
except StopIteration:
33+
return
34+
if not line:
35+
break
36+
else:
37+
if line:
38+
if maybe:
39+
yield 2, maybe
40+
yield 'row', line
41+
42+
43+
def iter_sections(lines):
44+
header = None
45+
section = []
46+
for kind, value in parse_table_lines(lines):
47+
if kind == 'row':
48+
if not section:
49+
if header is None:
50+
header = value
51+
continue
52+
raise NotImplementedError(value)
53+
yield tuple(section), value
54+
else:
55+
if header is None:
56+
header = False
57+
section[kind:] = [value]
58+
59+
60+
def collect_sections(lines):
61+
sections = {}
62+
for section, row in iter_sections(lines):
63+
if section not in sections:
64+
sections[section] = [row]
65+
else:
66+
sections[section].append(row)
67+
return sections
68+
69+
70+
def collate_sections(lines):
71+
collated = {}
72+
for section, rows in collect_sections(lines).items():
73+
parent = collated
74+
current = ()
75+
for name in section:
76+
current += (name,)
77+
try:
78+
child, secrows, totalrows = parent[name]
79+
except KeyError:
80+
child = {}
81+
secrows = []
82+
totalrows = []
83+
parent[name] = (child, secrows, totalrows)
84+
parent = child
85+
if current == section:
86+
secrows.extend(rows)
87+
totalrows.extend(rows)
88+
return collated
89+
90+
91+
#############################
92+
# the commands
93+
94+
def cmd_count_by_section(lines):
95+
total = 0
96+
def render_tree(root, depth=0):
97+
nonlocal total
98+
indent = ' ' * depth
99+
for name, data in root.items():
100+
subroot, rows, totalrows = data
101+
sectotal = f'({len(totalrows)})' if totalrows != rows else ''
102+
count = len(rows) if rows else ''
103+
yield f'{sectotal:>7} {count:>4} {indent}{name}'
104+
yield from render_tree(subroot, depth+1)
105+
total += len(rows)
106+
sections = collate_sections(lines)
107+
yield from render_tree(sections)
108+
yield f'(total: {total})'
109+
110+
111+
#############################
112+
# the script
113+
114+
def parse_args(argv=None, prog=None):
115+
import argparse
116+
parser = argparse.ArgumentParser(prog=prog)
117+
parser.add_argument('filename')
118+
119+
args = parser.parse_args(argv)
120+
ns = vars(args)
121+
122+
return ns
123+
124+
125+
def main(filename):
126+
with open(filename) as infile:
127+
for line in cmd_count_by_section(infile):
128+
print(line)
129+
130+
131+
if __name__ == '__main__':
132+
kwargs = parse_args()
133+
main(**kwargs)

0 commit comments

Comments
 (0)
Please sign in to comment.