Skip to content

gh-81057: Get the c-analyzer tool working again. #92246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Tools/c-analyzer/c_parser/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,9 @@ def from_data(cls, raw, index):
vartype = dict(raw.data)
del vartype['storage']
if 'size' in vartype:
size = int(vartype.pop('size'))
size = vartype.pop('size')
if isinstance(size, str) and size.isdigit():
size = int(size)
vartype = VarType(**vartype)
return cls(name, vartype, size)

Expand Down
2 changes: 1 addition & 1 deletion Tools/c-analyzer/c_parser/parser/_compound_decl_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def parse_body(source):
name = anon_name('struct-field-')
if size:
# data = (data, size)
data['size'] = int(size)
data['size'] = int(size) if size.isdigit() else size
else:
# This shouldn't happen (we expect each field to have a name).
raise NotImplementedError
Expand Down
7 changes: 7 additions & 0 deletions Tools/c-analyzer/c_parser/parser/_regexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def _ind(text, level=1, edges='both'):
(?: # <IDENTIFIER>
{STRICT_IDENTIFIER}
)
# Inside the brackets is actually a "constant expression".
(?: \s* \[ (?: \s* [^\]]+ \s* )? [\]] )* # arrays
)
|
Expand All @@ -184,6 +185,7 @@ def _ind(text, level=1, edges='both'):
(?: # <WRAPPED_IDENTIFIER>
{STRICT_IDENTIFIER}
)
# Inside the brackets is actually a "constant expression".
(?: \s* \[ (?: \s* [^\]]+ \s* )? [\]] )* # arrays
\s* [)]
)
Expand All @@ -194,6 +196,7 @@ def _ind(text, level=1, edges='both'):
(?: # <FUNC_IDENTIFIER>
{STRICT_IDENTIFIER}
)
# Inside the brackets is actually a "constant expression".
(?: \s* \[ (?: \s* [^\]]+ \s* )? [\]] )* # arrays
\s* [)]
# We allow for a single level of paren nesting in parameters.
Expand Down Expand Up @@ -322,7 +325,10 @@ def _ind(text, level=1, edges='both'):
(?:
\s* [:] \s*
(?: # <SIZE>
# This is actually a "constant expression".
\d+
|
[^'",}}]+
)
)?
\s*
Expand Down Expand Up @@ -357,6 +363,7 @@ def _ind(text, level=1, edges='both'):
(?:
\s* = \s*
(?: # <INIT>
# This is actually a "constant expression".
{_ind(STRING_LITERAL, 4)}
|
[^'",}}]+
Expand Down
7 changes: 5 additions & 2 deletions Tools/c-analyzer/cpython/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def clean_lines(text):
@end=sh@
'''

# XXX Handle these.
EXCLUDED = clean_lines('''
# @begin=conf@

Expand All @@ -69,6 +70,7 @@ def clean_lines(text):
Python/dynload_dl.c # dl.h
Python/dynload_hpux.c # dl.h
Python/thread_pthread.h
Python/emscripten_signal.c

# only huge constants (safe but parsing is slow)
Modules/_blake2/impl/blake2-kat.h
Expand Down Expand Up @@ -202,6 +204,7 @@ def clean_lines(text):
Include/cpython/traceback.h Py_CPYTHON_TRACEBACK_H 1
Include/cpython/tupleobject.h Py_CPYTHON_TUPLEOBJECT_H 1
Include/cpython/unicodeobject.h Py_CPYTHON_UNICODEOBJECT_H 1
Include/internal/pycore_code.h SIZEOF_VOID_P 8

# implied include of pyport.h
Include/**/*.h PyAPI_DATA(RTYPE) extern RTYPE
Expand Down Expand Up @@ -297,8 +300,8 @@ def clean_lines(text):
_abs('Objects/stringlib/unicode_format.h'): (10_000, 400),
_abs('Objects/typeobject.c'): (20_000, 200),
_abs('Python/compile.c'): (20_000, 500),
_abs('Python/pylifecycle.c'): (200_000, 5000),
_abs('Python/pystate.c'): (200_000, 5000),
_abs('Python/pylifecycle.c'): (500_000, 5000),
_abs('Python/pystate.c'): (500_000, 5000),
}


Expand Down