oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
/* Create a user function context for cross-call persistence */
- fctx = (BufferCachePagesContext *) palloc(sizeof(BufferCachePagesContext));
+ fctx = palloc_object(BufferCachePagesContext);
/*
* To smoothly support upgrades from version 1.0 of this extension
os_page_count = (endptr - startptr) / os_page_size;
/* Used to determine the NUMA node for all OS pages at once */
- os_page_ptrs = palloc0(sizeof(void *) * os_page_count);
- os_page_status = palloc(sizeof(int) * os_page_count);
+ os_page_ptrs = palloc0_array(void *, os_page_count);
+ os_page_status = palloc_array(int, os_page_count);
/*
* Fill pointers for all the memory pages. This loop stores and
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
/* Create a user function context for cross-call persistence */
- fctx = (BufferCacheOsPagesContext *) palloc(sizeof(BufferCacheOsPagesContext));
+ fctx = palloc_object(BufferCacheOsPagesContext);
if (get_call_result_type(fcinfo, NULL, &expected_tupledesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type");
int i,
len = len1 + len2;
- result = (pos_trgm *) palloc(sizeof(pos_trgm) * len);
+ result = palloc_array(pos_trgm, len);
for (i = 0; i < len1; i++)
{
lower = (flags & WORD_SIMILARITY_STRICT) ? 0 : -1;
/* Memorise last position of each trigram */
- lastpos = (int *) palloc(sizeof(int) * len);
+ lastpos = palloc_array(int, len);
memset(lastpos, -1, sizeof(int) * len);
for (i = 0; i < len2; i++)
* Merge positional trigrams array: enumerate each trigram and find its
* presence in required word.
*/
- trg2indexes = (int *) palloc(sizeof(int) * len2);
- found = (bool *) palloc0(sizeof(bool) * len);
+ trg2indexes = palloc_array(int, len2);
+ found = palloc0_array(bool, len);
ulen1 = 0;
j = 0;
tptr = GETARR(trg);
/* Allocate a buffer for blank-padded, but not yet case-folded, words */
- buf = palloc(sizeof(char) * (slen + 4));
+ buf = palloc_array(char, slen + 4);
/*
* Extract trigrams from each substring extracted by get_wildcard_part.
int i;
trg = generate_trgm(VARDATA_ANY(in), VARSIZE_ANY_EXHDR(in));
- d = (Datum *) palloc(sizeof(Datum) * (1 + ARRNELEM(trg)));
+ d = palloc_array(Datum, 1 + ARRNELEM(trg));
for (i = 0, ptr = GETARR(trg); i < ARRNELEM(trg); i++, ptr++)
{
lenk = ARRNELEM(key),
i;
- result = (bool *) palloc0(lenq * sizeof(bool));
+ result = palloc0_array(bool, lenq);
/* for each query trigram, do a binary search in the key array */
for (i = 0; i < lenq; i++)
* We use PgFdwRelationInfo to pass various information to subsequent
* functions.
*/
- fpinfo = (PgFdwRelationInfo *) palloc0(sizeof(PgFdwRelationInfo));
+ fpinfo = palloc0_object(PgFdwRelationInfo);
baserel->fdw_private = fpinfo;
/* Base foreign tables need to be pushed down always. */
/*
* We'll save private state in node->fdw_state.
*/
- fsstate = (PgFdwScanState *) palloc0(sizeof(PgFdwScanState));
+ fsstate = palloc0_object(PgFdwScanState);
node->fdw_state = fsstate;
/*
/*
* We'll save private state in node->fdw_state.
*/
- dmstate = (PgFdwDirectModifyState *) palloc0(sizeof(PgFdwDirectModifyState));
+ dmstate = palloc0_object(PgFdwDirectModifyState);
node->fdw_state = dmstate;
/*
ListCell *lc;
/* Begin constructing PgFdwModifyState. */
- fmstate = (PgFdwModifyState *) palloc0(sizeof(PgFdwModifyState));
+ fmstate = palloc0_object(PgFdwModifyState);
fmstate->rel = rel;
/* Identify which user to do the remote access as. */
/* Prepare for output conversion of parameters used in prepared stmt. */
n_params = list_length(fmstate->target_attrs) + 1;
- fmstate->p_flinfo = (FmgrInfo *) palloc0(sizeof(FmgrInfo) * n_params);
+ fmstate->p_flinfo = palloc0_array(FmgrInfo, n_params);
fmstate->p_nums = 0;
if (operation == CMD_UPDATE || operation == CMD_DELETE)
Assert(numParams > 0);
/* Prepare for output conversion of parameters used in remote query. */
- *param_flinfo = (FmgrInfo *) palloc0(sizeof(FmgrInfo) * numParams);
+ *param_flinfo = palloc0_array(FmgrInfo, numParams);
i = 0;
foreach(lc, fdw_exprs)
* if found safe. Once we know that this join can be pushed down, we fill
* the entry.
*/
- fpinfo = (PgFdwRelationInfo *) palloc0(sizeof(PgFdwRelationInfo));
+ fpinfo = palloc0_object(PgFdwRelationInfo);
fpinfo->pushdown_safe = false;
joinrel->fdw_private = fpinfo;
/* attrs_used is only for base relations. */
output_rel->fdw_private)
return;
- fpinfo = (PgFdwRelationInfo *) palloc0(sizeof(PgFdwRelationInfo));
+ fpinfo = palloc0_object(PgFdwRelationInfo);
fpinfo->pushdown_safe = false;
fpinfo->stage = stage;
output_rel->fdw_private = fpinfo;
fpinfo->pushdown_safe = true;
/* Construct PgFdwPathExtraData */
- fpextra = (PgFdwPathExtraData *) palloc0(sizeof(PgFdwPathExtraData));
+ fpextra = palloc0_object(PgFdwPathExtraData);
fpextra->target = root->upper_targets[UPPERREL_ORDERED];
fpextra->has_final_sort = true;
fpinfo->pushdown_safe = true;
/* Construct PgFdwPathExtraData */
- fpextra = (PgFdwPathExtraData *) palloc0(sizeof(PgFdwPathExtraData));
+ fpextra = palloc0_object(PgFdwPathExtraData);
fpextra->target = root->upper_targets[UPPERREL_FINAL];
fpextra->has_final_sort = has_final_sort;
fpextra->has_limit = extra->limit_needed;
* The reason for this is that a common case is for INSERT to insert a
* single tuple into a partitioned table and this must be fast.
*/
- proute = (PartitionTupleRouting *) palloc0(sizeof(PartitionTupleRouting));
+ proute = palloc0_object(PartitionTupleRouting);
proute->partition_root = rel;
proute->memcxt = CurrentMemoryContext;
/* Rest of members initialized by zeroing */
if (proute->max_partitions == 0)
{
proute->max_partitions = 8;
- proute->partitions = (ResultRelInfo **)
- palloc(sizeof(ResultRelInfo *) * proute->max_partitions);
- proute->is_borrowed_rel = (bool *)
- palloc(sizeof(bool) * proute->max_partitions);
+ proute->partitions = palloc_array(ResultRelInfo *, proute->max_partitions);
+ proute->is_borrowed_rel = palloc_array(bool, proute->max_partitions);
}
else
{
if (proute->max_dispatch == 0)
{
proute->max_dispatch = 4;
- proute->partition_dispatch_info = (PartitionDispatch *)
- palloc(sizeof(PartitionDispatch) * proute->max_dispatch);
- proute->nonleaf_partitions = (ResultRelInfo **)
- palloc(sizeof(ResultRelInfo *) * proute->max_dispatch);
+ proute->partition_dispatch_info = palloc_array(PartitionDispatch, proute->max_dispatch);
+ proute->nonleaf_partitions = palloc_array(ResultRelInfo *, proute->max_dispatch);
}
else
{
* arrays are in partition bounds order.
*/
pprune->nparts = partdesc->nparts;
- pprune->subplan_map = palloc(sizeof(int) * partdesc->nparts);
+ pprune->subplan_map = palloc_array(int, partdesc->nparts);
if (partdesc->nparts == pinfo->nparts &&
memcmp(partdesc->oids, pinfo->relid_map,
* attached. Cope with that by creating a map that skips any
* mismatches.
*/
- pprune->subpart_map = palloc(sizeof(int) * partdesc->nparts);
- pprune->leafpart_rti_map = palloc(sizeof(int) * partdesc->nparts);
+ pprune->subpart_map = palloc_array(int, partdesc->nparts);
+ pprune->leafpart_rti_map = palloc_array(int, partdesc->nparts);
for (pp_idx = 0; pp_idx < partdesc->nparts; pp_idx++)
{
context->partsupfunc = partkey->partsupfunc;
/* We'll look up type-specific support functions as needed */
- context->stepcmpfuncs = (FmgrInfo *)
- palloc0(sizeof(FmgrInfo) * n_steps * partnatts);
+ context->stepcmpfuncs = palloc0_array(FmgrInfo, n_steps * partnatts);
context->ppccontext = CurrentMemoryContext;
context->planstate = planstate;
context->exprcontext = econtext;
/* Initialize expression state for each expression we need */
- context->exprstates = (ExprState **)
- palloc0(sizeof(ExprState *) * n_steps * partnatts);
+ context->exprstates = palloc0_array(ExprState *, n_steps * partnatts);
foreach(lc, pruning_steps)
{
PartitionPruneStepOp *step = (PartitionPruneStepOp *) lfirst(lc);
* indexes to new ones. For convenience of initialization, we use
* 1-based indexes in this array and leave pruned items as 0.
*/
- new_subplan_indexes = (int *) palloc0(sizeof(int) * n_total_subplans);
+ new_subplan_indexes = palloc0_array(int, n_total_subplans);
newidx = 1;
i = -1;
while ((i = bms_next_member(initially_valid_subplans, i)) >= 0)
* that zero can represent an un-filled array entry.
*/
allpartrelids = NIL;
- relid_subplan_map = palloc0(sizeof(int) * root->simple_rel_array_size);
+ relid_subplan_map = palloc0_array(int, root->simple_rel_array_size);
i = 1;
foreach(lc, subpaths)
* In this phase we discover whether runtime pruning is needed at all; if
* not, we can avoid doing further work.
*/
- relid_subpart_map = palloc0(sizeof(int) * root->simple_rel_array_size);
+ relid_subpart_map = palloc0_array(int, root->simple_rel_array_size);
i = 1;
rti = -1;
context.boundinfo = rel->boundinfo;
context.partcollation = rel->part_scheme->partcollation;
context.partsupfunc = rel->part_scheme->partsupfunc;
- context.stepcmpfuncs = (FmgrInfo *) palloc0(sizeof(FmgrInfo) *
- context.partnatts *
- list_length(pruning_steps));
+ context.stepcmpfuncs = palloc0_array(FmgrInfo,
+ context.partnatts * list_length(pruning_steps));
context.ppccontext = CurrentMemoryContext;
/* These are not valid when being called from the planner */
return PARTCLAUSE_MATCH_STEPS;
}
- partclause = (PartClauseInfo *) palloc(sizeof(PartClauseInfo));
+ partclause = palloc_object(PartClauseInfo);
partclause->keyno = partkeyidx;
/* Do pruning with the Boolean equality operator. */
partclause->opno = BooleanEqualOperator;
/*
* Build the clause, passing the negator if applicable.
*/
- partclause = (PartClauseInfo *) palloc(sizeof(PartClauseInfo));
+ partclause = palloc_object(PartClauseInfo);
partclause->keyno = partkeyidx;
if (is_opne_listp)
{
StrategyNumber opstrategy, const Datum *values, int nvalues,
FmgrInfo *partsupfunc, Bitmapset *nullkeys)
{
- PruneStepResult *result = (PruneStepResult *) palloc0(sizeof(PruneStepResult));
+ PruneStepResult *result = palloc0_object(PruneStepResult);
PartitionBoundInfo boundinfo = context->boundinfo;
int *partindices = boundinfo->indexes;
int partnatts = context->partnatts;
StrategyNumber opstrategy, Datum value, int nvalues,
FmgrInfo *partsupfunc, Bitmapset *nullkeys)
{
- PruneStepResult *result = (PruneStepResult *) palloc0(sizeof(PruneStepResult));
+ PruneStepResult *result = palloc0_object(PruneStepResult);
PartitionBoundInfo boundinfo = context->boundinfo;
int off,
minoff,
StrategyNumber opstrategy, const Datum *values, int nvalues,
FmgrInfo *partsupfunc, Bitmapset *nullkeys)
{
- PruneStepResult *result = (PruneStepResult *) palloc0(sizeof(PruneStepResult));
+ PruneStepResult *result = palloc0_object(PruneStepResult);
PartitionBoundInfo boundinfo = context->boundinfo;
Oid *partcollation = context->partcollation;
int partnatts = context->partnatts;
{
PruneStepResult *result;
- result = (PruneStepResult *) palloc(sizeof(PruneStepResult));
+ result = palloc_object(PruneStepResult);
result->bound_offsets = NULL;
result->scan_default = false;
result->scan_null = false;
PartitionPruneStepCombine *cstep,
PruneStepResult **step_results)
{
- PruneStepResult *result = (PruneStepResult *) palloc0(sizeof(PruneStepResult));
+ PruneStepResult *result = palloc0_object(PruneStepResult);
bool firststep;
ListCell *lc1;
MVNDistinctItem *item = &result->items[itemcnt];
int j;
- item->attributes = palloc(sizeof(AttrNumber) * k);
+ item->attributes = palloc_array(AttrNumber, k);
item->nattributes = k;
/* translate the indexes to attnums */
* using the specified column combination as dimensions. We could try to
* sort in place, but it'd probably be more complex and bug-prone.
*/
- items = (SortItem *) palloc(numrows * sizeof(SortItem));
- values = (Datum *) palloc0(sizeof(Datum) * numrows * k);
- isnull = (bool *) palloc0(sizeof(bool) * numrows * k);
+ items = palloc_array(SortItem, numrows);
+ values = palloc0_array(Datum, numrows * k);
+ isnull = palloc0_array(bool, numrows * k);
for (i = 0; i < numrows; i++)
{
Assert((n >= k) && (k > 0));
/* allocate the generator state as a single chunk of memory */
- state = (CombinationGenerator *) palloc(sizeof(CombinationGenerator));
+ state = palloc_object(CombinationGenerator);
state->ncombinations = n_choose_k(n, k);
/* pre-allocate space for all combinations */
- state->combinations = (int *) palloc(sizeof(int) * k * state->ncombinations);
+ state->combinations = palloc_array(int, k * state->ncombinations);
state->current = 0;
state->k = k;
static void
generate_combinations(CombinationGenerator *state)
{
- int *current = (int *) palloc0(sizeof(int) * state->k);
+ int *current = palloc0_array(int, state->k);
generate_combinations_recurse(state, 0, 0, current);
if (nlocators == 0)
return;
- rels = palloc(sizeof(SMgrRelation) * nlocators); /* non-local relations */
+ rels = palloc_array(SMgrRelation, nlocators); /* non-local relations */
/* If it's a local relation, it's localbuf.c's problem. */
for (i = 0; i < nlocators; i++)
}
pfree(block);
- locators = palloc(sizeof(RelFileLocator) * n); /* non-local relations */
+ locators = palloc_array(RelFileLocator, n); /* non-local relations */
for (i = 0; i < n; i++)
locators[i] = rels[i]->smgr_rlocator.locator;
return;
/* fill-in array for qsort */
- srels = palloc(sizeof(SMgrSortArray) * nrels);
+ srels = palloc_array(SMgrSortArray, nrels);
for (i = 0; i < nrels; i++)
{