Skip to content

Commit 5888d48

Browse files
Consider private, non-static globals.
1 parent 6c1db44 commit 5888d48

File tree

4 files changed

+35
-56
lines changed

4 files changed

+35
-56
lines changed

Tools/c-analyzer/c_analyzer_common/_generate.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,26 @@ def _parse_global(line, funcname=None):
3838
# global-only
3939
elif line.startswith('PyAPI_DATA('): # only in .h files
4040
name, decl = parse_variable_declaration(line)
41+
elif line.startswith('extern '): # only in .h files
42+
name, decl = parse_variable_declaration(line)
4143
elif line.startswith('PyDoc_VAR('):
4244
decl = line.strip(';').strip()
4345
name = line.split('(')[1].split(')')[0].strip()
44-
# elif line.startswith(POTS): # implied static
45-
# if '(' in line and '[' not in line and ' = ' not in line:
46-
# return None, None
47-
# name, decl = parse_variable_declaration(line)
48-
# elif line.startswith(STRUCTS) and line.endswith(' = {'): # implied static
49-
# name, decl = parse_variable_declaration(line)
50-
# elif line.startswith(STRUCTS) and line.endswith(' = NULL;'): # implied static
51-
# name, decl = parse_variable_declaration(line)
52-
# elif line.startswith('struct '):
53-
# if not line.endswith(' = {'):
54-
# return None, None
55-
# if not line.partition(' ')[2].startswith(STRUCTS):
56-
# return None, None
57-
# # implied static
58-
# name, decl = parse_variable_declaration(line)
46+
elif line.startswith(POTS): # implied static
47+
if '(' in line and '[' not in line and ' = ' not in line:
48+
return None, None
49+
name, decl = parse_variable_declaration(line)
50+
elif line.startswith(STRUCTS) and line.endswith(' = {'): # implied static
51+
name, decl = parse_variable_declaration(line)
52+
elif line.startswith(STRUCTS) and line.endswith(' = NULL;'): # implied static
53+
name, decl = parse_variable_declaration(line)
54+
elif line.startswith('struct '):
55+
if not line.endswith(' = {'):
56+
return None, None
57+
if not line.partition(' ')[2].startswith(STRUCTS):
58+
return None, None
59+
# implied static
60+
name, decl = parse_variable_declaration(line)
5961

6062
# file-specific
6163
elif line.startswith(('SLOT1BINFULL(', 'SLOT1BIN(')):

Tools/c-analyzer/c_analyzer_common/known.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def from_file(infile, *,
3535
if kind == 'variable':
3636
values = known['variables']
3737
value = Variable(id, declaration)
38-
value._isglobal = _is_global(declaration)
38+
value._isglobal = _is_global(declaration) or id.funcname is None
3939
else:
4040
raise ValueError(f'unsupported kind in row {row}')
4141
if value.name == 'id' and declaration == UNKNOWN:

Tools/c-analyzer/c_globals/__main__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def _match_unused_global(variable, knownvars, used):
3131

3232

3333
def _check_results(unknown, knownvars, used):
34-
return
3534
badknown = set()
3635
for variable in sorted(unknown):
3736
msg = None
@@ -85,7 +84,7 @@ def _find_globals(dirnames, known, ignored):
8584
yield variable, is_supported(variable, ignored, known)
8685
used.add(variable.id)
8786

88-
_check_results(unknown, knownvars, used)
87+
#_check_results(unknown, knownvars, used)
8988

9089

9190
def cmd_check(cmd, dirs=SOURCE_DIRS, *,

Tools/c-analyzer/known.tsv

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Objects/genobject.c - ag_value_freelist_free variable static int ag_value_freeli
1414
Python/Python-ast.c - alias_fields variable static const char *alias_fields[]
1515
Python/Python-ast.c - alias_type variable static PyTypeObject *alias_type
1616
Modules/_tracemalloc.c - allocators variable static struct { PyMemAllocatorEx mem; PyMemAllocatorEx raw; PyMemAllocatorEx obj; } allocators
17-
Python/Python-ast.c - And_singleton variable PyObject *And_singleton
17+
Python/Python-ast.c - And_singleton variable static PyObject *And_singleton
1818
Python/Python-ast.c - And_type variable static PyTypeObject *And_type
1919
Python/Python-ast.c - AnnAssign_fields variable static const char *AnnAssign_fields[]
2020
Python/Python-ast.c - AnnAssign_type variable static PyTypeObject *AnnAssign_type
@@ -61,9 +61,9 @@ Python/Python-ast.c - Attribute_fields variable static const char *Attribute_fie
6161
Python/Python-ast.c - Attribute_type variable static PyTypeObject *Attribute_type
6262
Python/Python-ast.c - AugAssign_fields variable static const char *AugAssign_fields[]
6363
Python/Python-ast.c - AugAssign_type variable static PyTypeObject *AugAssign_type
64-
Python/Python-ast.c - AugLoad_singleton variable PyObject *AugLoad_singleton
64+
Python/Python-ast.c - AugLoad_singleton variable static PyObject *AugLoad_singleton
6565
Python/Python-ast.c - AugLoad_type variable static PyTypeObject *AugLoad_type
66-
Python/Python-ast.c - AugStore_singleton variable PyObject *AugStore_singleton
66+
Python/Python-ast.c - AugStore_singleton variable static PyObject *AugStore_singleton
6767
Python/Python-ast.c - AugStore_type variable static PyTypeObject *AugStore_type
6868
Python/Python-ast.c - Await_fields variable static const char *Await_fields[]
6969
Python/Python-ast.c - Await_type variable static PyTypeObject *Await_type
@@ -86,7 +86,6 @@ Python/Python-ast.c - boolop_type variable static PyTypeObject *boolop_type
8686
Python/Python-ast.c - BoolOp_type variable static PyTypeObject *BoolOp_type
8787
Python/_warnings.c is_internal_frame bootstrap_string variable static PyObject *bootstrap_string
8888
Python/Python-ast.c - Break_type variable static PyTypeObject *Break_type
89-
Python/ast.c decode_unicode_with_escapes buf variable char *buf
9089
Modules/_io/bufferedio.c - bufferediobase_methods variable static PyMethodDef bufferediobase_methods
9190
Modules/_io/bufferedio.c - bufferedrandom_getset variable static PyGetSetDef bufferedrandom_getset[]
9291
Modules/_io/bufferedio.c - bufferedrandom_members variable static PyMemberDef bufferedrandom_members[]
@@ -139,7 +138,7 @@ Objects/codeobject.c - code_methods variable static PyMethodDef code_methods
139138
Modules/_collectionsmodule.c - _collectionsmodule variable static struct PyModuleDef _collectionsmodule
140139
Modules/itertoolsmodule.c - combinations_methods variable static PyMethodDef combinations_methods
141140
Modules/itertoolsmodule.c - combinations_type variable static PyTypeObject combinations_type
142-
Objects/typeobject.c object_new comma_id variable "_Py_static_string(comma_id, "", "")"
141+
Objects/typeobject.c object_new comma_id variable _Py_static_string(comma_id, "", "")
143142
Python/Python-ast.c - Compare_fields variable static const char *Compare_fields[]
144143
Python/Python-ast.c - Compare_type variable static PyTypeObject *Compare_type
145144
Objects/complexobject.c - complex_as_number variable static PyNumberMethods complex_as_number
@@ -175,7 +174,7 @@ Modules/_collectionsmodule.c - defdict_methods variable static PyMethodDef defdi
175174
Modules/_collectionsmodule.c - defdict_type variable static PyTypeObject defdict_type
176175
Python/Python-ast.c - Delete_fields variable static const char *Delete_fields[]
177176
Python/Python-ast.c - Delete_type variable static PyTypeObject *Delete_type
178-
Python/Python-ast.c - Del_singleton variable PyObject *Del_singleton
177+
Python/Python-ast.c - Del_singleton variable static PyObject *Del_singleton
179178
Python/Python-ast.c - Del_type variable static PyTypeObject *Del_type
180179
Modules/_collectionsmodule.c - deque_as_number variable static PyNumberMethods deque_as_number
181180
Modules/_collectionsmodule.c - deque_as_sequence variable static PySequenceMethods deque_as_sequence
@@ -213,8 +212,8 @@ Python/Python-ast.c - Div_type variable static PyTypeObject *Div_type
213212
Python/compile.c - __doc__ variable static PyObject *__doc__
214213
Objects/classobject.c method_get_doc docstr variable static PyObject *docstr
215214
Objects/classobject.c instancemethod_get_doc docstr variable static PyObject *docstr
216-
Python/compile.c compiler_set_qualname dot variable "_Py_static_string(dot, ""."")"
217-
Python/compile.c compiler_set_qualname dot_locals variable "_Py_static_string(dot_locals, "".<locals>"")"
215+
Python/compile.c compiler_set_qualname dot variable _Py_static_string(dot, ""."")
216+
Python/compile.c compiler_set_qualname dot_locals variable _Py_static_string(dot_locals, "".<locals>"")
218217
Objects/floatobject.c - double_format variable static float_format_type double_format
219218
Modules/itertoolsmodule.c - dropwhile_methods variable static PyMethodDef dropwhile_methods
220219
Modules/itertoolsmodule.c - dropwhile_type variable static PyTypeObject dropwhile_type
@@ -333,25 +332,6 @@ Python/sysmodule.c - hash_info_desc variable static PyStructSequence_Desc hash_i
333332
Python/sysmodule.c - hash_info_fields variable static PyStructSequence_Field hash_info_fields[]
334333
Python/sysmodule.c - Hash_InfoType variable static PyTypeObject Hash_InfoType
335334
Python/import.c import_find_and_load header variable static int header
336-
Modules/_elementtree.c _elementtree_Element___deepcopy___impl id variable PyObject* id
337-
Objects/obmalloc.c _PyMem_DebugCheckAddress id variable char id
338-
Objects/obmalloc.c _PyObject_DebugDumpAddress id variable char id
339-
Python/ast.c ast_for_dotted_name id variable identifier id
340-
Python/Python-ast.c obj2ast_expr id variable identifier id
341-
Modules/_xxsubinterpretersmodule.c _channels_next_id id variable int64_t id
342-
Modules/_xxsubinterpretersmodule.c _channels_add id variable int64_t id
343-
Modules/_xxsubinterpretersmodule.c _channel_create id variable int64_t id
344-
Modules/_xxsubinterpretersmodule.c interp_get_main id variable PY_INT64_T id
345-
Objects/interpreteridobject.c _Py_CoerceID id variable int64_t id
346-
Objects/interpreteridobject.c interpid_new id variable int64_t id
347-
Objects/interpreteridobject.c interpid_dealloc id variable int64_t id
348-
Objects/interpreteridobject.c _PyInterpreterID_LookUp id variable int64_t id
349-
Objects/interpreteridobject.c _PyInterpreterState_GetIDObject id variable PY_INT64_T id
350-
Python/pystate.c interp_look_up_id id variable PY_INT64_T id
351-
??? ??? id variable ???
352-
??? ??? id variable ???
353-
??? ??? id variable ???
354-
??? ??? id variable ???
355335
Python/Python-ast.c - IfExp_fields variable static const char *IfExp_fields[]
356336
Python/Python-ast.c - IfExp_type variable static PyTypeObject *IfExp_type
357337
Python/Python-ast.c - If_fields variable static const char *If_fields[]
@@ -461,7 +441,7 @@ Objects/listobject.c - list_methods variable static PyMethodDef list_methods
461441
Objects/listobject.c - listreviter_methods variable static PyMethodDef listreviter_methods
462442
Python/Python-ast.c - List_type variable static PyTypeObject *List_type
463443
Python/ceval.c - lltrace variable static int lltrace
464-
Python/Python-ast.c - Load_singleton variable PyObject *Load_singleton
444+
Python/Python-ast.c - Load_singleton variable static PyObject *Load_singleton
465445
Python/Python-ast.c - Load_type variable static PyTypeObject *Load_type
466446
Modules/_threadmodule.c - localdummytype variable static PyTypeObject localdummytype
467447
Modules/_localemodule.c - _localemodule variable static struct PyModuleDef _localemodule
@@ -522,7 +502,6 @@ Python/frozen.c - M___hello__ variable static unsigned char M___hello__[]
522502
Python/Python-ast.c - Mod_singleton variable static PyObject *Mod_singleton
523503
Python/Python-ast.c - mod_type variable static PyTypeObject *mod_type
524504
Python/Python-ast.c - Mod_type variable static PyTypeObject *Mod_type
525-
Python/_warnings.c normalize_module module variable PyObject *module
526505
Modules/faulthandler.c - module_def variable static struct PyModuleDef module_def
527506
Modules/_tracemalloc.c - module_def variable static struct PyModuleDef module_def
528507
Python/Python-ast.c - Module_fields variable static const char *Module_fields[]
@@ -609,13 +588,13 @@ Objects/typeobject.c slot_nb_floor_divide op_id variable _Py_static_string(op_id
609588
Objects/typeobject.c slot_nb_true_divide op_id variable _Py_static_string(op_id, OPSTR)
610589
Python/getopt.c - opt_ptr variable static const wchar_t *opt_ptr
611590
Python/initconfig.c - orig_argv variable static PyWideStringList orig_argv
612-
Python/Python-ast.c - Or_singleton variable PyObject *Or_singleton
591+
Python/Python-ast.c - Or_singleton variable static PyObject *Or_singleton
613592
Python/Python-ast.c - Or_type variable static PyTypeObject *Or_type
614593
Objects/exceptions.c - OSError_getset variable static PyGetSetDef OSError_getset[]
615594
Objects/exceptions.c - OSError_members variable static PyMemberDef OSError_members[]
616595
Objects/exceptions.c - OSError_methods variable static PyMethodDef OSError_methods
617596
Python/dtoa.c - p5s variable static Bigint *p5s
618-
Python/Python-ast.c - Param_singleton variable PyObject *Param_singleton
597+
Python/Python-ast.c - Param_singleton variable static PyObject *Param_singleton
619598
Python/Python-ast.c - Param_type variable static PyTypeObject *Param_type
620599
Python/bltinmodule.c builtin_print _parser variable static struct _PyArg_Parser _parser
621600
Python/clinic/_warnings.c.h warnings_warn _parser variable static _PyArg_Parser _parser
@@ -802,7 +781,6 @@ Objects/weakrefobject.c - proxy_methods variable static PyMethodDef proxy_method
802781
Objects/typeobject.c resolve_slotdups ptrs variable static slotdef *ptrs[MAX_EQUIV]
803782
Modules/pwdmodule.c - pwd_methods variable static PyMethodDef pwd_methods
804783
Modules/pwdmodule.c - pwdmodule variable static struct PyModuleDef pwdmodule
805-
Objects/object.c - _Py_abstract_hack variable Py_ssize_t (*_Py_abstract_hack)(PyObject *)
806784
Objects/obmalloc.c - _Py_AllocatedBlocks variable static Py_ssize_t _Py_AllocatedBlocks
807785
Objects/genobject.c - _PyAsyncGenASend_Type variable PyTypeObject _PyAsyncGenASend_Type
808786
Objects/genobject.c - _PyAsyncGenAThrow_Type variable PyTypeObject _PyAsyncGenAThrow_Type
@@ -997,7 +975,7 @@ Objects/boolobject.c - _Py_FalseStruct variable static struct _longobject _Py_Fa
997975
Objects/stringlib/unicode_format.h - PyFieldNameIter_Type variable static PyTypeObject PyFieldNameIter_Type
998976
Modules/_io/fileio.c - PyFileIO_Type variable PyTypeObject PyFileIO_Type
999977
Python/preconfig.c - Py_FileSystemDefaultEncodeErrors variable const char *Py_FileSystemDefaultEncodeErrors
1000-
Python/preconfig.c - Py_FileSystemDefaultEncoding variable const char *Py_FileSystemDefaultEncoding
978+
Python/preconfig.c - Py_FileSystemDefaultEncoding variable const char * Py_FileSystemDefaultEncoding
1001979
Python/bltinmodule.c - PyFilter_Type variable PyTypeObject PyFilter_Type
1002980
Objects/floatobject.c - PyFloat_Type variable PyTypeObject PyFloat_Type
1003981
Objects/stringlib/unicode_format.h - PyFormatterIter_Type variable static PyTypeObject PyFormatterIter_Type
@@ -1018,13 +996,13 @@ Python/hamt.c - _PyHamtKeys_Type variable PyTypeObject _PyHamtKeys_Type
1018996
Python/hamt.c - PyHamt_methods variable static PyMethodDef PyHamt_methods
1019997
Python/hamt.c - _PyHamt_Type variable PyTypeObject _PyHamt_Type
1020998
Python/hamt.c - _PyHamtValues_Type variable PyTypeObject _PyHamtValues_Type
1021-
Python/preconfig.c - _Py_HasFileSystemDefaultEncodeErrors variable int _Py_HasFileSystemDefaultEncodeErrors
1022-
Python/preconfig.c - Py_HasFileSystemDefaultEncoding variable int Py_HasFileSystemDefaultEncoding
999+
Python/preconfig.c - _Py_HasFileSystemDefaultEncodeErrors variable const(int) _Py_HasFileSystemDefaultEncodeErrors
1000+
Python/preconfig.c - Py_HasFileSystemDefaultEncoding variable const(int) Py_HasFileSystemDefaultEncoding
10231001
Python/pyhash.c - PyHash_Func variable static PyHash_FuncDef PyHash_Func
10241002
Python/initconfig.c - Py_HashRandomizationFlag variable int Py_HashRandomizationFlag
10251003
Python/pyhash.c - _Py_HashSecret variable _Py_HashSecret_t _Py_HashSecret
10261004
Python/bootstrap_hash.c - _Py_HashSecret_Initialized variable static int _Py_HashSecret_Initialized
1027-
Python/codecs.c - Py_hexdigits variable const char *Py_hexdigits
1005+
Python/codecs.c - Py_hexdigits variable const char * Py_hexdigits
10281006
Python/sysmodule.c - PyId__ variable _Py_IDENTIFIER(_)
10291007
Modules/_abc.c - PyId__abc_impl variable _Py_IDENTIFIER(_abc_impl)
10301008
Objects/typeobject.c - PyId___abstractmethods__ variable _Py_IDENTIFIER(__abstractmethods__)
@@ -1408,7 +1386,7 @@ Python/bltinmodule.c - PyId_stdout variable _Py_IDENTIFIER(stdout)
14081386
Python/Python-ast.c - PyId_step variable _Py_IDENTIFIER(step)
14091387
Modules/posixmodule.c DirEntry_test_mode PyId_st_mode variable _Py_IDENTIFIER(st_mode)
14101388
Modules/_io/textio.c - PyId_strict variable _Py_IDENTIFIER(strict)
1411-
Python/pythonrun.c - PyId_string variable "_Py_static_string(PyId_string, ""<string>"")"
1389+
Python/pythonrun.c - PyId_string variable _Py_static_string(PyId_string, ""<string>"")
14121390
Modules/timemodule.c time_strptime PyId__strptime_time variable _Py_IDENTIFIER(_strptime_time)
14131391
Modules/posixmodule.c wait_helper PyId_struct_rusage variable _Py_IDENTIFIER(struct_rusage)
14141392
Modules/_abc.c - PyId___subclasscheck__ variable _Py_IDENTIFIER(__subclasscheck__)
@@ -1775,7 +1753,7 @@ Python/symtable.c - ste_memberlist variable static PyMemberDef ste_memberlist[]
17751753
Python/Python-ast.c - stmt_attributes variable static const char *stmt_attributes[]
17761754
Python/Python-ast.c - stmt_type variable static PyTypeObject *stmt_type
17771755
Objects/exceptions.c - StopIteration_members variable static PyMemberDef StopIteration_members[]
1778-
Python/Python-ast.c - Store_singleton variable PyObject *Store_singleton
1756+
Python/Python-ast.c - Store_singleton variable static PyObject *Store_singleton
17791757
Python/Python-ast.c - Store_type variable static PyTypeObject *Store_type
17801758
Python/ast_unparse.c - _str_close_br variable static PyObject *_str_close_br
17811759
Python/ast_unparse.c - _str_dbl_close_br variable static PyObject *_str_dbl_close_br

0 commit comments

Comments
 (0)