diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/checkapi | 66 | ||||
-rwxr-xr-x | bin/checkposix | 145 |
2 files changed, 131 insertions, 80 deletions
diff --git a/bin/checkapi b/bin/checkapi index d21863b..b4a08e8 100755 --- a/bin/checkapi +++ b/bin/checkapi @@ -17,33 +17,51 @@ require 5.003; # Purpose: insures that API functions aren't called internally. # Usage: checkapi H5*.c -my $comment = 0; -while (<>) { +my $filename = ""; +my $lastname = ""; - # Remove comments within the line. - s/\/\*.*?\*\///g; +if(<>) { + while (<>) { + if($ARGV =~ /\//) { + ($filename) = ($ARGV =~ /^.*\/([A-Za-z0-9_]*)\.c$/); + } else { + ($filename) = ($ARGV =~ /([A-Za-z0-9_]*)\.c$/); + } - # Process comment begin and end tokens on this line. - $comment-- if /\*\//; # count comment ends - next if $comment; # skip line if in comment - $comment++ if /\/\*/; # count comment starts - s/(.*)\/\*.*/$1/; # remove comments that begin on this line + if($filename =~ /H5FDmulti|H5FDstdio/) { + if($filename ne $lastname) { + print "$ARGV is exempt from checking\n"; + $lastname = $filename; + } + } else { + # Get rid of comments by removing the inside part. + s|/\*.*?\*/||g; + if ($in_comment) { + if (/\*\//) { + s|.*?\*/||; + $in_comment = 0; + } else { + $_="\n"; + } + } elsif (m|/\*|) { + s|/\*.*||; + $in_comment = 1; + } - # Remove character strings - s/\\.//g; # remove escaped characters - s/\".*?\"//g; # remove string constants + # Remove character strings + s/\\.//g; # remove escaped characters + s/\".*?\"//g; # remove string constants - # Disregard the following hits - next if /^H5/; - next if /^\#/; - next if /FUNC_ENTER(_NOINIT)*/; + # Disregard the following hits + next if /^H5/; + next if /^\#/; + next if /FUNC_ENTER(_NOINIT)*/; - next unless /(H5[A-Z]{1,2}[a-z]\w*)/; - print "$ARGV:$.: $1\n"; -} continue { - if (eof) { - print "$ARGV:$.: bad comment nesting\n" if $comment; - $comment = 0; - close ARGV; # reset line number - } + next unless /(H5[A-Z]{1,2}[a-z]\w*)/; + print "$ARGV:$.: $1\n"; + } + } continue { + close ARGV if eof; # reset line number + } } + diff --git a/bin/checkposix b/bin/checkposix index b295d7d..e3617e5 100755 --- a/bin/checkposix +++ b/bin/checkposix @@ -27,60 +27,93 @@ require 5.003; # use `next-error' (usually bound to M-`) to find each name # violation. -while (<>) { - - # Get rid of comments by removing the inside part. - s|/\*.*?\*/||g; - if ($in_comment) { - if (/\*\//) { - s|.*?\*/||; - $in_comment = 0; - } else { - $_="\n"; - } - } elsif (m|/\*|) { - s|/\*.*||; - $in_comment = 1; - } - - # Get rid of string constants if they begin and end on this line. - s/([\'\"])([^\1]|\\\1)*?\1/$1$1/g; - - # Get rid of preprocessor directives - s/^\#.*//; - - # Now find all function calls on this line - while (($name)=/\b([a-gi-z_A-GI-Z]\w*)\s*\(/) { - $_ = $'; - - # Ignore C statements that look sort of like function - # calls. - next if $name =~ /^(if|for|return|sizeof|switch|while|void)$/; - - # Ignore things that get misdetected because of the simplified - # parsing that takes place here. - next if $name =~ /^int$/; - - # These are really HDF5 functions/macros even though they don't - # start with `h' or `H'. - next if $name =~ /^FUNC_(ENTER|LEAVE)(_INIT)?$/; - next if $name =~ /^U?INT(8|16|32|64)(ENCODE|DECODE)$/; - next if $name =~ /^(MIN3?|MAX3?|NELMTS|BOUND|CONSTR)$/; - next if $name =~ /^IS_H5FD_MPIO$/; - next if $name =~ /^addr_defined$/; - - # These functions/macros are exempt. - next if $name =~ /^(assert|main|[fs]?printf|va_(start|arg|end))$/; - - # These are MPI function calls. Ignore them. - next if $name =~ /^MPI_/; - - # These are POSIX threads function calls. Ignore them. - next if $name =~ /^pthread_/; - - print "$ARGV:$.: $name\n"; - } - -} continue { - close ARGV if eof; +if(<>) { + if($ARGV =~ /\//) { + ($filename) = ($ARGV =~ /^.*\/([A-Za-z0-9_]*)\.c$/); + } else { + ($filename) = ($ARGV =~ /([A-Za-z0-9_]*)\.c$/); + } + + if($filename =~ /H5FDmulti|H5FDstdio/) { + print "$ARGV is exempt from using Standard library macro wrappers\n"; + } else { + while (<>) { + + # Get rid of comments by removing the inside part. + s|/\*.*?\*/||g; + if ($in_comment) { + if (/\*\//) { + s|.*?\*/||; + $in_comment = 0; + } else { + $_="\n"; + } + } elsif (m|/\*|) { + s|/\*.*||; + $in_comment = 1; + } + + # Get rid of string constants if they begin and end on this line. + s/([\'\"])([^\1]|\\\1)*?\1/$1$1/g; + + # Get rid of preprocessor directives + s/^\#.*//; + + # Skip callbacks invoked as methods in a struct + next if $_ =~ /\b(\)?->|\.)\(?([a-z_A-Z]\w*)\s*\(/; + + # Now find all function calls on this line which don't start with 'H' + while (($name)=/\b([a-z_A-GI-Z]\w*)\s*\(/) { + $_ = $'; + + # Ignore C statements that look sort of like function + # calls. + next if $name =~ /^(if|for|offsetof|return|sizeof|switch|while|void)$/; + + # Ignore things that get misdetected because of the simplified + # parsing that takes place here. + next if $name =~ /^(int|herr_t|_term_interface)$/; + + # These are really HDF5 functions/macros even though they don't + # start with `h' or `H'. + next if $name =~ /^FUNC_(ENTER|LEAVE)(_(NO)?API|_PACKAGE|_STATIC)?(_NOFS|_NOCLEAR|_NOINIT)?(_NOFUNC|_TAG)?$/; + next if $name =~ /^(BEGIN|END)_FUNC$/; + next if $name =~ /^U?INT(8|16|32|64)(ENCODE|DECODE)(_VAR)?$/; + next if $name =~ /^CI_(PRINT_STATS|INC_SRC|INC_DST)$/; + next if $name =~ /^(ABS|ADDR_OVERFLOW|ALL_MEMBERS|BOUND|CONSTR|DETECT_[I|F|M]|DOWN)$/; + next if $name =~ /^(MIN3?|MAX3?|NELMTS|POWER_OF_TWO|REGION_OVERFLOW)$/; + next if $name =~ /^(UNIQUE_MEMBERS)$/; + next if $name =~ /^(IS_H5FD_MPIO|IS_H5FD_MPIPOSIX)$/; + next if $name =~ /^addr_defined$/; + + # These functions/macros are exempt. + next if $name =~ /^(main|[fs]?printf|va_(start|arg|end))$/; + + # These are Windows system calls. Ignore them. + next if $name =~ /^(_get_osfhandle|GetFileInformationByHandle|SetFilePointer|GetLastError|SetEndOfFile)$/; + next if $name =~ /^(FindNextFile|FindClose|_tzset|Wgettimeofday|GetSystemTimeAsFileTime|Wgetlogin|GetUserName)$/; + + # These are GPFS function calls. Ignore them. + next if $name =~ /^gpfs_fcntl$/; + + # These are MPI function calls. Ignore them. + next if $name =~ /^(MPI_|MPE_)/; + + # These are POSIX threads function calls. Ignore them. + next if $name =~ /^pthread_/; + + # These are Windows threads function calls. Ignore them. + next if $name =~ /^(_beginthread|(Initialize|Enter|Leave)CriticalSection|TlsAlloc)$/; + + # These are zlib & szlib function calls. Ignore them. + next if $name =~ /^(inflate|SZ_)/; + next if $name =~ /^compress2$/; + + print "$ARGV:$.: $name\n"; + } + + } continue { + close ARGV if eof; # reset line number + } + } } |