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.)
From 585627bc317926eb1b690f4647566b4ae26a1453 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Sat, 3 Jan 2026 17:58:26 +0100
Subject: [PATCH] Remove bogus const qualifier on PageGetItem() argument

The function ends up casting away the const qualifier, so it was a
lie.  No callers appear to rely on the const qualifier on the
argument, so the simplest solution is to just remove it.
---
 src/include/storage/bufpage.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/include/storage/bufpage.h b/src/include/storage/bufpage.h
index 52989e5e535..ae3725b3b81 100644
--- a/src/include/storage/bufpage.h
+++ b/src/include/storage/bufpage.h
@@ -351,12 +351,12 @@ PageValidateSpecialPointer(const PageData *page)
  *             The semantics may change in the future.
  */
 static inline void *
-PageGetItem(const PageData *page, const ItemIdData *itemId)
+PageGetItem(PageData *page, const ItemIdData *itemId)
 {
        Assert(page);
        Assert(ItemIdHasStorage(itemId));
 
-       return (void *) (((const char *) page) + ItemIdGetOffset(itemId));
+       return (char *) page + ItemIdGetOffset(itemId);
 }
 
 /*
-- 
2.52.0

Reply via email to