This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: free() vs xfree() vs FREEIF() vs ISO-C
- To: GDB Discussion <gdb at sourceware dot cygnus dot com>
- Subject: Re: free() vs xfree() vs FREEIF() vs ISO-C
- From: Kevin Buettner <kevinb at cygnus dot com>
- Date: Wed, 29 Nov 2000 21:14:47 -0700
- References: <3A25AEDA.5A57A0F2@cygnus.com>
On Nov 30, 12:35pm, Andrew Cagney wrote:
> o Add/use xfree() which
> would guard against NULL.
[...]
> Does anyone have any thoughts? I tend towards the first one as that is
> fairly easy to implement. If adopted, I'd beg/borrow/con someone into
> converting all free() and free((PTR)) calls into xfree() :-)
I like this approach too.
I've eyeballed the diff output from the script below and it seems to
give pretty good results. I'll do a test build, and if all is well,
I'll post an rfc patch to gdb-patches. (Note that this patch doesn't
do any reindenting, but in the diffs I've looked at it, I don't see
a need for it in our present source tree.)
To run this script, just set your current directory to the gdb directory
and then do
subst-free-xfree .
(note the dot) or do
subst-free-xfree /path/to/gdb/sources
from anywhere.
--- 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' || (-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 (<>) {
s/\bfree \(/xfree (/g;
s/\bmake_cleanup \(free,/make_cleanup (xfree,/g;
s/\bfree\)/xfree)/g;
print;
}
--- end subst-free-xfree ---