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 commits
1b105f9472bd,
0c3c5c3b06a3,
31d3847a37be, and
4f7dacc5b82a. 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
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;
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];
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;
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;
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);
}
/*
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;
/*
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++)
* 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)
* 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;