Commit 33a3b03d authored by Tom Lane's avatar Tom Lane

Use FLEXIBLE_ARRAY_MEMBER in some more places.

Fix a batch of structs that are only visible within individual .c files.

Michael Paquier
parent c110eff1
...@@ -1836,7 +1836,7 @@ typedef struct BTVacInfo ...@@ -1836,7 +1836,7 @@ typedef struct BTVacInfo
BTCycleId cycle_ctr; /* cycle ID most recently assigned */ BTCycleId cycle_ctr; /* cycle ID most recently assigned */
int num_vacuums; /* number of currently active VACUUMs */ int num_vacuums; /* number of currently active VACUUMs */
int max_vacuums; /* allocated length of vacuums[] array */ int max_vacuums; /* allocated length of vacuums[] array */
BTOneVacInfo vacuums[1]; /* VARIABLE LENGTH ARRAY */ BTOneVacInfo vacuums[FLEXIBLE_ARRAY_MEMBER];
} BTVacInfo; } BTVacInfo;
static BTVacInfo *btvacinfo; static BTVacInfo *btvacinfo;
...@@ -1984,7 +1984,7 @@ BTreeShmemSize(void) ...@@ -1984,7 +1984,7 @@ BTreeShmemSize(void)
{ {
Size size; Size size;
size = offsetof(BTVacInfo, vacuums[0]); size = offsetof(BTVacInfo, vacuums);
size = add_size(size, mul_size(MaxBackends, sizeof(BTOneVacInfo))); size = add_size(size, mul_size(MaxBackends, sizeof(BTOneVacInfo)));
return size; return size;
} }
......
...@@ -258,7 +258,7 @@ typedef struct MultiXactStateData ...@@ -258,7 +258,7 @@ typedef struct MultiXactStateData
* stored in pg_control and used as truncation point for pg_multixact. At * stored in pg_control and used as truncation point for pg_multixact. At
* checkpoint or restartpoint, unneeded segments are removed. * checkpoint or restartpoint, unneeded segments are removed.
*/ */
MultiXactId perBackendXactIds[1]; /* VARIABLE LENGTH ARRAY */ MultiXactId perBackendXactIds[FLEXIBLE_ARRAY_MEMBER];
} MultiXactStateData; } MultiXactStateData;
/* /*
...@@ -1744,8 +1744,9 @@ MultiXactShmemSize(void) ...@@ -1744,8 +1744,9 @@ MultiXactShmemSize(void)
{ {
Size size; Size size;
/* We need 2*MaxOldestSlot + 1 perBackendXactIds[] entries */
#define SHARED_MULTIXACT_STATE_SIZE \ #define SHARED_MULTIXACT_STATE_SIZE \
add_size(sizeof(MultiXactStateData), \ add_size(offsetof(MultiXactStateData, perBackendXactIds) + sizeof(MultiXactId), \
mul_size(sizeof(MultiXactId) * 2, MaxOldestSlot)) mul_size(sizeof(MultiXactId) * 2, MaxOldestSlot))
size = SHARED_MULTIXACT_STATE_SIZE; size = SHARED_MULTIXACT_STATE_SIZE;
......
...@@ -134,12 +134,9 @@ typedef struct TwoPhaseStateData ...@@ -134,12 +134,9 @@ typedef struct TwoPhaseStateData
/* Number of valid prepXacts entries. */ /* Number of valid prepXacts entries. */
int numPrepXacts; int numPrepXacts;
/* /* There are max_prepared_xacts items in this array */
* There are max_prepared_xacts items in this array, but C wants a GlobalTransaction prepXacts[FLEXIBLE_ARRAY_MEMBER];
* fixed-size array. } TwoPhaseStateData;
*/
GlobalTransaction prepXacts[1]; /* VARIABLE LENGTH ARRAY */
} TwoPhaseStateData; /* VARIABLE LENGTH STRUCT */
static TwoPhaseStateData *TwoPhaseState; static TwoPhaseStateData *TwoPhaseState;
......
...@@ -1088,7 +1088,7 @@ GetDefaultTablespace(char relpersistence) ...@@ -1088,7 +1088,7 @@ GetDefaultTablespace(char relpersistence)
typedef struct typedef struct
{ {
int numSpcs; int numSpcs;
Oid tblSpcs[1]; /* VARIABLE LENGTH ARRAY */ Oid tblSpcs[FLEXIBLE_ARRAY_MEMBER];
} temp_tablespaces_extra; } temp_tablespaces_extra;
/* check_hook: validate new temp_tablespaces */ /* check_hook: validate new temp_tablespaces */
......
...@@ -3005,7 +3005,7 @@ typedef struct SetConstraintStateData ...@@ -3005,7 +3005,7 @@ typedef struct SetConstraintStateData
bool all_isdeferred; bool all_isdeferred;
int numstates; /* number of trigstates[] entries in use */ int numstates; /* number of trigstates[] entries in use */
int numalloc; /* allocated size of trigstates[] */ int numalloc; /* allocated size of trigstates[] */
SetConstraintTriggerData trigstates[1]; /* VARIABLE LENGTH ARRAY */ SetConstraintTriggerData trigstates[FLEXIBLE_ARRAY_MEMBER];
} SetConstraintStateData; } SetConstraintStateData;
typedef SetConstraintStateData *SetConstraintState; typedef SetConstraintStateData *SetConstraintState;
...@@ -4398,8 +4398,8 @@ SetConstraintStateCreate(int numalloc) ...@@ -4398,8 +4398,8 @@ SetConstraintStateCreate(int numalloc)
*/ */
state = (SetConstraintState) state = (SetConstraintState)
MemoryContextAllocZero(TopTransactionContext, MemoryContextAllocZero(TopTransactionContext,
sizeof(SetConstraintStateData) + offsetof(SetConstraintStateData, trigstates) +
(numalloc - 1) *sizeof(SetConstraintTriggerData)); numalloc * sizeof(SetConstraintTriggerData));
state->numalloc = numalloc; state->numalloc = numalloc;
...@@ -4440,8 +4440,8 @@ SetConstraintStateAddItem(SetConstraintState state, ...@@ -4440,8 +4440,8 @@ SetConstraintStateAddItem(SetConstraintState state,
newalloc = Max(newalloc, 8); /* in case original has size 0 */ newalloc = Max(newalloc, 8); /* in case original has size 0 */
state = (SetConstraintState) state = (SetConstraintState)
repalloc(state, repalloc(state,
sizeof(SetConstraintStateData) + offsetof(SetConstraintStateData, trigstates) +
(newalloc - 1) *sizeof(SetConstraintTriggerData)); newalloc * sizeof(SetConstraintTriggerData));
state->numalloc = newalloc; state->numalloc = newalloc;
Assert(state->numstates < state->numalloc); Assert(state->numstates < state->numalloc);
} }
......
...@@ -297,9 +297,9 @@ typedef struct AggHashEntryData *AggHashEntry; ...@@ -297,9 +297,9 @@ typedef struct AggHashEntryData *AggHashEntry;
typedef struct AggHashEntryData typedef struct AggHashEntryData
{ {
TupleHashEntryData shared; /* common header for hash table entries */ TupleHashEntryData shared; /* common header for hash table entries */
/* per-aggregate transition status array - must be last! */ /* per-aggregate transition status array */
AggStatePerGroupData pergroup[1]; /* VARIABLE LENGTH ARRAY */ AggStatePerGroupData pergroup[FLEXIBLE_ARRAY_MEMBER];
} AggHashEntryData; /* VARIABLE LENGTH STRUCT */ } AggHashEntryData;
static void initialize_aggregates(AggState *aggstate, static void initialize_aggregates(AggState *aggstate,
...@@ -941,8 +941,8 @@ build_hash_table(AggState *aggstate) ...@@ -941,8 +941,8 @@ build_hash_table(AggState *aggstate)
Assert(node->aggstrategy == AGG_HASHED); Assert(node->aggstrategy == AGG_HASHED);
Assert(node->numGroups > 0); Assert(node->numGroups > 0);
entrysize = sizeof(AggHashEntryData) + entrysize = offsetof(AggHashEntryData, pergroup) +
(aggstate->numaggs - 1) * sizeof(AggStatePerGroupData); aggstate->numaggs * sizeof(AggStatePerGroupData);
aggstate->hashtable = BuildTupleHashTable(node->numCols, aggstate->hashtable = BuildTupleHashTable(node->numCols,
node->grpColIdx, node->grpColIdx,
...@@ -1013,8 +1013,8 @@ hash_agg_entry_size(int numAggs) ...@@ -1013,8 +1013,8 @@ hash_agg_entry_size(int numAggs)
Size entrysize; Size entrysize;
/* This must match build_hash_table */ /* This must match build_hash_table */
entrysize = sizeof(AggHashEntryData) + entrysize = offsetof(AggHashEntryData, pergroup) +
(numAggs - 1) * sizeof(AggStatePerGroupData); numAggs * sizeof(AggStatePerGroupData);
entrysize = MAXALIGN(entrysize); entrysize = MAXALIGN(entrysize);
/* Account for hashtable overhead (assuming fill factor = 1) */ /* Account for hashtable overhead (assuming fill factor = 1) */
entrysize += 3 * sizeof(void *); entrysize += 3 * sizeof(void *);
......
...@@ -130,7 +130,7 @@ typedef struct ...@@ -130,7 +130,7 @@ typedef struct
int num_requests; /* current # of requests */ int num_requests; /* current # of requests */
int max_requests; /* allocated array size */ int max_requests; /* allocated array size */
CheckpointerRequest requests[1]; /* VARIABLE LENGTH ARRAY */ CheckpointerRequest requests[FLEXIBLE_ARRAY_MEMBER];
} CheckpointerShmemStruct; } CheckpointerShmemStruct;
static CheckpointerShmemStruct *CheckpointerShmem; static CheckpointerShmemStruct *CheckpointerShmem;
......
...@@ -66,7 +66,7 @@ struct PMSignalData ...@@ -66,7 +66,7 @@ struct PMSignalData
/* per-child-process flags */ /* per-child-process flags */
int num_child_flags; /* # of entries in PMChildFlags[] */ int num_child_flags; /* # of entries in PMChildFlags[] */
int next_child_flag; /* next slot to try to assign */ int next_child_flag; /* next slot to try to assign */
sig_atomic_t PMChildFlags[1]; /* VARIABLE LENGTH ARRAY */ sig_atomic_t PMChildFlags[FLEXIBLE_ARRAY_MEMBER];
}; };
NON_EXEC_STATIC volatile PMSignalData *PMSignalState = NULL; NON_EXEC_STATIC volatile PMSignalData *PMSignalState = NULL;
......
...@@ -90,11 +90,8 @@ typedef struct ProcArrayStruct ...@@ -90,11 +90,8 @@ typedef struct ProcArrayStruct
/* oldest catalog xmin of any replication slot */ /* oldest catalog xmin of any replication slot */
TransactionId replication_slot_catalog_xmin; TransactionId replication_slot_catalog_xmin;
/* /* indexes into allPgXact[], has PROCARRAY_MAXPROCS entries */
* We declare pgprocnos[] as 1 entry because C wants a fixed-size array, int pgprocnos[FLEXIBLE_ARRAY_MEMBER];
* but actually it is maxProcs entries long.
*/
int pgprocnos[1]; /* VARIABLE LENGTH ARRAY */
} ProcArrayStruct; } ProcArrayStruct;
static ProcArrayStruct *procArray; static ProcArrayStruct *procArray;
......
...@@ -122,8 +122,8 @@ typedef struct InvalidationChunk ...@@ -122,8 +122,8 @@ typedef struct InvalidationChunk
struct InvalidationChunk *next; /* list link */ struct InvalidationChunk *next; /* list link */
int nitems; /* # items currently stored in chunk */ int nitems; /* # items currently stored in chunk */
int maxitems; /* size of allocated array in this chunk */ int maxitems; /* size of allocated array in this chunk */
SharedInvalidationMessage msgs[1]; /* VARIABLE LENGTH ARRAY */ SharedInvalidationMessage msgs[FLEXIBLE_ARRAY_MEMBER];
} InvalidationChunk; /* VARIABLE LENGTH STRUCTURE */ } InvalidationChunk;
typedef struct InvalidationListHeader typedef struct InvalidationListHeader
{ {
...@@ -225,8 +225,8 @@ AddInvalidationMessage(InvalidationChunk **listHdr, ...@@ -225,8 +225,8 @@ AddInvalidationMessage(InvalidationChunk **listHdr,
#define FIRSTCHUNKSIZE 32 #define FIRSTCHUNKSIZE 32
chunk = (InvalidationChunk *) chunk = (InvalidationChunk *)
MemoryContextAlloc(CurTransactionContext, MemoryContextAlloc(CurTransactionContext,
sizeof(InvalidationChunk) + offsetof(InvalidationChunk, msgs) +
(FIRSTCHUNKSIZE - 1) *sizeof(SharedInvalidationMessage)); FIRSTCHUNKSIZE * sizeof(SharedInvalidationMessage));
chunk->nitems = 0; chunk->nitems = 0;
chunk->maxitems = FIRSTCHUNKSIZE; chunk->maxitems = FIRSTCHUNKSIZE;
chunk->next = *listHdr; chunk->next = *listHdr;
...@@ -239,8 +239,8 @@ AddInvalidationMessage(InvalidationChunk **listHdr, ...@@ -239,8 +239,8 @@ AddInvalidationMessage(InvalidationChunk **listHdr,
chunk = (InvalidationChunk *) chunk = (InvalidationChunk *)
MemoryContextAlloc(CurTransactionContext, MemoryContextAlloc(CurTransactionContext,
sizeof(InvalidationChunk) + offsetof(InvalidationChunk, msgs) +
(chunksize - 1) *sizeof(SharedInvalidationMessage)); chunksize * sizeof(SharedInvalidationMessage));
chunk->nitems = 0; chunk->nitems = 0;
chunk->maxitems = chunksize; chunk->maxitems = chunksize;
chunk->next = *listHdr; chunk->next = *listHdr;
......
...@@ -93,7 +93,7 @@ typedef struct TypeCacheEnumData ...@@ -93,7 +93,7 @@ typedef struct TypeCacheEnumData
Oid bitmap_base; /* OID corresponding to bit 0 of bitmapset */ Oid bitmap_base; /* OID corresponding to bit 0 of bitmapset */
Bitmapset *sorted_values; /* Set of OIDs known to be in order */ Bitmapset *sorted_values; /* Set of OIDs known to be in order */
int num_values; /* total number of values in enum */ int num_values; /* total number of values in enum */
EnumItem enum_values[1]; /* VARIABLE LENGTH ARRAY */ EnumItem enum_values[FLEXIBLE_ARRAY_MEMBER];
} TypeCacheEnumData; } TypeCacheEnumData;
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment