On 16.05.24 01:32, Tom Lane wrote:
As for the remainder, they aren't showing up because no variable
or field is declared using them, which means no debug symbol
table entry is made for them.  This means we could just drop those
typedefs and be little the worse off notationally.  I experimented
with a patch for that, as attached.  (In the case of NotificationHash,
I thought it better to arrange for there to be a suitable variable;
but it could certainly be done the other way too.)  Is this too anal?

I agree we should get rid of these.

Over the last release cycle, I've been leaning a bit more toward not typdef'ing enums and structs that are only in local use, in part because of the implied need to keep the typedefs list up to date.

In these cases, I think for

NotificationHash
ResourceOwnerData
WalSyncMethod

we can just get rid of the typedef.

ReadBuffersFlags shouldn't be an enum at all, because its values are used as flag bits.

WaitEventExtension, I'm not sure, it's like, an extensible enum? I guess let's remove the typedef there, too.

Attached is a variant patch.
diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c
index d0891e3f0e0..ab4c72762d8 100644
--- a/src/backend/commands/async.c
+++ b/src/backend/commands/async.c
@@ -396,10 +396,10 @@ typedef struct NotificationList
 
 #define MIN_HASHABLE_NOTIFIES 16       /* threshold to build hashtab */
 
-typedef struct NotificationHash
+struct NotificationHash
 {
        Notification *event;            /* => the actual Notification struct */
-} NotificationHash;
+};
 
 static NotificationList *pendingNotifies = NULL;
 
@@ -2299,7 +2299,7 @@ AddEventToPendingNotifies(Notification *n)
 
                /* Create the hash table */
                hash_ctl.keysize = sizeof(Notification *);
-               hash_ctl.entrysize = sizeof(NotificationHash);
+               hash_ctl.entrysize = sizeof(struct NotificationHash);
                hash_ctl.hash = notification_hash;
                hash_ctl.match = notification_match;
                hash_ctl.hcxt = CurTransactionContext;
diff --git a/src/backend/utils/resowner/resowner.c 
b/src/backend/utils/resowner/resowner.c
index ab9343bc5cf..505534ee8d3 100644
--- a/src/backend/utils/resowner/resowner.c
+++ b/src/backend/utils/resowner/resowner.c
@@ -107,7 +107,7 @@ 
StaticAssertDecl(RESOWNER_HASH_MAX_ITEMS(RESOWNER_HASH_INIT_SIZE) >= RESOWNER_AR
 /*
  * ResourceOwner objects look like this
  */
-typedef struct ResourceOwnerData
+struct ResourceOwnerData
 {
        ResourceOwner parent;           /* NULL if no parent (toplevel owner) */
        ResourceOwner firstchild;       /* head of linked list of children */
@@ -155,7 +155,7 @@ typedef struct ResourceOwnerData
 
        /* The local locks cache. */
        LOCALLOCK  *locks[MAX_RESOWNER_LOCKS];  /* list of owned locks */
-} ResourceOwnerData;
+};
 
 
 /*****************************************************************************
@@ -415,7 +415,7 @@ ResourceOwnerCreate(ResourceOwner parent, const char *name)
        ResourceOwner owner;
 
        owner = (ResourceOwner) MemoryContextAllocZero(TopMemoryContext,
-                                                                               
                   sizeof(ResourceOwnerData));
+                                                                               
                   sizeof(struct ResourceOwnerData));
        owner->name = name;
 
        if (parent)
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h
index 76787a82673..1a1f11a943f 100644
--- a/src/include/access/xlog.h
+++ b/src/include/access/xlog.h
@@ -19,14 +19,14 @@
 
 
 /* Sync methods */
-typedef enum WalSyncMethod
+enum WalSyncMethod
 {
        WAL_SYNC_METHOD_FSYNC = 0,
        WAL_SYNC_METHOD_FDATASYNC,
        WAL_SYNC_METHOD_OPEN,           /* for O_SYNC */
        WAL_SYNC_METHOD_FSYNC_WRITETHROUGH,
        WAL_SYNC_METHOD_OPEN_DSYNC      /* for O_DSYNC */
-} WalSyncMethod;
+};
 extern PGDLLIMPORT int wal_sync_method;
 
 extern PGDLLIMPORT XLogRecPtr ProcLastRecPtr;
diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h
index 42211bfec4f..08364447c74 100644
--- a/src/include/storage/bufmgr.h
+++ b/src/include/storage/bufmgr.h
@@ -107,14 +107,10 @@ typedef struct BufferManagerRelation
 #define BMR_REL(p_rel) ((BufferManagerRelation){.rel = p_rel})
 #define BMR_SMGR(p_smgr, p_relpersistence) ((BufferManagerRelation){.smgr = 
p_smgr, .relpersistence = p_relpersistence})
 
-typedef enum ReadBuffersFlags
-{
-       /* Zero out page if reading fails. */
-       READ_BUFFERS_ZERO_ON_ERROR = (1 << 0),
-
-       /* Call smgrprefetch() if I/O necessary. */
-       READ_BUFFERS_ISSUE_ADVICE = (1 << 1),
-} ReadBuffersFlags;
+/* Zero out page if reading fails. */
+#define READ_BUFFERS_ZERO_ON_ERROR (1 << 0)
+/* Call smgrprefetch() if I/O necessary. */
+#define READ_BUFFERS_ISSUE_ADVICE (1 << 1)
 
 struct ReadBuffersOperation
 {

Reply via email to