Re: const correctness

From: Thomas Munro <munro(at)ip9(dot)org>
To: Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: const correctness
Date: 2011-11-09 21:15:43
Message-ID: CADLWmXVqGBwhJnK7226AWa4eGMo4h-mOQpAUgofqojaqn4vtpQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 9 November 2011 19:35, Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov> wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>> So that's already duplicating list_head, foreach, and forboth.
>
> OK, I failed to pick up on that properly.  With that stripped out,
> you get the attached patch, which does nothing but add "const" to
> 661 lines.  It still applies cleanly, builds with no warnings, and
> passes regression tests.
>
> It is a bit disappointing that without creating two flavors of the
> list_head function and the foreach and forboth macros, there are a
> number of functions which aren't intended to modify their inputs
> which can't be declared with const parameters; but unless there is
> some demonstrable performance benefit from those changes, I agree
> that the argument for having the two flavors is thin.

There is another option: if list_head is changed to take a pointer to
const List and return a pointer to non-const ListCell (something I was
trying to avoid before), then no XXX_const functions/macros are
necessary, and all of the functions from the first patch can keep
their 'const', adding const to 930 lines.

I've attached a new patch, which simply adds the keyword 'const' in
lots of places, no new functions etc. This version generates no
warnings under -Wcast-qual (now that I've read Peter E's thread and
been inspired to fix up some places that previously cast away const)
for all code under backend/nodes. To achieve that I had to stray
outside backend/nodes and change get_leftop and get_rightop (from
clauses.h).

Attachment Content-Type Size
constify-2.patch text/x-patch 296.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kevin Grittner 2011-11-09 21:25:27 Re: const correctness
Previous Message Robert Haas 2011-11-09 21:12:22 Re: heap vacuum & cleanup locks