threadsafety.py: cleanup (#5132)
This commit is contained in:
parent
0727528876
commit
d4902109cd
|
@ -9,9 +9,6 @@ cppcheck addon for threadsafety detection.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -315,44 +312,24 @@ def checkstatic(data): # noqa: D103
|
||||||
'threadsafety')
|
'threadsafety')
|
||||||
|
|
||||||
|
|
||||||
def check_MTunsafe(data, srcfile, quiet=False):
|
def check_MTunsafe(cfg):
|
||||||
"""
|
"""
|
||||||
Look for functions marked MT-unsafe in their man pages.
|
Look for functions marked MT-unsafe in their man pages.
|
||||||
|
|
||||||
The MT-unsafe functions are listed in id_MTunsafe (and id_MTunsafe_full).
|
The MT-unsafe functions are listed in id_MTunsafe (and id_MTunsafe_full).
|
||||||
That section of code can be regenerated by the external script MT-Unsafe.py
|
That section of code can be regenerated by the external script MT-Unsafe.py
|
||||||
"""
|
"""
|
||||||
# Assume that the code is Multi-thread safe until proven otherwise
|
for token in cfg.tokenlist:
|
||||||
MTsafe = True
|
if token.str in id_MTunsafe:
|
||||||
|
reportError(token, 'warning', token.str + ' is MT-unsafe',
|
||||||
# go through each configuration
|
'unsafe-call')
|
||||||
for cfg in data.iterconfigurations():
|
|
||||||
if not quiet:
|
|
||||||
print('Checking %s, config %s...' % (srcfile, cfg.name))
|
|
||||||
|
|
||||||
# go through all tokens
|
|
||||||
for token in cfg.tokenlist:
|
|
||||||
if token.str in id_MTunsafe:
|
|
||||||
cppcheckdata.reportError(token, 'warning',
|
|
||||||
token.str + ' is MT-unsafe',
|
|
||||||
'threadsafety',
|
|
||||||
'unsafe-call')
|
|
||||||
MTsafe = False
|
|
||||||
|
|
||||||
return MTsafe
|
|
||||||
|
|
||||||
|
|
||||||
def get_args_parser(): # noqa: D103
|
|
||||||
parser = cppcheckdata.ArgumentParser()
|
|
||||||
return parser
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = get_args_parser()
|
parser = cppcheckdata.ArgumentParser()
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
exit_code = 0
|
quiet = args.quiet or args.cli
|
||||||
quiet = not any((args.quiet, args.cli))
|
|
||||||
|
|
||||||
if not args.dumpfile:
|
if not args.dumpfile:
|
||||||
if not args.quiet:
|
if not args.quiet:
|
||||||
|
@ -360,31 +337,14 @@ if __name__ == '__main__':
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
for dumpfile in args.dumpfile:
|
for dumpfile in args.dumpfile:
|
||||||
# for arg in sys.argv[1:]:
|
|
||||||
# if arg.startswith('-'):
|
|
||||||
# continue
|
|
||||||
|
|
||||||
if not args.quiet:
|
|
||||||
print('Checking ' + dumpfile + '...')
|
|
||||||
|
|
||||||
# load XML from .dump file
|
# load XML from .dump file
|
||||||
data = cppcheckdata.CppcheckData(dumpfile)
|
data = cppcheckdata.CppcheckData(dumpfile)
|
||||||
# data = cppcheckdata.CppcheckData(args)
|
|
||||||
|
|
||||||
# Convert dump file path to source file in format generated by
|
|
||||||
# cppcheck. For example after the following call:
|
|
||||||
# cppcheck ./src/my-src.c --dump
|
|
||||||
# We got 'src/my-src.c' value for 'file' field in cppcheckdata.
|
|
||||||
srcfile = dumpfile.rstrip('.dump')
|
|
||||||
srcfile = os.path.expanduser(srcfile)
|
|
||||||
srcfile = os.path.normpath(srcfile)
|
|
||||||
|
|
||||||
check_MTunsafe(data, srcfile, quiet)
|
|
||||||
|
|
||||||
print('Checking %s...' % args)
|
|
||||||
|
|
||||||
for cfg in data.iterconfigurations():
|
for cfg in data.iterconfigurations():
|
||||||
print('Checking %s, config %s...' % (args, cfg.name))
|
if not args.quiet:
|
||||||
|
srcfile = data.files[0]
|
||||||
|
print('Checking %s, config %s...' % (srcfile, cfg.name))
|
||||||
|
check_MTunsafe(cfg)
|
||||||
checkstatic(cfg)
|
checkstatic(cfg)
|
||||||
|
|
||||||
sys.exit(cppcheckdata.EXIT_CODE)
|
sys.exit(cppcheckdata.EXIT_CODE)
|
||||||
|
|
Loading…
Reference in New Issue