mirror of
https://github.com/postgres/postgres.git
synced 2026-04-22 06:37:06 -04:00
Use palloc_object() and palloc_array() in more areas of the logical replication.
The idea is to encourage the use of newer routines across the tree, as these offer stronger type-safety guarantees than raw palloc(). Similar work has been done in commits1b105f9472,0c3c5c3b06,31d3847a37, and4f7dacc5b8. This commit extends those changes to more locations within src/backend/replication/logical/. Author: Peter Smith <smithpb2250@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com> Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com> Discussion: https://postgr.es/m/CAHut+Pv4N7Vpxo18+NAR1r9RGvR8b0BtwTkoeCE2PfFoXgmR6A@mail.gmail.com
This commit is contained in:
parent
415100aa62
commit
50ea4e09b6
5 changed files with 18 additions and 17 deletions
|
|
@ -870,7 +870,7 @@ logicalrep_read_tuple(StringInfo in, LogicalRepTupleData *tuple)
|
|||
natts = pq_getmsgint(in, 2);
|
||||
|
||||
/* Allocate space for per-column values; zero out unused StringInfoDatas */
|
||||
tuple->colvalues = (StringInfoData *) palloc0(natts * sizeof(StringInfoData));
|
||||
tuple->colvalues = palloc0_array(StringInfoData, natts);
|
||||
tuple->colstatus = palloc_array(char, natts);
|
||||
tuple->ncols = natts;
|
||||
|
||||
|
|
|
|||
|
|
@ -2492,7 +2492,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
|
|||
int nrelations = 0;
|
||||
Relation *relations;
|
||||
|
||||
relations = palloc0(nrelids * sizeof(Relation));
|
||||
relations = palloc0_array(Relation, nrelids);
|
||||
for (i = 0; i < nrelids; i++)
|
||||
{
|
||||
Oid relid = change->data.truncate.relids[i];
|
||||
|
|
@ -3518,9 +3518,9 @@ ReorderBufferAccumulateInvalidations(SharedInvalidationMessage **invals_out,
|
|||
else
|
||||
{
|
||||
/* Enlarge the array of inval messages */
|
||||
*invals_out = (SharedInvalidationMessage *)
|
||||
repalloc(*invals_out, sizeof(SharedInvalidationMessage) *
|
||||
(*ninvals_out + nmsgs_new));
|
||||
*invals_out =
|
||||
repalloc_array(*invals_out, SharedInvalidationMessage,
|
||||
(*ninvals_out + nmsgs_new));
|
||||
memcpy(*invals_out + *ninvals_out, msgs_new,
|
||||
nmsgs_new * sizeof(SharedInvalidationMessage));
|
||||
*ninvals_out += nmsgs_new;
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ AllocateSnapshotBuilder(ReorderBuffer *reorder,
|
|||
builder->committed.xcnt = 0;
|
||||
builder->committed.xcnt_space = 128; /* arbitrary number */
|
||||
builder->committed.xip =
|
||||
palloc0(builder->committed.xcnt_space * sizeof(TransactionId));
|
||||
palloc0_array(TransactionId, builder->committed.xcnt_space);
|
||||
builder->committed.includes_all_transactions = true;
|
||||
|
||||
builder->catchange.xcnt = 0;
|
||||
|
|
@ -839,8 +839,9 @@ SnapBuildAddCommittedTxn(SnapBuild *builder, TransactionId xid)
|
|||
elog(DEBUG1, "increasing space for committed transactions to %u",
|
||||
(uint32) builder->committed.xcnt_space);
|
||||
|
||||
builder->committed.xip = repalloc(builder->committed.xip,
|
||||
builder->committed.xcnt_space * sizeof(TransactionId));
|
||||
builder->committed.xip = repalloc_array(builder->committed.xip,
|
||||
TransactionId,
|
||||
builder->committed.xcnt_space);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -901,8 +901,8 @@ fetch_remote_table_info(char *nspname, char *relname, LogicalRepRelation *lrel,
|
|||
nspname, relname, res->err)));
|
||||
|
||||
/* We don't know the number of rows coming, so allocate enough space. */
|
||||
lrel->attnames = palloc0(MaxTupleAttributeNumber * sizeof(char *));
|
||||
lrel->atttyps = palloc0(MaxTupleAttributeNumber * sizeof(Oid));
|
||||
lrel->attnames = palloc0_array(char *, MaxTupleAttributeNumber);
|
||||
lrel->atttyps = palloc0_array(Oid, MaxTupleAttributeNumber);
|
||||
lrel->attkeys = NULL;
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -978,8 +978,8 @@ slot_fill_defaults(LogicalRepRelMapEntry *rel, EState *estate,
|
|||
if (num_phys_attrs == rel->remoterel.natts)
|
||||
return;
|
||||
|
||||
defmap = (int *) palloc(num_phys_attrs * sizeof(int));
|
||||
defexprs = (ExprState **) palloc(num_phys_attrs * sizeof(ExprState *));
|
||||
defmap = palloc_array(int, num_phys_attrs);
|
||||
defexprs = palloc_array(ExprState *, num_phys_attrs);
|
||||
|
||||
Assert(rel->attrmap->maplen == num_phys_attrs);
|
||||
for (attnum = 0; attnum < num_phys_attrs; attnum++)
|
||||
|
|
@ -5306,8 +5306,8 @@ subxact_info_read(Oid subid, TransactionId xid)
|
|||
* to the subxact file and reset the logical streaming context.
|
||||
*/
|
||||
oldctx = MemoryContextSwitchTo(LogicalStreamingContext);
|
||||
subxact_data.subxacts = palloc(subxact_data.nsubxacts_max *
|
||||
sizeof(SubXactInfo));
|
||||
subxact_data.subxacts = palloc_array(SubXactInfo,
|
||||
subxact_data.nsubxacts_max);
|
||||
MemoryContextSwitchTo(oldctx);
|
||||
|
||||
if (len > 0)
|
||||
|
|
@ -5373,14 +5373,14 @@ subxact_info_add(TransactionId xid)
|
|||
* subxact_info_read.
|
||||
*/
|
||||
oldctx = MemoryContextSwitchTo(LogicalStreamingContext);
|
||||
subxacts = palloc(subxact_data.nsubxacts_max * sizeof(SubXactInfo));
|
||||
subxacts = palloc_array(SubXactInfo, subxact_data.nsubxacts_max);
|
||||
MemoryContextSwitchTo(oldctx);
|
||||
}
|
||||
else if (subxact_data.nsubxacts == subxact_data.nsubxacts_max)
|
||||
{
|
||||
subxact_data.nsubxacts_max *= 2;
|
||||
subxacts = repalloc(subxacts,
|
||||
subxact_data.nsubxacts_max * sizeof(SubXactInfo));
|
||||
subxacts = repalloc_array(subxacts, SubXactInfo,
|
||||
subxact_data.nsubxacts_max);
|
||||
}
|
||||
|
||||
subxacts[subxact_data.nsubxacts].xid = xid;
|
||||
|
|
|
|||
Loading…
Reference in a new issue