"Fossies" - the Fresh Open Source Software Archive

Member "cppcheck-1.89/addons/threadsafety.py" (1 Sep 2019, 1203 Bytes) of package /windows/misc/cppcheck-1.89.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "threadsafety.py" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.87_vs_1.88.

    1 #!/usr/bin/env python
    2 #
    3 # This script analyses Cppcheck dump files to locate threadsafety issues
    4 # - warn about static local objects
    5 #
    6 
    7 import cppcheckdata
    8 import sys
    9 
   10 def reportError(token, severity, msg, id):
   11     cppcheckdata.reportError(token, severity, msg, 'threadsafety', id)
   12 
   13 
   14 def checkstatic(data):
   15     for var in data.variables:
   16         if var.isStatic and var.isLocal:
   17             type = None
   18             if var.isClass:
   19                 type = 'object'
   20             else:
   21                 type = 'variable'
   22             if var.isConst:
   23                 reportError(var.typeStartToken, 'warning', 'Local constant static ' + type + ' \'' + var.nameToken.str + '\', dangerous if it is initialized in parallel threads', 'threadsafety')
   24             else:
   25                 reportError(var.typeStartToken, 'warning', 'Local static ' + type + ': ' + var.nameToken.str, 'threadsafety')
   26 
   27 for arg in sys.argv[1:]:
   28     if arg.startswith('-'):
   29         continue
   30     print('Checking ' + arg + '...')
   31     data = cppcheckdata.parsedump(arg)
   32     for cfg in data.configurations:
   33         if len(data.configurations) > 1:
   34             print('Checking ' + arg + ', config "' + cfg.name + '"...')
   35         checkstatic(cfg)