Re: Refactor to eliminate cast-away-const in pg_dump object sort comparator

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Cc: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Noah Misch <noah(at)leadboat(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: Refactor to eliminate cast-away-const in pg_dump object sort comparator
Date: 2026-01-05 13:24:58
Message-ID: 0f7bab70-7836-4927-acb6-970c9f769a59@eisentraut.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 30.12.25 10:03, Chao Li wrote:
> Thanks a lot for pointing out the error. v3 has reverted the changes to
> be the same as v1 and rebased.

The explanation of this patch doesn't seem right. The commit message
says "... eliminate cast-away-const ...", but that is not what is
happening in the code. For example, in

static int
DOTypeNameCompare(const void *p1, const void *p2)
{
- DumpableObject *obj1 = *(DumpableObject *const *) p1;
- DumpableObject *obj2 = *(DumpableObject *const *) p2;
+ const DumpableObject *obj1 = *(DumpableObject *const *) p1;
+ const DumpableObject *obj2 = *(DumpableObject *const *) p2;

p1 is of type pointer-to-const-void, which is then cast into
pointer-to-const-pointer-to-DumpableObject (which preserves the
qualifier, because it's pointer-to-const-xxx on both sides), which is
then dereferenced to result in type const-pointer-to-DumpableObject
(type DumpableObject * const, not const DumpableObject *), which is then
assigned by value to obj1 of type pointer-to-DumpableObject. This is
all entirely correct.

Now there is nothing wrong with making the receiving obj1 have an
additional const qualification, if that's the promise you want to make
about it for that scope. But that's separate from preserving the
qualifier on p1. And it's incorrect to claim that this is fixing an
existing cast-away-const issue.

Independent of that, there appears to be some not quite finished code here:

- AttrDefInfo *adobj1 = *(AttrDefInfo *const *) p1;
- AttrDefInfo *adobj2 = *(AttrDefInfo *const *) p2;
+ const AttrDefInfo *adobj1 = p1;//*(AttrDefInfo *const *) p1;
+ const AttrDefInfo *adobj2 = *(AttrDefInfo *const *) p2;

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2026-01-05 13:25:41 Re: index prefetching
Previous Message Jakub Wartak 2026-01-05 13:19:12 Re: confusing results from pg_get_replication_slots()