summaryrefslogtreecommitdiff
path: root/build-aux/useless-if-before-free
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2009-04-16 18:08:04 +0200
committerJim Meyering <meyering@redhat.com>2009-04-16 18:08:04 +0200
commitabb53db0ac56280d00b2cb8a67f61caff622ea89 (patch)
treea55f8278a754d9178fe3688d684e2dd194044c74 /build-aux/useless-if-before-free
parent8fdb8486e14c433b2b277eb11c97e859b282e7d1 (diff)
downloadgnulib-abb53db0ac56280d00b2cb8a67f61caff622ea89.tar.gz
useless-if-before-free: improve conversion code
* build-aux/useless-if-before-free: Adjust code-in-comment to match "...!= 0" as well as "...!= NULL". emacs has one of the former.
Diffstat (limited to 'build-aux/useless-if-before-free')
-rwxr-xr-xbuild-aux/useless-if-before-free12
1 files changed, 7 insertions, 5 deletions
diff --git a/build-aux/useless-if-before-free b/build-aux/useless-if-before-free
index 29d4917fdd..abcdef2cda 100755
--- a/build-aux/useless-if-before-free
+++ b/build-aux/useless-if-before-free
@@ -4,7 +4,7 @@
# 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
@@ -175,9 +175,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 +188,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.