diff --git a/addons/threadsafety.py b/addons/threadsafety.py index 07f737e62..9475e1a5b 100755 --- a/addons/threadsafety.py +++ b/addons/threadsafety.py @@ -9,9 +9,6 @@ cppcheck addon for threadsafety detection. """ -from __future__ import print_function - -import os import re import sys @@ -315,44 +312,24 @@ def checkstatic(data): # noqa: D103 'threadsafety') -def check_MTunsafe(data, srcfile, quiet=False): +def check_MTunsafe(cfg): """ Look for functions marked MT-unsafe in their man pages. 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 """ - # Assume that the code is Multi-thread safe until proven otherwise - MTsafe = True - - # go through each configuration - 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 + for token in cfg.tokenlist: + if token.str in id_MTunsafe: + reportError(token, 'warning', token.str + ' is MT-unsafe', + 'unsafe-call') if __name__ == '__main__': - parser = get_args_parser() + parser = cppcheckdata.ArgumentParser() args = parser.parse_args() - exit_code = 0 - quiet = not any((args.quiet, args.cli)) + quiet = args.quiet or args.cli if not args.dumpfile: if not args.quiet: @@ -360,31 +337,14 @@ if __name__ == '__main__': sys.exit(0) 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 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(): - 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) sys.exit(cppcheckdata.EXIT_CODE)