1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-13 14:22:43 +03:00

Use palloc_object() and palloc_array(), the last change

This is the last batch of changes that have been suggested by the
author, this part covering the non-trivial changes.  Some of the changes
suggested have been discarded as they seem to lead to more instructions
generated, leaving the parts that can be qualified as in-place
replacements.

Similar work has been done in 1b105f9472, 0c3c5c3b06 and
31d3847a37.

Author: David Geier <geidav.pg@gmail.com>
Discussion: https://postgr.es/m/ad0748d4-3080-436e-b0bc-ac8f86a3466a@gmail.com
This commit is contained in:
Michael Paquier
2025-12-11 14:29:12 +09:00
parent 3f83de20ba
commit 4f7dacc5b8
7 changed files with 53 additions and 60 deletions

View File

@@ -134,7 +134,7 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
/* Create a user function context for cross-call persistence */ /* 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 * To smoothly support upgrades from version 1.0 of this extension
@@ -382,8 +382,8 @@ pg_buffercache_os_pages_internal(FunctionCallInfo fcinfo, bool include_numa)
os_page_count = (endptr - startptr) / os_page_size; os_page_count = (endptr - startptr) / os_page_size;
/* Used to determine the NUMA node for all OS pages at once */ /* Used to determine the NUMA node for all OS pages at once */
os_page_ptrs = palloc0(sizeof(void *) * os_page_count); os_page_ptrs = palloc0_array(void *, os_page_count);
os_page_status = palloc(sizeof(int) * os_page_count); os_page_status = palloc_array(int, os_page_count);
/* /*
* Fill pointers for all the memory pages. This loop stores and * Fill pointers for all the memory pages. This loop stores and
@@ -425,7 +425,7 @@ pg_buffercache_os_pages_internal(FunctionCallInfo fcinfo, bool include_numa)
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
/* Create a user function context for cross-call persistence */ /* 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) if (get_call_result_type(fcinfo, NULL, &expected_tupledesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type"); elog(ERROR, "return type must be a row type");

View File

@@ -452,7 +452,7 @@ make_positional_trgm(trgm *trg1, int len1, trgm *trg2, int len2)
int i, int i,
len = len1 + len2; len = len1 + len2;
result = (pos_trgm *) palloc(sizeof(pos_trgm) * len); result = palloc_array(pos_trgm, len);
for (i = 0; i < len1; i++) for (i = 0; i < len1; i++)
{ {
@@ -535,7 +535,7 @@ iterate_word_similarity(int *trg2indexes,
lower = (flags & WORD_SIMILARITY_STRICT) ? 0 : -1; lower = (flags & WORD_SIMILARITY_STRICT) ? 0 : -1;
/* Memorise last position of each trigram */ /* Memorise last position of each trigram */
lastpos = (int *) palloc(sizeof(int) * len); lastpos = palloc_array(int, len);
memset(lastpos, -1, sizeof(int) * len); memset(lastpos, -1, sizeof(int) * len);
for (i = 0; i < len2; i++) for (i = 0; i < len2; i++)
@@ -711,8 +711,8 @@ calc_word_similarity(char *str1, int slen1, char *str2, int slen2,
* Merge positional trigrams array: enumerate each trigram and find its * Merge positional trigrams array: enumerate each trigram and find its
* presence in required word. * presence in required word.
*/ */
trg2indexes = (int *) palloc(sizeof(int) * len2); trg2indexes = palloc_array(int, len2);
found = (bool *) palloc0(sizeof(bool) * len); found = palloc0_array(bool, len);
ulen1 = 0; ulen1 = 0;
j = 0; j = 0;
@@ -938,7 +938,7 @@ generate_wildcard_trgm(const char *str, int slen)
tptr = GETARR(trg); tptr = GETARR(trg);
/* Allocate a buffer for blank-padded, but not yet case-folded, words */ /* 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. * Extract trigrams from each substring extracted by get_wildcard_part.
@@ -1008,7 +1008,7 @@ show_trgm(PG_FUNCTION_ARGS)
int i; int i;
trg = generate_trgm(VARDATA_ANY(in), VARSIZE_ANY_EXHDR(in)); 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++) for (i = 0, ptr = GETARR(trg); i < ARRNELEM(trg); i++, ptr++)
{ {
@@ -1136,7 +1136,7 @@ trgm_presence_map(TRGM *query, TRGM *key)
lenk = ARRNELEM(key), lenk = ARRNELEM(key),
i; 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 each query trigram, do a binary search in the key array */
for (i = 0; i < lenq; i++) for (i = 0; i < lenq; i++)

View File

@@ -633,7 +633,7 @@ postgresGetForeignRelSize(PlannerInfo *root,
* We use PgFdwRelationInfo to pass various information to subsequent * We use PgFdwRelationInfo to pass various information to subsequent
* functions. * functions.
*/ */
fpinfo = (PgFdwRelationInfo *) palloc0(sizeof(PgFdwRelationInfo)); fpinfo = palloc0_object(PgFdwRelationInfo);
baserel->fdw_private = fpinfo; baserel->fdw_private = fpinfo;
/* Base foreign tables need to be pushed down always. */ /* Base foreign tables need to be pushed down always. */
@@ -1517,7 +1517,7 @@ postgresBeginForeignScan(ForeignScanState *node, int eflags)
/* /*
* We'll save private state in node->fdw_state. * We'll save private state in node->fdw_state.
*/ */
fsstate = (PgFdwScanState *) palloc0(sizeof(PgFdwScanState)); fsstate = palloc0_object(PgFdwScanState);
node->fdw_state = fsstate; node->fdw_state = fsstate;
/* /*
@@ -2663,7 +2663,7 @@ postgresBeginDirectModify(ForeignScanState *node, int eflags)
/* /*
* We'll save private state in node->fdw_state. * We'll save private state in node->fdw_state.
*/ */
dmstate = (PgFdwDirectModifyState *) palloc0(sizeof(PgFdwDirectModifyState)); dmstate = palloc0_object(PgFdwDirectModifyState);
node->fdw_state = dmstate; node->fdw_state = dmstate;
/* /*
@@ -3977,7 +3977,7 @@ create_foreign_modify(EState *estate,
ListCell *lc; ListCell *lc;
/* Begin constructing PgFdwModifyState. */ /* Begin constructing PgFdwModifyState. */
fmstate = (PgFdwModifyState *) palloc0(sizeof(PgFdwModifyState)); fmstate = palloc0_object(PgFdwModifyState);
fmstate->rel = rel; fmstate->rel = rel;
/* Identify which user to do the remote access as. */ /* Identify which user to do the remote access as. */
@@ -4014,7 +4014,7 @@ create_foreign_modify(EState *estate,
/* Prepare for output conversion of parameters used in prepared stmt. */ /* Prepare for output conversion of parameters used in prepared stmt. */
n_params = list_length(fmstate->target_attrs) + 1; 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; fmstate->p_nums = 0;
if (operation == CMD_UPDATE || operation == CMD_DELETE) if (operation == CMD_UPDATE || operation == CMD_DELETE)
@@ -4814,7 +4814,7 @@ prepare_query_params(PlanState *node,
Assert(numParams > 0); Assert(numParams > 0);
/* Prepare for output conversion of parameters used in remote query. */ /* 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; i = 0;
foreach(lc, fdw_exprs) foreach(lc, fdw_exprs)
@@ -6297,7 +6297,7 @@ postgresGetForeignJoinPaths(PlannerInfo *root,
* if found safe. Once we know that this join can be pushed down, we fill * if found safe. Once we know that this join can be pushed down, we fill
* the entry. * the entry.
*/ */
fpinfo = (PgFdwRelationInfo *) palloc0(sizeof(PgFdwRelationInfo)); fpinfo = palloc0_object(PgFdwRelationInfo);
fpinfo->pushdown_safe = false; fpinfo->pushdown_safe = false;
joinrel->fdw_private = fpinfo; joinrel->fdw_private = fpinfo;
/* attrs_used is only for base relations. */ /* attrs_used is only for base relations. */
@@ -6666,7 +6666,7 @@ postgresGetForeignUpperPaths(PlannerInfo *root, UpperRelationKind stage,
output_rel->fdw_private) output_rel->fdw_private)
return; return;
fpinfo = (PgFdwRelationInfo *) palloc0(sizeof(PgFdwRelationInfo)); fpinfo = palloc0_object(PgFdwRelationInfo);
fpinfo->pushdown_safe = false; fpinfo->pushdown_safe = false;
fpinfo->stage = stage; fpinfo->stage = stage;
output_rel->fdw_private = fpinfo; output_rel->fdw_private = fpinfo;
@@ -6891,7 +6891,7 @@ add_foreign_ordered_paths(PlannerInfo *root, RelOptInfo *input_rel,
fpinfo->pushdown_safe = true; fpinfo->pushdown_safe = true;
/* Construct PgFdwPathExtraData */ /* Construct PgFdwPathExtraData */
fpextra = (PgFdwPathExtraData *) palloc0(sizeof(PgFdwPathExtraData)); fpextra = palloc0_object(PgFdwPathExtraData);
fpextra->target = root->upper_targets[UPPERREL_ORDERED]; fpextra->target = root->upper_targets[UPPERREL_ORDERED];
fpextra->has_final_sort = true; fpextra->has_final_sort = true;
@@ -7125,7 +7125,7 @@ add_foreign_final_paths(PlannerInfo *root, RelOptInfo *input_rel,
fpinfo->pushdown_safe = true; fpinfo->pushdown_safe = true;
/* Construct PgFdwPathExtraData */ /* Construct PgFdwPathExtraData */
fpextra = (PgFdwPathExtraData *) palloc0(sizeof(PgFdwPathExtraData)); fpextra = palloc0_object(PgFdwPathExtraData);
fpextra->target = root->upper_targets[UPPERREL_FINAL]; fpextra->target = root->upper_targets[UPPERREL_FINAL];
fpextra->has_final_sort = has_final_sort; fpextra->has_final_sort = has_final_sort;
fpextra->has_limit = extra->limit_needed; fpextra->has_limit = extra->limit_needed;

View File

@@ -227,7 +227,7 @@ ExecSetupPartitionTupleRouting(EState *estate, Relation rel)
* The reason for this is that a common case is for INSERT to insert a * 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. * 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->partition_root = rel;
proute->memcxt = CurrentMemoryContext; proute->memcxt = CurrentMemoryContext;
/* Rest of members initialized by zeroing */ /* Rest of members initialized by zeroing */
@@ -1198,10 +1198,8 @@ ExecInitRoutingInfo(ModifyTableState *mtstate,
if (proute->max_partitions == 0) if (proute->max_partitions == 0)
{ {
proute->max_partitions = 8; proute->max_partitions = 8;
proute->partitions = (ResultRelInfo **) proute->partitions = palloc_array(ResultRelInfo *, proute->max_partitions);
palloc(sizeof(ResultRelInfo *) * proute->max_partitions); proute->is_borrowed_rel = palloc_array(bool, proute->max_partitions);
proute->is_borrowed_rel = (bool *)
palloc(sizeof(bool) * proute->max_partitions);
} }
else else
{ {
@@ -1316,10 +1314,8 @@ ExecInitPartitionDispatchInfo(EState *estate,
if (proute->max_dispatch == 0) if (proute->max_dispatch == 0)
{ {
proute->max_dispatch = 4; proute->max_dispatch = 4;
proute->partition_dispatch_info = (PartitionDispatch *) proute->partition_dispatch_info = palloc_array(PartitionDispatch, proute->max_dispatch);
palloc(sizeof(PartitionDispatch) * proute->max_dispatch); proute->nonleaf_partitions = palloc_array(ResultRelInfo *, proute->max_dispatch);
proute->nonleaf_partitions = (ResultRelInfo **)
palloc(sizeof(ResultRelInfo *) * proute->max_dispatch);
} }
else else
{ {
@@ -2211,7 +2207,7 @@ CreatePartitionPruneState(EState *estate, PartitionPruneInfo *pruneinfo,
* arrays are in partition bounds order. * arrays are in partition bounds order.
*/ */
pprune->nparts = partdesc->nparts; 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 && if (partdesc->nparts == pinfo->nparts &&
memcmp(partdesc->oids, pinfo->relid_map, memcmp(partdesc->oids, pinfo->relid_map,
@@ -2238,8 +2234,8 @@ CreatePartitionPruneState(EState *estate, PartitionPruneInfo *pruneinfo,
* attached. Cope with that by creating a map that skips any * attached. Cope with that by creating a map that skips any
* mismatches. * mismatches.
*/ */
pprune->subpart_map = palloc(sizeof(int) * partdesc->nparts); pprune->subpart_map = palloc_array(int, partdesc->nparts);
pprune->leafpart_rti_map = palloc(sizeof(int) * partdesc->nparts); pprune->leafpart_rti_map = palloc_array(int, partdesc->nparts);
for (pp_idx = 0; pp_idx < partdesc->nparts; pp_idx++) for (pp_idx = 0; pp_idx < partdesc->nparts; pp_idx++)
{ {
@@ -2390,16 +2386,14 @@ InitPartitionPruneContext(PartitionPruneContext *context,
context->partsupfunc = partkey->partsupfunc; context->partsupfunc = partkey->partsupfunc;
/* We'll look up type-specific support functions as needed */ /* We'll look up type-specific support functions as needed */
context->stepcmpfuncs = (FmgrInfo *) context->stepcmpfuncs = palloc0_array(FmgrInfo, n_steps * partnatts);
palloc0(sizeof(FmgrInfo) * n_steps * partnatts);
context->ppccontext = CurrentMemoryContext; context->ppccontext = CurrentMemoryContext;
context->planstate = planstate; context->planstate = planstate;
context->exprcontext = econtext; context->exprcontext = econtext;
/* Initialize expression state for each expression we need */ /* Initialize expression state for each expression we need */
context->exprstates = (ExprState **) context->exprstates = palloc0_array(ExprState *, n_steps * partnatts);
palloc0(sizeof(ExprState *) * n_steps * partnatts);
foreach(lc, pruning_steps) foreach(lc, pruning_steps)
{ {
PartitionPruneStepOp *step = (PartitionPruneStepOp *) lfirst(lc); PartitionPruneStepOp *step = (PartitionPruneStepOp *) lfirst(lc);
@@ -2500,7 +2494,7 @@ InitExecPartitionPruneContexts(PartitionPruneState *prunestate,
* indexes to new ones. For convenience of initialization, we use * indexes to new ones. For convenience of initialization, we use
* 1-based indexes in this array and leave pruned items as 0. * 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; newidx = 1;
i = -1; i = -1;
while ((i = bms_next_member(initially_valid_subplans, i)) >= 0) while ((i = bms_next_member(initially_valid_subplans, i)) >= 0)

View File

@@ -246,7 +246,7 @@ make_partition_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel,
* that zero can represent an un-filled array entry. * that zero can represent an un-filled array entry.
*/ */
allpartrelids = NIL; 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; i = 1;
foreach(lc, subpaths) foreach(lc, subpaths)
@@ -465,7 +465,7 @@ make_partitionedrel_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel,
* In this phase we discover whether runtime pruning is needed at all; if * In this phase we discover whether runtime pruning is needed at all; if
* not, we can avoid doing further work. * 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; i = 1;
rti = -1; rti = -1;
@@ -818,9 +818,8 @@ prune_append_rel_partitions(RelOptInfo *rel)
context.boundinfo = rel->boundinfo; context.boundinfo = rel->boundinfo;
context.partcollation = rel->part_scheme->partcollation; context.partcollation = rel->part_scheme->partcollation;
context.partsupfunc = rel->part_scheme->partsupfunc; context.partsupfunc = rel->part_scheme->partsupfunc;
context.stepcmpfuncs = (FmgrInfo *) palloc0(sizeof(FmgrInfo) * context.stepcmpfuncs = palloc0_array(FmgrInfo,
context.partnatts * context.partnatts * list_length(pruning_steps));
list_length(pruning_steps));
context.ppccontext = CurrentMemoryContext; context.ppccontext = CurrentMemoryContext;
/* These are not valid when being called from the planner */ /* These are not valid when being called from the planner */
@@ -1890,7 +1889,7 @@ match_clause_to_partition_key(GeneratePruningStepsContext *context,
return PARTCLAUSE_MATCH_STEPS; return PARTCLAUSE_MATCH_STEPS;
} }
partclause = (PartClauseInfo *) palloc(sizeof(PartClauseInfo)); partclause = palloc_object(PartClauseInfo);
partclause->keyno = partkeyidx; partclause->keyno = partkeyidx;
/* Do pruning with the Boolean equality operator. */ /* Do pruning with the Boolean equality operator. */
partclause->opno = BooleanEqualOperator; partclause->opno = BooleanEqualOperator;
@@ -2147,7 +2146,7 @@ match_clause_to_partition_key(GeneratePruningStepsContext *context,
/* /*
* Build the clause, passing the negator if applicable. * Build the clause, passing the negator if applicable.
*/ */
partclause = (PartClauseInfo *) palloc(sizeof(PartClauseInfo)); partclause = palloc_object(PartClauseInfo);
partclause->keyno = partkeyidx; partclause->keyno = partkeyidx;
if (is_opne_listp) if (is_opne_listp)
{ {
@@ -2693,7 +2692,7 @@ get_matching_hash_bounds(PartitionPruneContext *context,
StrategyNumber opstrategy, const Datum *values, int nvalues, StrategyNumber opstrategy, const Datum *values, int nvalues,
FmgrInfo *partsupfunc, Bitmapset *nullkeys) FmgrInfo *partsupfunc, Bitmapset *nullkeys)
{ {
PruneStepResult *result = (PruneStepResult *) palloc0(sizeof(PruneStepResult)); PruneStepResult *result = palloc0_object(PruneStepResult);
PartitionBoundInfo boundinfo = context->boundinfo; PartitionBoundInfo boundinfo = context->boundinfo;
int *partindices = boundinfo->indexes; int *partindices = boundinfo->indexes;
int partnatts = context->partnatts; int partnatts = context->partnatts;
@@ -2770,7 +2769,7 @@ get_matching_list_bounds(PartitionPruneContext *context,
StrategyNumber opstrategy, Datum value, int nvalues, StrategyNumber opstrategy, Datum value, int nvalues,
FmgrInfo *partsupfunc, Bitmapset *nullkeys) FmgrInfo *partsupfunc, Bitmapset *nullkeys)
{ {
PruneStepResult *result = (PruneStepResult *) palloc0(sizeof(PruneStepResult)); PruneStepResult *result = palloc0_object(PruneStepResult);
PartitionBoundInfo boundinfo = context->boundinfo; PartitionBoundInfo boundinfo = context->boundinfo;
int off, int off,
minoff, minoff,
@@ -2981,7 +2980,7 @@ get_matching_range_bounds(PartitionPruneContext *context,
StrategyNumber opstrategy, const Datum *values, int nvalues, StrategyNumber opstrategy, const Datum *values, int nvalues,
FmgrInfo *partsupfunc, Bitmapset *nullkeys) FmgrInfo *partsupfunc, Bitmapset *nullkeys)
{ {
PruneStepResult *result = (PruneStepResult *) palloc0(sizeof(PruneStepResult)); PruneStepResult *result = palloc0_object(PruneStepResult);
PartitionBoundInfo boundinfo = context->boundinfo; PartitionBoundInfo boundinfo = context->boundinfo;
Oid *partcollation = context->partcollation; Oid *partcollation = context->partcollation;
int partnatts = context->partnatts; int partnatts = context->partnatts;
@@ -3504,7 +3503,7 @@ perform_pruning_base_step(PartitionPruneContext *context,
{ {
PruneStepResult *result; PruneStepResult *result;
result = (PruneStepResult *) palloc(sizeof(PruneStepResult)); result = palloc_object(PruneStepResult);
result->bound_offsets = NULL; result->bound_offsets = NULL;
result->scan_default = false; result->scan_default = false;
result->scan_null = false; result->scan_null = false;
@@ -3593,7 +3592,7 @@ perform_pruning_combine_step(PartitionPruneContext *context,
PartitionPruneStepCombine *cstep, PartitionPruneStepCombine *cstep,
PruneStepResult **step_results) PruneStepResult **step_results)
{ {
PruneStepResult *result = (PruneStepResult *) palloc0(sizeof(PruneStepResult)); PruneStepResult *result = palloc0_object(PruneStepResult);
bool firststep; bool firststep;
ListCell *lc1; ListCell *lc1;

View File

@@ -110,7 +110,7 @@ statext_ndistinct_build(double totalrows, StatsBuildData *data)
MVNDistinctItem *item = &result->items[itemcnt]; MVNDistinctItem *item = &result->items[itemcnt];
int j; int j;
item->attributes = palloc(sizeof(AttrNumber) * k); item->attributes = palloc_array(AttrNumber, k);
item->nattributes = k; item->nattributes = k;
/* translate the indexes to attnums */ /* translate the indexes to attnums */
@@ -359,9 +359,9 @@ ndistinct_for_combination(double totalrows, StatsBuildData *data,
* using the specified column combination as dimensions. We could try to * using the specified column combination as dimensions. We could try to
* sort in place, but it'd probably be more complex and bug-prone. * sort in place, but it'd probably be more complex and bug-prone.
*/ */
items = (SortItem *) palloc(numrows * sizeof(SortItem)); items = palloc_array(SortItem, numrows);
values = (Datum *) palloc0(sizeof(Datum) * numrows * k); values = palloc0_array(Datum, numrows * k);
isnull = (bool *) palloc0(sizeof(bool) * numrows * k); isnull = palloc0_array(bool, numrows * k);
for (i = 0; i < numrows; i++) for (i = 0; i < numrows; i++)
{ {
@@ -508,12 +508,12 @@ generator_init(int n, int k)
Assert((n >= k) && (k > 0)); Assert((n >= k) && (k > 0));
/* allocate the generator state as a single chunk of memory */ /* 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); state->ncombinations = n_choose_k(n, k);
/* pre-allocate space for all combinations */ /* 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->current = 0;
state->k = k; state->k = k;
@@ -606,7 +606,7 @@ generate_combinations_recurse(CombinationGenerator *state,
static void static void
generate_combinations(CombinationGenerator *state) 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); generate_combinations_recurse(state, 0, 0, current);

View File

@@ -4676,7 +4676,7 @@ DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
if (nlocators == 0) if (nlocators == 0)
return; 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. */ /* If it's a local relation, it's localbuf.c's problem. */
for (i = 0; i < nlocators; i++) for (i = 0; i < nlocators; i++)
@@ -4758,7 +4758,7 @@ DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
} }
pfree(block); pfree(block);
locators = palloc(sizeof(RelFileLocator) * n); /* non-local relations */ locators = palloc_array(RelFileLocator, n); /* non-local relations */
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
locators[i] = rels[i]->smgr_rlocator.locator; locators[i] = rels[i]->smgr_rlocator.locator;
@@ -5037,7 +5037,7 @@ FlushRelationsAllBuffers(SMgrRelation *smgrs, int nrels)
return; return;
/* fill-in array for qsort */ /* fill-in array for qsort */
srels = palloc(sizeof(SMgrSortArray) * nrels); srels = palloc_array(SMgrSortArray, nrels);
for (i = 0; i < nrels; i++) for (i = 0; i < nrels; i++)
{ {