Skip to content

Commit 89125e9

Browse files
Allow local use of static PyMutex in the C analyzer (python#127102)
1 parent 8c98ed8 commit 89125e9

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Tools/c-analyzer/cpython/_analyzer.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,26 @@ def _is_kwlist(decl):
280280
vartype = ''.join(str(decl.vartype).split())
281281
return vartype == 'char*[]'
282282

283+
def _is_local_static_mutex(decl):
284+
if not hasattr(decl, "vartype"):
285+
return False
286+
287+
if not hasattr(decl, "parent") or decl.parent is None:
288+
# We only want to allow local variables
289+
return False
290+
291+
vartype = decl.vartype
292+
return (vartype.typespec == 'PyMutex') and (decl.storage == 'static')
283293

284294
def _has_other_supported_type(decl):
285295
if hasattr(decl, 'file') and decl.file.filename.endswith('.c.h'):
286296
assert 'clinic' in decl.file.filename, (decl,)
287297
if decl.name == '_kwtuple':
288298
return True
299+
if _is_local_static_mutex(decl):
300+
# GH-127081: Local static mutexes are used to
301+
# wrap libc functions that aren't thread safe
302+
return True
289303
vartype = str(decl.vartype).split()
290304
if vartype[0] == 'struct':
291305
vartype = vartype[1:]

Tools/c-analyzer/cpython/ignored.tsv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,6 @@ Modules/expat/xmlrole.c - declClose -
739739
Modules/expat/xmlrole.c - error -
740740

741741
## other
742-
Modules/grpmodule.c grp_getgrall_impl getgrall_mutex -
743742
Modules/_io/_iomodule.c - _PyIO_Module -
744743
Modules/_sqlite/module.c - _sqlite3module -
745744
Modules/clinic/md5module.c.h _md5_md5 _keywords -

0 commit comments

Comments
 (0)