Refactor to eliminate cast-away-const in pg_dump object sort comparator
Hi Hacker,
While reviewing patch [1]/messages/by-id/CALDaNm2x3rd7C0_HjUpJFbxpAqXgm=QtoKfkEWDVA8h+JFpa_w@mail.gmail.com, I raised a comment about cast-away-const in
pg_dump_sort.c. However, the comment was not accepted and the argument was
that the nearby code did the same thing.
I saw Tom recently had a commit [2]https://git.postgresql.org/cgit/postgresql.git/commit/?id=4eda42e8bdf5bd3bf69576d54a45c10e7cbc3b35 that removed some cast-away-const in
ecpg, so I am filing this patch to eliminate all cast-away-const problems
in pg_dump_sort.c.
[1]: /messages/by-id/CALDaNm2x3rd7C0_HjUpJFbxpAqXgm=QtoKfkEWDVA8h+JFpa_w@mail.gmail.com
/messages/by-id/CALDaNm2x3rd7C0_HjUpJFbxpAqXgm=QtoKfkEWDVA8h+JFpa_w@mail.gmail.com
[2]: https://git.postgresql.org/cgit/postgresql.git/commit/?id=4eda42e8bdf5bd3bf69576d54a45c10e7cbc3b35
https://git.postgresql.org/cgit/postgresql.git/commit/?id=4eda42e8bdf5bd3bf69576d54a45c10e7cbc3b35
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
Attachments:
v1-0001-Refactor-to-eliminate-cast-away-const-in-pg_dump-.patchapplication/octet-stream; name=v1-0001-Refactor-to-eliminate-cast-away-const-in-pg_dump-.patchDownload
From 4d494a190c6b234db93c9c9e23979385438da577 Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Wed, 24 Dec 2025 09:43:21 +0800
Subject: [PATCH v1] Refactor to eliminate cast-away-const in pg_dump object
sort comparator
The qsort() comparator in pg_dump_sort.c does not modify the objects
being compared, but it previously assigned them to non-const pointers,
effectively casting away const. Refactor the local variable declarations
to use const-qualified pointers instead.
No functional change intended.
Author: Chao Li <lic@highgo.com>
---
src/bin/pg_dump/pg_dump_sort.c | 60 +++++++++++++++++-----------------
1 file changed, 30 insertions(+), 30 deletions(-)
diff --git a/src/bin/pg_dump/pg_dump_sort.c b/src/bin/pg_dump/pg_dump_sort.c
index e2a4df4cf4b..79ea0ee1121 100644
--- a/src/bin/pg_dump/pg_dump_sort.c
+++ b/src/bin/pg_dump/pg_dump_sort.c
@@ -199,8 +199,8 @@ sortDumpableObjectsByTypeName(DumpableObject **objs, int numObjs)
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;
int cmpval;
/* Sort by type's priority */
@@ -265,8 +265,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
*/
if (obj1->objType == DO_FUNC || obj1->objType == DO_AGG)
{
- FuncInfo *fobj1 = *(FuncInfo *const *) p1;
- FuncInfo *fobj2 = *(FuncInfo *const *) p2;
+ const FuncInfo *fobj1 = *(FuncInfo *const *) p1;
+ const FuncInfo *fobj2 = *(FuncInfo *const *) p2;
int i;
/* Sort by number of arguments, then argument type names */
@@ -283,8 +283,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_OPERATOR)
{
- OprInfo *oobj1 = *(OprInfo *const *) p1;
- OprInfo *oobj2 = *(OprInfo *const *) p2;
+ const OprInfo *oobj1 = *(OprInfo *const *) p1;
+ const OprInfo *oobj2 = *(OprInfo *const *) p2;
/* oprkind is 'l', 'r', or 'b'; this sorts prefix, postfix, infix */
cmpval = (oobj2->oprkind - oobj1->oprkind);
@@ -300,8 +300,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_OPCLASS)
{
- OpclassInfo *opcobj1 = *(OpclassInfo *const *) p1;
- OpclassInfo *opcobj2 = *(OpclassInfo *const *) p2;
+ const OpclassInfo *opcobj1 = *(OpclassInfo *const *) p1;
+ const OpclassInfo *opcobj2 = *(OpclassInfo *const *) p2;
/* Sort by access method name, per pg_opclass_am_name_nsp_index */
cmpval = accessMethodNameCompare(opcobj1->opcmethod,
@@ -311,8 +311,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_OPFAMILY)
{
- OpfamilyInfo *opfobj1 = *(OpfamilyInfo *const *) p1;
- OpfamilyInfo *opfobj2 = *(OpfamilyInfo *const *) p2;
+ const OpfamilyInfo *opfobj1 = *(OpfamilyInfo *const *) p1;
+ const OpfamilyInfo *opfobj2 = *(OpfamilyInfo *const *) p2;
/* Sort by access method name, per pg_opfamily_am_name_nsp_index */
cmpval = accessMethodNameCompare(opfobj1->opfmethod,
@@ -322,8 +322,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_COLLATION)
{
- CollInfo *cobj1 = *(CollInfo *const *) p1;
- CollInfo *cobj2 = *(CollInfo *const *) p2;
+ const CollInfo *cobj1 = *(CollInfo *const *) p1;
+ const CollInfo *cobj2 = *(CollInfo *const *) p2;
/*
* Sort by encoding, per pg_collation_name_enc_nsp_index. Technically,
@@ -344,8 +344,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_ATTRDEF)
{
- AttrDefInfo *adobj1 = *(AttrDefInfo *const *) p1;
- AttrDefInfo *adobj2 = *(AttrDefInfo *const *) p2;
+ const AttrDefInfo *adobj1 = *(AttrDefInfo *const *) p1;
+ const AttrDefInfo *adobj2 = *(AttrDefInfo *const *) p2;
/* Sort by attribute number */
cmpval = (adobj1->adnum - adobj2->adnum);
@@ -354,8 +354,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_POLICY)
{
- PolicyInfo *pobj1 = *(PolicyInfo *const *) p1;
- PolicyInfo *pobj2 = *(PolicyInfo *const *) p2;
+ const PolicyInfo *pobj1 = *(PolicyInfo *const *) p1;
+ const PolicyInfo *pobj2 = *(PolicyInfo *const *) p2;
/* Sort by table name (table namespace was considered already) */
cmpval = strcmp(pobj1->poltable->dobj.name,
@@ -365,8 +365,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_RULE)
{
- RuleInfo *robj1 = *(RuleInfo *const *) p1;
- RuleInfo *robj2 = *(RuleInfo *const *) p2;
+ const RuleInfo *robj1 = *(RuleInfo *const *) p1;
+ const RuleInfo *robj2 = *(RuleInfo *const *) p2;
/* Sort by table name (table namespace was considered already) */
cmpval = strcmp(robj1->ruletable->dobj.name,
@@ -376,8 +376,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_TRIGGER)
{
- TriggerInfo *tobj1 = *(TriggerInfo *const *) p1;
- TriggerInfo *tobj2 = *(TriggerInfo *const *) p2;
+ const TriggerInfo *tobj1 = *(TriggerInfo *const *) p1;
+ const TriggerInfo *tobj2 = *(TriggerInfo *const *) p2;
/* Sort by table name (table namespace was considered already) */
cmpval = strcmp(tobj1->tgtable->dobj.name,
@@ -388,8 +388,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
else if (obj1->objType == DO_CONSTRAINT ||
obj1->objType == DO_FK_CONSTRAINT)
{
- ConstraintInfo *robj1 = *(ConstraintInfo *const *) p1;
- ConstraintInfo *robj2 = *(ConstraintInfo *const *) p2;
+ const ConstraintInfo *robj1 = *(ConstraintInfo *const *) p1;
+ const ConstraintInfo *robj2 = *(ConstraintInfo *const *) p2;
/*
* Sort domain constraints before table constraints, for consistency
@@ -421,8 +421,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_DEFAULT_ACL)
{
- DefaultACLInfo *daclobj1 = *(DefaultACLInfo *const *) p1;
- DefaultACLInfo *daclobj2 = *(DefaultACLInfo *const *) p2;
+ const DefaultACLInfo *daclobj1 = *(DefaultACLInfo *const *) p1;
+ const DefaultACLInfo *daclobj2 = *(DefaultACLInfo *const *) p2;
/*
* Sort by defaclrole, per pg_default_acl_role_nsp_obj_index. The
@@ -434,8 +434,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_PUBLICATION_REL)
{
- PublicationRelInfo *probj1 = *(PublicationRelInfo *const *) p1;
- PublicationRelInfo *probj2 = *(PublicationRelInfo *const *) p2;
+ const PublicationRelInfo *probj1 = *(PublicationRelInfo *const *) p1;
+ const PublicationRelInfo *probj2 = *(PublicationRelInfo *const *) p2;
/* Sort by publication name, since (namespace, name) match the rel */
cmpval = strcmp(probj1->publication->dobj.name,
@@ -445,8 +445,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_PUBLICATION_TABLE_IN_SCHEMA)
{
- PublicationSchemaInfo *psobj1 = *(PublicationSchemaInfo *const *) p1;
- PublicationSchemaInfo *psobj2 = *(PublicationSchemaInfo *const *) p2;
+ const PublicationSchemaInfo *psobj1 = *(PublicationSchemaInfo *const *) p1;
+ const PublicationSchemaInfo *psobj2 = *(PublicationSchemaInfo *const *) p2;
/* Sort by publication name, since ->name is just nspname */
cmpval = strcmp(psobj1->publication->dobj.name,
@@ -456,8 +456,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_SUBSCRIPTION_REL)
{
- SubRelInfo *srobj1 = *(SubRelInfo *const *) p1;
- SubRelInfo *srobj2 = *(SubRelInfo *const *) p2;
+ const SubRelInfo *srobj1 = *(SubRelInfo *const *) p1;
+ const SubRelInfo *srobj2 = *(SubRelInfo *const *) p2;
/* Sort by subscription name, since (namespace, name) match the rel */
cmpval = strcmp(srobj1->subinfo->dobj.name,
--
2.39.5 (Apple Git-154)
On Dec 24, 2025, at 09:58, Chao Li <li.evan.chao@gmail.com> wrote:
Hi Hacker,
While reviewing patch [1]/messages/by-id/CALDaNm2x3rd7C0_HjUpJFbxpAqXgm=QtoKfkEWDVA8h+JFpa_w@mail.gmail.com, I raised a comment about cast-away-const in
pg_dump_sort.c. However, the comment was not accepted and the argument was
that the nearby code did the same thing.
I saw Tom recently had a commit [2]https://git.postgresql.org/cgit/postgresql.git/commit/?id=4eda42e8bdf5bd3bf69576d54a45c10e7cbc3b35 that removed some cast-away-const in
ecpg, so I am filing this patch to eliminate all cast-away-const problems
in pg_dump_sort.c.
[1]: /messages/by-id/CALDaNm2x3rd7C0_HjUpJFbxpAqXgm=QtoKfkEWDVA8h+JFpa_w@mail.gmail.com
/messages/by-id/CALDaNm2x3rd7C0_HjUpJFbxpAqXgm=QtoKfkEWDVA8h+JFpa_w@mail.gmail.com
[2]: https://git.postgresql.org/cgit/postgresql.git/commit/?id=4eda42e8bdf5bd3bf69576d54a45c10e7cbc3b35
https://git.postgresql.org/cgit/postgresql.git/commit/?id=4eda42e8bdf5bd3bf69576d54a45c10e7cbc3b35
I just noticed this patch does the similar thing as [3]/messages/by-id/aUQHy/MmWq7c97wK@ip-10-97-1-34.eu-west-3.compute.internal just handling a
different file. As Peter had a comment on [3]/messages/by-id/aUQHy/MmWq7c97wK@ip-10-97-1-34.eu-west-3.compute.internal, I addressed the comment as
well in v2.
[3]: /messages/by-id/aUQHy/MmWq7c97wK@ip-10-97-1-34.eu-west-3.compute.internal
/messages/by-id/aUQHy/MmWq7c97wK@ip-10-97-1-34.eu-west-3.compute.internal
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
Attachments:
v2-0001-Refactor-to-eliminate-cast-away-const-in-pg_dump-.patchapplication/octet-stream; name=v2-0001-Refactor-to-eliminate-cast-away-const-in-pg_dump-.patchDownload
From 5ba280cd91d4bd42f5ea0b3100c7721d84a9ac64 Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Wed, 24 Dec 2025 09:43:21 +0800
Subject: [PATCH v2] Refactor to eliminate cast-away-const in pg_dump object
sort comparator
The qsort() comparator in pg_dump_sort.c does not modify the objects
being compared, but it previously assigned them to non-const pointers,
effectively casting away const. Refactor the local variable declarations
to use const-qualified pointers instead.
No functional change intended.
Author: Chao Li <lic@highgo.com>
---
src/bin/pg_dump/pg_dump_sort.c | 60 +++++++++++++++++-----------------
1 file changed, 30 insertions(+), 30 deletions(-)
diff --git a/src/bin/pg_dump/pg_dump_sort.c b/src/bin/pg_dump/pg_dump_sort.c
index e2a4df4cf4b..ed5d4d07abf 100644
--- a/src/bin/pg_dump/pg_dump_sort.c
+++ b/src/bin/pg_dump/pg_dump_sort.c
@@ -199,8 +199,8 @@ sortDumpableObjectsByTypeName(DumpableObject **objs, int numObjs)
static int
DOTypeNameCompare(const void *p1, const void *p2)
{
- DumpableObject *obj1 = *(DumpableObject *const *) p1;
- DumpableObject *obj2 = *(DumpableObject *const *) p2;
+ const DumpableObject *obj1 = p1;
+ const DumpableObject *obj2 = p2;
int cmpval;
/* Sort by type's priority */
@@ -265,8 +265,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
*/
if (obj1->objType == DO_FUNC || obj1->objType == DO_AGG)
{
- FuncInfo *fobj1 = *(FuncInfo *const *) p1;
- FuncInfo *fobj2 = *(FuncInfo *const *) p2;
+ const FuncInfo *fobj1 = p1;
+ const FuncInfo *fobj2 = p2;
int i;
/* Sort by number of arguments, then argument type names */
@@ -283,8 +283,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_OPERATOR)
{
- OprInfo *oobj1 = *(OprInfo *const *) p1;
- OprInfo *oobj2 = *(OprInfo *const *) p2;
+ const OprInfo *oobj1 = p1;
+ const OprInfo *oobj2 = p2;
/* oprkind is 'l', 'r', or 'b'; this sorts prefix, postfix, infix */
cmpval = (oobj2->oprkind - oobj1->oprkind);
@@ -300,8 +300,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_OPCLASS)
{
- OpclassInfo *opcobj1 = *(OpclassInfo *const *) p1;
- OpclassInfo *opcobj2 = *(OpclassInfo *const *) p2;
+ const OpclassInfo *opcobj1 = p1;
+ const OpclassInfo *opcobj2 = p2;
/* Sort by access method name, per pg_opclass_am_name_nsp_index */
cmpval = accessMethodNameCompare(opcobj1->opcmethod,
@@ -311,8 +311,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_OPFAMILY)
{
- OpfamilyInfo *opfobj1 = *(OpfamilyInfo *const *) p1;
- OpfamilyInfo *opfobj2 = *(OpfamilyInfo *const *) p2;
+ const OpfamilyInfo *opfobj1 = p1;
+ const OpfamilyInfo *opfobj2 = p2;
/* Sort by access method name, per pg_opfamily_am_name_nsp_index */
cmpval = accessMethodNameCompare(opfobj1->opfmethod,
@@ -322,8 +322,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_COLLATION)
{
- CollInfo *cobj1 = *(CollInfo *const *) p1;
- CollInfo *cobj2 = *(CollInfo *const *) p2;
+ const CollInfo *cobj1 = *(CollInfo *const *) p1;
+ const CollInfo *cobj2 = *(CollInfo *const *) p2;
/*
* Sort by encoding, per pg_collation_name_enc_nsp_index. Technically,
@@ -344,8 +344,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_ATTRDEF)
{
- AttrDefInfo *adobj1 = *(AttrDefInfo *const *) p1;
- AttrDefInfo *adobj2 = *(AttrDefInfo *const *) p2;
+ const AttrDefInfo *adobj1 = p1;
+ const AttrDefInfo *adobj2 = p2;
/* Sort by attribute number */
cmpval = (adobj1->adnum - adobj2->adnum);
@@ -354,8 +354,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_POLICY)
{
- PolicyInfo *pobj1 = *(PolicyInfo *const *) p1;
- PolicyInfo *pobj2 = *(PolicyInfo *const *) p2;
+ const PolicyInfo *pobj1 = p1;
+ const PolicyInfo *pobj2 = p2;
/* Sort by table name (table namespace was considered already) */
cmpval = strcmp(pobj1->poltable->dobj.name,
@@ -365,8 +365,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_RULE)
{
- RuleInfo *robj1 = *(RuleInfo *const *) p1;
- RuleInfo *robj2 = *(RuleInfo *const *) p2;
+ const RuleInfo *robj1 = p1;
+ const RuleInfo *robj2 = p2;
/* Sort by table name (table namespace was considered already) */
cmpval = strcmp(robj1->ruletable->dobj.name,
@@ -376,8 +376,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_TRIGGER)
{
- TriggerInfo *tobj1 = *(TriggerInfo *const *) p1;
- TriggerInfo *tobj2 = *(TriggerInfo *const *) p2;
+ const TriggerInfo *tobj1 = p1;
+ const TriggerInfo *tobj2 = p2;
/* Sort by table name (table namespace was considered already) */
cmpval = strcmp(tobj1->tgtable->dobj.name,
@@ -388,8 +388,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
else if (obj1->objType == DO_CONSTRAINT ||
obj1->objType == DO_FK_CONSTRAINT)
{
- ConstraintInfo *robj1 = *(ConstraintInfo *const *) p1;
- ConstraintInfo *robj2 = *(ConstraintInfo *const *) p2;
+ const ConstraintInfo *robj1 = p1;
+ const ConstraintInfo *robj2 = p2;
/*
* Sort domain constraints before table constraints, for consistency
@@ -421,8 +421,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_DEFAULT_ACL)
{
- DefaultACLInfo *daclobj1 = *(DefaultACLInfo *const *) p1;
- DefaultACLInfo *daclobj2 = *(DefaultACLInfo *const *) p2;
+ const DefaultACLInfo *daclobj1 = p1;
+ const DefaultACLInfo *daclobj2 = p2;
/*
* Sort by defaclrole, per pg_default_acl_role_nsp_obj_index. The
@@ -434,8 +434,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_PUBLICATION_REL)
{
- PublicationRelInfo *probj1 = *(PublicationRelInfo *const *) p1;
- PublicationRelInfo *probj2 = *(PublicationRelInfo *const *) p2;
+ const PublicationRelInfo *probj1 = p1;
+ const PublicationRelInfo *probj2 = p2;
/* Sort by publication name, since (namespace, name) match the rel */
cmpval = strcmp(probj1->publication->dobj.name,
@@ -445,8 +445,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_PUBLICATION_TABLE_IN_SCHEMA)
{
- PublicationSchemaInfo *psobj1 = *(PublicationSchemaInfo *const *) p1;
- PublicationSchemaInfo *psobj2 = *(PublicationSchemaInfo *const *) p2;
+ const PublicationSchemaInfo *psobj1 = p1;
+ const PublicationSchemaInfo *psobj2 = p2;
/* Sort by publication name, since ->name is just nspname */
cmpval = strcmp(psobj1->publication->dobj.name,
@@ -456,8 +456,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_SUBSCRIPTION_REL)
{
- SubRelInfo *srobj1 = *(SubRelInfo *const *) p1;
- SubRelInfo *srobj2 = *(SubRelInfo *const *) p2;
+ const SubRelInfo *srobj1 = p1;
+ const SubRelInfo *srobj2 = p2;
/* Sort by subscription name, since (namespace, name) match the rel */
cmpval = strcmp(srobj1->subinfo->dobj.name,
--
2.39.5 (Apple Git-154)
Hi,
On Mon, Dec 29, 2025 at 05:44:22PM +0800, Chao Li wrote:
On Dec 24, 2025, at 09:58, Chao Li <li.evan.chao@gmail.com> wrote:
Hi Hacker,
While reviewing patch [1], I raised a comment about cast-away-const in
pg_dump_sort.c. However, the comment was not accepted and the argument was
that the nearby code did the same thing.I saw Tom recently had a commit [2] that removed some cast-away-const in
ecpg, so I am filing this patch to eliminate all cast-away-const problems
in pg_dump_sort.c.[1]
/messages/by-id/CALDaNm2x3rd7C0_HjUpJFbxpAqXgm=QtoKfkEWDVA8h+JFpa_w@mail.gmail.com
[2]
https://git.postgresql.org/cgit/postgresql.git/commit/?id=4eda42e8bdf5bd3bf69576d54a45c10e7cbc3b35I just noticed this patch does the similar thing as [3] just handling a
different file. As Peter had a comment on [3], I addressed the comment as
well in v2.
I think that your v1 was correct but your v2 now contains things like:
@@ -199,8 +199,8 @@ sortDumpableObjectsByTypeName(DumpableObject **objs, int numObjs)
static int
DOTypeNameCompare(const void *p1, const void *p2)
{
- DumpableObject *obj1 = *(DumpableObject *const *) p1;
- DumpableObject *obj2 = *(DumpableObject *const *) p2;
+ const DumpableObject *obj1 = p1;
+ const DumpableObject *obj2 = p2;
that don't look correct. Indeed in sortDumpableObjectsByTypeName(),
objs is pointer to pointer. So qsort passes &objs[0] and &objs[1] to the
comparator. So that dereference is still needed in DOTypeNameCompare().
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
On Mon, Dec 29, 2025 at 10:15 PM Bertrand Drouvot <
bertranddrouvot.pg@gmail.com> wrote:
Hi,
On Mon, Dec 29, 2025 at 05:44:22PM +0800, Chao Li wrote:
On Dec 24, 2025, at 09:58, Chao Li <li.evan.chao@gmail.com> wrote:
Hi Hacker,
While reviewing patch [1], I raised a comment about cast-away-const in
pg_dump_sort.c. However, the comment was not accepted and the argumentwas
that the nearby code did the same thing.
I saw Tom recently had a commit [2] that removed some cast-away-const in
ecpg, so I am filing this patch to eliminate all cast-away-const problems
in pg_dump_sort.c.[1]
/messages/by-id/CALDaNm2x3rd7C0_HjUpJFbxpAqXgm=QtoKfkEWDVA8h+JFpa_w@mail.gmail.com
[2]
https://git.postgresql.org/cgit/postgresql.git/commit/?id=4eda42e8bdf5bd3bf69576d54a45c10e7cbc3b35
I just noticed this patch does the similar thing as [3] just handling a
different file. As Peter had a comment on [3], I addressed the comment as
well in v2.I think that your v1 was correct but your v2 now contains things like:
@@ -199,8 +199,8 @@ sortDumpableObjectsByTypeName(DumpableObject **objs, int numObjs) static int DOTypeNameCompare(const void *p1, const void *p2) { - DumpableObject *obj1 = *(DumpableObject *const *) p1; - DumpableObject *obj2 = *(DumpableObject *const *) p2; + const DumpableObject *obj1 = p1; + const DumpableObject *obj2 = p2;that don't look correct. Indeed in sortDumpableObjectsByTypeName(),
objs is pointer to pointer. So qsort passes &objs[0] and &objs[1] to the
comparator. So that dereference is still needed in DOTypeNameCompare().Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
Hi Bertrand,
Thanks a lot for pointing out the error. v3 has reverted the changes to be
the same as v1 and rebased.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
Attachments:
v3-0001-Refactor-to-eliminate-cast-away-const-in-pg_dump-.patchapplication/octet-stream; name=v3-0001-Refactor-to-eliminate-cast-away-const-in-pg_dump-.patchDownload
From 912d0d155047e8ef831ce623065734a0df0dbf55 Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Tue, 30 Dec 2025 10:50:43 +0800
Subject: [PATCH v3] Refactor to eliminate cast-away-const in pg_dump object
sort comparator
The qsort() comparator in pg_dump_sort.c does not modify the objects
being compared, but it previously assigned them to non-const pointers,
effectively casting away const. Refactor the local variable declarations
to use const-qualified pointers instead.
No functional change intended.
Author: Chao Li <lic@highgo.com>
Discussion: https://postgr.es/m/CAEoWx2nN3LYhBmDBaXDoZ=+ikNJkJT7vzg+xPYsHUTSkV8unvg@mail.gmail.com
---
src/bin/pg_dump/pg_dump_sort.c | 60 +++++++++++++++++-----------------
1 file changed, 30 insertions(+), 30 deletions(-)
diff --git a/src/bin/pg_dump/pg_dump_sort.c b/src/bin/pg_dump/pg_dump_sort.c
index e2a4df4cf4b..684354d1ab9 100644
--- a/src/bin/pg_dump/pg_dump_sort.c
+++ b/src/bin/pg_dump/pg_dump_sort.c
@@ -199,8 +199,8 @@ sortDumpableObjectsByTypeName(DumpableObject **objs, int numObjs)
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;
int cmpval;
/* Sort by type's priority */
@@ -265,8 +265,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
*/
if (obj1->objType == DO_FUNC || obj1->objType == DO_AGG)
{
- FuncInfo *fobj1 = *(FuncInfo *const *) p1;
- FuncInfo *fobj2 = *(FuncInfo *const *) p2;
+ const FuncInfo *fobj1 = *(FuncInfo *const *) p1;
+ const FuncInfo *fobj2 = *(FuncInfo *const *) p2;
int i;
/* Sort by number of arguments, then argument type names */
@@ -283,8 +283,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_OPERATOR)
{
- OprInfo *oobj1 = *(OprInfo *const *) p1;
- OprInfo *oobj2 = *(OprInfo *const *) p2;
+ const OprInfo *oobj1 = *(OprInfo *const *) p1;
+ const OprInfo *oobj2 = *(OprInfo *const *) p2;
/* oprkind is 'l', 'r', or 'b'; this sorts prefix, postfix, infix */
cmpval = (oobj2->oprkind - oobj1->oprkind);
@@ -300,8 +300,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_OPCLASS)
{
- OpclassInfo *opcobj1 = *(OpclassInfo *const *) p1;
- OpclassInfo *opcobj2 = *(OpclassInfo *const *) p2;
+ const OpclassInfo *opcobj1 = *(OpclassInfo *const *) p1;
+ const OpclassInfo *opcobj2 = *(OpclassInfo *const *) p2;
/* Sort by access method name, per pg_opclass_am_name_nsp_index */
cmpval = accessMethodNameCompare(opcobj1->opcmethod,
@@ -311,8 +311,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_OPFAMILY)
{
- OpfamilyInfo *opfobj1 = *(OpfamilyInfo *const *) p1;
- OpfamilyInfo *opfobj2 = *(OpfamilyInfo *const *) p2;
+ const OpfamilyInfo *opfobj1 = *(OpfamilyInfo *const *) p1;
+ const OpfamilyInfo *opfobj2 = *(OpfamilyInfo *const *) p2;
/* Sort by access method name, per pg_opfamily_am_name_nsp_index */
cmpval = accessMethodNameCompare(opfobj1->opfmethod,
@@ -322,8 +322,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_COLLATION)
{
- CollInfo *cobj1 = *(CollInfo *const *) p1;
- CollInfo *cobj2 = *(CollInfo *const *) p2;
+ const CollInfo *cobj1 = *(CollInfo *const *) p1;
+ const CollInfo *cobj2 = *(CollInfo *const *) p2;
/*
* Sort by encoding, per pg_collation_name_enc_nsp_index. Technically,
@@ -344,8 +344,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_ATTRDEF)
{
- AttrDefInfo *adobj1 = *(AttrDefInfo *const *) p1;
- AttrDefInfo *adobj2 = *(AttrDefInfo *const *) p2;
+ const AttrDefInfo *adobj1 = p1;//*(AttrDefInfo *const *) p1;
+ const AttrDefInfo *adobj2 = *(AttrDefInfo *const *) p2;
/* Sort by attribute number */
cmpval = (adobj1->adnum - adobj2->adnum);
@@ -354,8 +354,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_POLICY)
{
- PolicyInfo *pobj1 = *(PolicyInfo *const *) p1;
- PolicyInfo *pobj2 = *(PolicyInfo *const *) p2;
+ const PolicyInfo *pobj1 = *(PolicyInfo *const *) p1;
+ const PolicyInfo *pobj2 = *(PolicyInfo *const *) p2;
/* Sort by table name (table namespace was considered already) */
cmpval = strcmp(pobj1->poltable->dobj.name,
@@ -365,8 +365,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_RULE)
{
- RuleInfo *robj1 = *(RuleInfo *const *) p1;
- RuleInfo *robj2 = *(RuleInfo *const *) p2;
+ const RuleInfo *robj1 = *(RuleInfo *const *) p1;
+ const RuleInfo *robj2 = *(RuleInfo *const *) p2;
/* Sort by table name (table namespace was considered already) */
cmpval = strcmp(robj1->ruletable->dobj.name,
@@ -376,8 +376,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_TRIGGER)
{
- TriggerInfo *tobj1 = *(TriggerInfo *const *) p1;
- TriggerInfo *tobj2 = *(TriggerInfo *const *) p2;
+ const TriggerInfo *tobj1 = *(TriggerInfo *const *) p1;
+ const TriggerInfo *tobj2 = *(TriggerInfo *const *) p2;
/* Sort by table name (table namespace was considered already) */
cmpval = strcmp(tobj1->tgtable->dobj.name,
@@ -388,8 +388,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
else if (obj1->objType == DO_CONSTRAINT ||
obj1->objType == DO_FK_CONSTRAINT)
{
- ConstraintInfo *robj1 = *(ConstraintInfo *const *) p1;
- ConstraintInfo *robj2 = *(ConstraintInfo *const *) p2;
+ const ConstraintInfo *robj1 = *(ConstraintInfo *const *) p1;
+ const ConstraintInfo *robj2 = *(ConstraintInfo *const *) p2;
/*
* Sort domain constraints before table constraints, for consistency
@@ -421,8 +421,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_DEFAULT_ACL)
{
- DefaultACLInfo *daclobj1 = *(DefaultACLInfo *const *) p1;
- DefaultACLInfo *daclobj2 = *(DefaultACLInfo *const *) p2;
+ const DefaultACLInfo *daclobj1 = *(DefaultACLInfo *const *) p1;
+ const DefaultACLInfo *daclobj2 = *(DefaultACLInfo *const *) p2;
/*
* Sort by defaclrole, per pg_default_acl_role_nsp_obj_index. The
@@ -434,8 +434,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_PUBLICATION_REL)
{
- PublicationRelInfo *probj1 = *(PublicationRelInfo *const *) p1;
- PublicationRelInfo *probj2 = *(PublicationRelInfo *const *) p2;
+ const PublicationRelInfo *probj1 = *(PublicationRelInfo *const *) p1;
+ const PublicationRelInfo *probj2 = *(PublicationRelInfo *const *) p2;
/* Sort by publication name, since (namespace, name) match the rel */
cmpval = strcmp(probj1->publication->dobj.name,
@@ -445,8 +445,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_PUBLICATION_TABLE_IN_SCHEMA)
{
- PublicationSchemaInfo *psobj1 = *(PublicationSchemaInfo *const *) p1;
- PublicationSchemaInfo *psobj2 = *(PublicationSchemaInfo *const *) p2;
+ const PublicationSchemaInfo *psobj1 = *(PublicationSchemaInfo *const *) p1;
+ const PublicationSchemaInfo *psobj2 = *(PublicationSchemaInfo *const *) p2;
/* Sort by publication name, since ->name is just nspname */
cmpval = strcmp(psobj1->publication->dobj.name,
@@ -456,8 +456,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_SUBSCRIPTION_REL)
{
- SubRelInfo *srobj1 = *(SubRelInfo *const *) p1;
- SubRelInfo *srobj2 = *(SubRelInfo *const *) p2;
+ const SubRelInfo *srobj1 = *(SubRelInfo *const *) p1;
+ const SubRelInfo *srobj2 = *(SubRelInfo *const *) p2;
/* Sort by subscription name, since (namespace, name) match the rel */
cmpval = strcmp(srobj1->subinfo->dobj.name,
--
2.39.5 (Apple Git-154)
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;
On Jan 5, 2026, at 21:24, Peter Eisentraut <peter@eisentraut.org> wrote:
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.
Thanks for the explanation, you’re right.
The original p1/p2 are pointers to pointers, and the const qualifier only
applies to the outer pointer. After dereferencing, the second-level pointer
(DumpableObject *) is obtained, and my change simply adds const
qualification to that pointer.
So this is not fixing a cast-away-const issue, but rather tightening the
const qualification of the local variables.
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;
Sorry for the dirty patch file of v3. I was doing some tests, and missed to
revert the dirty change.
V4 has updated the commit message and fixed the dirty code.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
Attachments:
v4-0001-Use-const-qualified-local-pointers-in-DOTypeNameC.patchapplication/octet-stream; name=v4-0001-Use-const-qualified-local-pointers-in-DOTypeNameC.patchDownload
From c6ce8f0396c6428d4667e1fb7b7329cee98499ee Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Tue, 30 Dec 2025 10:50:43 +0800
Subject: [PATCH v4] Use const-qualified local pointers in DOTypeNameCompare
Tighten const-correctness of local variables in DOTypeNameCompare() by
declaring the extracted DumpableObject pointers as const.
The comparator does not modify the referenced objects, and marking the
local pointers as const makes that intent explicit and prevents accidental
writes in the future. There is no behavioral change.
Author: Chao Li <lic@highgo.com>
Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://postgr.es/m/CAEoWx2nN3LYhBmDBaXDoZ=+ikNJkJT7vzg+xPYsHUTSkV8unvg@mail.gmail.com
---
src/bin/pg_dump/pg_dump_sort.c | 60 +++++++++++++++++-----------------
1 file changed, 30 insertions(+), 30 deletions(-)
diff --git a/src/bin/pg_dump/pg_dump_sort.c b/src/bin/pg_dump/pg_dump_sort.c
index 24bed6681de..98e5dae4417 100644
--- a/src/bin/pg_dump/pg_dump_sort.c
+++ b/src/bin/pg_dump/pg_dump_sort.c
@@ -199,8 +199,8 @@ sortDumpableObjectsByTypeName(DumpableObject **objs, int numObjs)
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;
int cmpval;
/* Sort by type's priority */
@@ -265,8 +265,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
*/
if (obj1->objType == DO_FUNC || obj1->objType == DO_AGG)
{
- FuncInfo *fobj1 = *(FuncInfo *const *) p1;
- FuncInfo *fobj2 = *(FuncInfo *const *) p2;
+ const FuncInfo *fobj1 = *(FuncInfo *const *) p1;
+ const FuncInfo *fobj2 = *(FuncInfo *const *) p2;
int i;
/* Sort by number of arguments, then argument type names */
@@ -283,8 +283,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_OPERATOR)
{
- OprInfo *oobj1 = *(OprInfo *const *) p1;
- OprInfo *oobj2 = *(OprInfo *const *) p2;
+ const OprInfo *oobj1 = *(OprInfo *const *) p1;
+ const OprInfo *oobj2 = *(OprInfo *const *) p2;
/* oprkind is 'l', 'r', or 'b'; this sorts prefix, postfix, infix */
cmpval = (oobj2->oprkind - oobj1->oprkind);
@@ -300,8 +300,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_OPCLASS)
{
- OpclassInfo *opcobj1 = *(OpclassInfo *const *) p1;
- OpclassInfo *opcobj2 = *(OpclassInfo *const *) p2;
+ const OpclassInfo *opcobj1 = *(OpclassInfo *const *) p1;
+ const OpclassInfo *opcobj2 = *(OpclassInfo *const *) p2;
/* Sort by access method name, per pg_opclass_am_name_nsp_index */
cmpval = accessMethodNameCompare(opcobj1->opcmethod,
@@ -311,8 +311,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_OPFAMILY)
{
- OpfamilyInfo *opfobj1 = *(OpfamilyInfo *const *) p1;
- OpfamilyInfo *opfobj2 = *(OpfamilyInfo *const *) p2;
+ const OpfamilyInfo *opfobj1 = *(OpfamilyInfo *const *) p1;
+ const OpfamilyInfo *opfobj2 = *(OpfamilyInfo *const *) p2;
/* Sort by access method name, per pg_opfamily_am_name_nsp_index */
cmpval = accessMethodNameCompare(opfobj1->opfmethod,
@@ -322,8 +322,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_COLLATION)
{
- CollInfo *cobj1 = *(CollInfo *const *) p1;
- CollInfo *cobj2 = *(CollInfo *const *) p2;
+ const CollInfo *cobj1 = *(CollInfo *const *) p1;
+ const CollInfo *cobj2 = *(CollInfo *const *) p2;
/*
* Sort by encoding, per pg_collation_name_enc_nsp_index. Technically,
@@ -344,8 +344,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_ATTRDEF)
{
- AttrDefInfo *adobj1 = *(AttrDefInfo *const *) p1;
- AttrDefInfo *adobj2 = *(AttrDefInfo *const *) p2;
+ const AttrDefInfo *adobj1 = *(AttrDefInfo *const *) p1;
+ const AttrDefInfo *adobj2 = *(AttrDefInfo *const *) p2;
/* Sort by attribute number */
cmpval = (adobj1->adnum - adobj2->adnum);
@@ -354,8 +354,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_POLICY)
{
- PolicyInfo *pobj1 = *(PolicyInfo *const *) p1;
- PolicyInfo *pobj2 = *(PolicyInfo *const *) p2;
+ const PolicyInfo *pobj1 = *(PolicyInfo *const *) p1;
+ const PolicyInfo *pobj2 = *(PolicyInfo *const *) p2;
/* Sort by table name (table namespace was considered already) */
cmpval = strcmp(pobj1->poltable->dobj.name,
@@ -365,8 +365,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_RULE)
{
- RuleInfo *robj1 = *(RuleInfo *const *) p1;
- RuleInfo *robj2 = *(RuleInfo *const *) p2;
+ const RuleInfo *robj1 = *(RuleInfo *const *) p1;
+ const RuleInfo *robj2 = *(RuleInfo *const *) p2;
/* Sort by table name (table namespace was considered already) */
cmpval = strcmp(robj1->ruletable->dobj.name,
@@ -376,8 +376,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_TRIGGER)
{
- TriggerInfo *tobj1 = *(TriggerInfo *const *) p1;
- TriggerInfo *tobj2 = *(TriggerInfo *const *) p2;
+ const TriggerInfo *tobj1 = *(TriggerInfo *const *) p1;
+ const TriggerInfo *tobj2 = *(TriggerInfo *const *) p2;
/* Sort by table name (table namespace was considered already) */
cmpval = strcmp(tobj1->tgtable->dobj.name,
@@ -388,8 +388,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
else if (obj1->objType == DO_CONSTRAINT ||
obj1->objType == DO_FK_CONSTRAINT)
{
- ConstraintInfo *robj1 = *(ConstraintInfo *const *) p1;
- ConstraintInfo *robj2 = *(ConstraintInfo *const *) p2;
+ const ConstraintInfo *robj1 = *(ConstraintInfo *const *) p1;
+ const ConstraintInfo *robj2 = *(ConstraintInfo *const *) p2;
/*
* Sort domain constraints before table constraints, for consistency
@@ -421,8 +421,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_DEFAULT_ACL)
{
- DefaultACLInfo *daclobj1 = *(DefaultACLInfo *const *) p1;
- DefaultACLInfo *daclobj2 = *(DefaultACLInfo *const *) p2;
+ const DefaultACLInfo *daclobj1 = *(DefaultACLInfo *const *) p1;
+ const DefaultACLInfo *daclobj2 = *(DefaultACLInfo *const *) p2;
/*
* Sort by defaclrole, per pg_default_acl_role_nsp_obj_index. The
@@ -434,8 +434,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_PUBLICATION_REL)
{
- PublicationRelInfo *probj1 = *(PublicationRelInfo *const *) p1;
- PublicationRelInfo *probj2 = *(PublicationRelInfo *const *) p2;
+ const PublicationRelInfo *probj1 = *(PublicationRelInfo *const *) p1;
+ const PublicationRelInfo *probj2 = *(PublicationRelInfo *const *) p2;
/* Sort by publication name, since (namespace, name) match the rel */
cmpval = strcmp(probj1->publication->dobj.name,
@@ -445,8 +445,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_PUBLICATION_TABLE_IN_SCHEMA)
{
- PublicationSchemaInfo *psobj1 = *(PublicationSchemaInfo *const *) p1;
- PublicationSchemaInfo *psobj2 = *(PublicationSchemaInfo *const *) p2;
+ const PublicationSchemaInfo *psobj1 = *(PublicationSchemaInfo *const *) p1;
+ const PublicationSchemaInfo *psobj2 = *(PublicationSchemaInfo *const *) p2;
/* Sort by publication name, since ->name is just nspname */
cmpval = strcmp(psobj1->publication->dobj.name,
@@ -456,8 +456,8 @@ DOTypeNameCompare(const void *p1, const void *p2)
}
else if (obj1->objType == DO_SUBSCRIPTION_REL)
{
- SubRelInfo *srobj1 = *(SubRelInfo *const *) p1;
- SubRelInfo *srobj2 = *(SubRelInfo *const *) p2;
+ const SubRelInfo *srobj1 = *(SubRelInfo *const *) p1;
+ const SubRelInfo *srobj2 = *(SubRelInfo *const *) p2;
/* Sort by subscription name, since (namespace, name) match the rel */
cmpval = strcmp(srobj1->subinfo->dobj.name,
--
2.39.5 (Apple Git-154)