On 2025-Apr-04, Nathan Bossart wrote:

> Prevent redeclaration of typedef TocEntry.
> 
> Commit 9c02e3a986 added a forward declaration for this typedef that
> caused redeclarations, which is not valid in C99.  To fix, add some
> preprocessor guards to avoid a redefinition, as is done elsewhere
> (e.g., commit 382092a0cd).

Hmm, I have the impression that this results from some very old
untidyness in the pg_dump headers in general.  The fact that
DataDumperPtr is in pg_backup.h seems now more of an accident than
something we would really choose to do nowadays -- it's been that way
since pg_dump was introduced in commit 500b62b0570f apparently.  I'm
sure there were good reasons to have it there then.  But we've
restructured the pg_dump headers at least once, and as far as I can see
there aren't anymore.  AFAICS we could move both DefnDumperPtr and
DataDumperPtr typedefs to pg_backup_archiver.h, together with struct
_tocEntry (the only place where they are used), and we'd have less of a
mess here.  Then we don't need struct TocEntry in pg_backup.h anymore.

Plus, these function typedefs aren't really "public interface" for
pg_dump anyway (which is what pg_backup.h claims to be), so I think it
would be a sensible cleanup.  Patch attached.

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/
Thou shalt check the array bounds of all strings (indeed, all arrays), for
surely where thou typest "foo" someone someday shall type
"supercalifragilisticexpialidocious" (5th Commandment for C programmers)
>From 769bf34bfd346e5a333e3dfd61519902fa3e7f55 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <alvhe...@alvh.no-ip.org>
Date: Fri, 4 Apr 2025 23:39:59 +0200
Subject: [PATCH] cleanup pg_dump headers a bit

---
 src/bin/pg_dump/pg_backup.h          | 10 ----------
 src/bin/pg_dump/pg_backup_archiver.h |  7 ++++---
 2 files changed, 4 insertions(+), 13 deletions(-)

diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h
index 8586cdaf541..af0007fb6d2 100644
--- a/src/bin/pg_dump/pg_backup.h
+++ b/src/bin/pg_dump/pg_backup.h
@@ -284,16 +284,6 @@ typedef int DumpId;
 /*
  * Function pointer prototypes for assorted callback methods.
  */
-
-/* forward declaration to avoid including pg_backup_archiver.h here */
-#ifndef HAVE_TOCENTRY_TYPEDEF
-typedef struct _tocEntry TocEntry;
-#define HAVE_TOCENTRY_TYPEDEF 1
-#endif
-
-typedef char *(*DefnDumperPtr) (Archive *AH, const void *userArg, const TocEntry *te);
-typedef int (*DataDumperPtr) (Archive *AH, const void *userArg);
-
 typedef void (*SetupWorkerPtrType) (Archive *AH);
 
 /*
diff --git a/src/bin/pg_dump/pg_backup_archiver.h b/src/bin/pg_dump/pg_backup_archiver.h
index e81a76ba25e..365073b3eae 100644
--- a/src/bin/pg_dump/pg_backup_archiver.h
+++ b/src/bin/pg_dump/pg_backup_archiver.h
@@ -97,10 +97,7 @@
 #define WORKER_IGNORED_ERRORS		  12
 
 typedef struct _archiveHandle ArchiveHandle;
-#ifndef HAVE_TOCENTRY_TYPEDEF
 typedef struct _tocEntry TocEntry;
-#define HAVE_TOCENTRY_TYPEDEF 1
-#endif
 struct ParallelState;
 
 #define READ_ERROR_EXIT(fd) \
@@ -344,6 +341,10 @@ struct _archiveHandle
 	struct _tocEntry *lastErrorTE;
 };
 
+
+typedef char *(*DefnDumperPtr) (Archive *AH, const void *userArg, const TocEntry *te);
+typedef int (*DataDumperPtr) (Archive *AH, const void *userArg);
+
 struct _tocEntry
 {
 	struct _tocEntry *prev;
-- 
2.39.5

Reply via email to