Skip to content

Commit 10b7218

Browse files
committed
Use macro to define the number of enum values
Refactoring in the interest of code consistency, a follow-up to 2e068db. 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
1 parent fc1b2ce commit 10b7218

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

contrib/pg_stat_statements/pg_stat_statements.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ typedef enum pgssStoreKind
126126
*/
127127
PGSS_PLAN = 0,
128128
PGSS_EXEC,
129-
130-
PGSS_NUMKIND /* Must be last value of this enum */
131129
} pgssStoreKind;
132130

131+
#define PGSS_NUMKIND (PGSS_EXEC + 1)
132+
133133
/*
134134
* Hashtable key that defines the identity of a hashtable entry. We separate
135135
* queries by user and by database even if they are otherwise identical.

src/backend/postmaster/autovacuum.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,10 @@ typedef enum
247247
{
248248
AutoVacForkFailed, /* failed trying to start a worker */
249249
AutoVacRebalance, /* rebalance the cost limits */
250-
AutoVacNumSignals, /* must be last */
251250
} AutoVacuumSignal;
252251

252+
#define AutoVacNumSignals (AutoVacRebalance + 1)
253+
253254
/*
254255
* Autovacuum workitem array, stored in AutoVacuumShmem->av_workItems. This
255256
* list is mostly protected by AutovacuumLock, except that if an item is

src/bin/pg_dump/pg_backup.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ enum _dumpPreparedQueries
7474
PREPQUERY_DUMPTABLEATTACH,
7575
PREPQUERY_GETCOLUMNACLS,
7676
PREPQUERY_GETDOMAINCONSTRAINTS,
77-
NUM_PREP_QUERIES /* must be last */
7877
};
7978

79+
#define NUM_PREP_QUERIES (PREPQUERY_GETDOMAINCONSTRAINTS + 1)
80+
8081
/* Parameters needed by ConnectDatabase; same for dump and restore */
8182
typedef struct _connParams
8283
{

src/include/storage/pmsignal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ typedef enum
4040
PMSIGNAL_BACKGROUND_WORKER_CHANGE, /* background worker state change */
4141
PMSIGNAL_START_WALRECEIVER, /* start a walreceiver */
4242
PMSIGNAL_ADVANCE_STATE_MACHINE, /* advance postmaster's state machine */
43-
44-
NUM_PMSIGNALS /* Must be last value of enum! */
4543
} PMSignalReason;
4644

45+
#define NUM_PMSIGNALS (PMSIGNAL_ADVANCE_STATE_MACHINE+1)
46+
4747
/*
4848
* Reasons why the postmaster would send SIGQUIT to its children.
4949
*/

src/include/storage/procsignal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ typedef enum
4747
PROCSIG_RECOVERY_CONFLICT_BUFFERPIN,
4848
PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK,
4949
PROCSIG_RECOVERY_CONFLICT_LAST = PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK,
50-
51-
NUM_PROCSIGNALS /* Must be last! */
5250
} ProcSignalReason;
5351

52+
#define NUM_PROCSIGNALS (PROCSIG_RECOVERY_CONFLICT_LAST + 1)
53+
5454
typedef enum
5555
{
5656
PROCSIGNAL_BARRIER_SMGRRELEASE, /* ask smgr to close files */

0 commit comments

Comments
 (0)