Use macro to define the number of enum values
authorPeter Eisentraut <[email protected]>
Tue, 1 Oct 2024 13:30:24 +0000 (09:30 -0400)
committerPeter Eisentraut <[email protected]>
Tue, 1 Oct 2024 13:30:24 +0000 (09:30 -0400)
Refactoring in the interest of code consistency, a follow-up to 2e068db56e31.

The argument against inserting a special enum value at the end of the enum
definition is that a switch statement might generate a compiler warning unless
it has a default clause.

Aleksander Alekseev, reviewed by Michael Paquier, Dean Rasheed, Peter Eisentraut

Discussion: https://postgr.es/m/CAJ7c6TMsiaV5urU_Pq6zJ2tXPDwk69-NKVh4AMN5XrRiM7N%2BGA%40mail.gmail.com

contrib/pg_stat_statements/pg_stat_statements.c
src/backend/postmaster/autovacuum.c
src/bin/pg_dump/pg_backup.h
src/include/storage/pmsignal.h
src/include/storage/procsignal.h

index 3c72e437f73979354c1450767765b1acd462e550..5765ef49b4c0750cd52f7ef3727d6a291c1df3e5 100644 (file)
@@ -126,10 +126,10 @@ typedef enum pgssStoreKind
     */
    PGSS_PLAN = 0,
    PGSS_EXEC,
-
-   PGSS_NUMKIND                /* Must be last value of this enum */
 } pgssStoreKind;
 
+#define PGSS_NUMKIND (PGSS_EXEC + 1)
+
 /*
  * Hashtable key that defines the identity of a hashtable entry.  We separate
  * queries by user and by database even if they are otherwise identical.
index 7d0877c95ec87cbc46bd5ca89443c033cd16127e..dc3cf87abab8d18a6d078d6f5d9cf2aa1ba0a018 100644 (file)
@@ -247,9 +247,10 @@ typedef enum
 {
    AutoVacForkFailed,          /* failed trying to start a worker */
    AutoVacRebalance,           /* rebalance the cost limits */
-   AutoVacNumSignals,          /* must be last */
 }          AutoVacuumSignal;
 
+#define AutoVacNumSignals (AutoVacRebalance + 1)
+
 /*
  * Autovacuum workitem array, stored in AutoVacuumShmem->av_workItems.  This
  * list is mostly protected by AutovacuumLock, except that if an item is
index fbf5f1c515e5e1436f7fc6d7dbf041bfc8fb3d26..68ae2970ade2c5935c6e86e0b26322aebe4c787c 100644 (file)
@@ -74,9 +74,10 @@ enum _dumpPreparedQueries
    PREPQUERY_DUMPTABLEATTACH,
    PREPQUERY_GETCOLUMNACLS,
    PREPQUERY_GETDOMAINCONSTRAINTS,
-   NUM_PREP_QUERIES            /* must be last */
 };
 
+#define NUM_PREP_QUERIES (PREPQUERY_GETDOMAINCONSTRAINTS + 1)
+
 /* Parameters needed by ConnectDatabase; same for dump and restore */
 typedef struct _connParams
 {
index 87ac91848bc1a71b64877728ee05b007e1c24d51..e5be0f121c242d793a00e0c358f91c8c2a709202 100644 (file)
@@ -40,10 +40,10 @@ typedef enum
    PMSIGNAL_BACKGROUND_WORKER_CHANGE,  /* background worker state change */
    PMSIGNAL_START_WALRECEIVER, /* start a walreceiver */
    PMSIGNAL_ADVANCE_STATE_MACHINE, /* advance postmaster's state machine */
-
-   NUM_PMSIGNALS               /* Must be last value of enum! */
 } PMSignalReason;
 
+#define NUM_PMSIGNALS (PMSIGNAL_ADVANCE_STATE_MACHINE+1)
+
 /*
  * Reasons why the postmaster would send SIGQUIT to its children.
  */
index f94c11a9a84235f98260c08a63905479154b3f33..221073def38bf4c2eff17f8c3b102eec4f6c4f4d 100644 (file)
@@ -47,10 +47,10 @@ typedef enum
    PROCSIG_RECOVERY_CONFLICT_BUFFERPIN,
    PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK,
    PROCSIG_RECOVERY_CONFLICT_LAST = PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK,
-
-   NUM_PROCSIGNALS             /* Must be last! */
 } ProcSignalReason;
 
+#define NUM_PROCSIGNALS (PROCSIG_RECOVERY_CONFLICT_LAST + 1)
+
 typedef enum
 {
    PROCSIGNAL_BARRIER_SMGRRELEASE, /* ask smgr to close files */