From: Janne Blomqvist <blomqvist.janne@gmail.com>
To: Jim Meyering <jim@meyering.net>
Cc: "Joseph S. Myers" <joseph@codesourcery.com>,
gcc-patches@gcc.gnu.org, java-patches@gcc.gnu.org,
fortran@gcc.gnu.org
Subject: Re: [PATCH v3] Re: avoid useless if-before-free tests
Date: Tue, 15 Mar 2011 09:19:00 -0000 [thread overview]
Message-ID: <AANLkTimAfkfmmfxrNp4w_wD2rGiQ7x07esgtVDT_-8Cj@mail.gmail.com> (raw)
In-Reply-To: <877hc9pkhp.fsf_-_@rho.meyering.net>
On Tue, Mar 8, 2011 at 19:53, Jim Meyering <jim@meyering.net> wrote:
> Relative to v2, I've added libgo/ to the list of exempt directories and added
> this recently discussed gfc_free patch, at the request of Tobias Burnus.
> Also, I corrected an error in fortran's ChangeLog and removed all
> whitespace changes from all ChangeLog files.
The libgfortran changes are Ok for 4.7.
For the gfortran frontend (gcc/fortran/*) I'd prefer if you'd
- Replace all calls to "gfc_free (x)" with "free (x)".
- Remove the gfc_free() function and prototype.
- Remove the free() macro which currently prevents calling free() directly.
> From 0d18b70a8821ab2fc58b5ed592ed611e05a29c7f Mon Sep 17 00:00:00 2001
> From: Jim Meyering <meyering@redhat.com>
> Date: Mon, 3 Jan 2011 16:52:37 +0100
> Subject: [PATCH 1/2] discourage unnecessary use of if before free
>
> * README.Portability: Explain why "if (P) free (P)" is best avoided.
> ---
> gcc/README.Portability | 23 ++++++++++++++++-------
> 1 files changed, 16 insertions(+), 7 deletions(-)
>
> diff --git a/gcc/README.Portability b/gcc/README.Portability
> index 32a33e2..e099a3f 100644
> --- a/gcc/README.Portability
> +++ b/gcc/README.Portability
> @@ -51,14 +51,24 @@ foo (bar, )
> needs to be coded in some other way.
>
>
> -free and realloc
> -----------------
> +Avoid unnecessary test before free
> +----------------------------------
>
> -Some implementations crash upon attempts to free or realloc the null
> -pointer. Thus if mem might be null, you need to write
> +Since SunOS 4 stopped being a reasonable portability target,
> +(which happened around 2007) there has been no need to guard
> +against "free (NULL)". Thus, any guard like the following
> +constitutes a redundant test:
>
> - if (mem)
> - free (mem);
> + if (P)
> + free (P);
> +
> +It is better to avoid the test.[*]
> +Instead, simply free P, regardless of whether it is NULL.
> +
> +[*] However, if your profiling exposes a test like this in a
> +performance-critical loop, say where P is nearly always NULL, and
> +the cost of calling free on a NULL pointer would be prohibitively
> +high, please let us know.
Instead of "please let us know", maybe recommend using
__builtin_expect instead? E.g. something like
if (__builtin_expect (ptr != NULL, 0))
free (ptr);
--
Janne Blomqvist
next prev parent reply other threads:[~2011-03-15 9:19 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <87zkp9zmq0.fsf@rho.meyering.net>
2011-03-05 19:16 ` Joseph S. Myers
2011-03-07 19:52 ` Dr Andrew John Hughes
2011-03-07 22:47 ` Joseph S. Myers
2011-03-08 16:57 ` Dr Andrew John Hughes
2011-03-08 17:07 ` Andrew Haley
2011-03-08 17:17 ` Jim Meyering
2011-03-08 10:45 ` Jim Meyering
2011-03-08 14:21 ` [PATCH v2] " Jim Meyering
2011-03-08 14:30 ` Rainer Orth
2011-03-08 15:28 ` Ian Lance Taylor
2011-03-08 15:36 ` Jakub Jelinek
2011-03-08 17:03 ` Jim Meyering
2011-03-08 18:45 ` Rainer Orth
2011-03-08 19:13 ` Jim Meyering
2011-03-08 19:20 ` Rainer Orth
2011-03-08 19:39 ` Jakub Jelinek
2011-03-08 17:54 ` [PATCH v3] " Jim Meyering
2011-03-08 19:34 ` DJ Delorie
2011-03-15 9:19 ` Janne Blomqvist [this message]
2011-03-15 10:03 ` [PATCH gcc/fortran] get rid of gfc_free Jim Meyering
2011-03-15 10:08 ` Jakub Jelinek
2011-03-15 10:27 ` Jim Meyering
2011-03-15 14:18 ` Janne Blomqvist
2011-03-15 18:21 ` Jim Meyering
2011-03-24 16:51 ` [PATCH v3] Re: avoid useless if-before-free tests Jim Meyering
2011-04-15 7:26 ` Janne Blomqvist
2011-04-15 7:54 ` Jim Meyering
2011-04-15 8:20 ` Janne Blomqvist
2011-04-15 8:23 ` Jim Meyering
2011-04-15 13:20 ` Tom Tromey
2011-04-15 17:52 ` Jim Meyering
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTimAfkfmmfxrNp4w_wD2rGiQ7x07esgtVDT_-8Cj@mail.gmail.com \
--to=blomqvist.janne@gmail.com \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=java-patches@gcc.gnu.org \
--cc=jim@meyering.net \
--cc=joseph@codesourcery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).