This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[SCRIPT] subst-free-xfree for free() -> xfree() substitutions


Below is the modified script that I used to make the changes in
part 2 of the free() -> xfree() patch recently posted.

--- subst-free-xfree ---
#!/usr/bin/perl -w

use File::Find;
use FileHandle;
use IPC::Open3;
use English;

my ($root) = @ARGV;

if (!defined($root)) {
    die "Usage: $0 root\n";
}

@ARGV = ();

find(
    sub { 
	if ($_ eq 'testsuite' || $_ eq 'gdbserver' || (-d && /-share$/)) {
	    $File::Find::prune = 1;
	} elsif (-f && -T && /\.c$/ && $_ ne "gnu-regex.c") {
	    push @ARGV, $File::Find::name;
	}
    },
    $root
);

$INPLACE_EDIT = '';
undef $/;			# slurp entire files

while (<>) {
    # Turn calls to free into calls to xfree
    s/\bfree			# free
      \s			# one space
      \(			# left paren
	(			# plus, optionally, a cast consisting of
	 \(			#  a left paren, plus either
	   (  PTR		#  PTR,
	    | char\s*\*)	#  or char *
	 \)			#  followed by a right paren
	 \s*			#  and any number of spaces
	)?
     /xfree (/gx;
    # Fix occurrences of free in make_cleanup calls
    s/\bmake_cleanup \(free,/make_cleanup (xfree,/g;
    # Fix occurrences of free in other calls where free appears as a
    # final parameter.
    s/\bfree\)/xfree)/g;

    print;
}
--- end subst-free-xfree ---

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]