Fix some confusing uses of const
authorPeter Eisentraut <peter@eisentraut.org>
Thu, 30 Oct 2025 09:44:36 +0000 (10:44 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Thu, 30 Oct 2025 10:20:04 +0000 (11:20 +0100)
There are a few places where we have

    typedef struct FooData { ... } FooData;
    typedef FooData *Foo;

and then function declarations with

    bar(const Foo x)

which isn't incorrect but probably meant

    bar(const FooData *x)

meaning that the thing x points to is immutable, not x itself.

This patch makes those changes where appropriate.  In one
case (execGrouping.c), the thing being pointed to was not immutable,
so in that case remove the const altogether, to avoid further
confusion.

Co-authored-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/CAEoWx2m2E0xE8Kvbkv31ULh_E%2B5zph-WA_bEdv3UR9CLhw%2B3vg%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/CAEoWx2kTDz%3Db6T2xHX78vy_B_osDeCC5dcTCi9eG0vXHp5QpdQ%40mail.gmail.com

contrib/pg_surgery/heap_surgery.c
src/backend/access/gin/ginget.c
src/backend/access/gin/ginpostinglist.c
src/backend/executor/execGrouping.c
src/backend/nodes/tidbitmap.c
src/backend/utils/adt/tsvector_op.c
src/include/access/gin_private.h
src/include/nodes/tidbitmap.h
src/tools/pgindent/typedefs.list

index 3e86283beb7cf007dfda9e776e8a32876eca722c..1096b05d7825b7d7eb21905f8963bee89989688e 100644 (file)
@@ -356,8 +356,8 @@ heap_force_common(FunctionCallInfo fcinfo, HeapTupleForceOption heap_force_opt)
 static int32
 tidcmp(const void *a, const void *b)
 {
-       ItemPointer iptr1 = ((const ItemPointer) a);
-       ItemPointer iptr2 = ((const ItemPointer) b);
+       const ItemPointerData *iptr1 = a;
+       const ItemPointerData *iptr2 = b;
 
        return ItemPointerCompare(iptr1, iptr2);
 }
index 656299b1b528fac35bf4549f66844f759969e872..0d4108d05a38ff6b865455a9c6221e29cfa94cbc 100644 (file)
@@ -489,7 +489,7 @@ restartScanEntry:
 static int
 entryIndexByFrequencyCmp(const void *a1, const void *a2, void *arg)
 {
-       const GinScanKey key = (const GinScanKey) arg;
+       const GinScanKeyData *key = arg;
        int                     i1 = *(const int *) a1;
        int                     i2 = *(const int *) a2;
        uint32          n1 = key->scanEntry[i1]->predictNumberResult;
index 48eadec87b0b1368e7529e290b77eb057d02a49e..1bf061803daddc337341341b9e50b1f6646b024d 100644 (file)
@@ -84,7 +84,7 @@
 #define MaxBytesPerInteger                             7
 
 static inline uint64
-itemptr_to_uint64(const ItemPointer iptr)
+itemptr_to_uint64(const ItemPointerData *iptr)
 {
        uint64          val;
 
@@ -194,7 +194,7 @@ decode_varbyte(unsigned char **ptr)
  * byte at the end, if any, is zero.
  */
 GinPostingList *
-ginCompressPostingList(const ItemPointer ipd, int nipd, int maxsize,
+ginCompressPostingList(const ItemPointerData *ipd, int nipd, int maxsize,
                                           int *nwritten)
 {
        uint64          prev;
index 75087204f0c69e74797d6e5916a764901f8e48be..f34530fdacfe1cab677c34f93fb2b3ffe0efc2ee 100644 (file)
@@ -20,9 +20,9 @@
 #include "miscadmin.h"
 #include "utils/lsyscache.h"
 
-static int     TupleHashTableMatch(struct tuplehash_hash *tb, const MinimalTuple tuple1, const MinimalTuple tuple2);
+static int     TupleHashTableMatch(struct tuplehash_hash *tb, MinimalTuple tuple1, MinimalTuple tuple2);
 static inline uint32 TupleHashTableHash_internal(struct tuplehash_hash *tb,
-                                                                                                const MinimalTuple tuple);
+                                                                                                MinimalTuple tuple);
 static inline TupleHashEntry LookupTupleHashEntry_internal(TupleHashTable hashtable,
                                                                                                                   TupleTableSlot *slot,
                                                                                                                   bool *isnew, uint32 hash);
@@ -419,7 +419,7 @@ FindTupleHashEntry(TupleHashTable hashtable, TupleTableSlot *slot,
  */
 static uint32
 TupleHashTableHash_internal(struct tuplehash_hash *tb,
-                                                       const MinimalTuple tuple)
+                                                       MinimalTuple tuple)
 {
        TupleHashTable hashtable = (TupleHashTable) tb->private_data;
        uint32          hashkey;
@@ -517,7 +517,7 @@ LookupTupleHashEntry_internal(TupleHashTable hashtable, TupleTableSlot *slot,
  * See whether two tuples (presumably of the same hash value) match
  */
 static int
-TupleHashTableMatch(struct tuplehash_hash *tb, const MinimalTuple tuple1, const MinimalTuple tuple2)
+TupleHashTableMatch(struct tuplehash_hash *tb, MinimalTuple tuple1, MinimalTuple tuple2)
 {
        TupleTableSlot *slot1;
        TupleTableSlot *slot2;
index fac2ba5d0caaeb7c2aebaccd90b2ae859dd1fa48..23d97b3a6c8f717298afc98d111f2b741dd2c4f9 100644 (file)
@@ -364,7 +364,7 @@ tbm_free_shared_area(dsa_area *dsa, dsa_pointer dp)
  * TBMIterateResult when any of these tuples are reported out.
  */
 void
-tbm_add_tuples(TIDBitmap *tbm, const ItemPointer tids, int ntids,
+tbm_add_tuples(TIDBitmap *tbm, const ItemPointerData *tids, int ntids,
                           bool recheck)
 {
        BlockNumber currblk = InvalidBlockNumber;
index 0625da9532f6ccee736454d5dee66db46945d039..c752cbe546397b790cd13217d78fb7f3df081137 100644 (file)
@@ -75,7 +75,7 @@ static bool TS_execute_locations_recurse(QueryItem *curitem,
                                                                                 void *arg,
                                                                                 TSExecuteCallback chkcond,
                                                                                 List **locations);
-static int     tsvector_bsearch(const TSVector tsv, char *lexeme, int lexeme_len);
+static int     tsvector_bsearch(const TSVectorData *tsv, char *lexeme, int lexeme_len);
 static Datum tsvector_update_trigger(PG_FUNCTION_ARGS, bool config_column);
 
 
@@ -83,7 +83,7 @@ static Datum tsvector_update_trigger(PG_FUNCTION_ARGS, bool config_column);
  * Order: haspos, len, word, for all positions (pos, weight)
  */
 static int
-silly_cmp_tsvector(const TSVector a, const TSVector b)
+silly_cmp_tsvector(const TSVectorData *a, const TSVectorData *b)
 {
        if (VARSIZE(a) < VARSIZE(b))
                return -1;
@@ -95,8 +95,8 @@ silly_cmp_tsvector(const TSVector a, const TSVector b)
                return 1;
        else
        {
-               WordEntry  *aptr = ARRPTR(a);
-               WordEntry  *bptr = ARRPTR(b);
+               const WordEntry *aptr = ARRPTR(a);
+               const WordEntry *bptr = ARRPTR(b);
                int                     i = 0;
                int                     res;
 
@@ -397,9 +397,9 @@ add_pos(TSVector src, WordEntry *srcptr,
  * found.
  */
 static int
-tsvector_bsearch(const TSVector tsv, char *lexeme, int lexeme_len)
+tsvector_bsearch(const TSVectorData *tsv, char *lexeme, int lexeme_len)
 {
-       WordEntry  *arrin = ARRPTR(tsv);
+       const WordEntry *arrin = ARRPTR(tsv);
        int                     StopLow = 0,
                                StopHigh = tsv->size,
                                StopMiddle,
index 9ea303a7c1b34bd0f90ede748a5f590ebe7b3c9a..db19ffd9897634e24b576bf954a361df3fd3925c 100644 (file)
@@ -333,7 +333,7 @@ typedef struct GinScanKeyData
        bool            curItemMatches;
        bool            recheckCurItem;
        bool            isFinished;
-}                      GinScanKeyData;
+} GinScanKeyData;
 
 typedef struct GinScanEntryData
 {
@@ -478,7 +478,7 @@ extern void ginInsertCleanup(GinState *ginstate, bool full_clean,
 
 /* ginpostinglist.c */
 
-extern GinPostingList *ginCompressPostingList(const ItemPointer ipd, int nipd,
+extern GinPostingList *ginCompressPostingList(const ItemPointerData *ipd, int nipd,
                                                                                          int maxsize, int *nwritten);
 extern int     ginPostingListDecodeAllSegmentsToTbm(GinPostingList *ptr, int len, TIDBitmap *tbm);
 
index f54e61c719040e84d642a3883c9026830d861fda..c24997d1c40c594c758b51dc1b47801e3354abb5 100644 (file)
@@ -85,7 +85,7 @@ extern void tbm_free(TIDBitmap *tbm);
 extern void tbm_free_shared_area(dsa_area *dsa, dsa_pointer dp);
 
 extern void tbm_add_tuples(TIDBitmap *tbm,
-                                                  const ItemPointer tids, int ntids,
+                                                  const ItemPointerData *tids, int ntids,
                                                   bool recheck);
 extern void tbm_add_page(TIDBitmap *tbm, BlockNumber pageno);
 
index df88c78fe3a42a54cd797a0352cd55e46b47f130..018b5919cf66ee3b0ccb4642d8710ee343b5e8ee 100644 (file)
@@ -1076,6 +1076,7 @@ GinQualCounts
 GinScanEntry
 GinScanItem
 GinScanKey
+GinScanKeyData
 GinScanOpaque
 GinScanOpaqueData
 GinSegmentInfo