X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=build-aux%2Fuseless-if-before-free;h=6aa7d3965f4514f480a74bf388aa9e3f44559d12;hb=e4c754e34096c0703a41f6c0e9fb7cc1f007b3ed;hp=29d4917fdde728db030a024b9b39db24b129fea2;hpb=d29d6c11acd73086ac7ffabb9a451faa1d4984f9;p=gnulib.git diff --git a/build-aux/useless-if-before-free b/build-aux/useless-if-before-free index 29d4917fd..6aa7d3965 100755 --- a/build-aux/useless-if-before-free +++ b/build-aux/useless-if-before-free @@ -1,16 +1,18 @@ -#!/usr/bin/perl -T +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. -my $VERSION = '2009-04-07 08:05'; # UTC +my $VERSION = '2009-04-16 15:57'; # 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-2010 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 @@ -175,9 +177,11 @@ my $foo = <<'EOF'; # This adjusts them, removing the unnecessary "if (p)" part. # FIXME: do something like this as an option (doesn't do braces): -useless-if-before-free -l $(lid -knone free) | xargs -0 \ - perl -0x3b -pi -e \ - 's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\)\s+(free\s*\((?:\s*\([^)]+\))?\s*\1\s*\))/$2/s' +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' # Use the following to remove redundant uses of kfree inside braces. # Note that -0777 puts perl in slurp-whole-file mode; @@ -186,7 +190,7 @@ free=kfree git grep -l -z "$free *(" \ | xargs -0 useless-if-before-free -l --name="$free" \ | xargs -0 perl -0777 -pi -e \ - 's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\)\s*\{\s*('"$free"'\s*\((?:\s*\([^)]+\))?\s*\1\s*\);)\s*\}[^\n]*$/$2/gms' + 's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*(?:0|NULL))?\s*\)\s*\{\s*('"$free"'\s*\((?:\s*\([^)]+\))?\s*\1\s*\);)\s*\}[^\n]*$/$2/gms' Be careful that the result of the above transformation is valid. If the matched string is followed by "else", then obviously, it won't be. @@ -195,6 +199,7 @@ When modifying files, refuse to process anything other than a regular file. EOF ## Local Variables: +## mode: perl ## indent-tabs-mode: nil ## eval: (add-hook 'write-file-hooks 'time-stamp) ## time-stamp-start: "my $VERSION = '"