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);
}
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.
/* 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;
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);
{
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;
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;
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;
{
astreamer_verify *streamer;
- streamer = palloc0(sizeof(astreamer_verify));
+ streamer = palloc0_object(astreamer_verify);
*((const astreamer_ops **) &streamer->base.bbs_ops) =
&astreamer_verify_ops;
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;
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);
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
/* 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)
{
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;
/* 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));
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);
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;
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
{
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;
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;
return NULL;
}
- filenames = (char **) palloc(fnsize * sizeof(char *));
+ filenames = palloc_array(char *, fnsize);
while (errno = 0, (file = readdir(dir)) != NULL)
{
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);
}
return false;
}
- dirnames = (char **) palloc(sizeof(char *) * dirnames_capacity);
+ dirnames = palloc_array(char *, dirnames_capacity);
while (errno = 0, (de = readdir(dir)))
{
static inline StringInfo
makeStringInfoInternal(int initsize)
{
- StringInfo res = (StringInfo) palloc(sizeof(StringInfoData));
+ StringInfo res = palloc_object(StringInfoData);
initStringInfoInternal(res, initsize);
return res;
{
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;
{
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);
#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;
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;
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;
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;
{
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;
{
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;
{
astreamer *streamer;
- streamer = palloc0(sizeof(astreamer));
+ streamer = palloc0_object(astreamer);
*((const astreamer_ops **) &streamer->bbs_ops) =
&astreamer_tar_terminator_ops;
streamer->bbs_next = 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_compressor_ops;
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;
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;
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++)
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;
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));
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);
* 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,
&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];
* 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;
"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;
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);
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;
{
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);
{
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;
/* 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;
{
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;
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++)
{
}
/* 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;
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;
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;
{
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;
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];
{
if (n > 0)
{
- *varnos = (int *) palloc(sizeof(int) * n);
+ *varnos = palloc_array(int, n);
n = 0;
for (i = datums_last; i < plpgsql_nDatums; i++)
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
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;
*/
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));
{
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);
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)
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;
{
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;
/* 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;
}
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;
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;
{
PLpgSQL_diag_item *new;
- new = palloc(sizeof(PLpgSQL_diag_item));
+ new = palloc_object(PLpgSQL_diag_item);
new->target = $1->dno;
new->kind = $3;
{
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;
{
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;
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;
{
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;
{
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;
"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)
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;
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;
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)
{
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;
{
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;
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);
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);
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;
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;
{
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;
{
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;
{
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;
* 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;
{
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;
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],
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;
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;
* 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: */
{
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;
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;
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;
*/
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];
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;
* 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++)
{
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"))
{
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;
oldcxt = MemoryContextSwitchTo(cxt);
- proc = (PLyProcedure *) palloc0(sizeof(PLyProcedure));
+ proc = palloc0_object(PLyProcedure);
proc->mcxt = cxt;
PG_TRY();
}
/* 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++)
{
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);
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;
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)
{
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;
* 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);
"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));
{
IndexBuildResult *result;
- result = (IndexBuildResult *) palloc(sizeof(IndexBuildResult));
+ result = palloc_object(IndexBuildResult);
/* let's pretend that no tuples were scanned */
result->heap_tuples = 0;
}
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));
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;
* 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++)
* 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++)
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);
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;
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);
* 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;
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)
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;
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;
/* 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? */
}
/* 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)
* 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 */
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);
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;
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;
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");
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]);
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;
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);
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);
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);
{
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;