gratuitous casting away const

From: Mark Dilger <hornschnorter(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: gratuitous casting away const
Date: 2016-09-20 19:57:52
Message-ID: ACF3A030-E3D5-4E68-B744-184E11DE68F3@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Friends,

There are places in the code that cast away const for no apparent
reason, fixed like such:

diff --git a/src/backend/executor/nodeIndexscan.c b/src/backend/executor/nodeIndexscan.c
index 3143bd9..fe2cfc2 100644
--- a/src/backend/executor/nodeIndexscan.c
+++ b/src/backend/executor/nodeIndexscan.c
@@ -409,8 +409,8 @@ static int
reorderqueue_cmp(const pairingheap_node *a, const pairingheap_node *b,
void *arg)
{
- ReorderTuple *rta = (ReorderTuple *) a;
- ReorderTuple *rtb = (ReorderTuple *) b;
+ const ReorderTuple *rta = (const ReorderTuple *) a;
+ const ReorderTuple *rtb = (const ReorderTuple *) b;
IndexScanState *node = (IndexScanState *) arg;

return -cmp_orderbyvals(rta->orderbyvals, rta->orderbynulls,

There are also places which appear to cast away const due to using
typedefs that don't include const, which make for a more messy fix,
like such:

diff --git a/src/backend/storage/page/bufpage.c b/src/backend/storage/page/bufpage.c
index 73aa0c0..9e157a3 100644
--- a/src/backend/storage/page/bufpage.c
+++ b/src/backend/storage/page/bufpage.c
@@ -1037,7 +1037,7 @@ PageIndexTupleDeleteNoCompact(Page page, OffsetNumber offnum)
*/
bool
PageIndexTupleOverwrite(Page page, OffsetNumber offnum,
- Item newtup, Size newsize)
+ const char *newtup, Size newsize)
{
PageHeader phdr = (PageHeader) page;
ItemId tupid;
diff --git a/src/include/storage/bufpage.h b/src/include/storage/bufpage.h
index ad4ab5f..cd97a1a 100644
--- a/src/include/storage/bufpage.h
+++ b/src/include/storage/bufpage.h
@@ -431,7 +431,7 @@ extern void PageIndexTupleDelete(Page page, OffsetNumber offset);
extern void PageIndexMultiDelete(Page page, OffsetNumber *itemnos, int nitems);
extern void PageIndexTupleDeleteNoCompact(Page page, OffsetNumber offset);
extern bool PageIndexTupleOverwrite(Page page, OffsetNumber offnum,
- Item newtup, Size newsize);
+ const char *newtup, Size newsize);
extern char *PageSetChecksumCopy(Page page, BlockNumber blkno);
extern void PageSetChecksumInplace(Page page, BlockNumber blkno);

Are these castings away of const consistent with the project's coding standards?
Would patches to not cast away const be considered?

Thanks,

Mark Dilger

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2016-09-20 20:05:44 Re: increasing the default WAL segment size
Previous Message Peter Eisentraut 2016-09-20 19:31:58 Re: Rename max_parallel_degree?