From bea72ffce0b5b981a06eb4e80f14f10412924f6b Mon Sep 17 00:00:00 2001 From: Simon Josefsson Date: Mon, 27 Apr 2009 14:46:32 +0200 Subject: [PATCH] Update gnulib files. --- build-aux/useless-if-before-free | 206 +++++++++++++++++++++++++++++++++++++ build-aux/vc-list-files | 116 +++++++++++++++++++++ gl/Makefile.am | 14 +++ gl/m4/gnulib-comp.m4 | 6 ++ gl/tests/Makefile.am | 9 ++ gl/tests/test-vc-list-files-cvs.sh | 62 +++++++++++ gl/tests/test-vc-list-files-git.sh | 46 +++++++++ maint.mk | 4 +- 8 files changed, 461 insertions(+), 2 deletions(-) create mode 100755 build-aux/useless-if-before-free create mode 100755 build-aux/vc-list-files create mode 100755 gl/tests/test-vc-list-files-cvs.sh create mode 100755 gl/tests/test-vc-list-files-git.sh diff --git a/build-aux/useless-if-before-free b/build-aux/useless-if-before-free new file mode 100755 index 0000000..abcdef2 --- /dev/null +++ b/build-aux/useless-if-before-free @@ -0,0 +1,206 @@ +#!/usr/bin/perl -T +# 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-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. + +# 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Written by Jim Meyering + +use strict; +use warnings; +use Getopt::Long; + +(my $ME = $0) =~ s|.*/||; + +# use File::Coda; # http://meyering.net/code/Coda/ +END { + defined fileno STDOUT or return; + close STDOUT and return; + warn "$ME: failed to close standard output: $!\n"; + $? ||= 1; +} + +sub usage ($) +{ + my ($exit_code) = @_; + my $STREAM = ($exit_code == 0 ? *STDOUT : *STDERR); + if ($exit_code != 0) + { + print $STREAM "Try `$ME --help' for more information.\n"; + } + else + { + print $STREAM < sub { usage 0 }, + version => sub { print "$ME version $VERSION\n"; exit }, + list => \$list, + 'name=s@' => \@name, + ) or usage 1; + + # Make sure we have the right number of non-option arguments. + # Always tell the user why we fail. + @ARGV < 1 + and (warn "$ME: missing FILE argument\n"), usage EXIT_ERROR; + + my $or = join '|', @name; + my $regexp = qr/(?:$or)/; + + # Set the input record separator. + # Note: this makes it impractical to print line numbers. + $/ = '"'; + + my $found_match = 0; + FILE: + foreach my $file (@ARGV) + { + open FH, '<', $file + 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*\{\s*$regexp\s*\((?:\s*\([^)]+\))?\s*([^)]+)\)\s*;\s*\}))/sxg) + { + my $all = $1; + my ($lhs, $rhs) = ($2, $3); + my ($free_opnd, $braced_free_opnd) = ($4, $5); + my $non_NULL; + if (!defined $rhs) { $non_NULL = $lhs } + elsif (is_NULL $rhs) { $non_NULL = $lhs } + elsif (is_NULL $lhs) { $non_NULL = $rhs } + else { next } + + # Compare the non-NULL part of the "if" expression and the + # free'd expression, without regard to white space. + $non_NULL =~ tr/ \t//d; + my $e2 = defined $free_opnd ? $free_opnd : $braced_free_opnd; + $e2 =~ tr/ \t//d; + if ($non_NULL eq $e2) + { + $found_match = 1; + $list + and (print "$file\0"), next FILE; + print "$file: $all\n"; + } + } + } + } + continue + { + close FH; + } + + $found_match && $err == EXIT_NO_MATCH + and $err = EXIT_MATCH; + + exit $err; +} + +my $foo = <<'EOF'; +# The above is to *find* them. +# This adjusts them, removing the unnecessary "if (p)" part. + +# FIXME: do something like this as an option (doesn't do braces): +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; +# but we have plenty of memory, these days... +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*(?: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. + +When modifying files, refuse to process anything other than a regular file. +EOF + +## Local Variables: +## indent-tabs-mode: nil +## eval: (add-hook 'write-file-hooks 'time-stamp) +## time-stamp-start: "my $VERSION = '" +## time-stamp-format: "%:y-%02m-%02d %02H:%02M" +## time-stamp-time-zone: "UTC" +## time-stamp-end: "'; # UTC" +## End: diff --git a/build-aux/vc-list-files b/build-aux/vc-list-files new file mode 100755 index 0000000..9376e3d --- /dev/null +++ b/build-aux/vc-list-files @@ -0,0 +1,116 @@ +#!/bin/sh +# List version-controlled file names. + +# Print a version string. +scriptversion=2009-04-25.13; # UTC + +# Copyright (C) 2006-2009 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +# List the specified version-controlled files. +# With no argument, list them all. With a single DIRECTORY argument, +# list the version-controlled files in that directory. + +# If there's an argument, it must be a single, "."-relative directory name. +# cvsu is part of the cvsutils package: http://www.red-bean.com/cvsutils/ + +postprocess= +case $1 in + --help) cat <. +EOF + exit ;; + + --version) + year=`echo "$scriptversion" | sed 's/[^0-9].*//'` + cat < +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. +EOF + exit ;; + + -C) + test "$2" = . || postprocess="| sed 's|^|$2/|'" + cd "$2" || exit 1 + shift; shift ;; +esac + +dir= +case $# in + 0) ;; + 1) dir=$1 ;; + *) echo "$0: too many arguments" 1>&2 + echo "Usage: $0 [-C srcdir] [DIR]" 1>&2; exit 1;; +esac + +test "x$dir" = x && dir=. + +if test -d .git; then + test "x$dir" = x. \ + && dir= sed_esc= \ + || dir="$dir/" sed_esc=`echo "$dir"|sed 's,\([\\/]\),\\\\\1,g'` + # Ignore git symlinks - either they point into the tree, in which case + # we don't need to visit the target twice, or they point somewhere + # else (often into a submodule), in which case the content does not + # belong to this package. + eval exec git ls-tree -r 'HEAD:"$dir"' \ + \| sed -n '"s/^100[^ ]*./$sed_esc/p"' $postprocess +elif test -d .hg; then + eval exec hg locate '"$dir/*"' $postprocess +elif test -d .bzr; then + test "$postprocess" = '' && postprocess="| sed 's|^\./||'" + eval exec bzr ls --versioned '"$dir"' $postprocess +elif test -d CVS; then + test "$postprocess" = '' && postprocess="| sed 's|^\./||'" + if test -x build-aux/cvsu; then + eval build-aux/cvsu --find --types=AFGM '"$dir"' $postprocess + elif (cvsu --help) >/dev/null 2>&1; then + eval cvsu --find --types=AFGM '"$dir"' $postprocess + else + eval awk -F/ \''{ \ + if (!$1 && $3 !~ /^-/) { \ + f=FILENAME; \ + if (f ~ /CVS\/Entries$/) \ + f = substr(f, 1, length(f)-11); \ + print f $2; \ + }}'\'' \ + `find "$dir" -name Entries -print` /dev/null' $postprocess + fi +else + echo "$0: Failed to determine type of version control used in `pwd`" 1>&2 + exit 1 +fi + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC" +# time-stamp-end: "; # UTC" +# End: diff --git a/gl/Makefile.am b/gl/Makefile.am index db003a5..95dc230 100644 --- a/gl/Makefile.am +++ b/gl/Makefile.am @@ -1046,6 +1046,13 @@ EXTRA_DIST += unistd.in.h ## end gnulib module unistd +## begin gnulib module useless-if-before-free + + +EXTRA_DIST += $(top_srcdir)/build-aux/useless-if-before-free + +## end gnulib module useless-if-before-free + ## begin gnulib module vasnprintf @@ -1055,6 +1062,13 @@ EXTRA_libgnu_la_SOURCES += asnprintf.c printf-args.c printf-parse.c vasnprintf.c ## end gnulib module vasnprintf +## begin gnulib module vc-list-files + + +EXTRA_DIST += $(top_srcdir)/build-aux/vc-list-files + +## end gnulib module vc-list-files + ## begin gnulib module version-etc libgnu_la_SOURCES += version-etc.h version-etc.c diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4 index db94eda..fc7e4eb 100644 --- a/gl/m4/gnulib-comp.m4 +++ b/gl/m4/gnulib-comp.m4 @@ -235,6 +235,8 @@ AC_SUBST([LTALLOCA]) gl_SYS_IOCTL_H AC_PROG_MKDIR_P AC_CHECK_FUNCS([shutdown]) + abs_aux_dir=`cd "$ac_aux_dir"; pwd` + AC_SUBST([abs_aux_dir]) m4_ifval(gltests_LIBSOURCES_LIST, [ m4_syscmd([test ! -d ]m4_defn([gltests_LIBSOURCES_DIR])[ || for gl_file in ]gltests_LIBSOURCES_LIST[ ; do @@ -332,6 +334,8 @@ AC_DEFUN([gl_FILE_LIST], [ build-aux/link-warning.h build-aux/pmccabe.css build-aux/pmccabe2html + build-aux/useless-if-before-free + build-aux/vc-list-files doc/fdl-1.3.texi doc/gendocs_template doc/gpl-3.0.texi @@ -521,6 +525,8 @@ AC_DEFUN([gl_FILE_LIST], [ tests/test-sys_time.c tests/test-unistd.c tests/test-vasnprintf.c + tests/test-vc-list-files-cvs.sh + tests/test-vc-list-files-git.sh tests/test-wchar.c tests=lib/dummy.c tests=lib/gettimeofday.c diff --git a/gl/tests/Makefile.am b/gl/tests/Makefile.am index d6d7b03..421303a 100644 --- a/gl/tests/Makefile.am +++ b/gl/tests/Makefile.am @@ -352,6 +352,15 @@ EXTRA_DIST += test-vasnprintf.c ## end gnulib module vasnprintf-tests +## begin gnulib module vc-list-files-tests + +TESTS += test-vc-list-files-git.sh +TESTS += test-vc-list-files-cvs.sh +TESTS_ENVIRONMENT += PATH='$(abs_aux_dir)'$(PATH_SEPARATOR)"$$PATH" +EXTRA_DIST += test-vc-list-files-git.sh test-vc-list-files-cvs.sh + +## end gnulib module vc-list-files-tests + ## begin gnulib module verify libtests_a_SOURCES += verify.h diff --git a/gl/tests/test-vc-list-files-cvs.sh b/gl/tests/test-vc-list-files-cvs.sh new file mode 100755 index 0000000..12c9366 --- /dev/null +++ b/gl/tests/test-vc-list-files-cvs.sh @@ -0,0 +1,62 @@ +#!/bin/sh +# Unit tests for vc-list-files +# Copyright (C) 2008 Free Software Foundation, Inc. +# This file is part of the GNUlib Library. +# +# 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 +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +tmpdir=vc-cvs-$$ +trap 'st=$?; cd '"`pwd`"' && rm -rf $tmpdir; exit $st' 0 +trap '(exit $?); exit $?' 1 2 13 15 + +if ( diff --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then + compare() { diff -u "$@"; } +elif ( cmp --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then + compare() { cmp -s "$@"; } +else + compare() { cmp "$@"; } +fi + +repo=`pwd`/$tmpdir/repo + +fail=0 +for i in with-cvsu without; do + # On the first iteration, test using cvsu, if it's in your path. + # On the second iteration, ensure that cvsu fails, so we'll + # exercise the awk-using code. + if test $i = without; then + printf '%s\n' '#!/bin/sh' 'exit 1' > cvsu + chmod a+x cvsu + PATH=`pwd`:$PATH + export PATH + fi + ok=0 + mkdir $tmpdir && cd $tmpdir && + # without cvs, skip the test + # The double use of 'exit' is needed for the reference to $? inside the trap. + { ( cvs -Q -d "$repo" init ) > /dev/null 2>&1 \ + || { echo "Skipping test: cvs not found in PATH"; (exit 77); exit 77; }; } && + mkdir w && cd w && + mkdir d && + touch d/a b c && + cvs -Q -d "$repo" import -m imp m M M0 && + cvs -Q -d "$repo" co m && cd m && + printf '%s\n' b c d/a > expected && + vc-list-files | sort > actual && + compare expected actual && + ok=1 + test $ok = 0 && fail=1 +done + +(exit $fail); exit $fail diff --git a/gl/tests/test-vc-list-files-git.sh b/gl/tests/test-vc-list-files-git.sh new file mode 100755 index 0000000..a42aec1 --- /dev/null +++ b/gl/tests/test-vc-list-files-git.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# Unit tests for vc-list-files +# Copyright (C) 2008 Free Software Foundation, Inc. +# This file is part of the GNUlib Library. +# +# 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 +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +if ( diff --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then + compare() { diff -u "$@"; } +elif ( cmp --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then + compare() { cmp -s "$@"; } +else + compare() { cmp "$@"; } +fi + +tmpdir=vc-git-$$ +trap 'st=$?; cd '"`pwd`"' && rm -rf $tmpdir; exit $st' 0 +trap '(exit $?); exit $?' 1 2 13 15 + +fail=1 +mkdir $tmpdir && cd $tmpdir && + # without git, skip the test + # The double use of 'exit' is needed for the reference to $? inside the trap. + { ( git init -q ) > /dev/null 2>&1 \ + || { echo "Skipping test: git not found in PATH"; (exit 77); exit 77; }; } && + mkdir d && + touch d/a b c && + git add . > /dev/null && + git commit -q -a -m log && + printf '%s\n' b c d/a > expected && + vc-list-files > actual && + compare expected actual && + fail=0 + +(exit $fail); exit $fail diff --git a/maint.mk b/maint.mk index 9a683a7..229b0dc 100644 --- a/maint.mk +++ b/maint.mk @@ -32,7 +32,7 @@ GIT = git VC = $(GIT) VC-tag = git tag -s -m '$(VERSION)' -u '$(gpg_key_ID)' -VC_LIST = $(gnulib_dir)/build-aux/vc-list-files -C $(srcdir) +VC_LIST = $(srcdir)/build-aux/vc-list-files -C $(srcdir) VC_LIST_EXCEPT = \ $(VC_LIST) | if test -f $(srcdir)/.x-$@; then grep -vEf $(srcdir)/.x-$@; else grep -v ChangeLog; fi @@ -111,7 +111,7 @@ define _prohibit_regexp endef sc_avoid_if_before_free: - @$(gnulib_dir)/build-aux/useless-if-before-free \ + @$(srcdir)/build-aux/useless-if-before-free \ $(useless_free_options) \ $$($(VC_LIST_EXCEPT)) && \ { echo '$(ME): found useless "if" before "free" above' 1>&2; \ -- 2.1.4