X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=build-aux%2Fuseless-if-before-free;h=663347a3a9cc133b49b319a4240670dc6a4eda9d;hb=5191b3546cfb6c163228c23f214e325ddf60d46f;hp=966d60462d6f91b639ec61161a97123aa1714ffe;hpb=3030c5b5e0a5199e16b05927da72c43c42f211c3;p=gnulib.git diff --git a/build-aux/useless-if-before-free b/build-aux/useless-if-before-free index 966d60462..663347a3a 100755 --- a/build-aux/useless-if-before-free +++ b/build-aux/useless-if-before-free @@ -2,17 +2,15 @@ eval '(exit $?0)' && eval 'exec perl -wST "$0" ${1+"$@"}' & eval 'exec perl -wST "$0" $argv:q' if 0; # Detect instances of "if (p) free (p);". -# Likewise for "if (p != NULL) free (p);". And with braces. -# Also detect "if (NULL != p) free (p);". -# And with 0 in place of NULL. +# Likewise "if (p != 0)", "if (0 != p)", or with NULL; and with braces. -my $VERSION = '2009-04-16 15:57'; # UTC +my $VERSION = '2012-01-06 07:23'; # UTC # The definition above must lie within the first 8 lines in order # for the Emacs time-stamp write hook (at end) to update it. # If you change this file with Emacs, please let the write hook # do its job. Otherwise, update this string manually. -# Copyright (C) 2008-2009 Free Software Foundation, Inc. +# Copyright (C) 2008-2013 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -49,7 +47,7 @@ sub usage ($) my $STREAM = ($exit_code == 0 ? *STDOUT : *STDERR); if ($exit_code != 0) { - print $STREAM "Try `$ME --help' for more information.\n"; + print $STREAM "Try '$ME --help' for more information.\n"; } else { @@ -63,8 +61,8 @@ detect free-like functions named FOO and BAR. OPTIONS: - --list print only the name of each matching FILE (\0-terminated) - --name=N add name N to the list of \`free\'-like functions to detect; + --list print only the name of each matching FILE (\\0-terminated) + --name=N add name N to the list of \'free\'-like functions to detect; may be repeated --help display this help and exit @@ -127,14 +125,14 @@ sub is_NULL ($) foreach my $file (@ARGV) { open FH, '<', $file - or (warn "$ME: can't open `$file' for reading: $!\n"), + or (warn "$ME: can't open '$file' for reading: $!\n"), $err = EXIT_ERROR, next; while (defined (my $line = )) { while ($line =~ /\b(if\s*\(\s*([^)]+?)(?:\s*!=\s*([^)]+?))?\s*\) # 1 2 3 - (?: \s*$regexp\s*\((?:\s*\([^)]+\))?\s*([^)]+)\)| + (?: \s*$regexp\s*\((?:\s*\([^)]+\))?\s*([^)]+)\)\s*;| \s*\{\s*$regexp\s*\((?:\s*\([^)]+\))?\s*([^)]+)\)\s*;\s*\}))/sxg) { my $all = $1; @@ -181,7 +179,7 @@ free=xfree git grep -l -z "$free *(" \ | xargs -0 useless-if-before-free -l --name="$free" \ | xargs -0 perl -0x3b -pi -e \ - 's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*(?:0|NULL))?\s*\)\s+('"$free"'\s*\((?:\s*\([^)]+\))?\s*\1\s*\))/$2/s' + 's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*(?:0|NULL))?\s*\)\s+('"$free"'\s*\((?:\s*\([^)]+\))?\s*\1\s*\)\s*;)/$2/s' # Use the following to remove redundant uses of kfree inside braces. # Note that -0777 puts perl in slurp-whole-file mode;