Skip to content

Commit 456cd51

Browse files
gh-81057: Get the c-analyzer tool working again. (gh-92246)
1 parent f03d3dd commit 456cd51

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

Tools/c-analyzer/c_parser/info.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,9 @@ def from_data(cls, raw, index):
11611161
vartype = dict(raw.data)
11621162
del vartype['storage']
11631163
if 'size' in vartype:
1164-
size = int(vartype.pop('size'))
1164+
size = vartype.pop('size')
1165+
if isinstance(size, str) and size.isdigit():
1166+
size = int(size)
11651167
vartype = VarType(**vartype)
11661168
return cls(name, vartype, size)
11671169

Tools/c-analyzer/c_parser/parser/_compound_decl_body.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def parse_body(source):
9999
name = anon_name('struct-field-')
100100
if size:
101101
# data = (data, size)
102-
data['size'] = int(size)
102+
data['size'] = int(size) if size.isdigit() else size
103103
else:
104104
# This shouldn't happen (we expect each field to have a name).
105105
raise NotImplementedError

Tools/c-analyzer/c_parser/parser/_regexes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ def _ind(text, level=1, edges='both'):
176176
(?: # <IDENTIFIER>
177177
{STRICT_IDENTIFIER}
178178
)
179+
# Inside the brackets is actually a "constant expression".
179180
(?: \s* \[ (?: \s* [^\]]+ \s* )? [\]] )* # arrays
180181
)
181182
|
@@ -184,6 +185,7 @@ def _ind(text, level=1, edges='both'):
184185
(?: # <WRAPPED_IDENTIFIER>
185186
{STRICT_IDENTIFIER}
186187
)
188+
# Inside the brackets is actually a "constant expression".
187189
(?: \s* \[ (?: \s* [^\]]+ \s* )? [\]] )* # arrays
188190
\s* [)]
189191
)
@@ -194,6 +196,7 @@ def _ind(text, level=1, edges='both'):
194196
(?: # <FUNC_IDENTIFIER>
195197
{STRICT_IDENTIFIER}
196198
)
199+
# Inside the brackets is actually a "constant expression".
197200
(?: \s* \[ (?: \s* [^\]]+ \s* )? [\]] )* # arrays
198201
\s* [)]
199202
# We allow for a single level of paren nesting in parameters.
@@ -322,7 +325,10 @@ def _ind(text, level=1, edges='both'):
322325
(?:
323326
\s* [:] \s*
324327
(?: # <SIZE>
328+
# This is actually a "constant expression".
325329
\d+
330+
|
331+
[^'",}}]+
326332
)
327333
)?
328334
\s*
@@ -357,6 +363,7 @@ def _ind(text, level=1, edges='both'):
357363
(?:
358364
\s* = \s*
359365
(?: # <INIT>
366+
# This is actually a "constant expression".
360367
{_ind(STRING_LITERAL, 4)}
361368
|
362369
[^'",}}]+

Tools/c-analyzer/cpython/_parser.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def clean_lines(text):
4646
@end=sh@
4747
'''
4848

49+
# XXX Handle these.
4950
EXCLUDED = clean_lines('''
5051
# @begin=conf@
5152
@@ -69,6 +70,7 @@ def clean_lines(text):
6970
Python/dynload_dl.c # dl.h
7071
Python/dynload_hpux.c # dl.h
7172
Python/thread_pthread.h
73+
Python/emscripten_signal.c
7274
7375
# only huge constants (safe but parsing is slow)
7476
Modules/_blake2/impl/blake2-kat.h
@@ -202,6 +204,7 @@ def clean_lines(text):
202204
Include/cpython/traceback.h Py_CPYTHON_TRACEBACK_H 1
203205
Include/cpython/tupleobject.h Py_CPYTHON_TUPLEOBJECT_H 1
204206
Include/cpython/unicodeobject.h Py_CPYTHON_UNICODEOBJECT_H 1
207+
Include/internal/pycore_code.h SIZEOF_VOID_P 8
205208
206209
# implied include of pyport.h
207210
Include/**/*.h PyAPI_DATA(RTYPE) extern RTYPE
@@ -297,8 +300,8 @@ def clean_lines(text):
297300
_abs('Objects/stringlib/unicode_format.h'): (10_000, 400),
298301
_abs('Objects/typeobject.c'): (20_000, 200),
299302
_abs('Python/compile.c'): (20_000, 500),
300-
_abs('Python/pylifecycle.c'): (200_000, 5000),
301-
_abs('Python/pystate.c'): (200_000, 5000),
303+
_abs('Python/pylifecycle.c'): (500_000, 5000),
304+
_abs('Python/pystate.c'): (500_000, 5000),
302305
}
303306

304307

0 commit comments

Comments
 (0)