summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/src/sgml/gist.sgml8
-rw-r--r--doc/src/sgml/xfunc.sgml2
-rw-r--r--doc/src/sgml/xtypes.sgml2
-rw-r--r--src/bin/pg_basebackup/astreamer_inject.c2
-rw-r--r--src/bin/pg_combinebackup/load_manifest.c2
-rw-r--r--src/bin/pg_dump/common.c2
-rw-r--r--src/bin/pg_verifybackup/astreamer_verify.c2
-rw-r--r--src/bin/pg_verifybackup/pg_verifybackup.c2
-rw-r--r--src/bin/scripts/vacuuming.c2
-rw-r--r--src/common/blkreftable.c21
-rw-r--r--src/common/parse_manifest.c4
-rw-r--r--src/common/pgfnames.c5
-rw-r--r--src/common/rmtree.c2
-rw-r--r--src/common/stringinfo.c2
-rw-r--r--src/fe_utils/astreamer_file.c4
-rw-r--r--src/fe_utils/astreamer_gzip.c4
-rw-r--r--src/fe_utils/astreamer_lz4.c4
-rw-r--r--src/fe_utils/astreamer_tar.c6
-rw-r--r--src/fe_utils/astreamer_zstd.c4
-rw-r--r--src/include/lib/radixtree.h8
-rw-r--r--src/pl/plperl/plperl.c12
-rw-r--r--src/pl/plpgsql/src/pl_comp.c32
-rw-r--r--src/pl/plpgsql/src/pl_exec.c9
-rw-r--r--src/pl/plpgsql/src/pl_gram.y92
-rw-r--r--src/pl/plpython/plpy_procedure.c6
-rw-r--r--src/pl/plpython/plpy_spi.c4
-rw-r--r--src/pl/plpython/plpy_typeio.c12
-rw-r--r--src/pl/tcl/pltcl.c4
-rw-r--r--src/test/modules/dummy_index_am/dummy_index_am.c2
-rw-r--r--src/test/modules/spgist_name_ops/spgist_name_ops.c10
-rw-r--r--src/test/modules/test_bitmapset/test_bitmapset.c2
-rw-r--r--src/test/modules/test_integerset/test_integerset.c2
-rw-r--r--src/test/modules/test_json_parser/test_json_parser_incremental.c2
-rw-r--r--src/test/modules/test_parser/test_parser.c4
-rw-r--r--src/test/modules/test_radixtree/test_radixtree.c2
-rw-r--r--src/test/modules/test_regex/test_regex.c14
-rw-r--r--src/test/modules/test_resowner/test_resowner_many.c2
-rw-r--r--src/test/modules/test_rls_hooks/test_rls_hooks.c4
-rw-r--r--src/test/modules/worker_spi/worker_spi.c2
-rw-r--r--src/test/regress/regress.c2
-rw-r--r--src/timezone/pgtz.c2
-rw-r--r--src/tutorial/complex.c6
-rw-r--r--src/tutorial/funcs.c2
43 files changed, 156 insertions, 161 deletions
diff --git a/doc/src/sgml/gist.sgml b/doc/src/sgml/gist.sgml
index ee86e170055..5cbea8c3d55 100644
--- a/doc/src/sgml/gist.sgml
+++ b/doc/src/sgml/gist.sgml
@@ -506,11 +506,11 @@ my_compress(PG_FUNCTION_ARGS)
if (entry->leafkey)
{
/* replace entry->key with a compressed version */
- compressed_data_type *compressed_data = palloc(sizeof(compressed_data_type));
+ compressed_data_type *compressed_data = palloc_object(compressed_data_type);
/* fill *compressed_data from entry->key ... */
- retval = palloc(sizeof(GISTENTRY));
+ retval = palloc_object(GISTENTRY);
gistentryinit(*retval, PointerGetDatum(compressed_data),
entry->rel, entry->page, entry->offset, FALSE);
}
@@ -921,8 +921,8 @@ my_fetch(PG_FUNCTION_ARGS)
fetched_data_type *fetched_data;
GISTENTRY *retval;
- retval = palloc(sizeof(GISTENTRY));
- fetched_data = palloc(sizeof(fetched_data_type));
+ retval = palloc_object(GISTENTRY);
+ fetched_data = palloc_object(fetched_data_type);
/*
* Convert 'fetched_data' into the a Datum of the original datatype.
diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml
index 8e936af465c..7c76ab8c349 100644
--- a/doc/src/sgml/xfunc.sgml
+++ b/doc/src/sgml/xfunc.sgml
@@ -2491,7 +2491,7 @@ makepoint(PG_FUNCTION_ARGS)
/* Here, the pass-by-reference nature of Point is not hidden. */
Point *pointx = PG_GETARG_POINT_P(0);
Point *pointy = PG_GETARG_POINT_P(1);
- Point *new_point = (Point *) palloc(sizeof(Point));
+ Point *new_point = palloc_object(Point);
new_point->x = pointx->x;
new_point->y = pointy->y;
diff --git a/doc/src/sgml/xtypes.sgml b/doc/src/sgml/xtypes.sgml
index e67e5bdf4c4..df56d1c3ace 100644
--- a/doc/src/sgml/xtypes.sgml
+++ b/doc/src/sgml/xtypes.sgml
@@ -89,7 +89,7 @@ complex_in(PG_FUNCTION_ARGS)
errmsg("invalid input syntax for type %s: \"%s\"",
"complex", str)));
- result = (Complex *) palloc(sizeof(Complex));
+ result = palloc_object(Complex);
result->x = x;
result->y = y;
PG_RETURN_POINTER(result);
diff --git a/src/bin/pg_basebackup/astreamer_inject.c b/src/bin/pg_basebackup/astreamer_inject.c
index 15334e458ad..e77de72f7ac 100644
--- a/src/bin/pg_basebackup/astreamer_inject.c
+++ b/src/bin/pg_basebackup/astreamer_inject.c
@@ -68,7 +68,7 @@ astreamer_recovery_injector_new(astreamer *next,
{
astreamer_recovery_injector *streamer;
- streamer = palloc0(sizeof(astreamer_recovery_injector));
+ streamer = palloc0_object(astreamer_recovery_injector);
*((const astreamer_ops **) &streamer->base.bbs_ops) =
&astreamer_recovery_injector_ops;
streamer->base.bbs_next = next;
diff --git a/src/bin/pg_combinebackup/load_manifest.c b/src/bin/pg_combinebackup/load_manifest.c
index 8e0d04a26a6..44db0d2b164 100644
--- a/src/bin/pg_combinebackup/load_manifest.c
+++ b/src/bin/pg_combinebackup/load_manifest.c
@@ -298,7 +298,7 @@ combinebackup_per_wal_range_cb(JsonManifestParseContext *context,
manifest_wal_range *range;
/* Allocate and initialize a struct describing this WAL range. */
- range = palloc(sizeof(manifest_wal_range));
+ range = palloc_object(manifest_wal_range);
range->tli = tli;
range->start_lsn = start_lsn;
range->end_lsn = end_lsn;
diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c
index 4e7303ea631..0007e78667f 100644
--- a/src/bin/pg_dump/common.c
+++ b/src/bin/pg_dump/common.c
@@ -353,7 +353,7 @@ flagInhTables(Archive *fout, TableInfo *tblinfo, int numTables,
tblinfo[i].numParents,
tblinfo[i].dobj.name);
- attachinfo = (TableAttachInfo *) palloc(sizeof(TableAttachInfo));
+ attachinfo = palloc_object(TableAttachInfo);
attachinfo->dobj.objType = DO_TABLE_ATTACH;
attachinfo->dobj.catId.tableoid = 0;
attachinfo->dobj.catId.oid = 0;
diff --git a/src/bin/pg_verifybackup/astreamer_verify.c b/src/bin/pg_verifybackup/astreamer_verify.c
index 33cf67670a7..e503a3ec487 100644
--- a/src/bin/pg_verifybackup/astreamer_verify.c
+++ b/src/bin/pg_verifybackup/astreamer_verify.c
@@ -69,7 +69,7 @@ astreamer_verify_content_new(astreamer *next, verifier_context *context,
{
astreamer_verify *streamer;
- streamer = palloc0(sizeof(astreamer_verify));
+ streamer = palloc0_object(astreamer_verify);
*((const astreamer_ops **) &streamer->base.bbs_ops) =
&astreamer_verify_ops;
diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c
index 8d5befa947f..c9b24df7c05 100644
--- a/src/bin/pg_verifybackup/pg_verifybackup.c
+++ b/src/bin/pg_verifybackup/pg_verifybackup.c
@@ -584,7 +584,7 @@ verifybackup_per_wal_range_cb(JsonManifestParseContext *context,
manifest_wal_range *range;
/* Allocate and initialize a struct describing this WAL range. */
- range = palloc(sizeof(manifest_wal_range));
+ range = palloc_object(manifest_wal_range);
range->tli = tli;
range->start_lsn = start_lsn;
range->end_lsn = end_lsn;
diff --git a/src/bin/scripts/vacuuming.c b/src/bin/scripts/vacuuming.c
index f836f21fb03..9f44cae02ae 100644
--- a/src/bin/scripts/vacuuming.c
+++ b/src/bin/scripts/vacuuming.c
@@ -530,7 +530,7 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts,
PQExpBufferData catalog_query;
PGresult *res;
SimpleStringListCell *cell;
- SimpleStringList *found_objs = palloc0(sizeof(SimpleStringList));
+ SimpleStringList *found_objs = palloc0_object(SimpleStringList);
bool objects_listed = false;
initPQExpBuffer(&catalog_query);
diff --git a/src/common/blkreftable.c b/src/common/blkreftable.c
index b935baf9ad4..0e08f4e40ed 100644
--- a/src/common/blkreftable.c
+++ b/src/common/blkreftable.c
@@ -234,7 +234,7 @@ static void BlockRefTableFileTerminate(BlockRefTableBuffer *buffer);
BlockRefTable *
CreateEmptyBlockRefTable(void)
{
- BlockRefTable *brtab = palloc(sizeof(BlockRefTable));
+ BlockRefTable *brtab = palloc_object(BlockRefTable);
/*
* Even completely empty database has a few hundred relation forks, so it
@@ -497,7 +497,7 @@ WriteBlockRefTable(BlockRefTable *brtab,
/* Extract entries into serializable format and sort them. */
sdata =
- palloc(brtab->hash->members * sizeof(BlockRefTableSerializedEntry));
+ palloc_array(BlockRefTableSerializedEntry, brtab->hash->members);
blockreftable_start_iterate(brtab->hash, &it);
while ((brtentry = blockreftable_iterate(brtab->hash, &it)) != NULL)
{
@@ -584,7 +584,7 @@ CreateBlockRefTableReader(io_callback_fn read_callback,
uint32 magic;
/* Initialize data structure. */
- reader = palloc0(sizeof(BlockRefTableReader));
+ reader = palloc0_object(BlockRefTableReader);
reader->buffer.io_callback = read_callback;
reader->buffer.io_callback_arg = read_callback_arg;
reader->error_filename = error_filename;
@@ -660,7 +660,7 @@ BlockRefTableReaderNextRelation(BlockRefTableReader *reader,
/* Read chunk size array. */
if (reader->chunk_size != NULL)
pfree(reader->chunk_size);
- reader->chunk_size = palloc(sentry.nchunks * sizeof(uint16));
+ reader->chunk_size = palloc_array(uint16, sentry.nchunks);
BlockRefTableRead(reader, reader->chunk_size,
sentry.nchunks * sizeof(uint16));
@@ -794,7 +794,7 @@ CreateBlockRefTableWriter(io_callback_fn write_callback,
uint32 magic = BLOCKREFTABLE_MAGIC;
/* Prepare buffer and CRC check and save callbacks. */
- writer = palloc0(sizeof(BlockRefTableWriter));
+ writer = palloc0_object(BlockRefTableWriter);
writer->buffer.io_callback = write_callback;
writer->buffer.io_callback_arg = write_callback_arg;
INIT_CRC32C(writer->buffer.crc);
@@ -874,7 +874,7 @@ DestroyBlockRefTableWriter(BlockRefTableWriter *writer)
BlockRefTableEntry *
CreateBlockRefTableEntry(RelFileLocator rlocator, ForkNumber forknum)
{
- BlockRefTableEntry *entry = palloc0(sizeof(BlockRefTableEntry));
+ BlockRefTableEntry *entry = palloc0_object(BlockRefTableEntry);
memcpy(&entry->key.rlocator, &rlocator, sizeof(RelFileLocator));
entry->key.forknum = forknum;
@@ -997,10 +997,9 @@ BlockRefTableEntryMarkBlockModified(BlockRefTableEntry *entry,
if (entry->nchunks == 0)
{
- entry->chunk_size = palloc0(sizeof(uint16) * max_chunks);
- entry->chunk_usage = palloc0(sizeof(uint16) * max_chunks);
- entry->chunk_data =
- palloc0(sizeof(BlockRefTableChunk) * max_chunks);
+ entry->chunk_size = palloc0_array(uint16, max_chunks);
+ entry->chunk_usage = palloc0_array(uint16, max_chunks);
+ entry->chunk_data = palloc0_array(BlockRefTableChunk, max_chunks);
}
else
{
@@ -1029,7 +1028,7 @@ BlockRefTableEntryMarkBlockModified(BlockRefTableEntry *entry,
if (entry->chunk_size[chunkno] == 0)
{
entry->chunk_data[chunkno] =
- palloc(sizeof(uint16) * INITIAL_ENTRIES_PER_CHUNK);
+ palloc_array(uint16, INITIAL_ENTRIES_PER_CHUNK);
entry->chunk_size[chunkno] = INITIAL_ENTRIES_PER_CHUNK;
entry->chunk_data[chunkno][0] = chunkoffset;
entry->chunk_usage[chunkno] = 1;
diff --git a/src/common/parse_manifest.c b/src/common/parse_manifest.c
index 58e0948100f..cc5fa0e5e07 100644
--- a/src/common/parse_manifest.c
+++ b/src/common/parse_manifest.c
@@ -132,8 +132,8 @@ json_parse_manifest_incremental_init(JsonManifestParseContext *context)
JsonManifestParseState *parse;
pg_cryptohash_ctx *manifest_ctx;
- incstate = palloc(sizeof(JsonManifestParseIncrementalState));
- parse = palloc(sizeof(JsonManifestParseState));
+ incstate = palloc_object(JsonManifestParseIncrementalState);
+ parse = palloc_object(JsonManifestParseState);
parse->context = context;
parse->state = JM_EXPECT_TOPLEVEL_START;
diff --git a/src/common/pgfnames.c b/src/common/pgfnames.c
index 8fb79105714..591535a24b8 100644
--- a/src/common/pgfnames.c
+++ b/src/common/pgfnames.c
@@ -49,7 +49,7 @@ pgfnames(const char *path)
return NULL;
}
- filenames = (char **) palloc(fnsize * sizeof(char *));
+ filenames = palloc_array(char *, fnsize);
while (errno = 0, (file = readdir(dir)) != NULL)
{
@@ -58,8 +58,7 @@ pgfnames(const char *path)
if (numnames + 1 >= fnsize)
{
fnsize *= 2;
- filenames = (char **) repalloc(filenames,
- fnsize * sizeof(char *));
+ filenames = repalloc_array(filenames, char *, fnsize);
}
filenames[numnames++] = pstrdup(file->d_name);
}
diff --git a/src/common/rmtree.c b/src/common/rmtree.c
index 2f364f84ae5..47cd0a4d8a1 100644
--- a/src/common/rmtree.c
+++ b/src/common/rmtree.c
@@ -64,7 +64,7 @@ rmtree(const char *path, bool rmtopdir)
return false;
}
- dirnames = (char **) palloc(sizeof(char *) * dirnames_capacity);
+ dirnames = palloc_array(char *, dirnames_capacity);
while (errno = 0, (de = readdir(dir)))
{
diff --git a/src/common/stringinfo.c b/src/common/stringinfo.c
index 22d03807697..a3e77088f8e 100644
--- a/src/common/stringinfo.c
+++ b/src/common/stringinfo.c
@@ -57,7 +57,7 @@ initStringInfoInternal(StringInfo str, int initsize)
static inline StringInfo
makeStringInfoInternal(int initsize)
{
- StringInfo res = (StringInfo) palloc(sizeof(StringInfoData));
+ StringInfo res = palloc_object(StringInfoData);
initStringInfoInternal(res, initsize);
return res;
diff --git a/src/fe_utils/astreamer_file.c b/src/fe_utils/astreamer_file.c
index c6856285086..940f0f5a1a6 100644
--- a/src/fe_utils/astreamer_file.c
+++ b/src/fe_utils/astreamer_file.c
@@ -82,7 +82,7 @@ astreamer_plain_writer_new(char *pathname, FILE *file)
{
astreamer_plain_writer *streamer;
- streamer = palloc0(sizeof(astreamer_plain_writer));
+ streamer = palloc0_object(astreamer_plain_writer);
*((const astreamer_ops **) &streamer->base.bbs_ops) =
&astreamer_plain_writer_ops;
@@ -189,7 +189,7 @@ astreamer_extractor_new(const char *basepath,
{
astreamer_extractor *streamer;
- streamer = palloc0(sizeof(astreamer_extractor));
+ streamer = palloc0_object(astreamer_extractor);
*((const astreamer_ops **) &streamer->base.bbs_ops) =
&astreamer_extractor_ops;
streamer->basepath = pstrdup(basepath);
diff --git a/src/fe_utils/astreamer_gzip.c b/src/fe_utils/astreamer_gzip.c
index a395f57edcd..06e2670d363 100644
--- a/src/fe_utils/astreamer_gzip.c
+++ b/src/fe_utils/astreamer_gzip.c
@@ -102,7 +102,7 @@ astreamer_gzip_writer_new(char *pathname, FILE *file,
#ifdef HAVE_LIBZ
astreamer_gzip_writer *streamer;
- streamer = palloc0(sizeof(astreamer_gzip_writer));
+ streamer = palloc0_object(astreamer_gzip_writer);
*((const astreamer_ops **) &streamer->base.bbs_ops) =
&astreamer_gzip_writer_ops;
@@ -241,7 +241,7 @@ astreamer_gzip_decompressor_new(astreamer *next)
Assert(next != NULL);
- streamer = palloc0(sizeof(astreamer_gzip_decompressor));
+ streamer = palloc0_object(astreamer_gzip_decompressor);
*((const astreamer_ops **) &streamer->base.bbs_ops) =
&astreamer_gzip_decompressor_ops;
diff --git a/src/fe_utils/astreamer_lz4.c b/src/fe_utils/astreamer_lz4.c
index 5f581d1de37..6aead209fd2 100644
--- a/src/fe_utils/astreamer_lz4.c
+++ b/src/fe_utils/astreamer_lz4.c
@@ -78,7 +78,7 @@ astreamer_lz4_compressor_new(astreamer *next, pg_compress_specification *compres
Assert(next != NULL);
- streamer = palloc0(sizeof(astreamer_lz4_frame));
+ streamer = palloc0_object(astreamer_lz4_frame);
*((const astreamer_ops **) &streamer->base.bbs_ops) =
&astreamer_lz4_compressor_ops;
@@ -282,7 +282,7 @@ astreamer_lz4_decompressor_new(astreamer *next)
Assert(next != NULL);
- streamer = palloc0(sizeof(astreamer_lz4_frame));
+ streamer = palloc0_object(astreamer_lz4_frame);
*((const astreamer_ops **) &streamer->base.bbs_ops) =
&astreamer_lz4_decompressor_ops;
diff --git a/src/fe_utils/astreamer_tar.c b/src/fe_utils/astreamer_tar.c
index 088e2357920..896f8ab4970 100644
--- a/src/fe_utils/astreamer_tar.c
+++ b/src/fe_utils/astreamer_tar.c
@@ -94,7 +94,7 @@ astreamer_tar_parser_new(astreamer *next)
{
astreamer_tar_parser *streamer;
- streamer = palloc0(sizeof(astreamer_tar_parser));
+ streamer = palloc0_object(astreamer_tar_parser);
*((const astreamer_ops **) &streamer->base.bbs_ops) =
&astreamer_tar_parser_ops;
streamer->base.bbs_next = next;
@@ -357,7 +357,7 @@ astreamer_tar_archiver_new(astreamer *next)
{
astreamer_tar_archiver *streamer;
- streamer = palloc0(sizeof(astreamer_tar_archiver));
+ streamer = palloc0_object(astreamer_tar_archiver);
*((const astreamer_ops **) &streamer->base.bbs_ops) =
&astreamer_tar_archiver_ops;
streamer->base.bbs_next = next;
@@ -463,7 +463,7 @@ astreamer_tar_terminator_new(astreamer *next)
{
astreamer *streamer;
- streamer = palloc0(sizeof(astreamer));
+ streamer = palloc0_object(astreamer);
*((const astreamer_ops **) &streamer->bbs_ops) =
&astreamer_tar_terminator_ops;
streamer->bbs_next = next;
diff --git a/src/fe_utils/astreamer_zstd.c b/src/fe_utils/astreamer_zstd.c
index bacdcc150c4..6666f1abeb3 100644
--- a/src/fe_utils/astreamer_zstd.c
+++ b/src/fe_utils/astreamer_zstd.c
@@ -75,7 +75,7 @@ astreamer_zstd_compressor_new(astreamer *next, pg_compress_specification *compre
Assert(next != NULL);
- streamer = palloc0(sizeof(astreamer_zstd_frame));
+ streamer = palloc0_object(astreamer_zstd_frame);
*((const astreamer_ops **) &streamer->base.bbs_ops) =
&astreamer_zstd_compressor_ops;
@@ -266,7 +266,7 @@ astreamer_zstd_decompressor_new(astreamer *next)
Assert(next != NULL);
- streamer = palloc0(sizeof(astreamer_zstd_frame));
+ streamer = palloc0_object(astreamer_zstd_frame);
*((const astreamer_ops **) &streamer->base.bbs_ops) =
&astreamer_zstd_decompressor_ops;
diff --git a/src/include/lib/radixtree.h b/src/include/lib/radixtree.h
index ead7500fe13..adf81c6f0eb 100644
--- a/src/include/lib/radixtree.h
+++ b/src/include/lib/radixtree.h
@@ -1825,7 +1825,7 @@ RT_CREATE(MemoryContext ctx)
dsa_pointer dp;
#endif
- tree = (RT_RADIX_TREE *) palloc0(sizeof(RT_RADIX_TREE));
+ tree = palloc0_object(RT_RADIX_TREE);
#ifdef RT_SHMEM
tree->dsa = dsa;
@@ -1835,7 +1835,7 @@ RT_CREATE(MemoryContext ctx)
tree->ctl->magic = RT_RADIX_TREE_MAGIC;
LWLockInitialize(&tree->ctl->lock, tranche_id);
#else
- tree->ctl = (RT_RADIX_TREE_CONTROL *) palloc0(sizeof(RT_RADIX_TREE_CONTROL));
+ tree->ctl = palloc0_object(RT_RADIX_TREE_CONTROL);
/* Create a slab context for each size class */
for (int i = 0; i < RT_NUM_SIZE_CLASSES; i++)
@@ -1868,7 +1868,7 @@ RT_ATTACH(dsa_area *dsa, RT_HANDLE handle)
RT_RADIX_TREE *tree;
dsa_pointer control;
- tree = (RT_RADIX_TREE *) palloc0(sizeof(RT_RADIX_TREE));
+ tree = palloc0_object(RT_RADIX_TREE);
/* Find the control object in shared memory */
control = handle;
@@ -2057,7 +2057,7 @@ RT_BEGIN_ITERATE(RT_RADIX_TREE * tree)
RT_ITER *iter;
RT_CHILD_PTR root;
- iter = (RT_ITER *) palloc0(sizeof(RT_ITER));
+ iter = palloc0_object(RT_ITER);
iter->tree = tree;
Assert(RT_PTR_ALLOC_IS_VALID(tree->ctl->root));
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c
index 73ba1748fe0..02eced3b2c5 100644
--- a/src/pl/plperl/plperl.c
+++ b/src/pl/plperl/plperl.c
@@ -1082,8 +1082,8 @@ plperl_build_tuple_result(HV *perlhash, TupleDesc td)
HE *he;
HeapTuple tup;
- values = palloc0(sizeof(Datum) * td->natts);
- nulls = palloc(sizeof(bool) * td->natts);
+ values = palloc0_array(Datum, td->natts);
+ nulls = palloc_array(bool, td->natts);
memset(nulls, true, sizeof(bool) * td->natts);
hv_iterinit(perlhash);
@@ -1502,7 +1502,7 @@ plperl_ref_from_pg_array(Datum arg, Oid typid)
* Currently we make no effort to cache any of the stuff we look up here,
* which is bad.
*/
- info = palloc0(sizeof(plperl_array_info));
+ info = palloc0_object(plperl_array_info);
/* get element type information, including output conversion function */
get_type_io_data(elementtype, IOFunc_output,
@@ -1538,7 +1538,7 @@ plperl_ref_from_pg_array(Datum arg, Oid typid)
&nitems);
/* Get total number of elements in each dimension */
- info->nelems = palloc(sizeof(int) * info->ndims);
+ info->nelems = palloc_array(int, info->ndims);
info->nelems[0] = nitems;
for (i = 1; i < info->ndims; i++)
info->nelems[i] = info->nelems[i - 1] / dims[i - 1];
@@ -2797,7 +2797,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger, bool is_event_trigger)
* struct prodesc and subsidiary data must all live in proc_cxt.
************************************************************/
oldcontext = MemoryContextSwitchTo(proc_cxt);
- prodesc = (plperl_proc_desc *) palloc0(sizeof(plperl_proc_desc));
+ prodesc = palloc0_object(plperl_proc_desc);
prodesc->proname = pstrdup(NameStr(procStruct->proname));
MemoryContextSetIdentifier(proc_cxt, prodesc->proname);
prodesc->fn_cxt = proc_cxt;
@@ -3596,7 +3596,7 @@ plperl_spi_prepare(char *query, int argc, SV **argv)
"PL/Perl spi_prepare query",
ALLOCSET_SMALL_SIZES);
MemoryContextSwitchTo(plan_cxt);
- qdesc = (plperl_query_desc *) palloc0(sizeof(plperl_query_desc));
+ qdesc = palloc0_object(plperl_query_desc);
snprintf(qdesc->qname, sizeof(qdesc->qname), "%p", qdesc);
qdesc->plan_cxt = plan_cxt;
qdesc->nargs = argc;
diff --git a/src/pl/plpgsql/src/pl_comp.c b/src/pl/plpgsql/src/pl_comp.c
index f6976689a69..4d90a0c2f06 100644
--- a/src/pl/plpgsql/src/pl_comp.c
+++ b/src/pl/plpgsql/src/pl_comp.c
@@ -298,8 +298,8 @@ plpgsql_compile_callback(FunctionCallInfo fcinfo,
forValidator,
plpgsql_error_funcname);
- in_arg_varnos = (int *) palloc(numargs * sizeof(int));
- out_arg_variables = (PLpgSQL_variable **) palloc(numargs * sizeof(PLpgSQL_variable *));
+ in_arg_varnos = palloc_array(int, numargs);
+ out_arg_variables = palloc_array(PLpgSQL_variable *, numargs);
MemoryContextSwitchTo(func_cxt);
@@ -772,7 +772,7 @@ plpgsql_compile_inline(char *proc_source)
plpgsql_check_syntax = check_function_bodies;
/* Function struct does not live past current statement */
- function = (PLpgSQL_function *) palloc0(sizeof(PLpgSQL_function));
+ function = palloc0_object(PLpgSQL_function);
plpgsql_curr_compile = function;
@@ -954,7 +954,7 @@ add_dummy_return(PLpgSQL_function *function)
{
PLpgSQL_stmt_block *new;
- new = palloc0(sizeof(PLpgSQL_stmt_block));
+ new = palloc0_object(PLpgSQL_stmt_block);
new->cmd_type = PLPGSQL_STMT_BLOCK;
new->stmtid = ++function->nstatements;
new->body = list_make1(function->action);
@@ -966,7 +966,7 @@ add_dummy_return(PLpgSQL_function *function)
{
PLpgSQL_stmt_return *new;
- new = palloc0(sizeof(PLpgSQL_stmt_return));
+ new = palloc0_object(PLpgSQL_stmt_return);
new->cmd_type = PLPGSQL_STMT_RETURN;
new->stmtid = ++function->nstatements;
new->expr = NULL;
@@ -1776,7 +1776,7 @@ plpgsql_build_variable(const char *refname, int lineno, PLpgSQL_type *dtype,
/* Ordinary scalar datatype */
PLpgSQL_var *var;
- var = palloc0(sizeof(PLpgSQL_var));
+ var = palloc0_object(PLpgSQL_var);
var->dtype = PLPGSQL_DTYPE_VAR;
var->refname = pstrdup(refname);
var->lineno = lineno;
@@ -1833,7 +1833,7 @@ plpgsql_build_record(const char *refname, int lineno,
{
PLpgSQL_rec *rec;
- rec = palloc0(sizeof(PLpgSQL_rec));
+ rec = palloc0_object(PLpgSQL_rec);
rec->dtype = PLPGSQL_DTYPE_REC;
rec->refname = pstrdup(refname);
rec->lineno = lineno;
@@ -1859,14 +1859,14 @@ build_row_from_vars(PLpgSQL_variable **vars, int numvars)
PLpgSQL_row *row;
int i;
- row = palloc0(sizeof(PLpgSQL_row));
+ row = palloc0_object(PLpgSQL_row);
row->dtype = PLPGSQL_DTYPE_ROW;
row->refname = "(unnamed row)";
row->lineno = -1;
row->rowtupdesc = CreateTemplateTupleDesc(numvars);
row->nfields = numvars;
- row->fieldnames = palloc(numvars * sizeof(char *));
- row->varnos = palloc(numvars * sizeof(int));
+ row->fieldnames = palloc_array(char *, numvars);
+ row->varnos = palloc_array(int, numvars);
for (i = 0; i < numvars; i++)
{
@@ -1940,7 +1940,7 @@ plpgsql_build_recfield(PLpgSQL_rec *rec, const char *fldname)
}
/* nope, so make a new one */
- recfield = palloc0(sizeof(PLpgSQL_recfield));
+ recfield = palloc0_object(PLpgSQL_recfield);
recfield->dtype = PLPGSQL_DTYPE_RECFIELD;
recfield->fieldname = pstrdup(fldname);
recfield->recparentno = rec->dno;
@@ -2004,7 +2004,7 @@ build_datatype(HeapTuple typeTup, int32 typmod,
errmsg("type \"%s\" is only a shell",
NameStr(typeStruct->typname))));
- typ = (PLpgSQL_type *) palloc(sizeof(PLpgSQL_type));
+ typ = palloc_object(PLpgSQL_type);
typ->typname = pstrdup(NameStr(typeStruct->typname));
typ->typoid = typeStruct->oid;
@@ -2184,7 +2184,7 @@ plpgsql_parse_err_condition(char *condname)
if (strcmp(condname, "others") == 0)
{
- new = palloc(sizeof(PLpgSQL_condition));
+ new = palloc_object(PLpgSQL_condition);
new->sqlerrstate = PLPGSQL_OTHERS;
new->condname = condname;
new->next = NULL;
@@ -2196,7 +2196,7 @@ plpgsql_parse_err_condition(char *condname)
{
if (strcmp(condname, exception_label_map[i].label) == 0)
{
- new = palloc(sizeof(PLpgSQL_condition));
+ new = palloc_object(PLpgSQL_condition);
new->sqlerrstate = exception_label_map[i].sqlerrstate;
new->condname = condname;
new->next = prev;
@@ -2258,7 +2258,7 @@ plpgsql_finish_datums(PLpgSQL_function *function)
int i;
function->ndatums = plpgsql_nDatums;
- function->datums = palloc(sizeof(PLpgSQL_datum *) * plpgsql_nDatums);
+ function->datums = palloc_array(PLpgSQL_datum *, plpgsql_nDatums);
for (i = 0; i < plpgsql_nDatums; i++)
{
function->datums[i] = plpgsql_Datums[i];
@@ -2323,7 +2323,7 @@ plpgsql_add_initdatums(int **varnos)
{
if (n > 0)
{
- *varnos = (int *) palloc(sizeof(int) * n);
+ *varnos = palloc_array(int, n);
n = 0;
for (i = datums_last; i < plpgsql_nDatums; i++)
diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c
index d19425b7a71..63598aba8a8 100644
--- a/src/pl/plpgsql/src/pl_exec.c
+++ b/src/pl/plpgsql/src/pl_exec.c
@@ -1318,8 +1318,7 @@ copy_plpgsql_datums(PLpgSQL_execstate *estate,
int i;
/* Allocate local datum-pointer array */
- estate->datums = (PLpgSQL_datum **)
- palloc(sizeof(PLpgSQL_datum *) * ndatums);
+ estate->datums = palloc_array(PLpgSQL_datum *, ndatums);
/*
* To reduce palloc overhead, we make a single palloc request for all the
@@ -1497,7 +1496,7 @@ plpgsql_fulfill_promise(PLpgSQL_execstate *estate,
int lbs[1];
int i;
- elems = palloc(sizeof(Datum) * nelems);
+ elems = palloc_array(Datum, nelems);
for (i = 0; i < nelems; i++)
elems[i] = CStringGetTextDatum(estate->trigdata->tg_trigger->tgargs[i]);
dims[0] = nelems;
@@ -2340,11 +2339,11 @@ make_callstmt_target(PLpgSQL_execstate *estate, PLpgSQL_expr *expr)
*/
MemoryContextSwitchTo(estate->func->fn_cxt);
- row = (PLpgSQL_row *) palloc0(sizeof(PLpgSQL_row));
+ row = palloc0_object(PLpgSQL_row);
row->dtype = PLPGSQL_DTYPE_ROW;
row->refname = "(unnamed row)";
row->lineno = -1;
- row->varnos = (int *) palloc(numargs * sizeof(int));
+ row->varnos = palloc_array(int, numargs);
MemoryContextSwitchTo(get_eval_mcontext(estate));
diff --git a/src/pl/plpgsql/src/pl_gram.y b/src/pl/plpgsql/src/pl_gram.y
index 17568d82554..cd1fe5a509f 100644
--- a/src/pl/plpgsql/src/pl_gram.y
+++ b/src/pl/plpgsql/src/pl_gram.y
@@ -426,7 +426,7 @@ pl_block : decl_sect K_BEGIN proc_sect exception_sect K_END opt_label
{
PLpgSQL_stmt_block *new;
- new = palloc0(sizeof(PLpgSQL_stmt_block));
+ new = palloc0_object(PLpgSQL_stmt_block);
new->cmd_type = PLPGSQL_STMT_BLOCK;
new->lineno = plpgsql_location_to_lineno(@2, yyscanner);
@@ -606,14 +606,14 @@ decl_cursor_args :
int i;
ListCell *l;
- new = palloc0(sizeof(PLpgSQL_row));
+ new = palloc0_object(PLpgSQL_row);
new->dtype = PLPGSQL_DTYPE_ROW;
new->refname = "(unnamed row)";
new->lineno = plpgsql_location_to_lineno(@1, yyscanner);
new->rowtupdesc = NULL;
new->nfields = list_length($2);
- new->fieldnames = palloc(new->nfields * sizeof(char *));
- new->varnos = palloc(new->nfields * sizeof(int));
+ new->fieldnames = palloc_array(char *, new->nfields);
+ new->varnos = palloc_array(int, new->nfields);
i = 0;
foreach (l, $2)
@@ -898,7 +898,7 @@ stmt_perform : K_PERFORM
PLpgSQL_stmt_perform *new;
int startloc;
- new = palloc0(sizeof(PLpgSQL_stmt_perform));
+ new = palloc0_object(PLpgSQL_stmt_perform);
new->cmd_type = PLPGSQL_STMT_PERFORM;
new->lineno = plpgsql_location_to_lineno(@1, yyscanner);
new->stmtid = ++plpgsql_curr_compile->nstatements;
@@ -934,7 +934,7 @@ stmt_call : K_CALL
{
PLpgSQL_stmt_call *new;
- new = palloc0(sizeof(PLpgSQL_stmt_call));
+ new = palloc0_object(PLpgSQL_stmt_call);
new->cmd_type = PLPGSQL_STMT_CALL;
new->lineno = plpgsql_location_to_lineno(@1, yyscanner);
new->stmtid = ++plpgsql_curr_compile->nstatements;
@@ -953,7 +953,7 @@ stmt_call : K_CALL
/* use the same structures as for CALL, for simplicity */
PLpgSQL_stmt_call *new;
- new = palloc0(sizeof(PLpgSQL_stmt_call));
+ new = palloc0_object(PLpgSQL_stmt_call);
new->cmd_type = PLPGSQL_STMT_CALL;
new->lineno = plpgsql_location_to_lineno(@1, yyscanner);
new->stmtid = ++plpgsql_curr_compile->nstatements;
@@ -992,7 +992,7 @@ stmt_assign : T_DATUM
}
check_assignable($1.datum, @1, yyscanner);
- new = palloc0(sizeof(PLpgSQL_stmt_assign));
+ new = palloc0_object(PLpgSQL_stmt_assign);
new->cmd_type = PLPGSQL_STMT_ASSIGN;
new->lineno = plpgsql_location_to_lineno(@1, yyscanner);
new->stmtid = ++plpgsql_curr_compile->nstatements;
@@ -1015,7 +1015,7 @@ stmt_getdiag : K_GET getdiag_area_opt K_DIAGNOSTICS getdiag_list ';'
PLpgSQL_stmt_getdiag *new;
ListCell *lc;
- new = palloc0(sizeof(PLpgSQL_stmt_getdiag));
+ new = palloc0_object(PLpgSQL_stmt_getdiag);
new->cmd_type = PLPGSQL_STMT_GETDIAG;
new->lineno = plpgsql_location_to_lineno(@1, yyscanner);
new->stmtid = ++plpgsql_curr_compile->nstatements;
@@ -1101,7 +1101,7 @@ getdiag_list_item : getdiag_target assign_operator getdiag_item
{
PLpgSQL_diag_item *new;
- new = palloc(sizeof(PLpgSQL_diag_item));
+ new = palloc_object(PLpgSQL_diag_item);
new->target = $1->dno;
new->kind = $3;
@@ -1191,7 +1191,7 @@ stmt_if : K_IF expr_until_then proc_sect stmt_elsifs stmt_else K_END K_IF ';'
{
PLpgSQL_stmt_if *new;
- new = palloc0(sizeof(PLpgSQL_stmt_if));
+ new = palloc0_object(PLpgSQL_stmt_if);
new->cmd_type = PLPGSQL_STMT_IF;
new->lineno = plpgsql_location_to_lineno(@1, yyscanner);
new->stmtid = ++plpgsql_curr_compile->nstatements;
@@ -1212,7 +1212,7 @@ stmt_elsifs :
{
PLpgSQL_if_elsif *new;
- new = palloc0(sizeof(PLpgSQL_if_elsif));
+ new = palloc0_object(PLpgSQL_if_elsif);
new->lineno = plpgsql_location_to_lineno(@2, yyscanner);
new->cond = $3;
new->stmts = $4;
@@ -1264,7 +1264,7 @@ case_when_list : case_when_list case_when
case_when : K_WHEN expr_until_then proc_sect
{
- PLpgSQL_case_when *new = palloc(sizeof(PLpgSQL_case_when));
+ PLpgSQL_case_when *new = palloc_object(PLpgSQL_case_when);
new->lineno = plpgsql_location_to_lineno(@1, yyscanner);
new->expr = $2;
@@ -1296,7 +1296,7 @@ stmt_loop : opt_loop_label K_LOOP loop_body
{
PLpgSQL_stmt_loop *new;
- new = palloc0(sizeof(PLpgSQL_stmt_loop));
+ new = palloc0_object(PLpgSQL_stmt_loop);
new->cmd_type = PLPGSQL_STMT_LOOP;
new->lineno = plpgsql_location_to_lineno(@2, yyscanner);
new->stmtid = ++plpgsql_curr_compile->nstatements;
@@ -1314,7 +1314,7 @@ stmt_while : opt_loop_label K_WHILE expr_until_loop loop_body
{
PLpgSQL_stmt_while *new;
- new = palloc0(sizeof(PLpgSQL_stmt_while));
+ new = palloc0_object(PLpgSQL_stmt_while);
new->cmd_type = PLPGSQL_STMT_WHILE;
new->lineno = plpgsql_location_to_lineno(@2, yyscanner);
new->stmtid = ++plpgsql_curr_compile->nstatements;
@@ -1380,7 +1380,7 @@ for_control : for_variable K_IN
"LOOP or USING",
&term, &yylval, &yylloc, yyscanner);
- new = palloc0(sizeof(PLpgSQL_stmt_dynfors));
+ new = palloc0_object(PLpgSQL_stmt_dynfors);
new->cmd_type = PLPGSQL_STMT_DYNFORS;
new->stmtid = ++plpgsql_curr_compile->nstatements;
if ($1.row)
@@ -1426,7 +1426,7 @@ for_control : for_variable K_IN
PLpgSQL_stmt_forc *new;
PLpgSQL_var *cursor = (PLpgSQL_var *) yylval.wdatum.datum;
- new = (PLpgSQL_stmt_forc *) palloc0(sizeof(PLpgSQL_stmt_forc));
+ new = palloc0_object(PLpgSQL_stmt_forc);
new->cmd_type = PLPGSQL_STMT_FORC;
new->stmtid = ++plpgsql_curr_compile->nstatements;
new->curvar = cursor->dno;
@@ -1545,7 +1545,7 @@ for_control : for_variable K_IN
NULL),
true);
- new = palloc0(sizeof(PLpgSQL_stmt_fori));
+ new = palloc0_object(PLpgSQL_stmt_fori);
new->cmd_type = PLPGSQL_STMT_FORI;
new->stmtid = ++plpgsql_curr_compile->nstatements;
new->var = fvar;
@@ -1573,7 +1573,7 @@ for_control : for_variable K_IN
check_sql_expr(expr1->query, expr1->parseMode,
expr1loc, yyscanner);
- new = palloc0(sizeof(PLpgSQL_stmt_fors));
+ new = palloc0_object(PLpgSQL_stmt_fors);
new->cmd_type = PLPGSQL_STMT_FORS;
new->stmtid = ++plpgsql_curr_compile->nstatements;
if ($1.row)
@@ -1675,7 +1675,7 @@ stmt_foreach_a : opt_loop_label K_FOREACH for_variable foreach_slice K_IN K_ARRA
{
PLpgSQL_stmt_foreach_a *new;
- new = palloc0(sizeof(PLpgSQL_stmt_foreach_a));
+ new = palloc0_object(PLpgSQL_stmt_foreach_a);
new->cmd_type = PLPGSQL_STMT_FOREACH_A;
new->lineno = plpgsql_location_to_lineno(@2, yyscanner);
new->stmtid = ++plpgsql_curr_compile->nstatements;
@@ -1723,7 +1723,7 @@ stmt_exit : exit_type opt_label opt_exitcond
{
PLpgSQL_stmt_exit *new;
- new = palloc0(sizeof(PLpgSQL_stmt_exit));
+ new = palloc0_object(PLpgSQL_stmt_exit);
new->cmd_type = PLPGSQL_STMT_EXIT;
new->stmtid = ++plpgsql_curr_compile->nstatements;
new->is_exit = $1;
@@ -1813,7 +1813,7 @@ stmt_raise : K_RAISE
PLpgSQL_stmt_raise *new;
int tok;
- new = palloc(sizeof(PLpgSQL_stmt_raise));
+ new = palloc_object(PLpgSQL_stmt_raise);
new->cmd_type = PLPGSQL_STMT_RAISE;
new->lineno = plpgsql_location_to_lineno(@1, yyscanner);
@@ -1959,7 +1959,7 @@ stmt_assert : K_ASSERT
PLpgSQL_stmt_assert *new;
int tok;
- new = palloc(sizeof(PLpgSQL_stmt_assert));
+ new = palloc_object(PLpgSQL_stmt_assert);
new->cmd_type = PLPGSQL_STMT_ASSERT;
new->lineno = plpgsql_location_to_lineno(@1, yyscanner);
@@ -2045,7 +2045,7 @@ stmt_dynexecute : K_EXECUTE
NULL, &endtoken,
&yylval, &yylloc, yyscanner);
- new = palloc(sizeof(PLpgSQL_stmt_dynexecute));
+ new = palloc_object(PLpgSQL_stmt_dynexecute);
new->cmd_type = PLPGSQL_STMT_DYNEXECUTE;
new->lineno = plpgsql_location_to_lineno(@1, yyscanner);
new->stmtid = ++plpgsql_curr_compile->nstatements;
@@ -2103,7 +2103,7 @@ stmt_open : K_OPEN cursor_variable
PLpgSQL_stmt_open *new;
int tok;
- new = palloc0(sizeof(PLpgSQL_stmt_open));
+ new = palloc0_object(PLpgSQL_stmt_open);
new->cmd_type = PLPGSQL_STMT_OPEN;
new->lineno = plpgsql_location_to_lineno(@1, yyscanner);
new->stmtid = ++plpgsql_curr_compile->nstatements;
@@ -2229,7 +2229,7 @@ stmt_close : K_CLOSE cursor_variable ';'
{
PLpgSQL_stmt_close *new;
- new = palloc(sizeof(PLpgSQL_stmt_close));
+ new = palloc_object(PLpgSQL_stmt_close);
new->cmd_type = PLPGSQL_STMT_CLOSE;
new->lineno = plpgsql_location_to_lineno(@1, yyscanner);
new->stmtid = ++plpgsql_curr_compile->nstatements;
@@ -2250,7 +2250,7 @@ stmt_commit : K_COMMIT opt_transaction_chain ';'
{
PLpgSQL_stmt_commit *new;
- new = palloc(sizeof(PLpgSQL_stmt_commit));
+ new = palloc_object(PLpgSQL_stmt_commit);
new->cmd_type = PLPGSQL_STMT_COMMIT;
new->lineno = plpgsql_location_to_lineno(@1, yyscanner);
new->stmtid = ++plpgsql_curr_compile->nstatements;
@@ -2264,7 +2264,7 @@ stmt_rollback : K_ROLLBACK opt_transaction_chain ';'
{
PLpgSQL_stmt_rollback *new;
- new = palloc(sizeof(PLpgSQL_stmt_rollback));
+ new = palloc_object(PLpgSQL_stmt_rollback);
new->cmd_type = PLPGSQL_STMT_ROLLBACK;
new->lineno = plpgsql_location_to_lineno(@1, yyscanner);
new->stmtid = ++plpgsql_curr_compile->nstatements;
@@ -2327,7 +2327,7 @@ exception_sect :
* current block.
*/
int lineno = plpgsql_location_to_lineno(@1, yyscanner);
- PLpgSQL_exception_block *new = palloc(sizeof(PLpgSQL_exception_block));
+ PLpgSQL_exception_block *new = palloc_object(PLpgSQL_exception_block);
PLpgSQL_variable *var;
plpgsql_curr_compile->has_exception_block = true;
@@ -2375,7 +2375,7 @@ proc_exception : K_WHEN proc_conditions K_THEN proc_sect
{
PLpgSQL_exception *new;
- new = palloc0(sizeof(PLpgSQL_exception));
+ new = palloc0_object(PLpgSQL_exception);
new->lineno = plpgsql_location_to_lineno(@1, yyscanner);
new->conditions = $2;
new->action = $4;
@@ -2420,7 +2420,7 @@ proc_condition : any_identifier
if (strspn(sqlstatestr, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") != 5)
yyerror(&yylloc, NULL, yyscanner, "invalid SQLSTATE code");
- new = palloc(sizeof(PLpgSQL_condition));
+ new = palloc_object(PLpgSQL_condition);
new->sqlerrstate =
MAKE_SQLSTATE(sqlstatestr[0],
sqlstatestr[1],
@@ -2671,7 +2671,7 @@ static PLpgSQL_expr *
make_plpgsql_expr(const char *query,
RawParseMode parsemode)
{
- PLpgSQL_expr *expr = palloc0(sizeof(PLpgSQL_expr));
+ PLpgSQL_expr *expr = palloc0_object(PLpgSQL_expr);
expr->query = pstrdup(query);
expr->parseMode = parsemode;
@@ -3181,7 +3181,7 @@ make_execsql_stmt(int firsttoken, int location, PLword *word, YYSTYPE *yylvalp,
check_sql_expr(expr->query, expr->parseMode, location, yyscanner);
- execsql = palloc0(sizeof(PLpgSQL_stmt_execsql));
+ execsql = palloc0_object(PLpgSQL_stmt_execsql);
execsql->cmd_type = PLPGSQL_STMT_EXECSQL;
execsql->lineno = plpgsql_location_to_lineno(location, yyscanner);
execsql->stmtid = ++plpgsql_curr_compile->nstatements;
@@ -3208,7 +3208,7 @@ read_fetch_direction(YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner)
* We create the PLpgSQL_stmt_fetch struct here, but only fill in the
* fields arising from the optional direction clause
*/
- fetch = (PLpgSQL_stmt_fetch *) palloc0(sizeof(PLpgSQL_stmt_fetch));
+ fetch = (PLpgSQL_stmt_fetch *) palloc0_object(PLpgSQL_stmt_fetch);
fetch->cmd_type = PLPGSQL_STMT_FETCH;
fetch->stmtid = ++plpgsql_curr_compile->nstatements;
/* set direction defaults: */
@@ -3360,7 +3360,7 @@ make_return_stmt(int location, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yysc
{
PLpgSQL_stmt_return *new;
- new = palloc0(sizeof(PLpgSQL_stmt_return));
+ new = palloc0_object(PLpgSQL_stmt_return);
new->cmd_type = PLPGSQL_STMT_RETURN;
new->lineno = plpgsql_location_to_lineno(location, yyscanner);
new->stmtid = ++plpgsql_curr_compile->nstatements;
@@ -3448,7 +3448,7 @@ make_return_next_stmt(int location, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t
errmsg("cannot use RETURN NEXT in a non-SETOF function"),
parser_errposition(location)));
- new = palloc0(sizeof(PLpgSQL_stmt_return_next));
+ new = palloc0_object(PLpgSQL_stmt_return_next);
new->cmd_type = PLPGSQL_STMT_RETURN_NEXT;
new->lineno = plpgsql_location_to_lineno(location, yyscanner);
new->stmtid = ++plpgsql_curr_compile->nstatements;
@@ -3512,7 +3512,7 @@ make_return_query_stmt(int location, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_
errmsg("cannot use RETURN QUERY in a non-SETOF function"),
parser_errposition(location)));
- new = palloc0(sizeof(PLpgSQL_stmt_return_query));
+ new = palloc0_object(PLpgSQL_stmt_return_query);
new->cmd_type = PLPGSQL_STMT_RETURN_QUERY;
new->lineno = plpgsql_location_to_lineno(location, yyscanner);
new->stmtid = ++plpgsql_curr_compile->nstatements;
@@ -3706,14 +3706,14 @@ read_into_scalar_list(char *initial_name,
*/
plpgsql_push_back_token(tok, yylvalp, yyllocp, yyscanner);
- row = palloc0(sizeof(PLpgSQL_row));
+ row = palloc0_object(PLpgSQL_row);
row->dtype = PLPGSQL_DTYPE_ROW;
row->refname = "(unnamed row)";
row->lineno = plpgsql_location_to_lineno(initial_location, yyscanner);
row->rowtupdesc = NULL;
row->nfields = nfields;
- row->fieldnames = palloc(sizeof(char *) * nfields);
- row->varnos = palloc(sizeof(int) * nfields);
+ row->fieldnames = palloc_array(char *, nfields);
+ row->varnos = palloc_array(int, nfields);
while (--nfields >= 0)
{
row->fieldnames[nfields] = fieldnames[nfields];
@@ -3741,14 +3741,14 @@ make_scalar_list1(char *initial_name,
check_assignable(initial_datum, location, yyscanner);
- row = palloc0(sizeof(PLpgSQL_row));
+ row = palloc0_object(PLpgSQL_row);
row->dtype = PLPGSQL_DTYPE_ROW;
row->refname = "(unnamed row)";
row->lineno = lineno;
row->rowtupdesc = NULL;
row->nfields = 1;
- row->fieldnames = palloc(sizeof(char *));
- row->varnos = palloc(sizeof(int));
+ row->fieldnames = palloc_object(char *);
+ row->varnos = palloc_object(int);
row->fieldnames[0] = initial_name;
row->varnos[0] = initial_datum->dno;
@@ -3955,7 +3955,7 @@ read_cursor_args(PLpgSQL_var *cursor, int until, YYSTYPE *yylvalp, YYLTYPE *yyll
* Read the arguments, one by one.
*/
row = (PLpgSQL_row *) plpgsql_Datums[cursor->cursor_explicit_argrow];
- argv = (char **) palloc0(row->nfields * sizeof(char *));
+ argv = (char **) palloc0_array(char *, row->nfields);
for (argc = 0; argc < row->nfields; argc++)
{
@@ -4091,7 +4091,7 @@ read_raise_options(YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t yyscanner)
if ((tok = yylex(yylvalp, yyllocp, yyscanner)) == 0)
yyerror(yyllocp, NULL, yyscanner, "unexpected end of function definition");
- opt = (PLpgSQL_raise_option *) palloc(sizeof(PLpgSQL_raise_option));
+ opt = palloc_object(PLpgSQL_raise_option);
if (tok_is_keyword(tok, yylvalp,
K_ERRCODE, "errcode"))
@@ -4182,7 +4182,7 @@ make_case(int location, PLpgSQL_expr *t_expr,
{
PLpgSQL_stmt_case *new;
- new = palloc(sizeof(PLpgSQL_stmt_case));
+ new = palloc_object(PLpgSQL_stmt_case);
new->cmd_type = PLPGSQL_STMT_CASE;
new->lineno = plpgsql_location_to_lineno(location, yyscanner);
new->stmtid = ++plpgsql_curr_compile->nstatements;
diff --git a/src/pl/plpython/plpy_procedure.c b/src/pl/plpython/plpy_procedure.c
index 655ab1d09ee..750ba586e0c 100644
--- a/src/pl/plpython/plpy_procedure.c
+++ b/src/pl/plpython/plpy_procedure.c
@@ -177,7 +177,7 @@ PLy_procedure_create(HeapTuple procTup, Oid fn_oid, PLyTrigType is_trigger)
oldcxt = MemoryContextSwitchTo(cxt);
- proc = (PLyProcedure *) palloc0(sizeof(PLyProcedure));
+ proc = palloc0_object(PLyProcedure);
proc->mcxt = cxt;
PG_TRY();
@@ -293,8 +293,8 @@ PLy_procedure_create(HeapTuple procTup, Oid fn_oid, PLyTrigType is_trigger)
}
/* Allocate arrays for per-input-argument data */
- proc->argnames = (char **) palloc0(sizeof(char *) * proc->nargs);
- proc->args = (PLyDatumToOb *) palloc0(sizeof(PLyDatumToOb) * proc->nargs);
+ proc->argnames = (char **) palloc0_array(char *, proc->nargs);
+ proc->args = (PLyDatumToOb *) palloc0_array(PLyDatumToOb, proc->nargs);
for (i = pos = 0; i < total; i++)
{
diff --git a/src/pl/plpython/plpy_spi.c b/src/pl/plpython/plpy_spi.c
index 1e386aadcca..46f2ca0f792 100644
--- a/src/pl/plpython/plpy_spi.c
+++ b/src/pl/plpython/plpy_spi.c
@@ -65,8 +65,8 @@ PLy_spi_prepare(PyObject *self, PyObject *args)
nargs = list ? PySequence_Length(list) : 0;
plan->nargs = nargs;
- plan->types = nargs ? palloc0(sizeof(Oid) * nargs) : NULL;
- plan->args = nargs ? palloc0(sizeof(PLyObToDatum) * nargs) : NULL;
+ plan->types = nargs ? palloc0_array(Oid, nargs) : NULL;
+ plan->args = nargs ? palloc0_array(PLyObToDatum, nargs) : NULL;
MemoryContextSwitchTo(oldcontext);
diff --git a/src/pl/plpython/plpy_typeio.c b/src/pl/plpython/plpy_typeio.c
index d88d10068f3..1f69109b081 100644
--- a/src/pl/plpython/plpy_typeio.c
+++ b/src/pl/plpython/plpy_typeio.c
@@ -1353,8 +1353,8 @@ PLyMapping_ToComposite(PLyObToDatum *arg, TupleDesc desc, PyObject *mapping)
Assert(PyMapping_Check(mapping));
/* Build tuple */
- values = palloc(sizeof(Datum) * desc->natts);
- nulls = palloc(sizeof(bool) * desc->natts);
+ values = palloc_array(Datum, desc->natts);
+ nulls = palloc_array(bool, desc->natts);
for (i = 0; i < desc->natts; ++i)
{
char *key;
@@ -1435,8 +1435,8 @@ PLySequence_ToComposite(PLyObToDatum *arg, TupleDesc desc, PyObject *sequence)
errmsg("length of returned sequence did not match number of columns in row")));
/* Build tuple */
- values = palloc(sizeof(Datum) * desc->natts);
- nulls = palloc(sizeof(bool) * desc->natts);
+ values = palloc_array(Datum, desc->natts);
+ nulls = palloc_array(bool, desc->natts);
idx = 0;
for (i = 0; i < desc->natts; ++i)
{
@@ -1493,8 +1493,8 @@ PLyGenericObject_ToComposite(PLyObToDatum *arg, TupleDesc desc, PyObject *object
volatile int i;
/* Build tuple */
- values = palloc(sizeof(Datum) * desc->natts);
- nulls = palloc(sizeof(bool) * desc->natts);
+ values = palloc_array(Datum, desc->natts);
+ nulls = palloc_array(bool, desc->natts);
for (i = 0; i < desc->natts; ++i)
{
char *key;
diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c
index 73d660e88a6..187698ccdd2 100644
--- a/src/pl/tcl/pltcl.c
+++ b/src/pl/tcl/pltcl.c
@@ -1586,7 +1586,7 @@ compile_pltcl_function(Oid fn_oid, Oid tgreloid,
* struct prodesc and subsidiary data must all live in proc_cxt.
************************************************************/
oldcontext = MemoryContextSwitchTo(proc_cxt);
- prodesc = (pltcl_proc_desc *) palloc0(sizeof(pltcl_proc_desc));
+ prodesc = palloc0_object(pltcl_proc_desc);
prodesc->user_proname = pstrdup(user_proname);
MemoryContextSetIdentifier(proc_cxt, prodesc->user_proname);
prodesc->internal_proname = pstrdup(internal_proname);
@@ -2668,7 +2668,7 @@ pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp,
"PL/Tcl spi_prepare query",
ALLOCSET_SMALL_SIZES);
MemoryContextSwitchTo(plan_cxt);
- qdesc = (pltcl_query_desc *) palloc0(sizeof(pltcl_query_desc));
+ qdesc = palloc0_object(pltcl_query_desc);
snprintf(qdesc->qname, sizeof(qdesc->qname), "%p", qdesc);
qdesc->nargs = nargs;
qdesc->argtypes = (Oid *) palloc(nargs * sizeof(Oid));
diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c
index 94ef639b6fc..a34382a5f79 100644
--- a/src/test/modules/dummy_index_am/dummy_index_am.c
+++ b/src/test/modules/dummy_index_am/dummy_index_am.c
@@ -138,7 +138,7 @@ dibuild(Relation heap, Relation index, IndexInfo *indexInfo)
{
IndexBuildResult *result;
- result = (IndexBuildResult *) palloc(sizeof(IndexBuildResult));
+ result = palloc_object(IndexBuildResult);
/* let's pretend that no tuples were scanned */
result->heap_tuples = 0;
diff --git a/src/test/modules/spgist_name_ops/spgist_name_ops.c b/src/test/modules/spgist_name_ops/spgist_name_ops.c
index 38e54e0e0a4..f32dfb317fa 100644
--- a/src/test/modules/spgist_name_ops/spgist_name_ops.c
+++ b/src/test/modules/spgist_name_ops/spgist_name_ops.c
@@ -171,7 +171,7 @@ spgist_name_choose(PG_FUNCTION_ARGS)
}
out->result.splitTuple.prefixNNodes = 1;
out->result.splitTuple.prefixNodeLabels =
- (Datum *) palloc(sizeof(Datum));
+ palloc_object(Datum);
out->result.splitTuple.prefixNodeLabels[0] =
Int16GetDatum(*(unsigned char *) (prefixStr + commonLen));
@@ -243,7 +243,7 @@ spgist_name_choose(PG_FUNCTION_ARGS)
out->result.splitTuple.prefixHasPrefix = in->hasPrefix;
out->result.splitTuple.prefixPrefixDatum = in->prefixDatum;
out->result.splitTuple.prefixNNodes = 1;
- out->result.splitTuple.prefixNodeLabels = (Datum *) palloc(sizeof(Datum));
+ out->result.splitTuple.prefixNodeLabels = palloc_object(Datum);
out->result.splitTuple.prefixNodeLabels[0] = Int16GetDatum(-2);
out->result.splitTuple.childNodeN = 0;
out->result.splitTuple.postfixHasPrefix = false;
@@ -318,9 +318,9 @@ spgist_name_inner_consistent(PG_FUNCTION_ARGS)
* and see if it's consistent with the query. If so, emit an entry into
* the output arrays.
*/
- out->nodeNumbers = (int *) palloc(sizeof(int) * in->nNodes);
- out->levelAdds = (int *) palloc(sizeof(int) * in->nNodes);
- out->reconstructedValues = (Datum *) palloc(sizeof(Datum) * in->nNodes);
+ out->nodeNumbers = palloc_array(int, in->nNodes);
+ out->levelAdds = palloc_array(int, in->nNodes);
+ out->reconstructedValues = palloc_array(Datum, in->nNodes);
out->nNodes = 0;
for (i = 0; i < in->nNodes; i++)
diff --git a/src/test/modules/test_bitmapset/test_bitmapset.c b/src/test/modules/test_bitmapset/test_bitmapset.c
index 8162285fcb3..69383a98e37 100644
--- a/src/test/modules/test_bitmapset/test_bitmapset.c
+++ b/src/test/modules/test_bitmapset/test_bitmapset.c
@@ -622,7 +622,7 @@ test_random_operations(PG_FUNCTION_ARGS)
* still possible if all the operations hit the "0" case during phase 4
* where multiple operation types are mixed together.
*/
- members = palloc(sizeof(int) * num_ops);
+ members = palloc_array(int, num_ops);
/* Phase 1: Random insertions in first set */
for (int i = 0; i < num_ops / 2; i++)
diff --git a/src/test/modules/test_integerset/test_integerset.c b/src/test/modules/test_integerset/test_integerset.c
index cfdc6762785..7ac1fe6cb23 100644
--- a/src/test/modules/test_integerset/test_integerset.c
+++ b/src/test/modules/test_integerset/test_integerset.c
@@ -385,7 +385,7 @@ test_single_value_and_filler(uint64 value, uint64 filler_min, uint64 filler_max)
intset = intset_create();
- iter_expected = palloc(sizeof(uint64) * (filler_max - filler_min + 1));
+ iter_expected = palloc_array(uint64, filler_max - filler_min + 1);
if (value < filler_min)
{
intset_add_member(intset, value);
diff --git a/src/test/modules/test_json_parser/test_json_parser_incremental.c b/src/test/modules/test_json_parser/test_json_parser_incremental.c
index 8c78061ee46..a95ac798481 100644
--- a/src/test/modules/test_json_parser/test_json_parser_incremental.c
+++ b/src/test/modules/test_json_parser/test_json_parser_incremental.c
@@ -124,7 +124,7 @@ main(int argc, char **argv)
break;
case 's': /* do semantic processing */
testsem = &sem;
- sem.semstate = palloc(sizeof(struct DoState));
+ sem.semstate = palloc_object(struct DoState);
((struct DoState *) sem.semstate)->lex = lex;
((struct DoState *) sem.semstate)->buf = makeStringInfo();
need_strings = true;
diff --git a/src/test/modules/test_parser/test_parser.c b/src/test/modules/test_parser/test_parser.c
index 15ed3617cb5..353f9072819 100644
--- a/src/test/modules/test_parser/test_parser.c
+++ b/src/test/modules/test_parser/test_parser.c
@@ -46,7 +46,7 @@ PG_FUNCTION_INFO_V1(testprs_lextype);
Datum
testprs_start(PG_FUNCTION_ARGS)
{
- ParserState *pst = (ParserState *) palloc0(sizeof(ParserState));
+ ParserState *pst = palloc0_object(ParserState);
pst->buffer = (char *) PG_GETARG_POINTER(0);
pst->len = PG_GETARG_INT32(1);
@@ -112,7 +112,7 @@ testprs_lextype(PG_FUNCTION_ARGS)
* the same lexids like Teodor in the default word parser; in this way we
* can reuse the headline function of the default word parser.
*/
- LexDescr *descr = (LexDescr *) palloc(sizeof(LexDescr) * (2 + 1));
+ LexDescr *descr = palloc_array(LexDescr, 2 + 1);
/* there are only two types in this parser */
descr[0].lexid = 3;
diff --git a/src/test/modules/test_radixtree/test_radixtree.c b/src/test/modules/test_radixtree/test_radixtree.c
index 606d8d3cd2d..031e8737d45 100644
--- a/src/test/modules/test_radixtree/test_radixtree.c
+++ b/src/test/modules/test_radixtree/test_radixtree.c
@@ -183,7 +183,7 @@ test_basic(rt_node_class_test_elem *test_info, int shift, bool asc)
elog(NOTICE, "testing node %s with shift %d and %s keys",
test_info->class_name, shift, asc ? "ascending" : "descending");
- keys = palloc(sizeof(uint64) * children);
+ keys = palloc_array(uint64, children);
for (int i = 0; i < children; i++)
{
if (asc)
diff --git a/src/test/modules/test_regex/test_regex.c b/src/test/modules/test_regex/test_regex.c
index 2548a0ef7b1..32ff9b13d8f 100644
--- a/src/test/modules/test_regex/test_regex.c
+++ b/src/test/modules/test_regex/test_regex.c
@@ -107,10 +107,8 @@ test_regex(PG_FUNCTION_ARGS)
true);
/* Pre-create workspace that build_test_match_result needs */
- matchctx->elems = (Datum *) palloc(sizeof(Datum) *
- (matchctx->npatterns + 1));
- matchctx->nulls = (bool *) palloc(sizeof(bool) *
- (matchctx->npatterns + 1));
+ matchctx->elems = palloc_array(Datum, matchctx->npatterns + 1);
+ matchctx->nulls = palloc_array(bool, matchctx->npatterns + 1);
MemoryContextSwitchTo(oldcontext);
funcctx->user_fctx = matchctx;
@@ -436,7 +434,7 @@ setup_test_matches(text *orig_str,
Oid collation,
bool use_subpatterns)
{
- test_regex_ctx *matchctx = palloc0(sizeof(test_regex_ctx));
+ test_regex_ctx *matchctx = palloc0_object(test_regex_ctx);
int eml = pg_database_encoding_max_length();
int orig_len;
pg_wchar *wide_str;
@@ -457,7 +455,7 @@ setup_test_matches(text *orig_str,
/* 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);
/* do we want to remember subpatterns? */
@@ -474,7 +472,7 @@ setup_test_matches(text *orig_str,
}
/* 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)
@@ -483,7 +481,7 @@ setup_test_matches(text *orig_str,
* 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/test/modules/test_resowner/test_resowner_many.c b/src/test/modules/test_resowner/test_resowner_many.c
index 1f64939404f..e43f911244a 100644
--- a/src/test/modules/test_resowner/test_resowner_many.c
+++ b/src/test/modules/test_resowner/test_resowner_many.c
@@ -121,7 +121,7 @@ RememberManyTestResources(ResourceOwner owner,
for (int i = 0; i < nresources; i++)
{
- ManyTestResource *mres = palloc(sizeof(ManyTestResource));
+ ManyTestResource *mres = palloc_object(ManyTestResource);
mres->kind = &kinds[kind_idx];
dlist_node_init(&mres->node);
diff --git a/src/test/modules/test_rls_hooks/test_rls_hooks.c b/src/test/modules/test_rls_hooks/test_rls_hooks.c
index b1f161cf7bb..86453f96147 100644
--- a/src/test/modules/test_rls_hooks/test_rls_hooks.c
+++ b/src/test/modules/test_rls_hooks/test_rls_hooks.c
@@ -44,7 +44,7 @@ List *
test_rls_hooks_permissive(CmdType cmdtype, Relation relation)
{
List *policies = NIL;
- RowSecurityPolicy *policy = palloc0(sizeof(RowSecurityPolicy));
+ RowSecurityPolicy *policy = palloc0_object(RowSecurityPolicy);
Datum role;
FuncCall *n;
Node *e;
@@ -112,7 +112,7 @@ List *
test_rls_hooks_restrictive(CmdType cmdtype, Relation relation)
{
List *policies = NIL;
- RowSecurityPolicy *policy = palloc0(sizeof(RowSecurityPolicy));
+ RowSecurityPolicy *policy = palloc0_object(RowSecurityPolicy);
Datum role;
FuncCall *n;
Node *e;
diff --git a/src/test/modules/worker_spi/worker_spi.c b/src/test/modules/worker_spi/worker_spi.c
index bea8339f464..1a21b8c8876 100644
--- a/src/test/modules/worker_spi/worker_spi.c
+++ b/src/test/modules/worker_spi/worker_spi.c
@@ -142,7 +142,7 @@ worker_spi_main(Datum main_arg)
char *p;
bits32 flags = 0;
- table = palloc(sizeof(worktable));
+ table = palloc_object(worktable);
sprintf(name, "schema%d", index);
table->schema = pstrdup(name);
table->name = pstrdup("counted");
diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c
index 56cc0567b1c..c27305cf10b 100644
--- a/src/test/regress/regress.c
+++ b/src/test/regress/regress.c
@@ -198,7 +198,7 @@ widget_in(PG_FUNCTION_ARGS)
errmsg("invalid input syntax for type %s: \"%s\"",
"widget", str)));
- result = (WIDGET *) palloc(sizeof(WIDGET));
+ result = palloc_object(WIDGET);
result->center.x = atof(coord[0]);
result->center.y = atof(coord[1]);
result->radius = atof(coord[2]);
diff --git a/src/timezone/pgtz.c b/src/timezone/pgtz.c
index 504c0235ffb..505a2d33839 100644
--- a/src/timezone/pgtz.c
+++ b/src/timezone/pgtz.c
@@ -396,7 +396,7 @@ struct pg_tzenum
pg_tzenum *
pg_tzenumerate_start(void)
{
- pg_tzenum *ret = (pg_tzenum *) palloc0(sizeof(pg_tzenum));
+ pg_tzenum *ret = palloc0_object(pg_tzenum);
char *startdir = pstrdup(pg_TZDIR());
ret->baselen = strlen(startdir) + 1;
diff --git a/src/tutorial/complex.c b/src/tutorial/complex.c
index 6798a9e6ba6..46dc54e62d0 100644
--- a/src/tutorial/complex.c
+++ b/src/tutorial/complex.c
@@ -41,7 +41,7 @@ complex_in(PG_FUNCTION_ARGS)
errmsg("invalid input syntax for type %s: \"%s\"",
"complex", str)));
- result = (Complex *) palloc(sizeof(Complex));
+ result = palloc_object(Complex);
result->x = x;
result->y = y;
PG_RETURN_POINTER(result);
@@ -73,7 +73,7 @@ complex_recv(PG_FUNCTION_ARGS)
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
Complex *result;
- result = (Complex *) palloc(sizeof(Complex));
+ result = palloc_object(Complex);
result->x = pq_getmsgfloat8(buf);
result->y = pq_getmsgfloat8(buf);
PG_RETURN_POINTER(result);
@@ -108,7 +108,7 @@ complex_add(PG_FUNCTION_ARGS)
Complex *b = (Complex *) PG_GETARG_POINTER(1);
Complex *result;
- result = (Complex *) palloc(sizeof(Complex));
+ result = palloc_object(Complex);
result->x = a->x + b->x;
result->y = a->y + b->y;
PG_RETURN_POINTER(result);
diff --git a/src/tutorial/funcs.c b/src/tutorial/funcs.c
index 3cc94534187..80882cf1414 100644
--- a/src/tutorial/funcs.c
+++ b/src/tutorial/funcs.c
@@ -50,7 +50,7 @@ makepoint(PG_FUNCTION_ARGS)
{
Point *pointx = PG_GETARG_POINT_P(0);
Point *pointy = PG_GETARG_POINT_P(1);
- Point *new_point = (Point *) palloc(sizeof(Point));
+ Point *new_point = palloc_object(Point);
new_point->x = pointx->x;
new_point->y = pointy->y;