[PATCH v2 2/3] Add const to read only TableInfo pointers in pg_dump
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
To:
Date: 2025-12-18T12:47:07Z
Lists: pgsql-hackers
Functions that dump table data receive their parameters through const void *
but were casting away const. Add const qualifiers to functions that only read
the table information.
Also change getRootTableInfo to return const TableInfo *, since it only traverses
the parent chain without modifying any TableInfo structures. This allows the dump
functions to maintain const correctness when calling it.
Discussion: https://postgr.es/m/aUQHy/MmWq7c97wK%40ip-10-97-1-34.eu-west-3.compute.internal
---
src/bin/pg_dump/pg_dump.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
100.0% src/bin/pg_dump/
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 27f6be3f0f8..3f5e917ad99 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -412,7 +412,7 @@ static void appendReloptionsArrayAH(PQExpBuffer buffer, const char *reloptions,
static char *get_synchronized_snapshot(Archive *fout);
static void set_restrict_relation_kind(Archive *AH, const char *value);
static void setupDumpWorker(Archive *AH);
-static TableInfo *getRootTableInfo(const TableInfo *tbinfo);
+static const TableInfo *getRootTableInfo(const TableInfo *tbinfo);
static bool forcePartitionRootLoad(const TableInfo *tbinfo);
static void read_dump_filters(const char *filename, DumpOptions *dopt);
@@ -2379,8 +2379,8 @@ selectDumpableObject(DumpableObject *dobj, Archive *fout)
static int
dumpTableData_copy(Archive *fout, const void *dcontext)
{
- TableDataInfo *tdinfo = (TableDataInfo *) dcontext;
- TableInfo *tbinfo = tdinfo->tdtable;
+ const TableDataInfo *tdinfo = dcontext;
+ const TableInfo *tbinfo = tdinfo->tdtable;
const char *classname = tbinfo->dobj.name;
PQExpBuffer q = createPQExpBuffer();
@@ -2547,8 +2547,8 @@ dumpTableData_copy(Archive *fout, const void *dcontext)
static int
dumpTableData_insert(Archive *fout, const void *dcontext)
{
- TableDataInfo *tdinfo = (TableDataInfo *) dcontext;
- TableInfo *tbinfo = tdinfo->tdtable;
+ const TableDataInfo *tdinfo = dcontext;
+ const TableInfo *tbinfo = tdinfo->tdtable;
DumpOptions *dopt = fout->dopt;
PQExpBuffer q = createPQExpBuffer();
PQExpBuffer insertStmt = NULL;
@@ -2618,7 +2618,7 @@ dumpTableData_insert(Archive *fout, const void *dcontext)
*/
if (insertStmt == NULL)
{
- TableInfo *targettab;
+ const TableInfo *targettab;
insertStmt = createPQExpBuffer();
@@ -2813,10 +2813,10 @@ dumpTableData_insert(Archive *fout, const void *dcontext)
* getRootTableInfo:
* get the root TableInfo for the given partition table.
*/
-static TableInfo *
+static const TableInfo *
getRootTableInfo(const TableInfo *tbinfo)
{
- TableInfo *parentTbinfo;
+ const TableInfo *parentTbinfo;
Assert(tbinfo->ispartition);
Assert(tbinfo->numParents == 1);
@@ -2870,7 +2870,7 @@ static void
dumpTableData(Archive *fout, const TableDataInfo *tdinfo)
{
DumpOptions *dopt = fout->dopt;
- TableInfo *tbinfo = tdinfo->tdtable;
+ const TableInfo *tbinfo = tdinfo->tdtable;
PQExpBuffer copyBuf = createPQExpBuffer();
PQExpBuffer clistBuf = createPQExpBuffer();
DataDumperPtr dumpFn;
@@ -2891,7 +2891,7 @@ dumpTableData(Archive *fout, const TableDataInfo *tdinfo)
(dopt->load_via_partition_root ||
forcePartitionRootLoad(tbinfo)))
{
- TableInfo *parentTbinfo;
+ const TableInfo *parentTbinfo;
char *sanitized;
parentTbinfo = getRootTableInfo(tbinfo);
--
2.34.1
--IBFQ0J+7bhRCocF6
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2-0003-Separate-read-and-write-pointers-in-pg_saslprep.patch"