From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Duy Nguyen" <pclouds@gmail.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Git Mailing List" <git@vger.kernel.org>,
"Michał Górny" <mgorny@gentoo.org>,
"Eric Sunshine" <sunshine@sunshineco.com>
Subject: Re: [PATCH] refactor various if (x) FREE_AND_NULL(x) to just FREE_AND_NULL(x)
Date: Fri, 17 Aug 2018 13:33:08 -0400 [thread overview]
Message-ID: <20180817173308.GA9111@sigill.intra.peff.net> (raw)
In-Reply-To: <xmqqlg94c46f.fsf@gitster-ct.c.googlers.com>
On Fri, Aug 17, 2018 at 10:07:36AM -0700, Junio C Hamano wrote:
> Junio C Hamano <gitster@pobox.com> writes:
>
> > It is a bit sad that
> >
> > - if (E)
> > FREE_AND_NULL(E);
> >
> > is not sufficient to catch it. Shouldn't we be doing the same for
> > regular free(E) as well? IOW, like the attached patch.
> > ...
>
> And revised even more to also spell "E" as "E != NULL" (and "!E" as
> "E == NULL"), which seems to make a difference, which is even more
> sad. I do not want to wonder if I have to also add "NULL == E" and
> other variants, so I'll stop here.
I think it makes sense that these are all distinct if you're using
coccinelle to do stylistic transformations between them (e.g., enforcing
curly braces even around one-liners).
I wonder if there is a way to "relax" a pattern where these semantically
equivalent cases can all be covered automatically. I don't know enough
about the tool to say.
I guess one way to do it would be to normalize the style in one rule
(e.g., always "!E" instead of "E == NULL"), and then you only have to
write the FREE_AND_NULL rule for the normalized form. For a single case
like this, the end result is about the same number of rules, but in the
long term it saves us work when we have a similar transformation.
-Peff
next prev parent reply other threads:[~2018-08-17 17:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-17 9:17 [PATCH] gpg-interface.c: Fix potentially freeing NULL values Michał Górny
2018-08-17 9:28 ` Eric Sunshine
2018-08-17 9:40 ` Michał Górny
2018-08-17 13:02 ` [PATCH] refactor various if (x) FREE_AND_NULL(x) to just FREE_AND_NULL(x) Ævar Arnfjörð Bjarmason
2018-08-17 14:36 ` Duy Nguyen
2018-08-17 15:10 ` Duy Nguyen
2018-08-17 16:53 ` Junio C Hamano
2018-08-17 17:07 ` Junio C Hamano
2018-08-17 17:33 ` Jeff King [this message]
2018-08-17 17:39 ` Jeff King
2018-08-17 17:44 ` Jeff King
2018-08-17 18:29 ` Duy Nguyen
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=20180817173308.GA9111@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mgorny@gentoo.org \
--cc=pclouds@gmail.com \
--cc=sunshine@sunshineco.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 NNTP newsgroup(s).