summaryrefslogtreecommitdiff
path: root/src/backend/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils')
-rw-r--r--src/backend/utils/activity/pgstat_relation.c2
-rw-r--r--src/backend/utils/activity/wait_event.c2
-rw-r--r--src/backend/utils/adt/acl.c6
-rw-r--r--src/backend/utils/adt/array_selfuncs.c8
-rw-r--r--src/backend/utils/adt/array_typanalyze.c7
-rw-r--r--src/backend/utils/adt/array_userfuncs.c12
-rw-r--r--src/backend/utils/adt/arrayfuncs.c14
-rw-r--r--src/backend/utils/adt/arraysubs.c2
-rw-r--r--src/backend/utils/adt/date.c24
-rw-r--r--src/backend/utils/adt/datetime.c10
-rw-r--r--src/backend/utils/adt/formatting.c2
-rw-r--r--src/backend/utils/adt/geo_ops.c94
-rw-r--r--src/backend/utils/adt/geo_spgist.c40
-rw-r--r--src/backend/utils/adt/int.c2
-rw-r--r--src/backend/utils/adt/int8.c2
-rw-r--r--src/backend/utils/adt/json.c6
-rw-r--r--src/backend/utils/adt/jsonb_gin.c19
-rw-r--r--src/backend/utils/adt/jsonb_util.c10
-rw-r--r--src/backend/utils/adt/jsonfuncs.c64
-rw-r--r--src/backend/utils/adt/jsonpath_exec.c27
-rw-r--r--src/backend/utils/adt/jsonpath_gram.y4
-rw-r--r--src/backend/utils/adt/lockfuncs.c2
-rw-r--r--src/backend/utils/adt/mac.c14
-rw-r--r--src/backend/utils/adt/mac8.c18
-rw-r--r--src/backend/utils/adt/mcxtfuncs.c2
-rw-r--r--src/backend/utils/adt/misc.c2
-rw-r--r--src/backend/utils/adt/multirangetypes.c8
-rw-r--r--src/backend/utils/adt/multirangetypes_selfuncs.c4
-rw-r--r--src/backend/utils/adt/multixactfuncs.c2
-rw-r--r--src/backend/utils/adt/network.c24
-rw-r--r--src/backend/utils/adt/network_gist.c10
-rw-r--r--src/backend/utils/adt/network_spgist.c6
-rw-r--r--src/backend/utils/adt/numeric.c13
-rw-r--r--src/backend/utils/adt/orderedsetaggs.c4
-rw-r--r--src/backend/utils/adt/pg_locale_libc.c6
-rw-r--r--src/backend/utils/adt/pg_ndistinct.c2
-rw-r--r--src/backend/utils/adt/rangetypes.c2
-rw-r--r--src/backend/utils/adt/rangetypes_gist.c15
-rw-r--r--src/backend/utils/adt/rangetypes_selfuncs.c4
-rw-r--r--src/backend/utils/adt/rangetypes_spgist.c18
-rw-r--r--src/backend/utils/adt/rangetypes_typanalyze.c8
-rw-r--r--src/backend/utils/adt/regexp.c20
-rw-r--r--src/backend/utils/adt/rowtypes.c24
-rw-r--r--src/backend/utils/adt/ruleutils.c4
-rw-r--r--src/backend/utils/adt/selfuncs.c4
-rw-r--r--src/backend/utils/adt/skipsupport.c2
-rw-r--r--src/backend/utils/adt/tid.c6
-rw-r--r--src/backend/utils/adt/timestamp.c46
-rw-r--r--src/backend/utils/adt/tsginidx.c10
-rw-r--r--src/backend/utils/adt/tsgistidx.c10
-rw-r--r--src/backend/utils/adt/tsquery.c12
-rw-r--r--src/backend/utils/adt/tsquery_cleanup.c2
-rw-r--r--src/backend/utils/adt/tsquery_gist.c4
-rw-r--r--src/backend/utils/adt/tsquery_op.c14
-rw-r--r--src/backend/utils/adt/tsquery_util.c18
-rw-r--r--src/backend/utils/adt/tsrank.c13
-rw-r--r--src/backend/utils/adt/tsvector.c4
-rw-r--r--src/backend/utils/adt/tsvector_op.c10
-rw-r--r--src/backend/utils/adt/tsvector_parser.c6
-rw-r--r--src/backend/utils/adt/uuid.c4
-rw-r--r--src/backend/utils/adt/varlena.c2
-rw-r--r--src/backend/utils/adt/xml.c6
-rw-r--r--src/backend/utils/cache/catcache.c4
-rw-r--r--src/backend/utils/cache/evtcache.c2
-rw-r--r--src/backend/utils/cache/inval.c2
-rw-r--r--src/backend/utils/cache/lsyscache.c6
-rw-r--r--src/backend/utils/cache/partcache.c24
-rw-r--r--src/backend/utils/cache/plancache.c15
-rw-r--r--src/backend/utils/cache/relcache.c30
-rw-r--r--src/backend/utils/cache/typcache.c2
-rw-r--r--src/backend/utils/error/elog.c2
-rw-r--r--src/backend/utils/fmgr/funcapi.c2
-rw-r--r--src/backend/utils/init/postinit.c2
-rw-r--r--src/backend/utils/mb/mbutils.c4
-rw-r--r--src/backend/utils/misc/conffiles.c2
-rw-r--r--src/backend/utils/misc/guc-file.l4
-rw-r--r--src/backend/utils/misc/guc.c4
-rw-r--r--src/backend/utils/misc/injection_point.c2
-rw-r--r--src/backend/utils/misc/queryenvironment.c2
-rw-r--r--src/backend/utils/misc/tzparser.c2
-rw-r--r--src/backend/utils/mmgr/dsa.c4
-rw-r--r--src/backend/utils/sort/logtape.c6
-rw-r--r--src/backend/utils/sort/sharedtuplestore.c4
-rw-r--r--src/backend/utils/sort/tuplesort.c2
-rw-r--r--src/backend/utils/sort/tuplesortvariants.c12
-rw-r--r--src/backend/utils/sort/tuplestore.c2
-rw-r--r--src/backend/utils/time/snapmgr.c2
87 files changed, 438 insertions, 447 deletions
diff --git a/src/backend/utils/activity/pgstat_relation.c b/src/backend/utils/activity/pgstat_relation.c
index 1de477cbeeb..b90754f8578 100644
--- a/src/backend/utils/activity/pgstat_relation.c
+++ b/src/backend/utils/activity/pgstat_relation.c
@@ -514,7 +514,7 @@ find_tabstat_entry(Oid rel_id)
}
tabentry = (PgStat_TableStatus *) entry_ref->pending;
- tablestatus = palloc(sizeof(PgStat_TableStatus));
+ tablestatus = palloc_object(PgStat_TableStatus);
*tablestatus = *tabentry;
/*
diff --git a/src/backend/utils/activity/wait_event.c b/src/backend/utils/activity/wait_event.c
index 96d61f77f6e..a8c287c289e 100644
--- a/src/backend/utils/activity/wait_event.c
+++ b/src/backend/utils/activity/wait_event.c
@@ -317,7 +317,7 @@ GetWaitEventCustomNames(uint32 classId, int *nwaitevents)
els = hash_get_num_entries(WaitEventCustomHashByName);
/* Allocate enough space for all entries */
- waiteventnames = palloc(els * sizeof(char *));
+ waiteventnames = palloc_array(char *, els);
/* Now scan the hash table to copy the data */
hash_seq_init(&hash_seq, WaitEventCustomHashByName);
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c
index fbcd64a2609..05d48412f82 100644
--- a/src/backend/utils/adt/acl.c
+++ b/src/backend/utils/adt/acl.c
@@ -618,7 +618,7 @@ aclitemin(PG_FUNCTION_ARGS)
Node *escontext = fcinfo->context;
AclItem *aip;
- aip = (AclItem *) palloc(sizeof(AclItem));
+ aip = palloc_object(AclItem);
s = aclparse(s, aip, escontext);
if (s == NULL)
@@ -1661,7 +1661,7 @@ makeaclitem(PG_FUNCTION_ARGS)
priv = convert_any_priv_string(privtext, any_priv_map);
- result = (AclItem *) palloc(sizeof(AclItem));
+ result = palloc_object(AclItem);
result->ai_grantee = grantee;
result->ai_grantor = grantor;
@@ -1821,7 +1821,7 @@ aclexplode(PG_FUNCTION_ARGS)
funcctx->tuple_desc = BlessTupleDesc(tupdesc);
/* allocate memory for user context */
- idx = (int *) palloc(sizeof(int[2]));
+ idx = palloc_array(int, 2);
idx[0] = 0; /* ACL array item index */
idx[1] = -1; /* privilege type counter */
funcctx->user_fctx = idx;
diff --git a/src/backend/utils/adt/array_selfuncs.c b/src/backend/utils/adt/array_selfuncs.c
index 4dab35b0057..cd201461c17 100644
--- a/src/backend/utils/adt/array_selfuncs.c
+++ b/src/backend/utils/adt/array_selfuncs.c
@@ -759,7 +759,7 @@ mcelem_array_contained_selec(const Datum *mcelem, int nmcelem,
* elem_selec is array of estimated frequencies for elements in the
* constant.
*/
- elem_selec = (float *) palloc(sizeof(float) * nitems);
+ elem_selec = palloc_array(float, nitems);
/* Scan mcelem and array in parallel. */
mcelem_index = 0;
@@ -936,7 +936,7 @@ calc_hist(const float4 *hist, int nhist, int n)
next_interval;
float frac;
- hist_part = (float *) palloc((n + 1) * sizeof(float));
+ hist_part = palloc_array(float, n + 1);
/*
* frac is a probability contribution for each interval between histogram
@@ -1028,8 +1028,8 @@ calc_distr(const float *p, int n, int m, float rest)
* Since we return only the last row of the matrix and need only the
* current and previous row for calculations, allocate two rows.
*/
- row = (float *) palloc((m + 1) * sizeof(float));
- prev_row = (float *) palloc((m + 1) * sizeof(float));
+ row = palloc_array(float, m + 1);
+ prev_row = palloc_array(float, m + 1);
/* M[0,0] = 1 */
row[0] = 1.0f;
diff --git a/src/backend/utils/adt/array_typanalyze.c b/src/backend/utils/adt/array_typanalyze.c
index 560b27f3ca7..61aedd31ff1 100644
--- a/src/backend/utils/adt/array_typanalyze.c
+++ b/src/backend/utils/adt/array_typanalyze.c
@@ -132,7 +132,7 @@ array_typanalyze(PG_FUNCTION_ARGS)
PG_RETURN_BOOL(true);
/* Store our findings for use by compute_array_stats() */
- extra_data = (ArrayAnalyzeExtraData *) palloc(sizeof(ArrayAnalyzeExtraData));
+ extra_data = palloc_object(ArrayAnalyzeExtraData);
extra_data->type_id = typentry->type_id;
extra_data->eq_opr = typentry->eq_opr;
extra_data->coll_id = stats->attrcollid; /* collation we should use */
@@ -469,7 +469,7 @@ compute_array_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
cutoff_freq = 9 * element_no / bucket_width;
i = hash_get_num_entries(elements_tab); /* surely enough space */
- sort_table = (TrackItem **) palloc(sizeof(TrackItem *) * i);
+ sort_table = palloc_array(TrackItem *, i);
hash_seq_init(&scan_status, elements_tab);
track_len = 0;
@@ -606,8 +606,7 @@ compute_array_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
* Create an array of DECountItem pointers, and sort them into
* increasing count order.
*/
- sorted_count_items = (DECountItem **)
- palloc(sizeof(DECountItem *) * count_items_count);
+ sorted_count_items = palloc_array(DECountItem *, count_items_count);
hash_seq_init(&scan_status, count_tab);
j = 0;
while ((count_item = (DECountItem *) hash_seq_search(&scan_status)) != NULL)
diff --git a/src/backend/utils/adt/array_userfuncs.c b/src/backend/utils/adt/array_userfuncs.c
index 8eb342e3382..c01bf466121 100644
--- a/src/backend/utils/adt/array_userfuncs.c
+++ b/src/backend/utils/adt/array_userfuncs.c
@@ -433,8 +433,8 @@ array_cat(PG_FUNCTION_ARGS)
* themselves) of the input argument arrays
*/
ndims = ndims1;
- dims = (int *) palloc(ndims * sizeof(int));
- lbs = (int *) palloc(ndims * sizeof(int));
+ dims = palloc_array(int, ndims);
+ lbs = palloc_array(int, ndims);
dims[0] = dims1[0] + dims2[0];
lbs[0] = lbs1[0];
@@ -459,8 +459,8 @@ array_cat(PG_FUNCTION_ARGS)
* the first argument inserted at the front of the outer dimension
*/
ndims = ndims2;
- dims = (int *) palloc(ndims * sizeof(int));
- lbs = (int *) palloc(ndims * sizeof(int));
+ dims = palloc_array(int, ndims);
+ lbs = palloc_array(int, ndims);
memcpy(dims, dims2, ndims * sizeof(int));
memcpy(lbs, lbs2, ndims * sizeof(int));
@@ -487,8 +487,8 @@ array_cat(PG_FUNCTION_ARGS)
* second argument appended to the end of the outer dimension
*/
ndims = ndims1;
- dims = (int *) palloc(ndims * sizeof(int));
- lbs = (int *) palloc(ndims * sizeof(int));
+ dims = palloc_array(int, ndims);
+ lbs = palloc_array(int, ndims);
memcpy(dims, dims1, ndims * sizeof(int));
memcpy(lbs, lbs1, ndims * sizeof(int));
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c
index 24e5b2adea1..b67ce57656a 100644
--- a/src/backend/utils/adt/arrayfuncs.c
+++ b/src/backend/utils/adt/arrayfuncs.c
@@ -3582,7 +3582,7 @@ construct_empty_array(Oid elmtype)
{
ArrayType *result;
- result = (ArrayType *) palloc0(sizeof(ArrayType));
+ result = palloc0_object(ArrayType);
SET_VARSIZE(result, sizeof(ArrayType));
result->ndim = 0;
result->dataoffset = 0;
@@ -3645,9 +3645,9 @@ deconstruct_array(const ArrayType *array,
Assert(ARR_ELEMTYPE(array) == elmtype);
nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
- *elemsp = elems = (Datum *) palloc(nelems * sizeof(Datum));
+ *elemsp = elems = palloc_array(Datum, nelems);
if (nullsp)
- *nullsp = nulls = (bool *) palloc0(nelems * sizeof(bool));
+ *nullsp = nulls = palloc0_array(bool, nelems);
else
nulls = NULL;
*nelemsp = nelems;
@@ -4209,7 +4209,7 @@ hash_array(PG_FUNCTION_ARGS)
* modify typentry, since that points directly into the type
* cache.
*/
- record_typentry = palloc0(sizeof(*record_typentry));
+ record_typentry = palloc0_object(TypeCacheEntry);
record_typentry->type_id = element_type;
/* fill in what we need below */
@@ -4597,7 +4597,7 @@ arraycontained(PG_FUNCTION_ARGS)
ArrayIterator
array_create_iterator(ArrayType *arr, int slice_ndim, ArrayMetaState *mstate)
{
- ArrayIterator iterator = palloc0(sizeof(ArrayIteratorData));
+ ArrayIterator iterator = palloc0_object(ArrayIteratorData);
/*
* Sanity-check inputs --- caller should have got this right already
@@ -5944,7 +5944,7 @@ generate_subscripts(PG_FUNCTION_ARGS)
* switch to memory context appropriate for multiple function calls
*/
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
- fctx = (generate_subscripts_fctx *) palloc(sizeof(generate_subscripts_fctx));
+ fctx = palloc_object(generate_subscripts_fctx);
lb = AARR_LBOUND(v);
dimv = AARR_DIMS(v);
@@ -6291,7 +6291,7 @@ array_unnest(PG_FUNCTION_ARGS)
arr = PG_GETARG_ANY_ARRAY_P(0);
/* allocate memory for user context */
- fctx = (array_unnest_fctx *) palloc(sizeof(array_unnest_fctx));
+ fctx = palloc_object(array_unnest_fctx);
/* initialize state */
array_iter_setup(&fctx->iter, arr);
diff --git a/src/backend/utils/adt/arraysubs.c b/src/backend/utils/adt/arraysubs.c
index b476fa586a9..f280212fd8f 100644
--- a/src/backend/utils/adt/arraysubs.c
+++ b/src/backend/utils/adt/arraysubs.c
@@ -497,7 +497,7 @@ array_exec_setup(const SubscriptingRef *sbsref,
/*
* Allocate type-specific workspace.
*/
- workspace = (ArraySubWorkspace *) palloc(sizeof(ArraySubWorkspace));
+ workspace = palloc_object(ArraySubWorkspace);
sbsrefstate->workspace = workspace;
/*
diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c
index c4b8125dd66..421ccc306f6 100644
--- a/src/backend/utils/adt/date.c
+++ b/src/backend/utils/adt/date.c
@@ -358,7 +358,7 @@ GetSQLCurrentTime(int32 typmod)
GetCurrentTimeUsec(tm, &fsec, &tz);
- result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
+ result = palloc_object(TimeTzADT);
tm2timetz(tm, fsec, tz, result);
AdjustTimeForTypmod(&(result->time), typmod);
return result;
@@ -2087,7 +2087,7 @@ time_interval(PG_FUNCTION_ARGS)
TimeADT time = PG_GETARG_TIMEADT(0);
Interval *result;
- result = (Interval *) palloc(sizeof(Interval));
+ result = palloc_object(Interval);
result->time = time;
result->day = 0;
@@ -2132,7 +2132,7 @@ time_mi_time(PG_FUNCTION_ARGS)
TimeADT time2 = PG_GETARG_TIMEADT(1);
Interval *result;
- result = (Interval *) palloc(sizeof(Interval));
+ result = palloc_object(Interval);
result->month = 0;
result->day = 0;
@@ -2399,7 +2399,7 @@ timetz_in(PG_FUNCTION_ARGS)
PG_RETURN_NULL();
}
- result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
+ result = palloc_object(TimeTzADT);
tm2timetz(tm, fsec, tz, result);
AdjustTimeForTypmod(&(result->time), typmod);
@@ -2438,7 +2438,7 @@ timetz_recv(PG_FUNCTION_ARGS)
int32 typmod = PG_GETARG_INT32(2);
TimeTzADT *result;
- result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
+ result = palloc_object(TimeTzADT);
result->time = pq_getmsgint64(buf);
@@ -2524,7 +2524,7 @@ timetz_scale(PG_FUNCTION_ARGS)
int32 typmod = PG_GETARG_INT32(1);
TimeTzADT *result;
- result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
+ result = palloc_object(TimeTzADT);
result->time = time->time;
result->zone = time->zone;
@@ -2700,7 +2700,7 @@ timetz_pl_interval(PG_FUNCTION_ARGS)
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("cannot add infinite interval to time")));
- result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
+ result = palloc_object(TimeTzADT);
result->time = time->time + span->time;
result->time -= result->time / USECS_PER_DAY * USECS_PER_DAY;
@@ -2727,7 +2727,7 @@ timetz_mi_interval(PG_FUNCTION_ARGS)
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("cannot subtract infinite interval from time")));
- result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
+ result = palloc_object(TimeTzADT);
result->time = time->time - span->time;
result->time -= result->time / USECS_PER_DAY * USECS_PER_DAY;
@@ -2934,7 +2934,7 @@ time_timetz(PG_FUNCTION_ARGS)
time2tm(time, tm, &fsec);
tz = DetermineTimeZoneOffset(tm, session_timezone);
- result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
+ result = palloc_object(TimeTzADT);
result->time = time;
result->zone = tz;
@@ -2964,7 +2964,7 @@ timestamptz_timetz(PG_FUNCTION_ARGS)
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
- result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
+ result = palloc_object(TimeTzADT);
tm2timetz(tm, fsec, tz, result);
@@ -3197,7 +3197,7 @@ timetz_zone(PG_FUNCTION_ARGS)
errmsg("timestamp out of range")));
}
- result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
+ result = palloc_object(TimeTzADT);
result->time = t->time + (t->zone - tz) * USECS_PER_SEC;
/* C99 modulo has the wrong sign convention for negative input */
@@ -3238,7 +3238,7 @@ timetz_izone(PG_FUNCTION_ARGS)
tz = -(zone->time / USECS_PER_SEC);
- result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
+ result = palloc_object(TimeTzADT);
result->time = time->time + (time->zone - tz) * USECS_PER_SEC;
/* C99 modulo has the wrong sign convention for negative input */
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 680fee2a844..e3a099eaa67 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -5152,7 +5152,7 @@ pg_timezone_abbrevs_zone(PG_FUNCTION_ARGS)
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
/* allocate memory for user context */
- pindex = (int *) palloc(sizeof(int));
+ pindex = palloc_object(int);
*pindex = 0;
funcctx->user_fctx = pindex;
@@ -5187,7 +5187,7 @@ pg_timezone_abbrevs_zone(PG_FUNCTION_ARGS)
/* Convert offset (in seconds) to an interval; can't overflow */
MemSet(&itm_in, 0, sizeof(struct pg_itm_in));
itm_in.tm_usec = (int64) gmtoff * USECS_PER_SEC;
- resInterval = (Interval *) palloc(sizeof(Interval));
+ resInterval = palloc_object(Interval);
(void) itmin2interval(&itm_in, resInterval);
values[1] = IntervalPGetDatum(resInterval);
@@ -5239,7 +5239,7 @@ pg_timezone_abbrevs_abbrevs(PG_FUNCTION_ARGS)
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
/* allocate memory for user context */
- pindex = (int *) palloc(sizeof(int));
+ pindex = palloc_object(int);
*pindex = 0;
funcctx->user_fctx = pindex;
@@ -5310,7 +5310,7 @@ pg_timezone_abbrevs_abbrevs(PG_FUNCTION_ARGS)
/* Convert offset (in seconds) to an interval; can't overflow */
MemSet(&itm_in, 0, sizeof(struct pg_itm_in));
itm_in.tm_usec = (int64) gmtoffset * USECS_PER_SEC;
- resInterval = (Interval *) palloc(sizeof(Interval));
+ resInterval = palloc_object(Interval);
(void) itmin2interval(&itm_in, resInterval);
values[1] = IntervalPGetDatum(resInterval);
@@ -5378,7 +5378,7 @@ pg_timezone_names(PG_FUNCTION_ARGS)
/* Convert tzoff to an interval; can't overflow */
MemSet(&itm_in, 0, sizeof(struct pg_itm_in));
itm_in.tm_usec = (int64) -tzoff * USECS_PER_SEC;
- resInterval = (Interval *) palloc(sizeof(Interval));
+ resInterval = palloc_object(Interval);
(void) itmin2interval(&itm_in, resInterval);
values[2] = IntervalPGetDatum(resInterval);
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index c3cb022a400..a4570471bba 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -4264,7 +4264,7 @@ parse_datetime(text *date_txt, text *fmt, Oid collid, bool strict,
{
if (flags & DCH_ZONED)
{
- TimeTzADT *result = palloc(sizeof(TimeTzADT));
+ TimeTzADT *result = palloc_object(TimeTzADT);
if (ftz.has_tz)
{
diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c
index 9101a720744..43b7eb43a79 100644
--- a/src/backend/utils/adt/geo_ops.c
+++ b/src/backend/utils/adt/geo_ops.c
@@ -423,7 +423,7 @@ box_in(PG_FUNCTION_ARGS)
{
char *str = PG_GETARG_CSTRING(0);
Node *escontext = fcinfo->context;
- BOX *box = (BOX *) palloc(sizeof(BOX));
+ BOX *box = palloc_object(BOX);
bool isopen;
float8 x,
y;
@@ -470,7 +470,7 @@ box_recv(PG_FUNCTION_ARGS)
float8 x,
y;
- box = (BOX *) palloc(sizeof(BOX));
+ box = palloc_object(BOX);
box->high.x = pq_getmsgfloat8(buf);
box->high.y = pq_getmsgfloat8(buf);
@@ -849,7 +849,7 @@ Datum
box_center(PG_FUNCTION_ARGS)
{
BOX *box = PG_GETARG_BOX_P(0);
- Point *result = (Point *) palloc(sizeof(Point));
+ Point *result = palloc_object(Point);
box_cn(result, box);
@@ -914,7 +914,7 @@ box_intersect(PG_FUNCTION_ARGS)
if (!box_ov(box1, box2))
PG_RETURN_NULL();
- result = (BOX *) palloc(sizeof(BOX));
+ result = palloc_object(BOX);
result->high.x = float8_min(box1->high.x, box2->high.x);
result->low.x = float8_max(box1->low.x, box2->low.x);
@@ -933,7 +933,7 @@ Datum
box_diagonal(PG_FUNCTION_ARGS)
{
BOX *box = PG_GETARG_BOX_P(0);
- LSEG *result = (LSEG *) palloc(sizeof(LSEG));
+ LSEG *result = palloc_object(LSEG);
statlseg_construct(result, &box->high, &box->low);
@@ -980,7 +980,7 @@ line_in(PG_FUNCTION_ARGS)
{
char *str = PG_GETARG_CSTRING(0);
Node *escontext = fcinfo->context;
- LINE *line = (LINE *) palloc(sizeof(LINE));
+ LINE *line = palloc_object(LINE);
LSEG lseg;
bool isopen;
char *s;
@@ -1040,7 +1040,7 @@ line_recv(PG_FUNCTION_ARGS)
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
LINE *line;
- line = (LINE *) palloc(sizeof(LINE));
+ line = palloc_object(LINE);
line->A = pq_getmsgfloat8(buf);
line->B = pq_getmsgfloat8(buf);
@@ -1116,7 +1116,7 @@ line_construct_pp(PG_FUNCTION_ARGS)
{
Point *pt1 = PG_GETARG_POINT_P(0);
Point *pt2 = PG_GETARG_POINT_P(1);
- LINE *result = (LINE *) palloc(sizeof(LINE));
+ LINE *result = palloc_object(LINE);
if (point_eq_point(pt1, pt2))
ereport(ERROR,
@@ -1289,7 +1289,7 @@ line_interpt(PG_FUNCTION_ARGS)
LINE *l2 = PG_GETARG_LINE_P(1);
Point *result;
- result = (Point *) palloc(sizeof(Point));
+ result = palloc_object(Point);
if (!line_interpt_line(result, l1, l2))
PG_RETURN_NULL();
@@ -1831,7 +1831,7 @@ Datum
point_in(PG_FUNCTION_ARGS)
{
char *str = PG_GETARG_CSTRING(0);
- Point *point = (Point *) palloc(sizeof(Point));
+ Point *point = palloc_object(Point);
/* Ignore failure from pair_decode, since our return value won't matter */
pair_decode(str, &point->x, &point->y, NULL, "point", str, fcinfo->context);
@@ -1855,7 +1855,7 @@ point_recv(PG_FUNCTION_ARGS)
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
Point *point;
- point = (Point *) palloc(sizeof(Point));
+ point = palloc_object(Point);
point->x = pq_getmsgfloat8(buf);
point->y = pq_getmsgfloat8(buf);
PG_RETURN_POINT_P(point);
@@ -2066,7 +2066,7 @@ lseg_in(PG_FUNCTION_ARGS)
{
char *str = PG_GETARG_CSTRING(0);
Node *escontext = fcinfo->context;
- LSEG *lseg = (LSEG *) palloc(sizeof(LSEG));
+ LSEG *lseg = palloc_object(LSEG);
bool isopen;
if (!path_decode(str, true, 2, &lseg->p[0], &isopen, NULL, "lseg", str,
@@ -2094,7 +2094,7 @@ lseg_recv(PG_FUNCTION_ARGS)
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
LSEG *lseg;
- lseg = (LSEG *) palloc(sizeof(LSEG));
+ lseg = palloc_object(LSEG);
lseg->p[0].x = pq_getmsgfloat8(buf);
lseg->p[0].y = pq_getmsgfloat8(buf);
@@ -2130,7 +2130,7 @@ lseg_construct(PG_FUNCTION_ARGS)
{
Point *pt1 = PG_GETARG_POINT_P(0);
Point *pt2 = PG_GETARG_POINT_P(1);
- LSEG *result = (LSEG *) palloc(sizeof(LSEG));
+ LSEG *result = palloc_object(LSEG);
statlseg_construct(result, pt1, pt2);
@@ -2318,7 +2318,7 @@ lseg_center(PG_FUNCTION_ARGS)
LSEG *lseg = PG_GETARG_LSEG_P(0);
Point *result;
- result = (Point *) palloc(sizeof(Point));
+ result = palloc_object(Point);
result->x = float8_div(float8_pl(lseg->p[0].x, lseg->p[1].x), 2.0);
result->y = float8_div(float8_pl(lseg->p[0].y, lseg->p[1].y), 2.0);
@@ -2364,7 +2364,7 @@ lseg_interpt(PG_FUNCTION_ARGS)
LSEG *l2 = PG_GETARG_LSEG_P(1);
Point *result;
- result = (Point *) palloc(sizeof(Point));
+ result = palloc_object(Point);
if (!lseg_interpt_lseg(result, l1, l2))
PG_RETURN_NULL();
@@ -2753,7 +2753,7 @@ close_pl(PG_FUNCTION_ARGS)
LINE *line = PG_GETARG_LINE_P(1);
Point *result;
- result = (Point *) palloc(sizeof(Point));
+ result = palloc_object(Point);
if (isnan(line_closept_point(result, line, pt)))
PG_RETURN_NULL();
@@ -2794,7 +2794,7 @@ close_ps(PG_FUNCTION_ARGS)
LSEG *lseg = PG_GETARG_LSEG_P(1);
Point *result;
- result = (Point *) palloc(sizeof(Point));
+ result = palloc_object(Point);
if (isnan(lseg_closept_point(result, lseg, pt)))
PG_RETURN_NULL();
@@ -2859,7 +2859,7 @@ close_lseg(PG_FUNCTION_ARGS)
if (lseg_sl(l1) == lseg_sl(l2))
PG_RETURN_NULL();
- result = (Point *) palloc(sizeof(Point));
+ result = palloc_object(Point);
if (isnan(lseg_closept_lseg(result, l2, l1)))
PG_RETURN_NULL();
@@ -2936,7 +2936,7 @@ close_pb(PG_FUNCTION_ARGS)
BOX *box = PG_GETARG_BOX_P(1);
Point *result;
- result = (Point *) palloc(sizeof(Point));
+ result = palloc_object(Point);
if (isnan(box_closept_point(result, box, pt)))
PG_RETURN_NULL();
@@ -2994,7 +2994,7 @@ close_ls(PG_FUNCTION_ARGS)
if (lseg_sl(lseg) == line_sl(line))
PG_RETURN_NULL();
- result = (Point *) palloc(sizeof(Point));
+ result = palloc_object(Point);
if (isnan(lseg_closept_line(result, lseg, line)))
PG_RETURN_NULL();
@@ -3066,7 +3066,7 @@ close_sb(PG_FUNCTION_ARGS)
BOX *box = PG_GETARG_BOX_P(1);
Point *result;
- result = (Point *) palloc(sizeof(Point));
+ result = palloc_object(Point);
if (isnan(box_closept_lseg(result, box, lseg)))
PG_RETURN_NULL();
@@ -4099,7 +4099,7 @@ construct_point(PG_FUNCTION_ARGS)
float8 y = PG_GETARG_FLOAT8(1);
Point *result;
- result = (Point *) palloc(sizeof(Point));
+ result = palloc_object(Point);
point_construct(result, x, y);
@@ -4122,7 +4122,7 @@ point_add(PG_FUNCTION_ARGS)
Point *p2 = PG_GETARG_POINT_P(1);
Point *result;
- result = (Point *) palloc(sizeof(Point));
+ result = palloc_object(Point);
point_add_point(result, p1, p2);
@@ -4145,7 +4145,7 @@ point_sub(PG_FUNCTION_ARGS)
Point *p2 = PG_GETARG_POINT_P(1);
Point *result;
- result = (Point *) palloc(sizeof(Point));
+ result = palloc_object(Point);
point_sub_point(result, p1, p2);
@@ -4170,7 +4170,7 @@ point_mul(PG_FUNCTION_ARGS)
Point *p2 = PG_GETARG_POINT_P(1);
Point *result;
- result = (Point *) palloc(sizeof(Point));
+ result = palloc_object(Point);
point_mul_point(result, p1, p2);
@@ -4199,7 +4199,7 @@ point_div(PG_FUNCTION_ARGS)
Point *p2 = PG_GETARG_POINT_P(1);
Point *result;
- result = (Point *) palloc(sizeof(Point));
+ result = palloc_object(Point);
point_div_point(result, p1, p2);
@@ -4220,7 +4220,7 @@ points_box(PG_FUNCTION_ARGS)
Point *p2 = PG_GETARG_POINT_P(1);
BOX *result;
- result = (BOX *) palloc(sizeof(BOX));
+ result = palloc_object(BOX);
box_construct(result, p1, p2);
@@ -4234,7 +4234,7 @@ box_add(PG_FUNCTION_ARGS)
Point *p = PG_GETARG_POINT_P(1);
BOX *result;
- result = (BOX *) palloc(sizeof(BOX));
+ result = palloc_object(BOX);
point_add_point(&result->high, &box->high, p);
point_add_point(&result->low, &box->low, p);
@@ -4249,7 +4249,7 @@ box_sub(PG_FUNCTION_ARGS)
Point *p = PG_GETARG_POINT_P(1);
BOX *result;
- result = (BOX *) palloc(sizeof(BOX));
+ result = palloc_object(BOX);
point_sub_point(&result->high, &box->high, p);
point_sub_point(&result->low, &box->low, p);
@@ -4266,7 +4266,7 @@ box_mul(PG_FUNCTION_ARGS)
Point high,
low;
- result = (BOX *) palloc(sizeof(BOX));
+ result = palloc_object(BOX);
point_mul_point(&high, &box->high, p);
point_mul_point(&low, &box->low, p);
@@ -4285,7 +4285,7 @@ box_div(PG_FUNCTION_ARGS)
Point high,
low;
- result = (BOX *) palloc(sizeof(BOX));
+ result = palloc_object(BOX);
point_div_point(&high, &box->high, p);
point_div_point(&low, &box->low, p);
@@ -4304,7 +4304,7 @@ point_box(PG_FUNCTION_ARGS)
Point *pt = PG_GETARG_POINT_P(0);
BOX *box;
- box = (BOX *) palloc(sizeof(BOX));
+ box = palloc_object(BOX);
box->high.x = pt->x;
box->low.x = pt->x;
@@ -4324,7 +4324,7 @@ boxes_bound_box(PG_FUNCTION_ARGS)
*box2 = PG_GETARG_BOX_P(1),
*container;
- container = (BOX *) palloc(sizeof(BOX));
+ container = palloc_object(BOX);
container->high.x = float8_max(box1->high.x, box2->high.x);
container->low.x = float8_min(box1->low.x, box2->low.x);
@@ -4506,7 +4506,7 @@ poly_center(PG_FUNCTION_ARGS)
Point *result;
CIRCLE circle;
- result = (Point *) palloc(sizeof(Point));
+ result = palloc_object(Point);
poly_to_circle(&circle, poly);
*result = circle.center;
@@ -4521,7 +4521,7 @@ poly_box(PG_FUNCTION_ARGS)
POLYGON *poly = PG_GETARG_POLYGON_P(0);
BOX *box;
- box = (BOX *) palloc(sizeof(BOX));
+ box = palloc_object(BOX);
*box = poly->boundbox;
PG_RETURN_BOX_P(box);
@@ -4612,7 +4612,7 @@ circle_in(PG_FUNCTION_ARGS)
{
char *str = PG_GETARG_CSTRING(0);
Node *escontext = fcinfo->context;
- CIRCLE *circle = (CIRCLE *) palloc(sizeof(CIRCLE));
+ CIRCLE *circle = palloc_object(CIRCLE);
char *s,
*cp;
int depth = 0;
@@ -4705,7 +4705,7 @@ circle_recv(PG_FUNCTION_ARGS)
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
CIRCLE *circle;
- circle = (CIRCLE *) palloc(sizeof(CIRCLE));
+ circle = palloc_object(CIRCLE);
circle->center.x = pq_getmsgfloat8(buf);
circle->center.y = pq_getmsgfloat8(buf);
@@ -4968,7 +4968,7 @@ circle_add_pt(PG_FUNCTION_ARGS)
Point *point = PG_GETARG_POINT_P(1);
CIRCLE *result;
- result = (CIRCLE *) palloc(sizeof(CIRCLE));
+ result = palloc_object(CIRCLE);
point_add_point(&result->center, &circle->center, point);
result->radius = circle->radius;
@@ -4983,7 +4983,7 @@ circle_sub_pt(PG_FUNCTION_ARGS)
Point *point = PG_GETARG_POINT_P(1);
CIRCLE *result;
- result = (CIRCLE *) palloc(sizeof(CIRCLE));
+ result = palloc_object(CIRCLE);
point_sub_point(&result->center, &circle->center, point);
result->radius = circle->radius;
@@ -5002,7 +5002,7 @@ circle_mul_pt(PG_FUNCTION_ARGS)
Point *point = PG_GETARG_POINT_P(1);
CIRCLE *result;
- result = (CIRCLE *) palloc(sizeof(CIRCLE));
+ result = palloc_object(CIRCLE);
point_mul_point(&result->center, &circle->center, point);
result->radius = float8_mul(circle->radius, hypot(point->x, point->y));
@@ -5017,7 +5017,7 @@ circle_div_pt(PG_FUNCTION_ARGS)
Point *point = PG_GETARG_POINT_P(1);
CIRCLE *result;
- result = (CIRCLE *) palloc(sizeof(CIRCLE));
+ result = palloc_object(CIRCLE);
point_div_point(&result->center, &circle->center, point);
result->radius = float8_div(circle->radius, hypot(point->x, point->y));
@@ -5145,7 +5145,7 @@ circle_center(PG_FUNCTION_ARGS)
CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
Point *result;
- result = (Point *) palloc(sizeof(Point));
+ result = palloc_object(Point);
result->x = circle->center.x;
result->y = circle->center.y;
@@ -5173,7 +5173,7 @@ cr_circle(PG_FUNCTION_ARGS)
float8 radius = PG_GETARG_FLOAT8(1);
CIRCLE *result;
- result = (CIRCLE *) palloc(sizeof(CIRCLE));
+ result = palloc_object(CIRCLE);
result->center.x = center->x;
result->center.y = center->y;
@@ -5189,7 +5189,7 @@ circle_box(PG_FUNCTION_ARGS)
BOX *box;
float8 delta;
- box = (BOX *) palloc(sizeof(BOX));
+ box = palloc_object(BOX);
delta = float8_div(circle->radius, sqrt(2.0));
@@ -5210,7 +5210,7 @@ box_circle(PG_FUNCTION_ARGS)
BOX *box = PG_GETARG_BOX_P(0);
CIRCLE *circle;
- circle = (CIRCLE *) palloc(sizeof(CIRCLE));
+ circle = palloc_object(CIRCLE);
circle->center.x = float8_div(float8_pl(box->high.x, box->low.x), 2.0);
circle->center.y = float8_div(float8_pl(box->high.y, box->low.y), 2.0);
@@ -5309,7 +5309,7 @@ poly_circle(PG_FUNCTION_ARGS)
POLYGON *poly = PG_GETARG_POLYGON_P(0);
CIRCLE *result;
- result = (CIRCLE *) palloc(sizeof(CIRCLE));
+ result = palloc_object(CIRCLE);
poly_to_circle(result, poly);
diff --git a/src/backend/utils/adt/geo_spgist.c b/src/backend/utils/adt/geo_spgist.c
index 4308a3065cd..94d351d4786 100644
--- a/src/backend/utils/adt/geo_spgist.c
+++ b/src/backend/utils/adt/geo_spgist.c
@@ -156,7 +156,7 @@ getQuadrant(BOX *centroid, BOX *inBox)
static RangeBox *
getRangeBox(BOX *box)
{
- RangeBox *range_box = (RangeBox *) palloc(sizeof(RangeBox));
+ RangeBox *range_box = palloc_object(RangeBox);
range_box->left.low = box->low.x;
range_box->left.high = box->high.x;
@@ -176,7 +176,7 @@ getRangeBox(BOX *box)
static RectBox *
initRectBox(void)
{
- RectBox *rect_box = (RectBox *) palloc(sizeof(RectBox));
+ RectBox *rect_box = palloc_object(RectBox);
float8 infinity = get_float8_infinity();
rect_box->range_box_x.left.low = -infinity;
@@ -204,7 +204,7 @@ initRectBox(void)
static RectBox *
nextRectBox(RectBox *rect_box, RangeBox *centroid, uint8 quadrant)
{
- RectBox *next_rect_box = (RectBox *) palloc(sizeof(RectBox));
+ RectBox *next_rect_box = palloc_object(RectBox);
memcpy(next_rect_box, rect_box, sizeof(RectBox));
@@ -445,10 +445,10 @@ spg_box_quad_picksplit(PG_FUNCTION_ARGS)
BOX *centroid;
int median,
i;
- float8 *lowXs = palloc(sizeof(float8) * in->nTuples);
- float8 *highXs = palloc(sizeof(float8) * in->nTuples);
- float8 *lowYs = palloc(sizeof(float8) * in->nTuples);
- float8 *highYs = palloc(sizeof(float8) * in->nTuples);
+ float8 *lowXs = palloc_array(float8, in->nTuples);
+ float8 *highXs = palloc_array(float8, in->nTuples);
+ float8 *lowYs = palloc_array(float8, in->nTuples);
+ float8 *highYs = palloc_array(float8, in->nTuples);
/* Calculate median of all 4D coordinates */
for (i = 0; i < in->nTuples; i++)
@@ -468,7 +468,7 @@ spg_box_quad_picksplit(PG_FUNCTION_ARGS)
median = in->nTuples / 2;
- centroid = palloc(sizeof(BOX));
+ centroid = palloc_object(BOX);
centroid->low.x = lowXs[median];
centroid->high.x = highXs[median];
@@ -482,8 +482,8 @@ spg_box_quad_picksplit(PG_FUNCTION_ARGS)
out->nNodes = 16;
out->nodeLabels = NULL; /* We don't need node labels. */
- out->mapTuplesToNodes = palloc(sizeof(int) * in->nTuples);
- out->leafTupleDatums = palloc(sizeof(Datum) * in->nTuples);
+ out->mapTuplesToNodes = palloc_array(int, in->nTuples);
+ out->leafTupleDatums = palloc_array(Datum, in->nTuples);
/*
* Assign ranges to corresponding nodes according to quadrants relative to
@@ -574,13 +574,13 @@ spg_box_quad_inner_consistent(PG_FUNCTION_ARGS)
{
/* Report that all nodes should be visited */
out->nNodes = in->nNodes;
- out->nodeNumbers = (int *) palloc(sizeof(int) * in->nNodes);
+ out->nodeNumbers = palloc_array(int, in->nNodes);
for (i = 0; i < in->nNodes; i++)
out->nodeNumbers[i] = i;
if (in->norderbys > 0 && in->nNodes > 0)
{
- double *distances = palloc(sizeof(double) * in->norderbys);
+ double *distances = palloc_array(double, in->norderbys);
int j;
for (j = 0; j < in->norderbys; j++)
@@ -590,12 +590,12 @@ spg_box_quad_inner_consistent(PG_FUNCTION_ARGS)
distances[j] = pointToRectBoxDistance(pt, rect_box);
}
- out->distances = (double **) palloc(sizeof(double *) * in->nNodes);
+ out->distances = palloc_array(double *, in->nNodes);
out->distances[0] = distances;
for (i = 1; i < in->nNodes; i++)
{
- out->distances[i] = palloc(sizeof(double) * in->norderbys);
+ out->distances[i] = palloc_array(double, in->norderbys);
memcpy(out->distances[i], distances,
sizeof(double) * in->norderbys);
}
@@ -609,7 +609,7 @@ spg_box_quad_inner_consistent(PG_FUNCTION_ARGS)
* following operations.
*/
centroid = getRangeBox(DatumGetBoxP(in->prefixDatum));
- queries = (RangeBox **) palloc(in->nkeys * sizeof(RangeBox *));
+ queries = palloc_array(RangeBox *, in->nkeys);
for (i = 0; i < in->nkeys; i++)
{
BOX *box = spg_box_quad_get_scankey_bbox(&in->scankeys[i], NULL);
@@ -619,10 +619,10 @@ spg_box_quad_inner_consistent(PG_FUNCTION_ARGS)
/* Allocate enough memory for nodes */
out->nNodes = 0;
- out->nodeNumbers = (int *) palloc(sizeof(int) * in->nNodes);
- out->traversalValues = (void **) palloc(sizeof(void *) * in->nNodes);
+ out->nodeNumbers = palloc_array(int, in->nNodes);
+ out->traversalValues = palloc_array(void *, in->nNodes);
if (in->norderbys > 0)
- out->distances = (double **) palloc(sizeof(double *) * in->nNodes);
+ out->distances = palloc_array(double *, in->nNodes);
/*
* We switch memory context, because we want to allocate memory for new
@@ -703,7 +703,7 @@ spg_box_quad_inner_consistent(PG_FUNCTION_ARGS)
if (in->norderbys > 0)
{
- double *distances = palloc(sizeof(double) * in->norderbys);
+ double *distances = palloc_array(double, in->norderbys);
int j;
out->distances[out->nNodes] = distances;
@@ -878,7 +878,7 @@ spg_poly_quad_compress(PG_FUNCTION_ARGS)
POLYGON *polygon = PG_GETARG_POLYGON_P(0);
BOX *box;
- box = (BOX *) palloc(sizeof(BOX));
+ box = palloc_object(BOX);
*box = polygon->boundbox;
PG_RETURN_BOX_P(box);
diff --git a/src/backend/utils/adt/int.c b/src/backend/utils/adt/int.c
index b5781989a64..60411ee024d 100644
--- a/src/backend/utils/adt/int.c
+++ b/src/backend/utils/adt/int.c
@@ -1537,7 +1537,7 @@ generate_series_step_int4(PG_FUNCTION_ARGS)
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
/* allocate memory for user context */
- fctx = (generate_series_fctx *) palloc(sizeof(generate_series_fctx));
+ fctx = palloc_object(generate_series_fctx);
/*
* Use fctx to keep state from call to call. Seed current with the
diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c
index 9cd420b4b9d..678f971508b 100644
--- a/src/backend/utils/adt/int8.c
+++ b/src/backend/utils/adt/int8.c
@@ -1411,7 +1411,7 @@ generate_series_step_int8(PG_FUNCTION_ARGS)
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
/* allocate memory for user context */
- fctx = (generate_series_fctx *) palloc(sizeof(generate_series_fctx));
+ fctx = palloc_object(generate_series_fctx);
/*
* Use fctx to keep state from call to call. Seed current with the
diff --git a/src/backend/utils/adt/json.c b/src/backend/utils/adt/json.c
index 06dd62f0008..73cacf33e61 100644
--- a/src/backend/utils/adt/json.c
+++ b/src/backend/utils/adt/json.c
@@ -807,7 +807,7 @@ json_agg_transfn_worker(FunctionCallInfo fcinfo, bool absent_on_null)
* use the right context to enlarge the object if necessary.
*/
oldcontext = MemoryContextSwitchTo(aggcontext);
- state = (JsonAggState *) palloc(sizeof(JsonAggState));
+ state = palloc_object(JsonAggState);
state->str = makeStringInfo();
MemoryContextSwitchTo(oldcontext);
@@ -1029,7 +1029,7 @@ json_object_agg_transfn_worker(FunctionCallInfo fcinfo,
* sure they use the right context to enlarge the object if necessary.
*/
oldcontext = MemoryContextSwitchTo(aggcontext);
- state = (JsonAggState *) palloc(sizeof(JsonAggState));
+ state = palloc_object(JsonAggState);
state->str = makeStringInfo();
if (unique_keys)
json_unique_builder_init(&state->unique_check);
@@ -1762,7 +1762,7 @@ json_unique_object_start(void *_state)
return JSON_SUCCESS;
/* push object entry to stack */
- entry = palloc(sizeof(*entry));
+ entry = palloc_object(JsonUniqueStackEntry);
entry->object_id = state->id_counter++;
entry->parent = state->stack;
state->stack = entry;
diff --git a/src/backend/utils/adt/jsonb_gin.c b/src/backend/utils/adt/jsonb_gin.c
index a6d3332bb42..a1daa3f5034 100644
--- a/src/backend/utils/adt/jsonb_gin.c
+++ b/src/backend/utils/adt/jsonb_gin.c
@@ -163,7 +163,7 @@ static void
init_gin_entries(GinEntries *entries, int preallocated)
{
entries->allocated = preallocated;
- entries->buf = preallocated ? palloc(sizeof(Datum) * preallocated) : NULL;
+ entries->buf = preallocated ? palloc_array(Datum, preallocated) : NULL;
entries->count = 0;
}
@@ -178,13 +178,14 @@ add_gin_entry(GinEntries *entries, Datum entry)
if (entries->allocated)
{
entries->allocated *= 2;
- entries->buf = repalloc(entries->buf,
- sizeof(Datum) * entries->allocated);
+ entries->buf = repalloc_array(entries->buf,
+ Datum,
+ entries->allocated);
}
else
{
entries->allocated = 8;
- entries->buf = palloc(sizeof(Datum) * entries->allocated);
+ entries->buf = palloc_array(Datum, entries->allocated);
}
}
@@ -307,7 +308,7 @@ jsonb_ops__add_path_item(JsonPathGinPath *path, JsonPathItem *jsp)
return false;
}
- pentry = palloc(sizeof(*pentry));
+ pentry = palloc_object(JsonPathGinPathItem);
pentry->type = jsp->type;
pentry->keyName = keyName;
@@ -785,7 +786,7 @@ extract_jsp_query(JsonPath *jp, StrategyNumber strat, bool pathOps,
if (!*nentries)
return NULL;
- *extra_data = palloc0(sizeof(**extra_data) * entries.count);
+ *extra_data = palloc0_array(Pointer, entries.count);
**extra_data = (Pointer) node;
return entries.buf;
@@ -869,7 +870,7 @@ gin_extract_jsonb_query(PG_FUNCTION_ARGS)
text *query = PG_GETARG_TEXT_PP(0);
*nentries = 1;
- entries = (Datum *) palloc(sizeof(Datum));
+ entries = palloc_object(Datum);
entries[0] = make_text_key(JGINFLAG_KEY,
VARDATA_ANY(query),
VARSIZE_ANY_EXHDR(query));
@@ -887,7 +888,7 @@ gin_extract_jsonb_query(PG_FUNCTION_ARGS)
deconstruct_array_builtin(query, TEXTOID, &key_datums, &key_nulls, &key_count);
- entries = (Datum *) palloc(sizeof(Datum) * key_count);
+ entries = palloc_array(Datum, key_count);
for (i = 0, j = 0; i < key_count; i++)
{
@@ -1124,7 +1125,7 @@ gin_extract_jsonb_path(PG_FUNCTION_ARGS)
case WJB_BEGIN_OBJECT:
/* Push a stack level for this object */
parent = stack;
- stack = (PathHashStack *) palloc(sizeof(PathHashStack));
+ stack = palloc_object(PathHashStack);
/*
* We pass forward hashes from outer nesting levels so that
diff --git a/src/backend/utils/adt/jsonb_util.c b/src/backend/utils/adt/jsonb_util.c
index 1eb8dffa8bd..28e1ee18ce1 100644
--- a/src/backend/utils/adt/jsonb_util.c
+++ b/src/backend/utils/adt/jsonb_util.c
@@ -359,7 +359,7 @@ findJsonbValueFromContainer(JsonbContainer *container, uint32 flags,
if ((flags & JB_FARRAY) && JsonContainerIsArray(container))
{
- JsonbValue *result = palloc(sizeof(JsonbValue));
+ JsonbValue *result = palloc_object(JsonbValue);
char *base_addr = (char *) (children + count);
uint32 offset = 0;
int i;
@@ -442,7 +442,7 @@ getKeyJsonValueFromContainer(JsonbContainer *container,
int index = stopMiddle + count;
if (!res)
- res = palloc(sizeof(JsonbValue));
+ res = palloc_object(JsonbValue);
fillJsonbValue(container, index, baseAddr,
getJsonbOffset(container, index),
@@ -484,7 +484,7 @@ getIthJsonbValueFromContainer(JsonbContainer *container, uint32 i)
if (i >= nelements)
return NULL;
- result = palloc(sizeof(JsonbValue));
+ result = palloc_object(JsonbValue);
fillJsonbValue(container, i, base_addr,
getJsonbOffset(container, i),
@@ -1127,7 +1127,7 @@ iteratorFromContainer(JsonbContainer *container, JsonbIterator *parent)
{
JsonbIterator *it;
- it = palloc0(sizeof(JsonbIterator));
+ it = palloc0_object(JsonbIterator);
it->container = container;
it->parent = parent;
it->nElems = JsonContainerSize(container);
@@ -1373,7 +1373,7 @@ JsonbDeepContains(JsonbIterator **val, JsonbIterator **mContained)
uint32 j = 0;
/* Make room for all possible values */
- lhsConts = palloc(sizeof(JsonbValue) * nLhsElems);
+ lhsConts = palloc_array(JsonbValue, nLhsElems);
for (i = 0; i < nLhsElems; i++)
{
diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c
index 22de18bc5b9..980e2882957 100644
--- a/src/backend/utils/adt/jsonfuncs.c
+++ b/src/backend/utils/adt/jsonfuncs.c
@@ -593,12 +593,12 @@ jsonb_object_keys(PG_FUNCTION_ARGS)
funcctx = SRF_FIRSTCALL_INIT();
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
- state = palloc(sizeof(OkeysState));
+ state = palloc_object(OkeysState);
state->result_size = JB_ROOT_COUNT(jb);
state->result_count = 0;
state->sent_count = 0;
- state->result = palloc(state->result_size * sizeof(char *));
+ state->result = palloc_array(char *, state->result_size);
it = JsonbIteratorInit(&jb->root);
@@ -744,14 +744,14 @@ json_object_keys(PG_FUNCTION_ARGS)
funcctx = SRF_FIRSTCALL_INIT();
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
- state = palloc(sizeof(OkeysState));
- sem = palloc0(sizeof(JsonSemAction));
+ state = palloc_object(OkeysState);
+ sem = palloc0_object(JsonSemAction);
state->lex = makeJsonLexContext(&lex, json, true);
state->result_size = 256;
state->result_count = 0;
state->sent_count = 0;
- state->result = palloc(256 * sizeof(char *));
+ state->result = palloc_array(char *, 256);
sem->semstate = state;
sem->array_start = okeys_array_start;
@@ -1045,8 +1045,8 @@ get_path_all(FunctionCallInfo fcinfo, bool as_text)
deconstruct_array_builtin(path, TEXTOID, &pathtext, &pathnulls, &npath);
- tpath = palloc(npath * sizeof(char *));
- ipath = palloc(npath * sizeof(int));
+ tpath = palloc_array(char *, npath);
+ ipath = palloc_array(int, npath);
for (i = 0; i < npath; i++)
{
@@ -1106,8 +1106,8 @@ get_worker(text *json,
int npath,
bool normalize_results)
{
- JsonSemAction *sem = palloc0(sizeof(JsonSemAction));
- GetState *state = palloc0(sizeof(GetState));
+ JsonSemAction *sem = palloc0_object(JsonSemAction);
+ GetState *state = palloc0_object(GetState);
Assert(npath >= 0);
@@ -1118,8 +1118,8 @@ get_worker(text *json,
state->npath = npath;
state->path_names = tpath;
state->path_indexes = ipath;
- state->pathok = palloc0(sizeof(bool) * npath);
- state->array_cur_index = palloc(sizeof(int) * npath);
+ state->pathok = palloc0_array(bool, npath);
+ state->array_cur_index = palloc_array(int, npath);
if (npath > 0)
state->pathok[0] = true;
@@ -1681,7 +1681,7 @@ jsonb_set_element(Jsonb *jb, const Datum *path, int path_len,
{
JsonbInState state = {0};
JsonbIterator *it;
- bool *path_nulls = palloc0(path_len * sizeof(bool));
+ bool *path_nulls = palloc0_array(bool, path_len);
if (newval->type == jbvArray && newval->val.array.rawScalar)
*newval = newval->val.array.elems[0];
@@ -1726,7 +1726,7 @@ push_path(JsonbInState *st, int level, const Datum *path_elems,
* it contains only information about path slice from level to the end,
* the access index must be normalized by level.
*/
- enum jbvType *tpath = palloc0((path_len - level) * sizeof(enum jbvType));
+ enum jbvType *tpath = palloc0_array(enum jbvType, path_len - level);
JsonbValue newkey;
/*
@@ -1853,14 +1853,14 @@ json_array_length(PG_FUNCTION_ARGS)
JsonLexContext lex;
JsonSemAction *sem;
- state = palloc0(sizeof(AlenState));
+ state = palloc0_object(AlenState);
state->lex = makeJsonLexContext(&lex, json, false);
/* palloc0 does this for us */
#if 0
state->count = 0;
#endif
- sem = palloc0(sizeof(JsonSemAction));
+ sem = palloc0_object(JsonSemAction);
sem->semstate = state;
sem->object_start = alen_object_start;
sem->scalar = alen_scalar;
@@ -2060,8 +2060,8 @@ each_worker(FunctionCallInfo fcinfo, bool as_text)
ReturnSetInfo *rsi;
EachState *state;
- state = palloc0(sizeof(EachState));
- sem = palloc0(sizeof(JsonSemAction));
+ state = palloc0_object(EachState);
+ sem = palloc0_object(JsonSemAction);
rsi = (ReturnSetInfo *) fcinfo->resultinfo;
@@ -2313,8 +2313,8 @@ elements_worker(FunctionCallInfo fcinfo, const char *funcname, bool as_text)
/* elements only needs escaped strings when as_text */
makeJsonLexContext(&lex, json, as_text);
- state = palloc0(sizeof(ElementsState));
- sem = palloc0(sizeof(JsonSemAction));
+ state = palloc0_object(ElementsState);
+ sem = palloc0_object(JsonSemAction);
InitMaterializedSRF(fcinfo, MAT_SRF_USE_EXPECTED_DESC | MAT_SRF_BLESS);
rsi = (ReturnSetInfo *) fcinfo->resultinfo;
@@ -2569,8 +2569,8 @@ populate_array_assign_ndims(PopulateArrayContext *ctx, int ndims)
}
ctx->ndims = ndims;
- ctx->dims = palloc(sizeof(int) * ndims);
- ctx->sizes = palloc0(sizeof(int) * ndims);
+ ctx->dims = palloc_array(int, ndims);
+ ctx->sizes = palloc0_array(int, ndims);
for (i = 0; i < ndims; i++)
ctx->dims[i] = -1; /* dimensions are unknown yet */
@@ -2955,7 +2955,7 @@ populate_array(ArrayIOData *aio,
Assert(ctx.ndims > 0);
- lbs = palloc(sizeof(int) * ctx.ndims);
+ lbs = palloc_array(int, ctx.ndims);
for (i = 0; i < ctx.ndims; i++)
lbs[i] = 1;
@@ -3821,8 +3821,8 @@ get_json_object_as_hash(const char *json, int len, const char *funcname,
&ctl,
HASH_ELEM | HASH_STRINGS | HASH_CONTEXT);
- state = palloc0(sizeof(JHashState));
- sem = palloc0(sizeof(JsonSemAction));
+ state = palloc0_object(JHashState);
+ sem = palloc0_object(JsonSemAction);
state->function_name = funcname;
state->hash = tab;
@@ -4119,7 +4119,7 @@ populate_recordset_worker(FunctionCallInfo fcinfo, const char *funcname,
*/
update_cached_tupdesc(&cache->c.io.composite, cache->fn_mcxt);
- state = palloc0(sizeof(PopulateRecordsetState));
+ state = palloc0_object(PopulateRecordsetState);
/* make tuplestore in a sufficiently long-lived memory context */
old_cxt = MemoryContextSwitchTo(rsi->econtext->ecxt_per_query_memory);
@@ -4138,7 +4138,7 @@ populate_recordset_worker(FunctionCallInfo fcinfo, const char *funcname,
JsonLexContext lex;
JsonSemAction *sem;
- sem = palloc0(sizeof(JsonSemAction));
+ sem = palloc0_object(JsonSemAction);
makeJsonLexContext(&lex, json, true);
@@ -4508,8 +4508,8 @@ json_strip_nulls(PG_FUNCTION_ARGS)
JsonLexContext lex;
JsonSemAction *sem;
- state = palloc0(sizeof(StripnullState));
- sem = palloc0(sizeof(JsonSemAction));
+ state = palloc0_object(StripnullState);
+ sem = palloc0_object(JsonSemAction);
initStringInfo(&strbuf);
state->lex = makeJsonLexContext(&lex, json, true);
@@ -5700,8 +5700,8 @@ iterate_json_values(text *json, uint32 flags, void *action_state,
JsonIterateStringValuesAction action)
{
JsonLexContext lex;
- JsonSemAction *sem = palloc0(sizeof(JsonSemAction));
- IterateJsonStringValuesState *state = palloc0(sizeof(IterateJsonStringValuesState));
+ JsonSemAction *sem = palloc0_object(JsonSemAction);
+ IterateJsonStringValuesState *state = palloc0_object(IterateJsonStringValuesState);
state->lex = makeJsonLexContext(&lex, json, true);
state->action = action;
@@ -5820,8 +5820,8 @@ transform_json_string_values(text *json, void *action_state,
JsonTransformStringValuesAction transform_action)
{
JsonLexContext lex;
- JsonSemAction *sem = palloc0(sizeof(JsonSemAction));
- TransformJsonStringValuesState *state = palloc0(sizeof(TransformJsonStringValuesState));
+ JsonSemAction *sem = palloc0_object(JsonSemAction);
+ TransformJsonStringValuesState *state = palloc0_object(TransformJsonStringValuesState);
StringInfoData strbuf;
initStringInfo(&strbuf);
diff --git a/src/backend/utils/adt/jsonpath_exec.c b/src/backend/utils/adt/jsonpath_exec.c
index 3f92baf6e82..fc0e05e8789 100644
--- a/src/backend/utils/adt/jsonpath_exec.c
+++ b/src/backend/utils/adt/jsonpath_exec.c
@@ -775,7 +775,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
break;
}
- v = hasNext ? &vbuf : palloc(sizeof(*v));
+ v = hasNext ? &vbuf : palloc_object(JsonbValue);
baseObject = cxt->baseObject;
getJsonPathItem(cxt, jsp, v);
@@ -1088,7 +1088,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
case jpiType:
{
- JsonbValue *jbv = palloc(sizeof(*jbv));
+ JsonbValue *jbv = palloc_object(JsonbValue);
jbv->type = jbvString;
jbv->val.string.val = pstrdup(JsonbTypeName(jb));
@@ -1118,7 +1118,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
size = 1;
}
- jb = palloc(sizeof(*jb));
+ jb = palloc_object(JsonbValue);
jb->type = jbvNumeric;
jb->val.numeric = int64_to_numeric(size);
@@ -1249,7 +1249,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
last = cxt->innermostArraySize - 1;
- lastjbv = hasNext ? &tmpjbv : palloc(sizeof(*lastjbv));
+ lastjbv = hasNext ? &tmpjbv : palloc_object(JsonbValue);
lastjbv->type = jbvNumeric;
lastjbv->val.numeric = int64_to_numeric(last);
@@ -2162,7 +2162,7 @@ executeBinaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (!jspGetNext(jsp, &elem) && !found)
return jperOk;
- lval = palloc(sizeof(*lval));
+ lval = palloc_object(JsonbValue);
lval->type = jbvNumeric;
lval->val.numeric = res;
@@ -2317,7 +2317,7 @@ executeNumericItemMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (!jspGetNext(jsp, &next) && !found)
return jperOk;
- jb = palloc(sizeof(*jb));
+ jb = palloc_object(JsonbValue);
jb->type = jbvNumeric;
jb->val.numeric = DatumGetNumeric(datum);
@@ -2783,7 +2783,7 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (!hasNext && !found)
return res;
- jb = hasNext ? &jbvbuf : palloc(sizeof(*jb));
+ jb = hasNext ? &jbvbuf : palloc_object(JsonbValue);
jb->type = jbvDatetime;
jb->val.datetime.value = value;
@@ -3018,7 +3018,7 @@ GetJsonPathVar(void *cxt, char *varName, int varNameLen,
return NULL;
}
- result = palloc(sizeof(JsonbValue));
+ result = palloc_object(JsonbValue);
if (var->isnull)
{
*baseObjectId = 0;
@@ -3445,7 +3445,7 @@ compareNumeric(Numeric a, Numeric b)
static JsonbValue *
copyJsonbValue(JsonbValue *src)
{
- JsonbValue *dst = palloc(sizeof(*dst));
+ JsonbValue *dst = palloc_object(JsonbValue);
*dst = *src;
@@ -4121,7 +4121,7 @@ JsonTableInitOpaque(TableFuncScanState *state, int natts)
JsonExpr *je = castNode(JsonExpr, tf->docexpr);
List *args = NIL;
- cxt = palloc0(sizeof(JsonTableExecContext));
+ cxt = palloc0_object(JsonTableExecContext);
cxt->magic = JSON_TABLE_EXEC_CONTEXT_MAGIC;
/*
@@ -4140,7 +4140,7 @@ JsonTableInitOpaque(TableFuncScanState *state, int natts)
{
ExprState *state = lfirst_node(ExprState, exprlc);
String *name = lfirst_node(String, namelc);
- JsonPathVariable *var = palloc(sizeof(*var));
+ JsonPathVariable *var = palloc_object(JsonPathVariable);
var->name = pstrdup(name->sval);
var->namelen = strlen(var->name);
@@ -4158,8 +4158,7 @@ JsonTableInitOpaque(TableFuncScanState *state, int natts)
}
}
- cxt->colplanstates = palloc(sizeof(JsonTablePlanState *) *
- list_length(tf->colvalexprs));
+ cxt->colplanstates = palloc_array(JsonTablePlanState *, list_length(tf->colvalexprs));
/*
* Initialize plan for the root path and, recursively, also any child
@@ -4197,7 +4196,7 @@ JsonTableInitPlan(JsonTableExecContext *cxt, JsonTablePlan *plan,
JsonTablePlanState *parentstate,
List *args, MemoryContext mcxt)
{
- JsonTablePlanState *planstate = palloc0(sizeof(*planstate));
+ JsonTablePlanState *planstate = palloc0_object(JsonTablePlanState);
planstate->plan = plan;
planstate->parent = parentstate;
diff --git a/src/backend/utils/adt/jsonpath_gram.y b/src/backend/utils/adt/jsonpath_gram.y
index 499745a8fef..411a8baf380 100644
--- a/src/backend/utils/adt/jsonpath_gram.y
+++ b/src/backend/utils/adt/jsonpath_gram.y
@@ -120,7 +120,7 @@ static bool makeItemLikeRegex(JsonPathParseItem *expr,
result:
mode expr_or_predicate {
- *result = palloc(sizeof(JsonPathParseResult));
+ *result = palloc_object(JsonPathParseResult);
(*result)->expr = $2;
(*result)->lax = $1;
(void) yynerrs;
@@ -384,7 +384,7 @@ method:
static JsonPathParseItem *
makeItemType(JsonPathItemType type)
{
- JsonPathParseItem *v = palloc(sizeof(*v));
+ JsonPathParseItem *v = palloc_object(JsonPathParseItem);
CHECK_FOR_INTERRUPTS();
diff --git a/src/backend/utils/adt/lockfuncs.c b/src/backend/utils/adt/lockfuncs.c
index df938812dd3..bf38d68aa03 100644
--- a/src/backend/utils/adt/lockfuncs.c
+++ b/src/backend/utils/adt/lockfuncs.c
@@ -152,7 +152,7 @@ pg_lock_status(PG_FUNCTION_ARGS)
* Collect all the locking information that we will format and send
* out as a result set.
*/
- mystatus = (PG_Lock_Status *) palloc(sizeof(PG_Lock_Status));
+ mystatus = palloc_object(PG_Lock_Status);
funcctx->user_fctx = mystatus;
mystatus->lockData = GetLockStatusData();
diff --git a/src/backend/utils/adt/mac.c b/src/backend/utils/adt/mac.c
index bb38ef2f5e4..35234e700ff 100644
--- a/src/backend/utils/adt/mac.c
+++ b/src/backend/utils/adt/mac.c
@@ -101,7 +101,7 @@ macaddr_in(PG_FUNCTION_ARGS)
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("invalid octet value in \"macaddr\" value: \"%s\"", str)));
- result = (macaddr *) palloc(sizeof(macaddr));
+ result = palloc_object(macaddr);
result->a = a;
result->b = b;
@@ -142,7 +142,7 @@ macaddr_recv(PG_FUNCTION_ARGS)
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
macaddr *addr;
- addr = (macaddr *) palloc(sizeof(macaddr));
+ addr = palloc_object(macaddr);
addr->a = pq_getmsgbyte(buf);
addr->b = pq_getmsgbyte(buf);
@@ -289,7 +289,7 @@ macaddr_not(PG_FUNCTION_ARGS)
macaddr *addr = PG_GETARG_MACADDR_P(0);
macaddr *result;
- result = (macaddr *) palloc(sizeof(macaddr));
+ result = palloc_object(macaddr);
result->a = ~addr->a;
result->b = ~addr->b;
result->c = ~addr->c;
@@ -306,7 +306,7 @@ macaddr_and(PG_FUNCTION_ARGS)
macaddr *addr2 = PG_GETARG_MACADDR_P(1);
macaddr *result;
- result = (macaddr *) palloc(sizeof(macaddr));
+ result = palloc_object(macaddr);
result->a = addr1->a & addr2->a;
result->b = addr1->b & addr2->b;
result->c = addr1->c & addr2->c;
@@ -323,7 +323,7 @@ macaddr_or(PG_FUNCTION_ARGS)
macaddr *addr2 = PG_GETARG_MACADDR_P(1);
macaddr *result;
- result = (macaddr *) palloc(sizeof(macaddr));
+ result = palloc_object(macaddr);
result->a = addr1->a | addr2->a;
result->b = addr1->b | addr2->b;
result->c = addr1->c | addr2->c;
@@ -343,7 +343,7 @@ macaddr_trunc(PG_FUNCTION_ARGS)
macaddr *addr = PG_GETARG_MACADDR_P(0);
macaddr *result;
- result = (macaddr *) palloc(sizeof(macaddr));
+ result = palloc_object(macaddr);
result->a = addr->a;
result->b = addr->b;
@@ -374,7 +374,7 @@ macaddr_sortsupport(PG_FUNCTION_ARGS)
oldcontext = MemoryContextSwitchTo(ssup->ssup_cxt);
- uss = palloc(sizeof(macaddr_sortsupport_state));
+ uss = palloc_object(macaddr_sortsupport_state);
uss->input_count = 0;
uss->estimating = true;
initHyperLogLog(&uss->abbr_card, 10);
diff --git a/src/backend/utils/adt/mac8.c b/src/backend/utils/adt/mac8.c
index 08e41ba4eea..ea715a7a0d4 100644
--- a/src/backend/utils/adt/mac8.c
+++ b/src/backend/utils/adt/mac8.c
@@ -207,7 +207,7 @@ macaddr8_in(PG_FUNCTION_ARGS)
else if (count != 8)
goto fail;
- result = (macaddr8 *) palloc0(sizeof(macaddr8));
+ result = palloc0_object(macaddr8);
result->a = a;
result->b = b;
@@ -256,7 +256,7 @@ macaddr8_recv(PG_FUNCTION_ARGS)
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
macaddr8 *addr;
- addr = (macaddr8 *) palloc0(sizeof(macaddr8));
+ addr = palloc0_object(macaddr8);
addr->a = pq_getmsgbyte(buf);
addr->b = pq_getmsgbyte(buf);
@@ -417,7 +417,7 @@ macaddr8_not(PG_FUNCTION_ARGS)
macaddr8 *addr = PG_GETARG_MACADDR8_P(0);
macaddr8 *result;
- result = (macaddr8 *) palloc0(sizeof(macaddr8));
+ result = palloc0_object(macaddr8);
result->a = ~addr->a;
result->b = ~addr->b;
result->c = ~addr->c;
@@ -437,7 +437,7 @@ macaddr8_and(PG_FUNCTION_ARGS)
macaddr8 *addr2 = PG_GETARG_MACADDR8_P(1);
macaddr8 *result;
- result = (macaddr8 *) palloc0(sizeof(macaddr8));
+ result = palloc0_object(macaddr8);
result->a = addr1->a & addr2->a;
result->b = addr1->b & addr2->b;
result->c = addr1->c & addr2->c;
@@ -457,7 +457,7 @@ macaddr8_or(PG_FUNCTION_ARGS)
macaddr8 *addr2 = PG_GETARG_MACADDR8_P(1);
macaddr8 *result;
- result = (macaddr8 *) palloc0(sizeof(macaddr8));
+ result = palloc0_object(macaddr8);
result->a = addr1->a | addr2->a;
result->b = addr1->b | addr2->b;
result->c = addr1->c | addr2->c;
@@ -479,7 +479,7 @@ macaddr8_trunc(PG_FUNCTION_ARGS)
macaddr8 *addr = PG_GETARG_MACADDR8_P(0);
macaddr8 *result;
- result = (macaddr8 *) palloc0(sizeof(macaddr8));
+ result = palloc0_object(macaddr8);
result->a = addr->a;
result->b = addr->b;
@@ -502,7 +502,7 @@ macaddr8_set7bit(PG_FUNCTION_ARGS)
macaddr8 *addr = PG_GETARG_MACADDR8_P(0);
macaddr8 *result;
- result = (macaddr8 *) palloc0(sizeof(macaddr8));
+ result = palloc0_object(macaddr8);
result->a = addr->a | 0x02;
result->b = addr->b;
@@ -526,7 +526,7 @@ macaddrtomacaddr8(PG_FUNCTION_ARGS)
macaddr *addr6 = PG_GETARG_MACADDR_P(0);
macaddr8 *result;
- result = (macaddr8 *) palloc0(sizeof(macaddr8));
+ result = palloc0_object(macaddr8);
result->a = addr6->a;
result->b = addr6->b;
@@ -547,7 +547,7 @@ macaddr8tomacaddr(PG_FUNCTION_ARGS)
macaddr8 *addr = PG_GETARG_MACADDR8_P(0);
macaddr *result;
- result = (macaddr *) palloc0(sizeof(macaddr));
+ result = palloc0_object(macaddr);
if ((addr->d != 0xFF) || (addr->e != 0xFE))
ereport(ERROR,
diff --git a/src/backend/utils/adt/mcxtfuncs.c b/src/backend/utils/adt/mcxtfuncs.c
index fe6dce9cba3..46dfb3dd133 100644
--- a/src/backend/utils/adt/mcxtfuncs.c
+++ b/src/backend/utils/adt/mcxtfuncs.c
@@ -52,7 +52,7 @@ int_list_to_array(const List *list)
ArrayType *result_array;
length = list_length(list);
- datum_array = (Datum *) palloc(length * sizeof(Datum));
+ datum_array = palloc_array(Datum, length);
foreach_int(i, list)
datum_array[foreach_current_index(i)] = Int32GetDatum(i);
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c
index a365c432d34..c32f24fbf97 100644
--- a/src/backend/utils/adt/misc.c
+++ b/src/backend/utils/adt/misc.c
@@ -487,7 +487,7 @@ pg_get_catalog_foreign_keys(PG_FUNCTION_ARGS)
* array_in, and it wouldn't be very efficient if we could. Fill an
* FmgrInfo to use for the call.
*/
- arrayinp = (FmgrInfo *) palloc(sizeof(FmgrInfo));
+ arrayinp = palloc_object(FmgrInfo);
fmgr_info(F_ARRAY_IN, arrayinp);
funcctx->user_fctx = arrayinp;
diff --git a/src/backend/utils/adt/multirangetypes.c b/src/backend/utils/adt/multirangetypes.c
index e259644c6ca..169acf0ef63 100644
--- a/src/backend/utils/adt/multirangetypes.c
+++ b/src/backend/utils/adt/multirangetypes.c
@@ -125,7 +125,7 @@ multirange_in(PG_FUNCTION_ARGS)
int32 range_count = 0;
int32 range_capacity = 8;
RangeType *range;
- RangeType **ranges = palloc(range_capacity * sizeof(RangeType *));
+ RangeType **ranges = palloc_array(RangeType *, range_capacity);
MultirangeIOData *cache;
MultirangeType *ret;
MultirangeParseState parse_state;
@@ -348,7 +348,7 @@ multirange_recv(PG_FUNCTION_ARGS)
cache = get_multirange_io_data(fcinfo, mltrngtypoid, IOFunc_receive);
range_count = pq_getmsgint(buf, 4);
- ranges = palloc(range_count * sizeof(RangeType *));
+ ranges = palloc_array(RangeType *, range_count);
initStringInfo(&tmpbuf);
for (int i = 0; i < range_count; i++)
@@ -836,7 +836,7 @@ multirange_deserialize(TypeCacheEntry *rangetyp,
{
int i;
- *ranges = palloc(*range_count * sizeof(RangeType *));
+ *ranges = palloc_array(RangeType *, *range_count);
for (i = 0; i < *range_count; i++)
(*ranges)[i] = multirange_get_range(rangetyp, multirange, i);
}
@@ -2818,7 +2818,7 @@ multirange_unnest(PG_FUNCTION_ARGS)
mr = PG_GETARG_MULTIRANGE_P(0);
/* allocate memory for user context */
- fctx = (multirange_unnest_fctx *) palloc(sizeof(multirange_unnest_fctx));
+ fctx = palloc_object(multirange_unnest_fctx);
/* initialize state */
fctx->mr = mr;
diff --git a/src/backend/utils/adt/multirangetypes_selfuncs.c b/src/backend/utils/adt/multirangetypes_selfuncs.c
index 21f0205d803..fc5a4354fce 100644
--- a/src/backend/utils/adt/multirangetypes_selfuncs.c
+++ b/src/backend/utils/adt/multirangetypes_selfuncs.c
@@ -496,8 +496,8 @@ calc_hist_selectivity(TypeCacheEntry *typcache, VariableStatData *vardata,
* bounds.
*/
nhist = hslot.nvalues;
- hist_lower = (RangeBound *) palloc(sizeof(RangeBound) * nhist);
- hist_upper = (RangeBound *) palloc(sizeof(RangeBound) * nhist);
+ hist_lower = palloc_array(RangeBound, nhist);
+ hist_upper = palloc_array(RangeBound, nhist);
for (i = 0; i < nhist; i++)
{
bool empty;
diff --git a/src/backend/utils/adt/multixactfuncs.c b/src/backend/utils/adt/multixactfuncs.c
index e74ea938348..a428e140bc4 100644
--- a/src/backend/utils/adt/multixactfuncs.c
+++ b/src/backend/utils/adt/multixactfuncs.c
@@ -50,7 +50,7 @@ pg_get_multixact_members(PG_FUNCTION_ARGS)
funccxt = SRF_FIRSTCALL_INIT();
oldcxt = MemoryContextSwitchTo(funccxt->multi_call_memory_ctx);
- multi = palloc(sizeof(mxact));
+ multi = palloc_object(mxact);
/* no need to allow for old values here */
multi->nmembers = GetMultiXactIdMembers(mxid, &multi->members, false,
false);
diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c
index 3cb0ab6829a..3a2002097dd 100644
--- a/src/backend/utils/adt/network.c
+++ b/src/backend/utils/adt/network.c
@@ -75,7 +75,7 @@ network_in(char *src, bool is_cidr, Node *escontext)
int bits;
inet *dst;
- dst = (inet *) palloc0(sizeof(inet));
+ dst = (inet *) palloc0_object(inet);
/*
* First, check to see if this is an IPv6 or IPv4 address. IPv6 addresses
@@ -196,7 +196,7 @@ network_recv(StringInfo buf, bool is_cidr)
i;
/* make sure any unused bits in a CIDR value are zeroed */
- addr = (inet *) palloc0(sizeof(inet));
+ addr = palloc0_object(inet);
ip_family(addr) = pq_getmsgbyte(buf);
if (ip_family(addr) != PGSQL_AF_INET &&
@@ -363,7 +363,7 @@ cidr_set_masklen(PG_FUNCTION_ARGS)
inet *
cidr_set_masklen_internal(const inet *src, int bits)
{
- inet *dst = (inet *) palloc0(sizeof(inet));
+ inet *dst = palloc0_object(inet);
ip_family(dst) = ip_family(src);
ip_bits(dst) = bits;
@@ -444,7 +444,7 @@ network_sortsupport(PG_FUNCTION_ARGS)
oldcontext = MemoryContextSwitchTo(ssup->ssup_cxt);
- uss = palloc(sizeof(network_sortsupport_state));
+ uss = palloc_object(network_sortsupport_state);
uss->input_count = 0;
uss->estimating = true;
initHyperLogLog(&uss->abbr_card, 10);
@@ -1227,7 +1227,7 @@ network_broadcast(PG_FUNCTION_ARGS)
*b;
/* make sure any unused bits are zeroed */
- dst = (inet *) palloc0(sizeof(inet));
+ dst = palloc0_object(inet);
maxbytes = ip_addrsize(ip);
bits = ip_bits(ip);
@@ -1271,7 +1271,7 @@ network_network(PG_FUNCTION_ARGS)
*b;
/* make sure any unused bits are zeroed */
- dst = (inet *) palloc0(sizeof(inet));
+ dst = palloc0_object(inet);
bits = ip_bits(ip);
a = ip_addr(ip);
@@ -1314,7 +1314,7 @@ network_netmask(PG_FUNCTION_ARGS)
unsigned char *b;
/* make sure any unused bits are zeroed */
- dst = (inet *) palloc0(sizeof(inet));
+ dst = palloc0_object(inet);
bits = ip_bits(ip);
b = ip_addr(dst);
@@ -1357,7 +1357,7 @@ network_hostmask(PG_FUNCTION_ARGS)
unsigned char *b;
/* make sure any unused bits are zeroed */
- dst = (inet *) palloc0(sizeof(inet));
+ dst = palloc0_object(inet);
maxbytes = ip_addrsize(ip);
bits = ip_maxbits(ip) - ip_bits(ip);
@@ -1792,7 +1792,7 @@ inetnot(PG_FUNCTION_ARGS)
inet *ip = PG_GETARG_INET_PP(0);
inet *dst;
- dst = (inet *) palloc0(sizeof(inet));
+ dst = palloc0_object(inet);
{
int nb = ip_addrsize(ip);
@@ -1818,7 +1818,7 @@ inetand(PG_FUNCTION_ARGS)
inet *ip2 = PG_GETARG_INET_PP(1);
inet *dst;
- dst = (inet *) palloc0(sizeof(inet));
+ dst = palloc0_object(inet);
if (ip_family(ip) != ip_family(ip2))
ereport(ERROR,
@@ -1850,7 +1850,7 @@ inetor(PG_FUNCTION_ARGS)
inet *ip2 = PG_GETARG_INET_PP(1);
inet *dst;
- dst = (inet *) palloc0(sizeof(inet));
+ dst = palloc0_object(inet);
if (ip_family(ip) != ip_family(ip2))
ereport(ERROR,
@@ -1880,7 +1880,7 @@ internal_inetpl(inet *ip, int64 addend)
{
inet *dst;
- dst = (inet *) palloc0(sizeof(inet));
+ dst = palloc0_object(inet);
{
int nb = ip_addrsize(ip);
diff --git a/src/backend/utils/adt/network_gist.c b/src/backend/utils/adt/network_gist.c
index a08c4953789..30145f5985a 100644
--- a/src/backend/utils/adt/network_gist.c
+++ b/src/backend/utils/adt/network_gist.c
@@ -475,7 +475,7 @@ build_inet_union_key(int family, int minbits, int commonbits,
GistInetKey *result;
/* Make sure any unused bits are zeroed. */
- result = (GistInetKey *) palloc0(sizeof(GistInetKey));
+ result = palloc0_object(GistInetKey);
gk_ip_family(result) = family;
gk_ip_minbits(result) = minbits;
@@ -546,13 +546,13 @@ inet_gist_compress(PG_FUNCTION_ARGS)
if (entry->leafkey)
{
- retval = palloc(sizeof(GISTENTRY));
+ retval = palloc_object(GISTENTRY);
if (DatumGetPointer(entry->key) != NULL)
{
inet *in = DatumGetInetPP(entry->key);
GistInetKey *r;
- r = (GistInetKey *) palloc0(sizeof(GistInetKey));
+ r = palloc0_object(GistInetKey);
gk_ip_family(r) = ip_family(in);
gk_ip_minbits(r) = ip_bits(in);
@@ -594,14 +594,14 @@ inet_gist_fetch(PG_FUNCTION_ARGS)
GISTENTRY *retval;
inet *dst;
- dst = (inet *) palloc0(sizeof(inet));
+ dst = palloc0_object(inet);
ip_family(dst) = gk_ip_family(key);
ip_bits(dst) = gk_ip_minbits(key);
memcpy(ip_addr(dst), gk_ip_addr(key), ip_addrsize(dst));
SET_INET_VARSIZE(dst);
- retval = palloc(sizeof(GISTENTRY));
+ retval = palloc_object(GISTENTRY);
gistentryinit(*retval, InetPGetDatum(dst), entry->rel, entry->page,
entry->offset, false);
diff --git a/src/backend/utils/adt/network_spgist.c b/src/backend/utils/adt/network_spgist.c
index a84747d9275..9bdacca5abd 100644
--- a/src/backend/utils/adt/network_spgist.c
+++ b/src/backend/utils/adt/network_spgist.c
@@ -196,8 +196,8 @@ inet_spg_picksplit(PG_FUNCTION_ARGS)
/* Don't need labels; allocate output arrays */
out->nodeLabels = NULL;
- out->mapTuplesToNodes = (int *) palloc(sizeof(int) * in->nTuples);
- out->leafTupleDatums = (Datum *) palloc(sizeof(Datum) * in->nTuples);
+ out->mapTuplesToNodes = palloc_array(int, in->nTuples);
+ out->leafTupleDatums = palloc_array(Datum, in->nTuples);
if (differentFamilies)
{
@@ -301,7 +301,7 @@ inet_spg_inner_consistent(PG_FUNCTION_ARGS)
if (which)
{
- out->nodeNumbers = (int *) palloc(sizeof(int) * in->nNodes);
+ out->nodeNumbers = palloc_array(int, in->nNodes);
for (i = 0; i < in->nNodes; i++)
{
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index 1d626aecbe7..2460698df01 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -1759,8 +1759,7 @@ generate_series_step_numeric(PG_FUNCTION_ARGS)
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
/* allocate memory for user context */
- fctx = (generate_series_numeric_fctx *)
- palloc(sizeof(generate_series_numeric_fctx));
+ fctx = palloc_object(generate_series_numeric_fctx);
/*
* Use fctx to keep state from call to call. Seed current with the
@@ -2117,7 +2116,7 @@ numeric_sortsupport(PG_FUNCTION_ARGS)
NumericSortSupport *nss;
MemoryContext oldcontext = MemoryContextSwitchTo(ssup->ssup_cxt);
- nss = palloc(sizeof(NumericSortSupport));
+ nss = palloc_object(NumericSortSupport);
/*
* palloc a buffer for handling unaligned packed values in addition to
@@ -4754,7 +4753,7 @@ makeNumericAggState(FunctionCallInfo fcinfo, bool calcSumX2)
old_context = MemoryContextSwitchTo(agg_context);
- state = (NumericAggState *) palloc0(sizeof(NumericAggState));
+ state = palloc0_object(NumericAggState);
state->calcSumX2 = calcSumX2;
state->agg_context = agg_context;
@@ -4772,7 +4771,7 @@ makeNumericAggStateCurrentContext(bool calcSumX2)
{
NumericAggState *state;
- state = (NumericAggState *) palloc0(sizeof(NumericAggState));
+ state = palloc0_object(NumericAggState);
state->calcSumX2 = calcSumX2;
state->agg_context = CurrentMemoryContext;
@@ -5418,7 +5417,7 @@ makeInt128AggState(FunctionCallInfo fcinfo, bool calcSumX2)
old_context = MemoryContextSwitchTo(agg_context);
- state = (Int128AggState *) palloc0(sizeof(Int128AggState));
+ state = palloc0_object(Int128AggState);
state->calcSumX2 = calcSumX2;
MemoryContextSwitchTo(old_context);
@@ -5435,7 +5434,7 @@ makeInt128AggStateCurrentContext(bool calcSumX2)
{
Int128AggState *state;
- state = (Int128AggState *) palloc0(sizeof(Int128AggState));
+ state = palloc0_object(Int128AggState);
state->calcSumX2 = calcSumX2;
return state;
diff --git a/src/backend/utils/adt/orderedsetaggs.c b/src/backend/utils/adt/orderedsetaggs.c
index 2121cc05f28..ac3963fc3e0 100644
--- a/src/backend/utils/adt/orderedsetaggs.c
+++ b/src/backend/utils/adt/orderedsetaggs.c
@@ -153,7 +153,7 @@ ordered_set_startup(FunctionCallInfo fcinfo, bool use_tuples)
qcontext = fcinfo->flinfo->fn_mcxt;
oldcontext = MemoryContextSwitchTo(qcontext);
- qstate = (OSAPerQueryState *) palloc0(sizeof(OSAPerQueryState));
+ qstate = palloc0_object(OSAPerQueryState);
qstate->aggref = aggref;
qstate->qcontext = qcontext;
@@ -278,7 +278,7 @@ ordered_set_startup(FunctionCallInfo fcinfo, bool use_tuples)
/* Now build the stuff we need in group-lifespan context */
oldcontext = MemoryContextSwitchTo(gcontext);
- osastate = (OSAPerGroupState *) palloc(sizeof(OSAPerGroupState));
+ osastate = palloc_object(OSAPerGroupState);
osastate->qstate = qstate;
osastate->gcontext = gcontext;
diff --git a/src/backend/utils/adt/pg_locale_libc.c b/src/backend/utils/adt/pg_locale_libc.c
index 6ad3f93b543..b125b5da3a6 100644
--- a/src/backend/utils/adt/pg_locale_libc.c
+++ b/src/backend/utils/adt/pg_locale_libc.c
@@ -486,7 +486,7 @@ strlower_libc_mb(char *dest, size_t destsize, const char *src, ssize_t srclen,
errmsg("out of memory")));
/* Output workspace cannot have more codes than input bytes */
- workspace = (wchar_t *) palloc((srclen + 1) * sizeof(wchar_t));
+ workspace = palloc_array(wchar_t, srclen + 1);
char2wchar(workspace, srclen + 1, src, srclen, loc);
@@ -591,7 +591,7 @@ strtitle_libc_mb(char *dest, size_t destsize, const char *src, ssize_t srclen,
errmsg("out of memory")));
/* Output workspace cannot have more codes than input bytes */
- workspace = (wchar_t *) palloc((srclen + 1) * sizeof(wchar_t));
+ workspace = palloc_array(wchar_t, srclen + 1);
char2wchar(workspace, srclen + 1, src, srclen, loc);
@@ -684,7 +684,7 @@ strupper_libc_mb(char *dest, size_t destsize, const char *src, ssize_t srclen,
errmsg("out of memory")));
/* Output workspace cannot have more codes than input bytes */
- workspace = (wchar_t *) palloc((srclen + 1) * sizeof(wchar_t));
+ workspace = palloc_array(wchar_t, srclen + 1);
char2wchar(workspace, srclen + 1, src, srclen, loc);
diff --git a/src/backend/utils/adt/pg_ndistinct.c b/src/backend/utils/adt/pg_ndistinct.c
index 34e35aa7026..8ff4353c4e7 100644
--- a/src/backend/utils/adt/pg_ndistinct.c
+++ b/src/backend/utils/adt/pg_ndistinct.c
@@ -175,7 +175,7 @@ ndistinct_object_end(void *state)
}
/* Create the MVNDistinctItem */
- item = palloc(sizeof(MVNDistinctItem));
+ item = palloc_object(MVNDistinctItem);
item->nattributes = natts;
item->attributes = palloc0(natts * sizeof(AttrNumber));
item->ndistinct = (double) parse->ndistinct;
diff --git a/src/backend/utils/adt/rangetypes.c b/src/backend/utils/adt/rangetypes.c
index d8e5130d642..0c454b136e2 100644
--- a/src/backend/utils/adt/rangetypes.c
+++ b/src/backend/utils/adt/rangetypes.c
@@ -1258,7 +1258,7 @@ range_minus_multi(PG_FUNCTION_ARGS)
elog(ERROR, "range types do not match");
/* allocate memory for user context */
- fctx = (struct range_minus_multi_fctx *) palloc(sizeof(struct range_minus_multi_fctx));
+ fctx = palloc_object(struct range_minus_multi_fctx);
/*
* Initialize state. We can't store the range typcache in fn_extra
diff --git a/src/backend/utils/adt/rangetypes_gist.c b/src/backend/utils/adt/rangetypes_gist.c
index a60ee985e74..33c705e6a87 100644
--- a/src/backend/utils/adt/rangetypes_gist.c
+++ b/src/backend/utils/adt/rangetypes_gist.c
@@ -251,7 +251,7 @@ multirange_gist_compress(PG_FUNCTION_ARGS)
MultirangeType *mr = DatumGetMultirangeTypeP(entry->key);
RangeType *r;
TypeCacheEntry *typcache;
- GISTENTRY *retval = palloc(sizeof(GISTENTRY));
+ GISTENTRY *retval = palloc_object(GISTENTRY);
typcache = multirange_get_typcache(fcinfo, MultirangeTypeGetOid(mr));
r = multirange_get_union_range(typcache->rngtype, mr);
@@ -1240,8 +1240,7 @@ range_gist_single_sorting_split(TypeCacheEntry *typcache,
maxoff = entryvec->n - 1;
- sortItems = (SingleBoundSortItem *)
- palloc(maxoff * sizeof(SingleBoundSortItem));
+ sortItems = palloc_array(SingleBoundSortItem, maxoff);
/*
* Prepare auxiliary array and sort the values.
@@ -1343,8 +1342,8 @@ range_gist_double_sorting_split(TypeCacheEntry *typcache,
context.first = true;
/* Allocate arrays for sorted range bounds */
- by_lower = (NonEmptyRange *) palloc(nentries * sizeof(NonEmptyRange));
- by_upper = (NonEmptyRange *) palloc(nentries * sizeof(NonEmptyRange));
+ by_lower = palloc_array(NonEmptyRange, nentries);
+ by_upper = palloc_array(NonEmptyRange, nentries);
/* Fill arrays of bounds */
for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
@@ -1499,8 +1498,8 @@ range_gist_double_sorting_split(TypeCacheEntry *typcache,
*/
/* Allocate vectors for results */
- v->spl_left = (OffsetNumber *) palloc(nentries * sizeof(OffsetNumber));
- v->spl_right = (OffsetNumber *) palloc(nentries * sizeof(OffsetNumber));
+ v->spl_left = palloc_array(OffsetNumber, nentries);
+ v->spl_right = palloc_array(OffsetNumber, nentries);
v->spl_nleft = 0;
v->spl_nright = 0;
@@ -1509,7 +1508,7 @@ range_gist_double_sorting_split(TypeCacheEntry *typcache,
* either group without affecting overlap along selected axis.
*/
common_entries_count = 0;
- common_entries = (CommonEntry *) palloc(nentries * sizeof(CommonEntry));
+ common_entries = palloc_array(CommonEntry, nentries);
/*
* Distribute entries which can be distributed unambiguously, and collect
diff --git a/src/backend/utils/adt/rangetypes_selfuncs.c b/src/backend/utils/adt/rangetypes_selfuncs.c
index d85252cafb2..27d736a40e5 100644
--- a/src/backend/utils/adt/rangetypes_selfuncs.c
+++ b/src/backend/utils/adt/rangetypes_selfuncs.c
@@ -412,8 +412,8 @@ calc_hist_selectivity(TypeCacheEntry *typcache, VariableStatData *vardata,
* bounds.
*/
nhist = hslot.nvalues;
- hist_lower = (RangeBound *) palloc(sizeof(RangeBound) * nhist);
- hist_upper = (RangeBound *) palloc(sizeof(RangeBound) * nhist);
+ hist_lower = palloc_array(RangeBound, nhist);
+ hist_upper = palloc_array(RangeBound, nhist);
for (i = 0; i < nhist; i++)
{
range_deserialize(typcache, DatumGetRangeTypeP(hslot.values[i]),
diff --git a/src/backend/utils/adt/rangetypes_spgist.c b/src/backend/utils/adt/rangetypes_spgist.c
index be519654880..14e5d6065f8 100644
--- a/src/backend/utils/adt/rangetypes_spgist.c
+++ b/src/backend/utils/adt/rangetypes_spgist.c
@@ -216,8 +216,8 @@ spg_range_quad_picksplit(PG_FUNCTION_ARGS)
RangeTypeGetOid(DatumGetRangeTypeP(in->datums[0])));
/* Allocate memory for bounds */
- lowerBounds = palloc(sizeof(RangeBound) * in->nTuples);
- upperBounds = palloc(sizeof(RangeBound) * in->nTuples);
+ lowerBounds = palloc_array(RangeBound, in->nTuples);
+ upperBounds = palloc_array(RangeBound, in->nTuples);
j = 0;
/* Deserialize bounds of ranges, count non-empty ranges */
@@ -243,8 +243,8 @@ spg_range_quad_picksplit(PG_FUNCTION_ARGS)
out->prefixDatum = PointerGetDatum(NULL);
out->nodeLabels = NULL;
- out->mapTuplesToNodes = palloc(sizeof(int) * in->nTuples);
- out->leafTupleDatums = palloc(sizeof(Datum) * in->nTuples);
+ out->mapTuplesToNodes = palloc_array(int, in->nTuples);
+ out->leafTupleDatums = palloc_array(Datum, in->nTuples);
/* Place all ranges into node 0 */
for (i = 0; i < in->nTuples; i++)
@@ -273,8 +273,8 @@ spg_range_quad_picksplit(PG_FUNCTION_ARGS)
out->nNodes = (in->level == 0) ? 5 : 4;
out->nodeLabels = NULL; /* we don't need node labels */
- out->mapTuplesToNodes = palloc(sizeof(int) * in->nTuples);
- out->leafTupleDatums = palloc(sizeof(Datum) * in->nTuples);
+ out->mapTuplesToNodes = palloc_array(int, in->nTuples);
+ out->leafTupleDatums = palloc_array(Datum, in->nTuples);
/*
* Assign ranges to corresponding nodes according to quadrants relative to
@@ -316,7 +316,7 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS)
{
/* Report that all nodes should be visited */
out->nNodes = in->nNodes;
- out->nodeNumbers = (int *) palloc(sizeof(int) * in->nNodes);
+ out->nodeNumbers = palloc_array(int, in->nNodes);
for (i = 0; i < in->nNodes; i++)
out->nodeNumbers[i] = i;
PG_RETURN_VOID();
@@ -732,9 +732,9 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS)
}
/* We must descend into the quadrant(s) identified by 'which' */
- out->nodeNumbers = (int *) palloc(sizeof(int) * in->nNodes);
+ out->nodeNumbers = palloc_array(int, in->nNodes);
if (needPrevious)
- out->traversalValues = (void **) palloc(sizeof(void *) * in->nNodes);
+ out->traversalValues = palloc_array(void *, in->nNodes);
out->nNodes = 0;
/*
diff --git a/src/backend/utils/adt/rangetypes_typanalyze.c b/src/backend/utils/adt/rangetypes_typanalyze.c
index 36e885af2dd..45ea6cbc780 100644
--- a/src/backend/utils/adt/rangetypes_typanalyze.c
+++ b/src/backend/utils/adt/rangetypes_typanalyze.c
@@ -151,9 +151,9 @@ compute_range_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
has_subdiff = OidIsValid(typcache->rng_subdiff_finfo.fn_oid);
/* Allocate memory to hold range bounds and lengths of the sample ranges. */
- lowers = (RangeBound *) palloc(sizeof(RangeBound) * samplerows);
- uppers = (RangeBound *) palloc(sizeof(RangeBound) * samplerows);
- lengths = (float8 *) palloc(sizeof(float8) * samplerows);
+ lowers = palloc_array(RangeBound, samplerows);
+ uppers = palloc_array(RangeBound, samplerows);
+ lengths = palloc_array(float8, samplerows);
/* Loop over the sample ranges. */
for (range_no = 0; range_no < samplerows; range_no++)
@@ -401,7 +401,7 @@ compute_range_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
stats->statypalign[slot_idx] = 'd';
/* Store the fraction of empty ranges */
- emptyfrac = (float4 *) palloc(sizeof(float4));
+ emptyfrac = palloc_object(float4);
*emptyfrac = ((double) empty_cnt) / ((double) non_null_cnt);
stats->stanumbers[slot_idx] = emptyfrac;
stats->numnumbers[slot_idx] = 1;
diff --git a/src/backend/utils/adt/regexp.c b/src/backend/utils/adt/regexp.c
index b0cdef9b19f..6542e8c1df0 100644
--- a/src/backend/utils/adt/regexp.c
+++ b/src/backend/utils/adt/regexp.c
@@ -189,7 +189,7 @@ RE_compile_and_cache(text *text_re, int cflags, Oid collation)
*/
/* Convert pattern string to wide characters */
- pattern = (pg_wchar *) palloc((text_re_len + 1) * sizeof(pg_wchar));
+ pattern = palloc_array(pg_wchar, text_re_len + 1);
pattern_len = pg_mb2wchar_with_len(text_re_val,
pattern,
text_re_len);
@@ -329,7 +329,7 @@ RE_execute(regex_t *re, char *dat, int dat_len,
bool match;
/* Convert data string to wide characters */
- data = (pg_wchar *) palloc((dat_len + 1) * sizeof(pg_wchar));
+ data = palloc_array(pg_wchar, dat_len + 1);
data_len = pg_mb2wchar_with_len(dat, data, dat_len);
/* Perform RE match and return result */
@@ -1389,8 +1389,8 @@ regexp_match(PG_FUNCTION_ARGS)
Assert(matchctx->nmatches == 1);
/* Create workspace that build_regexp_match_result needs */
- matchctx->elems = (Datum *) palloc(sizeof(Datum) * matchctx->npatterns);
- matchctx->nulls = (bool *) palloc(sizeof(bool) * matchctx->npatterns);
+ matchctx->elems = palloc_array(Datum, matchctx->npatterns);
+ matchctx->nulls = palloc_array(bool, matchctx->npatterns);
PG_RETURN_DATUM(PointerGetDatum(build_regexp_match_result(matchctx)));
}
@@ -1432,8 +1432,8 @@ regexp_matches(PG_FUNCTION_ARGS)
true, false, false);
/* Pre-create workspace that build_regexp_match_result needs */
- matchctx->elems = (Datum *) palloc(sizeof(Datum) * matchctx->npatterns);
- matchctx->nulls = (bool *) palloc(sizeof(bool) * matchctx->npatterns);
+ matchctx->elems = palloc_array(Datum, matchctx->npatterns);
+ matchctx->nulls = palloc_array(bool, matchctx->npatterns);
MemoryContextSwitchTo(oldcontext);
funcctx->user_fctx = matchctx;
@@ -1489,7 +1489,7 @@ setup_regexp_matches(text *orig_str, text *pattern, pg_re_flags *re_flags,
bool ignore_degenerate,
bool fetching_unmatched)
{
- regexp_matches_ctx *matchctx = palloc0(sizeof(regexp_matches_ctx));
+ regexp_matches_ctx *matchctx = palloc0_object(regexp_matches_ctx);
int eml = pg_database_encoding_max_length();
int orig_len;
pg_wchar *wide_str;
@@ -1509,7 +1509,7 @@ setup_regexp_matches(text *orig_str, text *pattern, pg_re_flags *re_flags,
/* convert string to pg_wchar form for matching */
orig_len = VARSIZE_ANY_EXHDR(orig_str);
- wide_str = (pg_wchar *) palloc(sizeof(pg_wchar) * (orig_len + 1));
+ wide_str = palloc_array(pg_wchar, orig_len + 1);
wide_len = pg_mb2wchar_with_len(VARDATA_ANY(orig_str), wide_str, orig_len);
/* set up the compiled pattern */
@@ -1532,7 +1532,7 @@ setup_regexp_matches(text *orig_str, text *pattern, pg_re_flags *re_flags,
}
/* temporary output space for RE package */
- pmatch = palloc(sizeof(regmatch_t) * pmatch_len);
+ pmatch = palloc_array(regmatch_t, pmatch_len);
/*
* the real output space (grown dynamically if needed)
@@ -1541,7 +1541,7 @@ setup_regexp_matches(text *orig_str, text *pattern, pg_re_flags *re_flags,
* than at 2^27
*/
array_len = re_flags->glob ? 255 : 31;
- matchctx->match_locs = (int *) palloc(sizeof(int) * array_len);
+ matchctx->match_locs = palloc_array(int, array_len);
array_idx = 0;
/* search for the pattern, perhaps repeatedly */
diff --git a/src/backend/utils/adt/rowtypes.c b/src/backend/utils/adt/rowtypes.c
index 38e6fe1c43a..7220995ce21 100644
--- a/src/backend/utils/adt/rowtypes.c
+++ b/src/backend/utils/adt/rowtypes.c
@@ -140,8 +140,8 @@ record_in(PG_FUNCTION_ARGS)
my_extra->ncolumns = ncolumns;
}
- values = (Datum *) palloc(ncolumns * sizeof(Datum));
- nulls = (bool *) palloc(ncolumns * sizeof(bool));
+ values = palloc_array(Datum, ncolumns);
+ nulls = palloc_array(bool, ncolumns);
/*
* Scan the string. We use "buf" to accumulate the de-quoted data for
@@ -383,8 +383,8 @@ record_out(PG_FUNCTION_ARGS)
my_extra->ncolumns = ncolumns;
}
- values = (Datum *) palloc(ncolumns * sizeof(Datum));
- nulls = (bool *) palloc(ncolumns * sizeof(bool));
+ values = palloc_array(Datum, ncolumns);
+ nulls = palloc_array(bool, ncolumns);
/* Break down the tuple into fields */
heap_deform_tuple(&tuple, tupdesc, values, nulls);
@@ -539,8 +539,8 @@ record_recv(PG_FUNCTION_ARGS)
my_extra->ncolumns = ncolumns;
}
- values = (Datum *) palloc(ncolumns * sizeof(Datum));
- nulls = (bool *) palloc(ncolumns * sizeof(bool));
+ values = palloc_array(Datum, ncolumns);
+ nulls = palloc_array(bool, ncolumns);
/* Fetch number of columns user thinks it has */
usercols = pq_getmsgint(buf, 4);
@@ -741,8 +741,8 @@ record_send(PG_FUNCTION_ARGS)
my_extra->ncolumns = ncolumns;
}
- values = (Datum *) palloc(ncolumns * sizeof(Datum));
- nulls = (bool *) palloc(ncolumns * sizeof(bool));
+ values = palloc_array(Datum, ncolumns);
+ nulls = palloc_array(bool, ncolumns);
/* Break down the tuple into fields */
heap_deform_tuple(&tuple, tupdesc, values, nulls);
@@ -1863,8 +1863,8 @@ hash_record(PG_FUNCTION_ARGS)
}
/* Break down the tuple into fields */
- values = (Datum *) palloc(ncolumns * sizeof(Datum));
- nulls = (bool *) palloc(ncolumns * sizeof(bool));
+ values = palloc_array(Datum, ncolumns);
+ nulls = palloc_array(bool, ncolumns);
heap_deform_tuple(&tuple, tupdesc, values, nulls);
for (int i = 0; i < ncolumns; i++)
@@ -1984,8 +1984,8 @@ hash_record_extended(PG_FUNCTION_ARGS)
}
/* Break down the tuple into fields */
- values = (Datum *) palloc(ncolumns * sizeof(Datum));
- nulls = (bool *) palloc(ncolumns * sizeof(bool));
+ values = palloc_array(Datum, ncolumns);
+ nulls = palloc_array(bool, ncolumns);
heap_deform_tuple(&tuple, tupdesc, values, nulls);
for (int i = 0; i < ncolumns; i++)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6cf90be40bb..9f85eb86da1 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -3713,7 +3713,7 @@ deparse_context_for(const char *aliasname, Oid relid)
deparse_namespace *dpns;
RangeTblEntry *rte;
- dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
+ dpns = palloc0_object(deparse_namespace);
/* Build a minimal RTE for the rel */
rte = makeNode(RangeTblEntry);
@@ -3757,7 +3757,7 @@ deparse_context_for_plan_tree(PlannedStmt *pstmt, List *rtable_names)
{
deparse_namespace *dpns;
- dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
+ dpns = palloc0_object(deparse_namespace);
/* Initialize fields that stay the same across the whole plan tree */
dpns->rtable = pstmt->rtable;
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 540aa9628d7..c760b19db55 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -3683,7 +3683,7 @@ add_unique_group_var(PlannerInfo *root, List *varinfos,
}
}
- varinfo = (GroupVarInfo *) palloc(sizeof(GroupVarInfo));
+ varinfo = palloc_object(GroupVarInfo);
varinfo->var = var;
varinfo->rel = vardata->rel;
@@ -4264,7 +4264,7 @@ estimate_multivariate_bucketsize(PlannerInfo *root, RelOptInfo *inner,
* estimate_multivariate_ndistinct(), which doesn't care about
* ndistinct and isdefault fields. Thus, skip these fields.
*/
- varinfo = (GroupVarInfo *) palloc0(sizeof(GroupVarInfo));
+ varinfo = palloc0_object(GroupVarInfo);
varinfo->var = expr;
varinfo->rel = root->simple_rel_array[relid];
varinfos = lappend(varinfos, varinfo);
diff --git a/src/backend/utils/adt/skipsupport.c b/src/backend/utils/adt/skipsupport.c
index 2bd35d2d272..2fcf5782ec8 100644
--- a/src/backend/utils/adt/skipsupport.c
+++ b/src/backend/utils/adt/skipsupport.c
@@ -38,7 +38,7 @@ PrepareSkipSupportFromOpclass(Oid opfamily, Oid opcintype, bool reverse)
if (!OidIsValid(skipSupportFunction))
return NULL;
- sksup = palloc(sizeof(SkipSupportData));
+ sksup = palloc_object(SkipSupportData);
OidFunctionCall1(skipSupportFunction, PointerGetDatum(sksup));
if (reverse)
diff --git a/src/backend/utils/adt/tid.c b/src/backend/utils/adt/tid.c
index 0cfb0bd3735..435d40fee3e 100644
--- a/src/backend/utils/adt/tid.c
+++ b/src/backend/utils/adt/tid.c
@@ -104,7 +104,7 @@ tidin(PG_FUNCTION_ARGS)
"tid", str)));
offsetNumber = (OffsetNumber) cvt;
- result = (ItemPointer) palloc(sizeof(ItemPointerData));
+ result = (ItemPointer) palloc_object(ItemPointerData);
ItemPointerSet(result, blockNumber, offsetNumber);
@@ -146,7 +146,7 @@ tidrecv(PG_FUNCTION_ARGS)
blockNumber = pq_getmsgint(buf, sizeof(blockNumber));
offsetNumber = pq_getmsgint(buf, sizeof(offsetNumber));
- result = (ItemPointer) palloc(sizeof(ItemPointerData));
+ result = (ItemPointer) palloc_object(ItemPointerData);
ItemPointerSet(result, blockNumber, offsetNumber);
@@ -300,7 +300,7 @@ currtid_internal(Relation rel, const ItemPointerData *tid)
Snapshot snapshot;
TableScanDesc scan;
- result = (ItemPointer) palloc(sizeof(ItemPointerData));
+ result = (ItemPointer) palloc_object(ItemPointerData);
aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(),
ACL_SELECT);
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 2dc90a2b8a9..3569d201ee1 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -937,7 +937,7 @@ interval_in(PG_FUNCTION_ARGS)
PG_RETURN_NULL();
}
- result = (Interval *) palloc(sizeof(Interval));
+ result = palloc_object(Interval);
switch (dtype)
{
@@ -1004,7 +1004,7 @@ interval_recv(PG_FUNCTION_ARGS)
int32 typmod = PG_GETARG_INT32(2);
Interval *interval;
- interval = (Interval *) palloc(sizeof(Interval));
+ interval = palloc_object(Interval);
interval->time = pq_getmsgint64(buf);
interval->day = pq_getmsgint(buf, sizeof(interval->day));
@@ -1331,7 +1331,7 @@ interval_scale(PG_FUNCTION_ARGS)
int32 typmod = PG_GETARG_INT32(1);
Interval *result;
- result = palloc(sizeof(Interval));
+ result = palloc_object(Interval);
*result = *interval;
AdjustIntervalForTypmod(result, typmod, NULL);
@@ -1545,7 +1545,7 @@ make_interval(PG_FUNCTION_ARGS)
if (isinf(secs) || isnan(secs))
goto out_of_range;
- result = (Interval *) palloc(sizeof(Interval));
+ result = palloc_object(Interval);
/* years and months -> months */
if (pg_mul_s32_overflow(years, MONTHS_PER_YEAR, &result->month) ||
@@ -2830,7 +2830,7 @@ timestamp_mi(PG_FUNCTION_ARGS)
Timestamp dt2 = PG_GETARG_TIMESTAMP(1);
Interval *result;
- result = (Interval *) palloc(sizeof(Interval));
+ result = palloc_object(Interval);
/*
* Handle infinities.
@@ -2925,7 +2925,7 @@ interval_justify_interval(PG_FUNCTION_ARGS)
TimeOffset wholeday;
int32 wholemonth;
- result = (Interval *) palloc(sizeof(Interval));
+ result = palloc_object(Interval);
result->month = span->month;
result->day = span->day;
result->time = span->time;
@@ -3004,7 +3004,7 @@ interval_justify_hours(PG_FUNCTION_ARGS)
Interval *result;
TimeOffset wholeday;
- result = (Interval *) palloc(sizeof(Interval));
+ result = palloc_object(Interval);
result->month = span->month;
result->day = span->day;
result->time = span->time;
@@ -3046,7 +3046,7 @@ interval_justify_days(PG_FUNCTION_ARGS)
Interval *result;
int32 wholemonth;
- result = (Interval *) palloc(sizeof(Interval));
+ result = palloc_object(Interval);
result->month = span->month;
result->day = span->day;
result->time = span->time;
@@ -3448,7 +3448,7 @@ interval_um(PG_FUNCTION_ARGS)
Interval *interval = PG_GETARG_INTERVAL_P(0);
Interval *result;
- result = (Interval *) palloc(sizeof(Interval));
+ result = palloc_object(Interval);
interval_um_internal(interval, result);
PG_RETURN_INTERVAL_P(result);
@@ -3506,7 +3506,7 @@ interval_pl(PG_FUNCTION_ARGS)
Interval *span2 = PG_GETARG_INTERVAL_P(1);
Interval *result;
- result = (Interval *) palloc(sizeof(Interval));
+ result = palloc_object(Interval);
/*
* Handle infinities.
@@ -3562,7 +3562,7 @@ interval_mi(PG_FUNCTION_ARGS)
Interval *span2 = PG_GETARG_INTERVAL_P(1);
Interval *result;
- result = (Interval *) palloc(sizeof(Interval));
+ result = palloc_object(Interval);
/*
* Handle infinities.
@@ -3616,7 +3616,7 @@ interval_mul(PG_FUNCTION_ARGS)
orig_day = span->day;
Interval *result;
- result = (Interval *) palloc(sizeof(Interval));
+ result = palloc_object(Interval);
/*
* Handle NaN and infinities.
@@ -3746,7 +3746,7 @@ interval_div(PG_FUNCTION_ARGS)
orig_day = span->day;
Interval *result;
- result = (Interval *) palloc(sizeof(Interval));
+ result = palloc_object(Interval);
if (factor == 0.0)
ereport(ERROR,
@@ -3975,7 +3975,7 @@ makeIntervalAggState(FunctionCallInfo fcinfo)
old_context = MemoryContextSwitchTo(agg_context);
- state = (IntervalAggState *) palloc0(sizeof(IntervalAggState));
+ state = palloc0_object(IntervalAggState);
MemoryContextSwitchTo(old_context);
@@ -4162,7 +4162,7 @@ interval_avg_deserialize(PG_FUNCTION_ARGS)
initReadOnlyStringInfo(&buf, VARDATA_ANY(sstate),
VARSIZE_ANY_EXHDR(sstate));
- result = (IntervalAggState *) palloc0(sizeof(IntervalAggState));
+ result = palloc0_object(IntervalAggState);
/* N */
result->N = pq_getmsgint64(&buf);
@@ -4229,7 +4229,7 @@ interval_avg(PG_FUNCTION_ARGS)
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("interval out of range")));
- result = (Interval *) palloc(sizeof(Interval));
+ result = palloc_object(Interval);
if (state->pInfcount > 0)
INTERVAL_NOEND(result);
else
@@ -4266,7 +4266,7 @@ interval_sum(PG_FUNCTION_ARGS)
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("interval out of range")));
- result = (Interval *) palloc(sizeof(Interval));
+ result = palloc_object(Interval);
if (state->pInfcount > 0)
INTERVAL_NOEND(result);
@@ -4299,7 +4299,7 @@ timestamp_age(PG_FUNCTION_ARGS)
struct pg_tm tt2,
*tm2 = &tt2;
- result = (Interval *) palloc(sizeof(Interval));
+ result = palloc_object(Interval);
/*
* Handle infinities.
@@ -4447,7 +4447,7 @@ timestamptz_age(PG_FUNCTION_ARGS)
int tz1;
int tz2;
- result = (Interval *) palloc(sizeof(Interval));
+ result = palloc_object(Interval);
/*
* Handle infinities.
@@ -5120,7 +5120,7 @@ interval_trunc(PG_FUNCTION_ARGS)
struct pg_itm tt,
*tm = &tt;
- result = (Interval *) palloc(sizeof(Interval));
+ result = palloc_object(Interval);
lowunits = downcase_truncate_identifier(VARDATA_ANY(units),
VARSIZE_ANY_EXHDR(units),
@@ -6687,8 +6687,7 @@ generate_series_timestamp(PG_FUNCTION_ARGS)
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
/* allocate memory for user context */
- fctx = (generate_series_timestamp_fctx *)
- palloc(sizeof(generate_series_timestamp_fctx));
+ fctx = palloc_object(generate_series_timestamp_fctx);
/*
* Use fctx to keep state from call to call. Seed current with the
@@ -6772,8 +6771,7 @@ generate_series_timestamptz_internal(FunctionCallInfo fcinfo)
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
/* allocate memory for user context */
- fctx = (generate_series_timestamptz_fctx *)
- palloc(sizeof(generate_series_timestamptz_fctx));
+ fctx = palloc_object(generate_series_timestamptz_fctx);
/*
* Use fctx to keep state from call to call. Seed current with the
diff --git a/src/backend/utils/adt/tsginidx.c b/src/backend/utils/adt/tsginidx.c
index 2712fd89df0..24a1cbe89ed 100644
--- a/src/backend/utils/adt/tsginidx.c
+++ b/src/backend/utils/adt/tsginidx.c
@@ -73,7 +73,7 @@ gin_extract_tsvector(PG_FUNCTION_ARGS)
int i;
WordEntry *we = ARRPTR(vector);
- entries = (Datum *) palloc(sizeof(Datum) * vector->size);
+ entries = palloc_array(Datum, vector->size);
for (i = 0; i < vector->size; i++)
{
@@ -133,16 +133,16 @@ gin_extract_tsquery(PG_FUNCTION_ARGS)
}
*nentries = j;
- entries = (Datum *) palloc(sizeof(Datum) * j);
- partialmatch = *ptr_partialmatch = (bool *) palloc(sizeof(bool) * j);
+ entries = palloc_array(Datum, j);
+ partialmatch = *ptr_partialmatch = palloc_array(bool, j);
/*
* Make map to convert item's number to corresponding operand's (the
* same, entry's) number. Entry's number is used in check array in
* consistent method. We use the same map for each entry.
*/
- *extra_data = (Pointer *) palloc(sizeof(Pointer) * j);
- map_item_operand = (int *) palloc0(sizeof(int) * query->size);
+ *extra_data = palloc_array(Pointer, j);
+ map_item_operand = palloc0_array(int, query->size);
/* Now rescan the VAL items and fill in the arrays */
j = 0;
diff --git a/src/backend/utils/adt/tsgistidx.c b/src/backend/utils/adt/tsgistidx.c
index 935187b37c7..01e43f86214 100644
--- a/src/backend/utils/adt/tsgistidx.c
+++ b/src/backend/utils/adt/tsgistidx.c
@@ -212,7 +212,7 @@ gtsvector_compress(PG_FUNCTION_ARGS)
res = ressign;
}
- retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
+ retval = palloc_object(GISTENTRY);
gistentryinit(*retval, PointerGetDatum(res),
entry->rel, entry->page,
entry->offset, false);
@@ -231,7 +231,7 @@ gtsvector_compress(PG_FUNCTION_ARGS)
}
res = gtsvector_alloc(SIGNKEY | ALLISTRUE, siglen, sign);
- retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
+ retval = palloc_object(GISTENTRY);
gistentryinit(*retval, PointerGetDatum(res),
entry->rel, entry->page,
entry->offset, false);
@@ -251,7 +251,7 @@ gtsvector_decompress(PG_FUNCTION_ARGS)
if (key != (SignTSVector *) DatumGetPointer(entry->key))
{
- GISTENTRY *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
+ GISTENTRY *retval = palloc_object(GISTENTRY);
gistentryinit(*retval, PointerGetDatum(key),
entry->rel, entry->page,
@@ -641,7 +641,7 @@ gtsvector_picksplit(PG_FUNCTION_ARGS)
v->spl_left = (OffsetNumber *) palloc(nbytes);
v->spl_right = (OffsetNumber *) palloc(nbytes);
- cache = (CACHESIGN *) palloc(sizeof(CACHESIGN) * (maxoff + 2));
+ cache = palloc_array(CACHESIGN, maxoff + 2);
cache_sign = palloc(siglen * (maxoff + 2));
for (j = 0; j < maxoff + 2; j++)
@@ -688,7 +688,7 @@ gtsvector_picksplit(PG_FUNCTION_ARGS)
maxoff = OffsetNumberNext(maxoff);
fillcache(&cache[maxoff], GETENTRY(entryvec, maxoff), siglen);
/* sort before ... */
- costvector = (SPLITCOST *) palloc(sizeof(SPLITCOST) * maxoff);
+ costvector = palloc_array(SPLITCOST, maxoff);
for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j))
{
costvector[j - 1].pos = j;
diff --git a/src/backend/utils/adt/tsquery.c b/src/backend/utils/adt/tsquery.c
index 717de8073d5..a0c990fdfa0 100644
--- a/src/backend/utils/adt/tsquery.c
+++ b/src/backend/utils/adt/tsquery.c
@@ -534,7 +534,7 @@ pushOperator(TSQueryParserState state, int8 oper, int16 distance)
Assert(oper == OP_NOT || oper == OP_AND || oper == OP_OR || oper == OP_PHRASE);
- tmp = (QueryOperator *) palloc0(sizeof(QueryOperator));
+ tmp = palloc0_object(QueryOperator);
tmp->type = QI_OPR;
tmp->oper = oper;
tmp->distance = (oper == OP_PHRASE) ? distance : 0;
@@ -559,7 +559,7 @@ pushValue_internal(TSQueryParserState state, pg_crc32 valcrc, int distance, int
errmsg("operand is too long in tsquery: \"%s\"",
state->buffer)));
- tmp = (QueryOperand *) palloc0(sizeof(QueryOperand));
+ tmp = palloc0_object(QueryOperand);
tmp->type = QI_VAL;
tmp->weight = weight;
tmp->prefix = prefix;
@@ -617,7 +617,7 @@ pushStop(TSQueryParserState state)
{
QueryOperand *tmp;
- tmp = (QueryOperand *) palloc0(sizeof(QueryOperand));
+ tmp = palloc0_object(QueryOperand);
tmp->type = QI_VALSTOP;
state->polstr = lcons(tmp, state->polstr);
@@ -1101,7 +1101,7 @@ infix(INFIX *in, int parentPriority, bool rightPhraseOp)
nrm.curpol = in->curpol;
nrm.op = in->op;
nrm.buflen = 16;
- nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
+ nrm.cur = nrm.buf = palloc_array(char, nrm.buflen);
/* get right operand */
infix(&nrm, priority, (op == OP_PHRASE));
@@ -1157,7 +1157,7 @@ tsqueryout(PG_FUNCTION_ARGS)
}
nrm.curpol = GETQUERY(query);
nrm.buflen = 32;
- nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
+ nrm.cur = nrm.buf = palloc_array(char, nrm.buflen);
*(nrm.cur) = '\0';
nrm.op = GETOPERAND(query);
infix(&nrm, -1 /* lowest priority */ , false);
@@ -1385,7 +1385,7 @@ tsquerytree(PG_FUNCTION_ARGS)
{
nrm.curpol = q;
nrm.buflen = 32;
- nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
+ nrm.cur = nrm.buf = palloc_array(char, nrm.buflen);
*(nrm.cur) = '\0';
nrm.op = GETOPERAND(query);
infix(&nrm, -1, false);
diff --git a/src/backend/utils/adt/tsquery_cleanup.c b/src/backend/utils/adt/tsquery_cleanup.c
index 590d7c7989c..45de2da900c 100644
--- a/src/backend/utils/adt/tsquery_cleanup.c
+++ b/src/backend/utils/adt/tsquery_cleanup.c
@@ -32,7 +32,7 @@ typedef struct NODE
static NODE *
maketree(QueryItem *in)
{
- NODE *node = (NODE *) palloc(sizeof(NODE));
+ NODE *node = palloc_object(NODE);
/* since this function recurses, it could be driven to stack overflow. */
check_stack_depth();
diff --git a/src/backend/utils/adt/tsquery_gist.c b/src/backend/utils/adt/tsquery_gist.c
index f7f94c1c760..55fc93ebef5 100644
--- a/src/backend/utils/adt/tsquery_gist.c
+++ b/src/backend/utils/adt/tsquery_gist.c
@@ -33,7 +33,7 @@ gtsquery_compress(PG_FUNCTION_ARGS)
{
TSQuerySign sign;
- retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
+ retval = palloc_object(GISTENTRY);
sign = makeTSQuerySign(DatumGetTSQuery(entry->key));
gistentryinit(*retval, TSQuerySignGetDatum(sign),
@@ -213,7 +213,7 @@ gtsquery_picksplit(PG_FUNCTION_ARGS)
datum_r = GETENTRY(entryvec, seed_2);
maxoff = OffsetNumberNext(maxoff);
- costvector = (SPLITCOST *) palloc(sizeof(SPLITCOST) * maxoff);
+ costvector = palloc_array(SPLITCOST, maxoff);
for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j))
{
costvector[j - 1].pos = j;
diff --git a/src/backend/utils/adt/tsquery_op.c b/src/backend/utils/adt/tsquery_op.c
index bb77e923062..84bf070dff2 100644
--- a/src/backend/utils/adt/tsquery_op.c
+++ b/src/backend/utils/adt/tsquery_op.c
@@ -32,17 +32,17 @@ tsquery_numnode(PG_FUNCTION_ARGS)
static QTNode *
join_tsqueries(TSQuery a, TSQuery b, int8 operator, uint16 distance)
{
- QTNode *res = (QTNode *) palloc0(sizeof(QTNode));
+ QTNode *res = palloc0_object(QTNode);
res->flags |= QTN_NEEDFREE;
- res->valnode = (QueryItem *) palloc0(sizeof(QueryItem));
+ res->valnode = palloc0_object(QueryItem);
res->valnode->type = QI_OPR;
res->valnode->qoperator.oper = operator;
if (operator == OP_PHRASE)
res->valnode->qoperator.distance = distance;
- res->child = (QTNode **) palloc0(sizeof(QTNode *) * 2);
+ res->child = palloc0_array(QTNode *, 2);
res->child[0] = QT2QTN(GETQUERY(b), GETOPERAND(b));
res->child[1] = QT2QTN(GETQUERY(a), GETOPERAND(a));
res->nchild = 2;
@@ -165,15 +165,15 @@ tsquery_not(PG_FUNCTION_ARGS)
if (a->size == 0)
PG_RETURN_POINTER(a);
- res = (QTNode *) palloc0(sizeof(QTNode));
+ res = palloc0_object(QTNode);
res->flags |= QTN_NEEDFREE;
- res->valnode = (QueryItem *) palloc0(sizeof(QueryItem));
+ res->valnode = palloc0_object(QueryItem);
res->valnode->type = QI_OPR;
res->valnode->qoperator.oper = OP_NOT;
- res->child = (QTNode **) palloc0(sizeof(QTNode *));
+ res->child = palloc0_object(QTNode *);
res->child[0] = QT2QTN(GETQUERY(a), GETOPERAND(a));
res->nchild = 1;
@@ -272,7 +272,7 @@ collectTSQueryValues(TSQuery a, int *nvalues_p)
int nvalues = 0;
int i;
- values = (char **) palloc(sizeof(char *) * a->size);
+ values = palloc_array(char *, a->size);
for (i = 0; i < a->size; i++)
{
diff --git a/src/backend/utils/adt/tsquery_util.c b/src/backend/utils/adt/tsquery_util.c
index 1c24b041aa2..2ccfc9d3303 100644
--- a/src/backend/utils/adt/tsquery_util.c
+++ b/src/backend/utils/adt/tsquery_util.c
@@ -24,7 +24,7 @@
QTNode *
QT2QTN(QueryItem *in, char *operand)
{
- QTNode *node = (QTNode *) palloc0(sizeof(QTNode));
+ QTNode *node = palloc0_object(QTNode);
/* since this function recurses, it could be driven to stack overflow. */
check_stack_depth();
@@ -33,7 +33,7 @@ QT2QTN(QueryItem *in, char *operand)
if (in->type == QI_OPR)
{
- node->child = (QTNode **) palloc0(sizeof(QTNode *) * 2);
+ node->child = palloc0_array(QTNode *, 2);
node->child[0] = QT2QTN(in + 1, operand);
node->sign = node->child[0]->sign;
if (in->qoperator.oper == OP_NOT)
@@ -226,7 +226,7 @@ QTNTernary(QTNode *in)
int oldnchild = in->nchild;
in->nchild += cc->nchild - 1;
- in->child = (QTNode **) repalloc(in->child, in->nchild * sizeof(QTNode *));
+ in->child = repalloc_array(in->child, QTNode *, in->nchild);
if (i + 1 != oldnchild)
memmove(in->child + i + cc->nchild, in->child + i + 1,
@@ -262,10 +262,10 @@ QTNBinary(QTNode *in)
while (in->nchild > 2)
{
- QTNode *nn = (QTNode *) palloc0(sizeof(QTNode));
+ QTNode *nn = palloc0_object(QTNode);
- nn->valnode = (QueryItem *) palloc0(sizeof(QueryItem));
- nn->child = (QTNode **) palloc0(sizeof(QTNode *) * 2);
+ nn->valnode = palloc0_object(QueryItem);
+ nn->child = palloc0_array(QTNode *, 2);
nn->nchild = 2;
nn->flags = QTN_NEEDFREE;
@@ -400,10 +400,10 @@ QTNCopy(QTNode *in)
/* since this function recurses, it could be driven to stack overflow. */
check_stack_depth();
- out = (QTNode *) palloc(sizeof(QTNode));
+ out = palloc_object(QTNode);
*out = *in;
- out->valnode = (QueryItem *) palloc(sizeof(QueryItem));
+ out->valnode = palloc_object(QueryItem);
*(out->valnode) = *(in->valnode);
out->flags |= QTN_NEEDFREE;
@@ -418,7 +418,7 @@ QTNCopy(QTNode *in)
{
int i;
- out->child = (QTNode **) palloc(sizeof(QTNode *) * in->nchild);
+ out->child = palloc_array(QTNode *, in->nchild);
for (i = 0; i < in->nchild; i++)
out->child[i] = QTNCopy(in->child[i]);
diff --git a/src/backend/utils/adt/tsrank.c b/src/backend/utils/adt/tsrank.c
index e863aa58653..4a341848647 100644
--- a/src/backend/utils/adt/tsrank.c
+++ b/src/backend/utils/adt/tsrank.c
@@ -160,7 +160,7 @@ SortAndUniqItems(TSQuery q, int *size)
**ptr,
**prevptr;
- ptr = res = (QueryOperand **) palloc(sizeof(QueryOperand *) * *size);
+ ptr = res = palloc_array(QueryOperand *, *size);
/* Collect all operands from the tree to res */
while ((*size)--)
@@ -225,7 +225,7 @@ calc_rank_and(const float *w, TSVector t, TSQuery q)
pfree(item);
return calc_rank_or(w, t, q);
}
- pos = (WordEntryPosVector **) palloc0(sizeof(WordEntryPosVector *) * q->size);
+ pos = palloc0_array(WordEntryPosVector *, q->size);
/* A dummy WordEntryPos array to use when haspos is false */
posnull.npos = 1;
@@ -743,7 +743,7 @@ get_docrep(TSVector txt, QueryRepresentation *qr, int *doclen)
cur = 0;
DocRepresentation *doc;
- doc = (DocRepresentation *) palloc(sizeof(DocRepresentation) * len);
+ doc = palloc_array(DocRepresentation, len);
/*
* Iterate through query to make DocRepresentation for words and it's
@@ -815,7 +815,7 @@ get_docrep(TSVector txt, QueryRepresentation *qr, int *doclen)
* Join QueryItem per WordEntry and its position
*/
storage.pos = doc->pos;
- storage.data.query.items = palloc(sizeof(QueryItem *) * qr->query->size);
+ storage.data.query.items = palloc_array(QueryItem *, qr->query->size);
storage.data.query.items[0] = doc->data.map.item;
storage.data.query.nitem = 1;
@@ -832,7 +832,7 @@ get_docrep(TSVector txt, QueryRepresentation *qr, int *doclen)
*wptr = storage;
wptr++;
storage.pos = rptr->pos;
- storage.data.query.items = palloc(sizeof(QueryItem *) * qr->query->size);
+ storage.data.query.items = palloc_array(QueryItem *, qr->query->size);
storage.data.query.items[0] = rptr->data.map.item;
storage.data.query.nitem = 1;
}
@@ -878,8 +878,7 @@ calc_rank_cd(const float4 *arrdata, TSVector txt, TSQuery query, int method)
}
qr.query = query;
- qr.operandData = (QueryRepresentationOperand *)
- palloc0(sizeof(QueryRepresentationOperand) * query->size);
+ qr.operandData = palloc0_array(QueryRepresentationOperand, query->size);
doc = get_docrep(txt, &qr, &doclen);
if (!doc)
diff --git a/src/backend/utils/adt/tsvector.c b/src/backend/utils/adt/tsvector.c
index f568f1fce99..d00c6032087 100644
--- a/src/backend/utils/adt/tsvector.c
+++ b/src/backend/utils/adt/tsvector.c
@@ -202,8 +202,8 @@ tsvectorin(PG_FUNCTION_ARGS)
state = init_tsvector_parser(buf, 0, escontext);
arrlen = 64;
- arr = (WordEntryIN *) palloc(sizeof(WordEntryIN) * arrlen);
- cur = tmpbuf = (char *) palloc(buflen);
+ arr = palloc_array(WordEntryIN, arrlen);
+ cur = tmpbuf = palloc_array(char, buflen);
while (gettoken_tsvector(state, &token, &toklen, &pos, &poslen, NULL))
{
diff --git a/src/backend/utils/adt/tsvector_op.c b/src/backend/utils/adt/tsvector_op.c
index c752cbe5463..b809089ac5d 100644
--- a/src/backend/utils/adt/tsvector_op.c
+++ b/src/backend/utils/adt/tsvector_op.c
@@ -1212,7 +1212,7 @@ checkclass_str(CHKVAL *chkval, WordEntry *entry, QueryOperand *val,
/*
* Filter position information by weights
*/
- dptr = data->pos = palloc(sizeof(WordEntryPos) * posvec->npos);
+ dptr = data->pos = palloc_array(WordEntryPos, posvec->npos);
data->allocated = true;
/* Is there a position with a matching weight? */
@@ -1391,12 +1391,12 @@ checkcondition_str(void *checkval, QueryOperand *val, ExecPhraseData *data)
if (totalpos == 0)
{
totalpos = 256;
- allpos = palloc(sizeof(WordEntryPos) * totalpos);
+ allpos = palloc_array(WordEntryPos, totalpos);
}
else
{
totalpos *= 2;
- allpos = repalloc(allpos, sizeof(WordEntryPos) * totalpos);
+ allpos = repalloc_array(allpos, WordEntryPos, totalpos);
}
}
@@ -2456,7 +2456,7 @@ ts_setup_firstcall(FunctionCallInfo fcinfo, FuncCallContext *funcctx,
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
- stat->stack = palloc0(sizeof(StatEntry *) * (stat->maxdepth + 1));
+ stat->stack = palloc0_array(StatEntry *, stat->maxdepth + 1);
stat->stackpos = 0;
node = stat->root;
@@ -2839,7 +2839,7 @@ tsvector_update_trigger(PG_FUNCTION_ARGS, bool config_column)
prs.lenwords = 32;
prs.curwords = 0;
prs.pos = 0;
- prs.words = (ParsedWord *) palloc(sizeof(ParsedWord) * prs.lenwords);
+ prs.words = palloc_array(ParsedWord, prs.lenwords);
/* find all words in indexable column(s) */
for (i = 2; i < trigger->tgnargs; i++)
diff --git a/src/backend/utils/adt/tsvector_parser.c b/src/backend/utils/adt/tsvector_parser.c
index e1620d3ed1f..a1c374a04a4 100644
--- a/src/backend/utils/adt/tsvector_parser.c
+++ b/src/backend/utils/adt/tsvector_parser.c
@@ -58,7 +58,7 @@ init_tsvector_parser(char *input, int flags, Node *escontext)
{
TSVectorParseState state;
- state = (TSVectorParseState) palloc(sizeof(struct TSVectorParseStateData));
+ state = palloc_object(struct TSVectorParseStateData);
state->prsbuf = input;
state->bufstart = input;
state->len = 32;
@@ -322,13 +322,13 @@ gettoken_tsvector(TSVectorParseState state,
if (posalen == 0)
{
posalen = 4;
- pos = (WordEntryPos *) palloc(sizeof(WordEntryPos) * posalen);
+ pos = palloc_array(WordEntryPos, posalen);
npos = 0;
}
else if (npos + 1 >= posalen)
{
posalen *= 2;
- pos = (WordEntryPos *) repalloc(pos, sizeof(WordEntryPos) * posalen);
+ pos = repalloc_array(pos, WordEntryPos, posalen);
}
npos++;
WEP_SETPOS(pos[npos - 1], LIMITPOS(atoi(state->prsbuf)));
diff --git a/src/backend/utils/adt/uuid.c b/src/backend/utils/adt/uuid.c
index 5df35d7cacb..2bc915edc2e 100644
--- a/src/backend/utils/adt/uuid.c
+++ b/src/backend/utils/adt/uuid.c
@@ -80,7 +80,7 @@ uuid_in(PG_FUNCTION_ARGS)
char *uuid_str = PG_GETARG_CSTRING(0);
pg_uuid_t *uuid;
- uuid = (pg_uuid_t *) palloc(sizeof(*uuid));
+ uuid = palloc_object(pg_uuid_t);
string_to_uuid(uuid_str, uuid, fcinfo->context);
PG_RETURN_UUID_P(uuid);
}
@@ -288,7 +288,7 @@ uuid_sortsupport(PG_FUNCTION_ARGS)
oldcontext = MemoryContextSwitchTo(ssup->ssup_cxt);
- uss = palloc(sizeof(uuid_sortsupport_state));
+ uss = palloc_object(uuid_sortsupport_state);
uss->input_count = 0;
uss->estimating = true;
initHyperLogLog(&uss->abbr_card, 10);
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index f202b8df4e2..baa5b44ea8d 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -1703,7 +1703,7 @@ varstr_sortsupport(SortSupport ssup, Oid typid, Oid collid)
*/
if (abbreviate || !collate_c)
{
- sss = palloc(sizeof(VarStringSortSupport));
+ sss = palloc_object(VarStringSortSupport);
sss->buf1 = palloc(TEXTBUFLEN);
sss->buflen1 = TEXTBUFLEN;
sss->buf2 = palloc(TEXTBUFLEN);
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index 41e775570ec..c8ab9d61c68 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -1255,7 +1255,7 @@ pg_xml_init(PgXmlStrictness strictness)
pg_xml_init_library();
/* Create error handling context structure */
- errcxt = (PgXmlErrorContext *) palloc(sizeof(PgXmlErrorContext));
+ errcxt = palloc_object(PgXmlErrorContext);
errcxt->magic = ERRCXT_MAGIC;
errcxt->strictness = strictness;
errcxt->err_occurred = false;
@@ -4733,10 +4733,10 @@ XmlTableInitOpaque(TableFuncScanState *state, int natts)
XmlTableBuilderData *xtCxt;
PgXmlErrorContext *xmlerrcxt;
- xtCxt = palloc0(sizeof(XmlTableBuilderData));
+ xtCxt = palloc0_object(XmlTableBuilderData);
xtCxt->magic = XMLTABLE_CONTEXT_MAGIC;
xtCxt->natts = natts;
- xtCxt->xpathscomp = palloc0(sizeof(xmlXPathCompExprPtr) * natts);
+ xtCxt->xpathscomp = palloc0_array(xmlXPathCompExprPtr, natts);
xmlerrcxt = pg_xml_init(PG_XML_STRICTNESS_ALL);
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c
index 02ae7d5a831..84f1f80607e 100644
--- a/src/backend/utils/cache/catcache.c
+++ b/src/backend/utils/cache/catcache.c
@@ -920,7 +920,7 @@ InitCatCache(int id,
*/
if (CacheHdr == NULL)
{
- CacheHdr = (CatCacheHeader *) palloc(sizeof(CatCacheHeader));
+ CacheHdr = palloc_object(CatCacheHeader);
slist_init(&CacheHdr->ch_caches);
CacheHdr->ch_ntup = 0;
#ifdef CATCACHE_STATS
@@ -2243,7 +2243,7 @@ CatalogCacheCreateEntry(CatCache *cache, HeapTuple ntp, Datum *arguments,
{
/* Set up keys for a negative cache entry */
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
- ct = (CatCTup *) palloc(sizeof(CatCTup));
+ ct = palloc_object(CatCTup);
/*
* Store keys - they'll point into separately allocated memory if not
diff --git a/src/backend/utils/cache/evtcache.c b/src/backend/utils/cache/evtcache.c
index 76ba2db5390..7f8e246e804 100644
--- a/src/backend/utils/cache/evtcache.c
+++ b/src/backend/utils/cache/evtcache.c
@@ -172,7 +172,7 @@ BuildEventTriggerCache(void)
oldcontext = MemoryContextSwitchTo(EventTriggerCacheContext);
/* Allocate new cache item. */
- item = palloc0(sizeof(EventTriggerCacheItem));
+ item = palloc0_object(EventTriggerCacheItem);
item->fnoid = form->evtfoid;
item->enabled = form->evtenabled;
diff --git a/src/backend/utils/cache/inval.c b/src/backend/utils/cache/inval.c
index 06f736cab45..868f8f6188f 100644
--- a/src/backend/utils/cache/inval.c
+++ b/src/backend/utils/cache/inval.c
@@ -758,7 +758,7 @@ PrepareInplaceInvalidationState(void)
Assert(inplaceInvalInfo == NULL);
/* gone after WAL insertion CritSection ends, so use current context */
- myInfo = (InvalidationInfo *) palloc0(sizeof(InvalidationInfo));
+ myInfo = palloc0_object(InvalidationInfo);
/* Stash our messages past end of the transactional messages, if any. */
if (transInvalInfo != NULL)
diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c
index fa7cd7e06a7..5aa7a26d95c 100644
--- a/src/backend/utils/cache/lsyscache.c
+++ b/src/backend/utils/cache/lsyscache.c
@@ -702,8 +702,7 @@ get_op_index_interpretation(Oid opno)
if (cmptype == COMPARE_INVALID)
continue;
- thisresult = (OpIndexInterpretation *)
- palloc(sizeof(OpIndexInterpretation));
+ thisresult = palloc_object(OpIndexInterpretation);
thisresult->opfamily_id = op_form->amopfamily;
thisresult->cmptype = cmptype;
thisresult->oplefttype = op_form->amoplefttype;
@@ -748,8 +747,7 @@ get_op_index_interpretation(Oid opno)
continue;
/* OK, report it as COMPARE_NE */
- thisresult = (OpIndexInterpretation *)
- palloc(sizeof(OpIndexInterpretation));
+ thisresult = palloc_object(OpIndexInterpretation);
thisresult->opfamily_id = op_form->amopfamily;
thisresult->cmptype = COMPARE_NE;
thisresult->oplefttype = op_form->amoplefttype;
diff --git a/src/backend/utils/cache/partcache.c b/src/backend/utils/cache/partcache.c
index f5d7d70def0..67e88440038 100644
--- a/src/backend/utils/cache/partcache.c
+++ b/src/backend/utils/cache/partcache.c
@@ -167,18 +167,18 @@ RelationBuildPartitionKey(Relation relation)
/* Allocate assorted arrays in the partkeycxt, which we'll fill below */
oldcxt = MemoryContextSwitchTo(partkeycxt);
- key->partattrs = (AttrNumber *) palloc0(key->partnatts * sizeof(AttrNumber));
- key->partopfamily = (Oid *) palloc0(key->partnatts * sizeof(Oid));
- key->partopcintype = (Oid *) palloc0(key->partnatts * sizeof(Oid));
- key->partsupfunc = (FmgrInfo *) palloc0(key->partnatts * sizeof(FmgrInfo));
-
- key->partcollation = (Oid *) palloc0(key->partnatts * sizeof(Oid));
- key->parttypid = (Oid *) palloc0(key->partnatts * sizeof(Oid));
- key->parttypmod = (int32 *) palloc0(key->partnatts * sizeof(int32));
- key->parttyplen = (int16 *) palloc0(key->partnatts * sizeof(int16));
- key->parttypbyval = (bool *) palloc0(key->partnatts * sizeof(bool));
- key->parttypalign = (char *) palloc0(key->partnatts * sizeof(char));
- key->parttypcoll = (Oid *) palloc0(key->partnatts * sizeof(Oid));
+ key->partattrs = palloc0_array(AttrNumber, key->partnatts);
+ key->partopfamily = palloc0_array(Oid, key->partnatts);
+ key->partopcintype = palloc0_array(Oid, key->partnatts);
+ key->partsupfunc = palloc0_array(FmgrInfo, key->partnatts);
+
+ key->partcollation = palloc0_array(Oid, key->partnatts);
+ key->parttypid = palloc0_array(Oid, key->partnatts);
+ key->parttypmod = palloc0_array(int32, key->partnatts);
+ key->parttyplen = palloc0_array(int16, key->partnatts);
+ key->parttypbyval = palloc0_array(bool, key->partnatts);
+ key->parttypalign = palloc0_array(char, key->partnatts);
+ key->parttypcoll = palloc0_array(Oid, key->partnatts);
MemoryContextSwitchTo(oldcxt);
/* determine support function number to search for */
diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c
index 6661d2c6b73..45261caaf47 100644
--- a/src/backend/utils/cache/plancache.c
+++ b/src/backend/utils/cache/plancache.c
@@ -207,7 +207,7 @@ CreateCachedPlan(RawStmt *raw_parse_tree,
*/
oldcxt = MemoryContextSwitchTo(source_context);
- plansource = (CachedPlanSource *) palloc0(sizeof(CachedPlanSource));
+ plansource = palloc0_object(CachedPlanSource);
plansource->magic = CACHEDPLANSOURCE_MAGIC;
plansource->raw_parse_tree = copyObject(raw_parse_tree);
plansource->analyzed_parse_tree = NULL;
@@ -307,7 +307,7 @@ CreateOneShotCachedPlan(RawStmt *raw_parse_tree,
* Create and fill the CachedPlanSource struct within the caller's memory
* context. Most fields are just left empty for the moment.
*/
- plansource = (CachedPlanSource *) palloc0(sizeof(CachedPlanSource));
+ plansource = palloc0_object(CachedPlanSource);
plansource->magic = CACHEDPLANSOURCE_MAGIC;
plansource->raw_parse_tree = raw_parse_tree;
plansource->analyzed_parse_tree = NULL;
@@ -469,7 +469,7 @@ CompleteCachedPlan(CachedPlanSource *plansource,
if (num_params > 0)
{
- plansource->param_types = (Oid *) palloc(num_params * sizeof(Oid));
+ plansource->param_types = palloc_array(Oid, num_params);
memcpy(plansource->param_types, param_types, num_params * sizeof(Oid));
}
else
@@ -1119,7 +1119,7 @@ BuildCachedPlan(CachedPlanSource *plansource, List *qlist,
/*
* Create and fill the CachedPlan struct within the new context.
*/
- plan = (CachedPlan *) palloc(sizeof(CachedPlan));
+ plan = palloc_object(CachedPlan);
plan->magic = CACHEDPLAN_MAGIC;
plan->stmt_list = plist;
@@ -1691,7 +1691,7 @@ CopyCachedPlan(CachedPlanSource *plansource)
oldcxt = MemoryContextSwitchTo(source_context);
- newsource = (CachedPlanSource *) palloc0(sizeof(CachedPlanSource));
+ newsource = palloc0_object(CachedPlanSource);
newsource->magic = CACHEDPLANSOURCE_MAGIC;
newsource->raw_parse_tree = copyObject(plansource->raw_parse_tree);
newsource->analyzed_parse_tree = copyObject(plansource->analyzed_parse_tree);
@@ -1700,8 +1700,7 @@ CopyCachedPlan(CachedPlanSource *plansource)
newsource->commandTag = plansource->commandTag;
if (plansource->num_params > 0)
{
- newsource->param_types = (Oid *)
- palloc(plansource->num_params * sizeof(Oid));
+ newsource->param_types = palloc_array(Oid, plansource->num_params);
memcpy(newsource->param_types, plansource->param_types,
plansource->num_params * sizeof(Oid));
}
@@ -1840,7 +1839,7 @@ GetCachedExpression(Node *expr)
oldcxt = MemoryContextSwitchTo(cexpr_context);
- cexpr = (CachedExpression *) palloc(sizeof(CachedExpression));
+ cexpr = palloc_object(CachedExpression);
cexpr->magic = CACHEDEXPR_MAGIC;
cexpr->expr = copyObject(expr);
cexpr->is_valid = true;
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 915d0bc9084..a4dc1cbe5ae 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -422,7 +422,7 @@ AllocateRelationDesc(Form_pg_class relp)
/*
* allocate and zero space for new relation descriptor
*/
- relation = (Relation) palloc0(sizeof(RelationData));
+ relation = palloc0_object(RelationData);
/* make sure relation is marked as having no open file yet */
relation->rd_smgr = NULL;
@@ -1902,7 +1902,7 @@ formrdesc(const char *relationName, Oid relationReltype,
/*
* allocate new relation desc, clear all fields of reldesc
*/
- relation = (Relation) palloc0(sizeof(RelationData));
+ relation = palloc0_object(RelationData);
/* make sure relation is marked as having no open file yet */
relation->rd_smgr = NULL;
@@ -1994,7 +1994,7 @@ formrdesc(const char *relationName, Oid relationReltype,
/* mark not-null status */
if (has_not_null)
{
- TupleConstr *constr = (TupleConstr *) palloc0(sizeof(TupleConstr));
+ TupleConstr *constr = palloc0_object(TupleConstr);
constr->has_not_null = true;
relation->rd_att->constr = constr;
@@ -3579,7 +3579,7 @@ RelationBuildLocalRelation(const char *relname,
/*
* allocate a new relation descriptor and fill in basic state fields.
*/
- rel = (Relation) palloc0(sizeof(RelationData));
+ rel = palloc0_object(RelationData);
/* make sure relation is marked as having no open file yet */
rel->rd_smgr = NULL;
@@ -3627,7 +3627,7 @@ RelationBuildLocalRelation(const char *relname,
if (has_not_null)
{
- TupleConstr *constr = (TupleConstr *) palloc0(sizeof(TupleConstr));
+ TupleConstr *constr = palloc0_object(TupleConstr);
constr->has_not_null = true;
rel->rd_att->constr = constr;
@@ -5670,9 +5670,9 @@ RelationGetExclusionInfo(Relation indexRelation,
indnkeyatts = IndexRelationGetNumberOfKeyAttributes(indexRelation);
/* Allocate result space in caller context */
- *operators = ops = (Oid *) palloc(sizeof(Oid) * indnkeyatts);
- *procs = funcs = (Oid *) palloc(sizeof(Oid) * indnkeyatts);
- *strategies = strats = (uint16 *) palloc(sizeof(uint16) * indnkeyatts);
+ *operators = ops = palloc_array(Oid, indnkeyatts);
+ *procs = funcs = palloc_array(Oid, indnkeyatts);
+ *strategies = strats = palloc_array(uint16, indnkeyatts);
/* Quick exit if we have the data cached already */
if (indexRelation->rd_exclstrats != NULL)
@@ -5763,9 +5763,9 @@ RelationGetExclusionInfo(Relation indexRelation,
/* Save a copy of the results in the relcache entry. */
oldcxt = MemoryContextSwitchTo(indexRelation->rd_indexcxt);
- indexRelation->rd_exclops = (Oid *) palloc(sizeof(Oid) * indnkeyatts);
- indexRelation->rd_exclprocs = (Oid *) palloc(sizeof(Oid) * indnkeyatts);
- indexRelation->rd_exclstrats = (uint16 *) palloc(sizeof(uint16) * indnkeyatts);
+ indexRelation->rd_exclops = palloc_array(Oid, indnkeyatts);
+ indexRelation->rd_exclprocs = palloc_array(Oid, indnkeyatts);
+ indexRelation->rd_exclstrats = palloc_array(uint16, indnkeyatts);
memcpy(indexRelation->rd_exclops, ops, sizeof(Oid) * indnkeyatts);
memcpy(indexRelation->rd_exclprocs, funcs, sizeof(Oid) * indnkeyatts);
memcpy(indexRelation->rd_exclstrats, strats, sizeof(uint16) * indnkeyatts);
@@ -5959,7 +5959,7 @@ RelationBuildPublicationDesc(Relation relation, PublicationDesc *pubdesc)
/* Now save copy of the descriptor in the relcache entry. */
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
- relation->rd_pubdesc = palloc(sizeof(PublicationDesc));
+ relation->rd_pubdesc = palloc_object(PublicationDesc);
memcpy(relation->rd_pubdesc, pubdesc, sizeof(PublicationDesc));
MemoryContextSwitchTo(oldcxt);
}
@@ -5967,7 +5967,7 @@ RelationBuildPublicationDesc(Relation relation, PublicationDesc *pubdesc)
static bytea **
CopyIndexAttOptions(bytea **srcopts, int natts)
{
- bytea **opts = palloc(sizeof(*opts) * natts);
+ bytea **opts = palloc_array(bytea *, natts);
for (int i = 0; i < natts; i++)
{
@@ -5999,7 +5999,7 @@ RelationGetIndexAttOptions(Relation relation, bool copy)
return copy ? CopyIndexAttOptions(opts, natts) : opts;
/* Get and parse opclass options. */
- opts = palloc0(sizeof(*opts) * natts);
+ opts = palloc0_array(bytea *, natts);
for (i = 0; i < natts; i++)
{
@@ -6292,7 +6292,7 @@ load_relcache_init_file(bool shared)
/* mark not-null status */
if (has_not_null)
{
- TupleConstr *constr = (TupleConstr *) palloc0(sizeof(TupleConstr));
+ TupleConstr *constr = palloc0_object(TupleConstr);
constr->has_not_null = true;
rel->rd_att->constr = constr;
diff --git a/src/backend/utils/cache/typcache.c b/src/backend/utils/cache/typcache.c
index 6a347698edf..0c17d99d021 100644
--- a/src/backend/utils/cache/typcache.c
+++ b/src/backend/utils/cache/typcache.c
@@ -2764,7 +2764,7 @@ load_enum_cache_data(TypeCacheEntry *tcache)
* through.
*/
maxitems = 64;
- items = (EnumItem *) palloc(sizeof(EnumItem) * maxitems);
+ items = palloc_array(EnumItem, maxitems);
numitems = 0;
/* Scan pg_enum for the members of the target enum type. */
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 29643c51439..4c5a9283208 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -1774,7 +1774,7 @@ CopyErrorData(void)
Assert(CurrentMemoryContext != ErrorContext);
/* Copy the struct itself */
- newedata = (ErrorData *) palloc(sizeof(ErrorData));
+ newedata = palloc_object(ErrorData);
memcpy(newedata, edata, sizeof(ErrorData));
/*
diff --git a/src/backend/utils/fmgr/funcapi.c b/src/backend/utils/fmgr/funcapi.c
index 5f2317211c9..f40879f0617 100644
--- a/src/backend/utils/fmgr/funcapi.c
+++ b/src/backend/utils/fmgr/funcapi.c
@@ -1436,7 +1436,7 @@ get_func_arg_info(HeapTuple procTup,
&elems, NULL, &nelems);
if (nelems != numargs) /* should not happen */
elog(ERROR, "proargnames must have the same number of elements as the function has arguments");
- *p_argnames = (char **) palloc(sizeof(char *) * numargs);
+ *p_argnames = palloc_array(char *, numargs);
for (i = 0; i < numargs; i++)
(*p_argnames)[i] = TextDatumGetCString(elems[i]);
}
diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c
index 98f9598cd78..4ed69ac7ba2 100644
--- a/src/backend/utils/init/postinit.c
+++ b/src/backend/utils/init/postinit.c
@@ -1260,7 +1260,7 @@ process_startup_options(Port *port, bool am_superuser)
maxac = 2 + (strlen(port->cmdline_options) + 1) / 2;
- av = (char **) palloc(maxac * sizeof(char *));
+ av = palloc_array(char *, maxac);
ac = 0;
av[ac++] = "postgres";
diff --git a/src/backend/utils/mb/mbutils.c b/src/backend/utils/mb/mbutils.c
index fb629ed5c8f..dbce0e61812 100644
--- a/src/backend/utils/mb/mbutils.c
+++ b/src/backend/utils/mb/mbutils.c
@@ -1792,7 +1792,7 @@ pgwin32_message_to_UTF16(const char *str, int len, int *utf16len)
*/
if (codepage != 0)
{
- utf16 = (WCHAR *) palloc(sizeof(WCHAR) * (len + 1));
+ utf16 = palloc_array(WCHAR, len + 1);
dstlen = MultiByteToWideChar(codepage, 0, str, len, utf16, len);
utf16[dstlen] = (WCHAR) 0;
}
@@ -1816,7 +1816,7 @@ pgwin32_message_to_UTF16(const char *str, int len, int *utf16len)
else
utf8 = (char *) str;
- utf16 = (WCHAR *) palloc(sizeof(WCHAR) * (len + 1));
+ utf16 = palloc_array(WCHAR, len + 1);
dstlen = MultiByteToWideChar(CP_UTF8, 0, utf8, len, utf16, len);
utf16[dstlen] = (WCHAR) 0;
diff --git a/src/backend/utils/misc/conffiles.c b/src/backend/utils/misc/conffiles.c
index 23ebad4749b..e702d1d8e31 100644
--- a/src/backend/utils/misc/conffiles.c
+++ b/src/backend/utils/misc/conffiles.c
@@ -108,7 +108,7 @@ GetConfFilesInDir(const char *includedir, const char *calling_file,
* them prior to caller processing the contents.
*/
size_filenames = 32;
- filenames = (char **) palloc(size_filenames * sizeof(char *));
+ filenames = palloc_array(char *, size_filenames);
*num_filenames = 0;
while ((de = ReadDir(d, directory)) != NULL)
diff --git a/src/backend/utils/misc/guc-file.l b/src/backend/utils/misc/guc-file.l
index 11a1e2a3f9f..c3d0f599be8 100644
--- a/src/backend/utils/misc/guc-file.l
+++ b/src/backend/utils/misc/guc-file.l
@@ -283,7 +283,7 @@ record_config_file_error(const char *errmsg,
{
ConfigVariable *item;
- item = palloc(sizeof *item);
+ item = palloc_object(ConfigVariable);
item->name = NULL;
item->value = NULL;
item->errmsg = pstrdup(errmsg);
@@ -482,7 +482,7 @@ ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel,
else
{
/* ordinary variable, append to list */
- item = palloc(sizeof *item);
+ item = palloc_object(ConfigVariable);
item->name = opt_name;
item->value = opt_value;
item->errmsg = NULL;
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index d495ff15945..f7d63e04c04 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -844,7 +844,7 @@ get_guc_variables(int *num_vars)
int i;
*num_vars = hash_get_num_entries(guc_hashtab);
- result = palloc(sizeof(struct config_generic *) * *num_vars);
+ result = palloc_array(struct config_generic *, *num_vars);
/* Extract pointers from the hash table */
i = 0;
@@ -5208,7 +5208,7 @@ get_explain_guc_options(int *num)
* While only a fraction of all the GUC variables are marked GUC_EXPLAIN,
* it doesn't seem worth dynamically resizing this array.
*/
- result = palloc(sizeof(struct config_generic *) * hash_get_num_entries(guc_hashtab));
+ result = palloc_array(struct config_generic *, hash_get_num_entries(guc_hashtab));
/* We need only consider GUCs with source not PGC_S_DEFAULT */
dlist_foreach(iter, &guc_nondef_list)
diff --git a/src/backend/utils/misc/injection_point.c b/src/backend/utils/misc/injection_point.c
index d02618c7ffe..54a9fe8e163 100644
--- a/src/backend/utils/misc/injection_point.c
+++ b/src/backend/utils/misc/injection_point.c
@@ -614,7 +614,7 @@ InjectionPointList(void)
if (generation % 2 == 0)
continue;
- inj_point = (InjectionPointData *) palloc0(sizeof(InjectionPointData));
+ inj_point = palloc0_object(InjectionPointData);
inj_point->name = pstrdup(entry->name);
inj_point->library = pstrdup(entry->library);
inj_point->function = pstrdup(entry->function);
diff --git a/src/backend/utils/misc/queryenvironment.c b/src/backend/utils/misc/queryenvironment.c
index 7bc72dabe67..06983090039 100644
--- a/src/backend/utils/misc/queryenvironment.c
+++ b/src/backend/utils/misc/queryenvironment.c
@@ -38,7 +38,7 @@ struct QueryEnvironment
QueryEnvironment *
create_queryEnv(void)
{
- return (QueryEnvironment *) palloc0(sizeof(QueryEnvironment));
+ return palloc0_object(QueryEnvironment);
}
EphemeralNamedRelationMetadata
diff --git a/src/backend/utils/misc/tzparser.c b/src/backend/utils/misc/tzparser.c
index 6aaf7395ba8..d7e84bab981 100644
--- a/src/backend/utils/misc/tzparser.c
+++ b/src/backend/utils/misc/tzparser.c
@@ -466,7 +466,7 @@ load_tzoffsets(const char *filename)
/* Initialize array at a reasonable size */
arraysize = 128;
- array = (tzEntry *) palloc(arraysize * sizeof(tzEntry));
+ array = palloc_array(tzEntry, arraysize);
/* Parse the file(s) */
n = ParseTzFile(filename, 0, &array, &arraysize, 0);
diff --git a/src/backend/utils/mmgr/dsa.c b/src/backend/utils/mmgr/dsa.c
index 4b6bcffea28..6b37839e925 100644
--- a/src/backend/utils/mmgr/dsa.c
+++ b/src/backend/utils/mmgr/dsa.c
@@ -1330,7 +1330,7 @@ create_internal(void *place, size_t size,
* area. Other backends will need to obtain their own dsa_area object by
* attaching.
*/
- area = palloc(sizeof(dsa_area));
+ area = palloc_object(dsa_area);
area->control = control;
area->resowner = CurrentResourceOwner;
memset(area->segment_maps, 0, sizeof(dsa_segment_map) * DSA_MAX_SEGMENTS);
@@ -1386,7 +1386,7 @@ attach_internal(void *place, dsm_segment *segment, dsa_handle handle)
(DSA_SEGMENT_HEADER_MAGIC ^ handle ^ 0));
/* Build the backend-local area object. */
- area = palloc(sizeof(dsa_area));
+ area = palloc_object(dsa_area);
area->control = control;
area->resowner = CurrentResourceOwner;
memset(&area->segment_maps[0], 0,
diff --git a/src/backend/utils/sort/logtape.c b/src/backend/utils/sort/logtape.c
index 452d89a8c0f..42bf50221b8 100644
--- a/src/backend/utils/sort/logtape.c
+++ b/src/backend/utils/sort/logtape.c
@@ -437,7 +437,7 @@ ltsGetPreallocBlock(LogicalTapeSet *lts, LogicalTape *lt)
if (lt->prealloc == NULL)
{
lt->prealloc_size = TAPE_WRITE_PREALLOC_MIN;
- lt->prealloc = (int64 *) palloc(sizeof(int64) * lt->prealloc_size);
+ lt->prealloc = palloc_array(int64, lt->prealloc_size);
}
else if (lt->prealloc_size < TAPE_WRITE_PREALLOC_MAX)
{
@@ -560,7 +560,7 @@ LogicalTapeSetCreate(bool preallocate, SharedFileSet *fileset, int worker)
/*
* Create top-level struct including per-tape LogicalTape structs.
*/
- lts = (LogicalTapeSet *) palloc(sizeof(LogicalTapeSet));
+ lts = palloc_object(LogicalTapeSet);
lts->nBlocksAllocated = 0L;
lts->nBlocksWritten = 0L;
lts->nHoleBlocks = 0L;
@@ -700,7 +700,7 @@ ltsCreateTape(LogicalTapeSet *lts)
/*
* Create per-tape struct. Note we allocate the I/O buffer lazily.
*/
- lt = palloc(sizeof(LogicalTape));
+ lt = palloc_object(LogicalTape);
lt->tapeSet = lts;
lt->writing = true;
lt->frozen = false;
diff --git a/src/backend/utils/sort/sharedtuplestore.c b/src/backend/utils/sort/sharedtuplestore.c
index 1dedbaa29cf..e77d857ff3f 100644
--- a/src/backend/utils/sort/sharedtuplestore.c
+++ b/src/backend/utils/sort/sharedtuplestore.c
@@ -160,7 +160,7 @@ sts_initialize(SharedTuplestore *sts, int participants,
sts->participants[i].writing = false;
}
- accessor = palloc0(sizeof(SharedTuplestoreAccessor));
+ accessor = palloc0_object(SharedTuplestoreAccessor);
accessor->participant = my_participant_number;
accessor->sts = sts;
accessor->fileset = fileset;
@@ -182,7 +182,7 @@ sts_attach(SharedTuplestore *sts,
Assert(my_participant_number < sts->nparticipants);
- accessor = palloc0(sizeof(SharedTuplestoreAccessor));
+ accessor = palloc0_object(SharedTuplestoreAccessor);
accessor->participant = my_participant_number;
accessor->sts = sts;
accessor->fileset = fileset;
diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c
index 5d4411dc33f..c1fa7a97509 100644
--- a/src/backend/utils/sort/tuplesort.c
+++ b/src/backend/utils/sort/tuplesort.c
@@ -673,7 +673,7 @@ tuplesort_begin_common(int workMem, SortCoordinate coordinate, int sortopt)
*/
oldcontext = MemoryContextSwitchTo(maincontext);
- state = (Tuplesortstate *) palloc0(sizeof(Tuplesortstate));
+ state = palloc0_object(Tuplesortstate);
if (trace_sort)
pg_rusage_init(&state->ru_start);
diff --git a/src/backend/utils/sort/tuplesortvariants.c b/src/backend/utils/sort/tuplesortvariants.c
index 9751a7fc495..079a51c474d 100644
--- a/src/backend/utils/sort/tuplesortvariants.c
+++ b/src/backend/utils/sort/tuplesortvariants.c
@@ -265,7 +265,7 @@ tuplesort_begin_cluster(TupleDesc tupDesc,
Assert(indexRel->rd_rel->relam == BTREE_AM_OID);
oldcontext = MemoryContextSwitchTo(base->maincontext);
- arg = (TuplesortClusterArg *) palloc0(sizeof(TuplesortClusterArg));
+ arg = palloc0_object(TuplesortClusterArg);
if (trace_sort)
elog(LOG,
@@ -372,7 +372,7 @@ tuplesort_begin_index_btree(Relation heapRel,
int i;
oldcontext = MemoryContextSwitchTo(base->maincontext);
- arg = (TuplesortIndexBTreeArg *) palloc(sizeof(TuplesortIndexBTreeArg));
+ arg = palloc_object(TuplesortIndexBTreeArg);
if (trace_sort)
elog(LOG,
@@ -453,7 +453,7 @@ tuplesort_begin_index_hash(Relation heapRel,
TuplesortIndexHashArg *arg;
oldcontext = MemoryContextSwitchTo(base->maincontext);
- arg = (TuplesortIndexHashArg *) palloc(sizeof(TuplesortIndexHashArg));
+ arg = palloc_object(TuplesortIndexHashArg);
if (trace_sort)
elog(LOG,
@@ -502,7 +502,7 @@ tuplesort_begin_index_gist(Relation heapRel,
int i;
oldcontext = MemoryContextSwitchTo(base->maincontext);
- arg = (TuplesortIndexBTreeArg *) palloc(sizeof(TuplesortIndexBTreeArg));
+ arg = palloc_object(TuplesortIndexBTreeArg);
if (trace_sort)
elog(LOG,
@@ -662,7 +662,7 @@ tuplesort_begin_datum(Oid datumType, Oid sortOperator, Oid sortCollation,
bool typbyval;
oldcontext = MemoryContextSwitchTo(base->maincontext);
- arg = (TuplesortDatumArg *) palloc(sizeof(TuplesortDatumArg));
+ arg = palloc_object(TuplesortDatumArg);
if (trace_sort)
elog(LOG,
@@ -694,7 +694,7 @@ tuplesort_begin_datum(Oid datumType, Oid sortOperator, Oid sortCollation,
base->tuples = !typbyval;
/* Prepare SortSupport data */
- base->sortKeys = (SortSupport) palloc0(sizeof(SortSupportData));
+ base->sortKeys = palloc0_object(SortSupportData);
base->sortKeys->ssup_cxt = CurrentMemoryContext;
base->sortKeys->ssup_collation = sortCollation;
diff --git a/src/backend/utils/sort/tuplestore.c b/src/backend/utils/sort/tuplestore.c
index c9aecab8d66..def945b0454 100644
--- a/src/backend/utils/sort/tuplestore.c
+++ b/src/backend/utils/sort/tuplestore.c
@@ -257,7 +257,7 @@ tuplestore_begin_common(int eflags, bool interXact, int maxKBytes)
{
Tuplestorestate *state;
- state = (Tuplestorestate *) palloc0(sizeof(Tuplestorestate));
+ state = palloc0_object(Tuplestorestate);
state->status = TSS_INMEM;
state->eflags = eflags;
diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c
index 24f73a49d27..40a2e90e071 100644
--- a/src/backend/utils/time/snapmgr.c
+++ b/src/backend/utils/time/snapmgr.c
@@ -1179,7 +1179,7 @@ ExportSnapshot(Snapshot snapshot)
snapshot = CopySnapshot(snapshot);
oldcxt = MemoryContextSwitchTo(TopTransactionContext);
- esnap = (ExportedSnapshot *) palloc(sizeof(ExportedSnapshot));
+ esnap = palloc_object(ExportedSnapshot);
esnap->snapfile = pstrdup(path);
esnap->snapshot = snapshot;
exportedSnapshots = lappend(exportedSnapshots, esnap);