From: Thomas Haller <thaller@redhat.com>
To: Florian Westphal <fw@strlen.de>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>,
NetFilter <netfilter-devel@vger.kernel.org>
Subject: Re: [PATCH nft 1/3] parser: don't mark "string" as const
Date: Fri, 10 Nov 2023 09:09:47 +0100 [thread overview]
Message-ID: <4c592bd9b7c5a1d7f24a12ae26c6c6196f96061d.camel@redhat.com> (raw)
In-Reply-To: <20231109231043.GB8000@breakpoint.cc>
On Fri, 2023-11-10 at 00:10 +0100, Florian Westphal wrote:
> Thomas Haller <thaller@redhat.com> wrote:
> > ifname_expr_alloc() calls `free(name)`, destroying the thing that
> > is
> > pointed at. That's a modification.
> >
> > The code required to cast away the constness, which also indicates
> > that
> > it is not actually const.
>
> It it. I hate that free() isn't const void *.
That would work too. But C choose instead to disallow that.
Note that in nftables, ~75% of the free() operate on non-const just
fine. And the compiler is helpful confirming that.
>
> I prefer to have const used as much as humanly possible.
>
Definitely. Especially for long-lived data.
The "string" in question is a short-lived data allocated by "scanner.l"
and handed over to "parser_bison.y".
See:
»·······»·······»·······|»······rule_alloc»·····comment_spec
»·······»·······»·······{
»·······»·······»·······»·······$$->cOmment = $2;
»·······»·······»·······}
Here no free() is involved, but ownership is passed on without
strdup(). If "string" is const, this is another ugliness where you pass
on a string that you seemingly don't own.
There are places where it's ugly and const-correctness breaks down
(during destruction/ref/unref). See free_const() and
datatype_get()/datatype_free(). But those places should be at a minimum
by choosing const (and free_const()) when it makes sense.
Thomas
prev parent reply other threads:[~2023-11-10 17:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-09 18:59 [PATCH nft 1/3] parser: don't mark "string" as const Thomas Haller
2023-11-09 18:59 ` [PATCH nft 2/3] parser: remove "const" from argument of input_descriptor_destroy() Thomas Haller
2023-11-15 9:42 ` Florian Westphal
2023-11-09 18:59 ` [PATCH nft 3/3] parser: use size_t type for strlen() results Thomas Haller
2023-11-15 9:41 ` Florian Westphal
2023-11-09 19:22 ` [PATCH nft 1/3] parser: don't mark "string" as const Pablo Neira Ayuso
2023-11-09 20:34 ` Thomas Haller
2023-11-09 23:10 ` Florian Westphal
2023-11-10 8:09 ` Thomas Haller [this message]
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=4c592bd9b7c5a1d7f24a12ae26c6c6196f96061d.camel@redhat.com \
--to=thaller@redhat.com \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/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).