Re: some Page/PageData const stuff

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: some Page/PageData const stuff
Date: 2026-01-03 17:05:19
Message-ID: de2a82a7-bef5-4fef-955e-1477e1836d8f@eisentraut.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 02.01.26 20:17, Andres Freund wrote:
> On 2025-01-20 15:01:08 +0100, Peter Eisentraut wrote:
>> This has been committed.
>
> I don't like the const markings in PageGetItem():
>
>
> /*
> * PageGetItem
> * Retrieves an item on the given page.
> *
> * Note:
> * This does not change the status of any of the resources passed.
> * The semantics may change in the future.
> */
> static inline void *
> PageGetItem(const PageData *page, const ItemIdData *itemId)
> {
> Assert(page);
> Assert(ItemIdHasStorage(itemId));
>
> return (void *) (((const char *) page) + ItemIdGetOffset(itemId));
> }
>
> The const for PageData seems like a lie to me, because we cast it away. And
> indeed, we often then use the returned value to set hint bits etc.

I agree this is incorrect. Since no callers appear to rely on the const
qualification of the argument, the easiest solution would be to just
remove it. See attached patch.

(In the future, this might be a candidate for a qualifier-preserving
polymorphic function like the C23 string functions, but that's for
another day.)

Attachment Content-Type Size
0001-Remove-bogus-const-qualifier-on-PageGetItem-argument.patch text/plain 1.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David E. Wheeler 2026-01-03 17:14:00 Re: access numeric data in module
Previous Message Andres Freund 2026-01-03 16:47:09 Re: remove pg_restrict workaround