DumpOptions *
NewDumpOptions(void)
{
- DumpOptions *opts = (DumpOptions *) pg_malloc(sizeof(DumpOptions));
+ DumpOptions *opts = pg_malloc_object(DumpOptions);
InitDumpOptions(opts);
return opts;
{
RestoreOptions *opts;
- opts = (RestoreOptions *) pg_malloc0(sizeof(RestoreOptions));
+ opts = pg_malloc0_object(RestoreOptions);
/* set any fields that shouldn't default to zeroes */
opts->format = archUnknown;
ArchiveHandle *AH = (ArchiveHandle *) AHX;
TocEntry *newToc;
- newToc = (TocEntry *) pg_malloc0(sizeof(TocEntry));
+ newToc = pg_malloc0_object(TocEntry);
AH->tocCount++;
if (dumpId > AH->maxDumpId)
if (opts->nDeps > 0)
{
- newToc->dependencies = (DumpId *) pg_malloc(opts->nDeps * sizeof(DumpId));
+ newToc->dependencies = pg_malloc_array(DumpId, opts->nDeps);
memcpy(newToc->dependencies, opts->deps, opts->nDeps * sizeof(DumpId));
newToc->nDeps = opts->nDeps;
}
StringInfoData linebuf;
/* Allocate space for the 'wanted' array, and init it */
- ropt->idWanted = (bool *) pg_malloc0(sizeof(bool) * AH->maxDumpId);
+ ropt->idWanted = pg_malloc0_array(bool, AH->maxDumpId);
/* Setup the file */
fh = fopen(ropt->tocFile, PG_BINARY_R);
DumpId maxDumpId = AH->maxDumpId;
TocEntry *te;
- AH->tocsByDumpId = (TocEntry **) pg_malloc0((maxDumpId + 1) * sizeof(TocEntry *));
- AH->tableDataId = (DumpId *) pg_malloc0((maxDumpId + 1) * sizeof(DumpId));
+ AH->tocsByDumpId = pg_malloc0_array(TocEntry *, (maxDumpId + 1));
+ AH->tableDataId = pg_malloc0_array(DumpId, (maxDumpId + 1));
for (te = AH->toc->next; te != AH->toc; te = te->next)
{
pg_log_debug("allocating AH for %s, format %d",
FileSpec ? FileSpec : "(stdio)", fmt);
- AH = (ArchiveHandle *) pg_malloc0(sizeof(ArchiveHandle));
+ AH = pg_malloc0_object(ArchiveHandle);
AH->version = K_VERS_SELF;
AH->currTablespace = NULL; /* ditto */
AH->currTableAm = NULL; /* ditto */
- AH->toc = (TocEntry *) pg_malloc0(sizeof(TocEntry));
+ AH->toc = pg_malloc0_object(TocEntry);
AH->toc->next = AH->toc;
AH->toc->prev = AH->toc;
TocEntry **tes;
int ntes;
- tes = (TocEntry **) pg_malloc(AH->tocCount * sizeof(TocEntry *));
+ tes = pg_malloc_array(TocEntry *, AH->tocCount);
ntes = 0;
for (te = AH->toc->next; te != AH->toc; te = te->next)
{
for (i = 0; i < AH->tocCount; i++)
{
- te = (TocEntry *) pg_malloc0(sizeof(TocEntry));
+ te = pg_malloc0_object(TocEntry);
te->dumpId = ReadInt(AH);
if (te->dumpId > AH->maxDumpId)
if (AH->version >= K_VERS_1_5)
{
depSize = 100;
- deps = (DumpId *) pg_malloc(sizeof(DumpId) * depSize);
+ deps = pg_malloc_array(DumpId, depSize);
depIdx = 0;
for (;;)
{
if (depIdx >= depSize)
{
depSize *= 2;
- deps = (DumpId *) pg_realloc(deps, sizeof(DumpId) * depSize);
+ deps = pg_realloc_array(deps, DumpId, depSize);
}
sscanf(tmp, "%d", &deps[depIdx]);
free(tmp);
if (depIdx > 0) /* We have a non-null entry */
{
- deps = (DumpId *) pg_realloc(deps, sizeof(DumpId) * depIdx);
+ deps = pg_realloc_array(deps, DumpId, depIdx);
te->dependencies = deps;
te->nDeps = depIdx;
}
{
if (strcmp(te2->desc, "BLOBS") == 0)
{
- te->dependencies = (DumpId *) pg_malloc(sizeof(DumpId));
+ te->dependencies = pg_malloc_object(DumpId);
te->dependencies[0] = te2->dumpId;
te->nDeps++;
te->depCount++;
for (te = AH->toc->next; te != AH->toc; te = te->next)
{
if (te->nRevDeps > 0)
- te->revDeps = (DumpId *) pg_malloc(te->nRevDeps * sizeof(DumpId));
+ te->revDeps = pg_malloc_array(DumpId, te->nRevDeps);
te->nRevDeps = 0;
}
* difference between a dependency on a table and a dependency on its
* data, so that closer analysis would be needed here.
*/
- lockids = (DumpId *) pg_malloc(te->nDeps * sizeof(DumpId));
+ lockids = pg_malloc_array(DumpId, te->nDeps);
nlockids = 0;
for (i = 0; i < te->nDeps; i++)
{
return;
}
- te->lockDeps = pg_realloc(lockids, nlockids * sizeof(DumpId));
+ te->lockDeps = pg_realloc_array(lockids, DumpId, nlockids);
te->nLockDeps = nlockids;
}
ArchiveHandle *clone;
/* Make a "flat" copy */
- clone = (ArchiveHandle *) pg_malloc(sizeof(ArchiveHandle));
+ clone = pg_malloc_object(ArchiveHandle);
memcpy(clone, AH, sizeof(ArchiveHandle));
/* Likewise flat-copy the RestoreOptions, so we can alter them locally */
- clone->public.ropt = (RestoreOptions *) pg_malloc(sizeof(RestoreOptions));
+ clone->public.ropt = pg_malloc_object(RestoreOptions);
memcpy(clone->public.ropt, AH->public.ropt, sizeof(RestoreOptions));
/* Handle format-independent fields */
* Initialize prepared-query state to "nothing prepared". We do this here
* so that a parallel dump worker will have its own state.
*/
- AH->is_prepared = (bool *) pg_malloc0(NUM_PREP_QUERIES * sizeof(bool));
+ AH->is_prepared = pg_malloc0_array(bool, NUM_PREP_QUERIES);
/*
* Start transaction-snapshot mode transaction to dump consistent data.
* actual column value --- but we can save a few cycles by fetching nulls
* rather than the uninteresting-to-us value.
*/
- attgenerated = (char *) pg_malloc(tbinfo->numatts * sizeof(char));
+ attgenerated = pg_malloc_array(char, tbinfo->numatts);
appendPQExpBufferStr(q, "DECLARE _pg_dump_cursor CURSOR FOR SELECT ");
nfields = 0;
for (i = 0; i < tbinfo->numatts; i++)
return;
/* OK, let's dump it */
- tdinfo = (TableDataInfo *) pg_malloc(sizeof(TableDataInfo));
+ tdinfo = pg_malloc_object(TableDataInfo);
if (tbinfo->relkind == RELKIND_MATVIEW)
tdinfo->dobj.objType = DO_REFRESH_MATVIEW;
* Create a "BLOBS" data item for the group, too. This is just a
* placeholder for sorting; it carries no data now.
*/
- lodata = (DumpableObject *) pg_malloc(sizeof(DumpableObject));
+ lodata = pg_malloc_object(DumpableObject);
lodata->objType = DO_LARGE_OBJECT_DATA;
lodata->catId = nilCatalogId;
AssignDumpId(lodata);
lodata->name = pg_strdup(namebuf);
lodata->components |= DUMP_COMPONENT_DATA;
/* Set up explicit dependency from data to metadata */
- lodata->dependencies = (DumpId *) pg_malloc(sizeof(DumpId));
+ lodata->dependencies = pg_malloc_object(DumpId);
lodata->dependencies[0] = loinfo->dobj.dumpId;
lodata->nDeps = lodata->allocDeps = 1;
}
* Note: use tableoid 0 so that this object won't be mistaken for
* something that pg_depend entries apply to.
*/
- polinfo = pg_malloc(sizeof(PolicyInfo));
+ polinfo = pg_malloc_object(PolicyInfo);
polinfo->dobj.objType = DO_POLICY;
polinfo->dobj.catId.tableoid = 0;
polinfo->dobj.catId.oid = tbinfo->dobj.catId.oid;
i_polqual = PQfnumber(res, "polqual");
i_polwithcheck = PQfnumber(res, "polwithcheck");
- polinfo = pg_malloc(ntups * sizeof(PolicyInfo));
+ polinfo = pg_malloc_array(PolicyInfo, ntups);
for (j = 0; j < ntups; j++)
{
i_pubviaroot = PQfnumber(res, "pubviaroot");
i_pubgencols = PQfnumber(res, "pubgencols");
- pubinfo = pg_malloc(ntups * sizeof(PublicationInfo));
+ pubinfo = pg_malloc_array(PublicationInfo, ntups);
for (i = 0; i < ntups; i++)
{
i_pnnspid = PQfnumber(res, "pnnspid");
/* this allocation may be more than we need */
- pubsinfo = pg_malloc(ntups * sizeof(PublicationSchemaInfo));
+ pubsinfo = pg_malloc_array(PublicationSchemaInfo, ntups);
j = 0;
for (i = 0; i < ntups; i++)
i_prattrs = PQfnumber(res, "prattrs");
/* this allocation may be more than we need */
- pubrinfo = pg_malloc(ntups * sizeof(PublicationRelInfo));
+ pubrinfo = pg_malloc_array(PublicationRelInfo, ntups);
j = 0;
for (i = 0; i < ntups; i++)
i_suborigin = PQfnumber(res, "suborigin");
i_suboriginremotelsn = PQfnumber(res, "suboriginremotelsn");
- subinfo = pg_malloc(ntups * sizeof(SubscriptionInfo));
+ subinfo = pg_malloc_array(SubscriptionInfo, ntups);
for (i = 0; i < ntups; i++)
{
i_srsubstate = PQfnumber(res, "srsubstate");
i_srsublsn = PQfnumber(res, "srsublsn");
- subrinfo = pg_malloc(ntups * sizeof(SubRelInfo));
+ subrinfo = pg_malloc_array(SubRelInfo, ntups);
for (int i = 0; i < ntups; i++)
{
Oid cur_srsubid = atooid(PQgetvalue(res, i, i_srsubid));
res = ExecuteSqlQuery(fout, query, PGRES_TUPLES_OK);
nbinaryUpgradeClassOids = PQntuples(res);
- binaryUpgradeClassOids = (BinaryUpgradeClassOidItem *)
- pg_malloc(nbinaryUpgradeClassOids * sizeof(BinaryUpgradeClassOidItem));
+ binaryUpgradeClassOids =
+ pg_malloc_array(BinaryUpgradeClassOidItem, nbinaryUpgradeClassOids);
for (int i = 0; i < nbinaryUpgradeClassOids; i++)
{
ntups = PQntuples(res);
- nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
+ nsinfo = pg_malloc_array(NamespaceInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
if (ntups == 0)
goto cleanup;
- extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
+ extinfo = pg_malloc_array(ExtensionInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
ntups = PQntuples(res);
- tyinfo = (TypeInfo *) pg_malloc(ntups * sizeof(TypeInfo));
+ tyinfo = pg_malloc_array(TypeInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
(tyinfo[i].typtype == TYPTYPE_BASE ||
tyinfo[i].typtype == TYPTYPE_RANGE))
{
- stinfo = (ShellTypeInfo *) pg_malloc(sizeof(ShellTypeInfo));
+ stinfo = pg_malloc_object(ShellTypeInfo);
stinfo->dobj.objType = DO_SHELL_TYPE;
stinfo->dobj.catId = nilCatalogId;
AssignDumpId(&stinfo->dobj);
ntups = PQntuples(res);
- oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
+ oprinfo = pg_malloc_array(OprInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
ntups = PQntuples(res);
- collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
+ collinfo = pg_malloc_array(CollInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
ntups = PQntuples(res);
- convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
+ convinfo = pg_malloc_array(ConvInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
ntups = PQntuples(res);
- aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
+ aminfo = pg_malloc_array(AccessMethodInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
ntups = PQntuples(res);
- opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
+ opcinfo = pg_malloc_array(OpclassInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
ntups = PQntuples(res);
- opfinfo = (OpfamilyInfo *) pg_malloc(ntups * sizeof(OpfamilyInfo));
+ opfinfo = pg_malloc_array(OpfamilyInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
ntups = PQntuples(res);
- agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
+ agginfo = pg_malloc_array(AggInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
agginfo[i].aggfn.argtypes = NULL;
else
{
- agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
+ agginfo[i].aggfn.argtypes = pg_malloc_array(Oid, agginfo[i].aggfn.nargs);
parseOidArray(PQgetvalue(res, i, i_proargtypes),
agginfo[i].aggfn.argtypes,
agginfo[i].aggfn.nargs);
ntups = PQntuples(res);
- finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo));
+ finfo = pg_malloc0_array(FuncInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
finfo[i].argtypes = NULL;
else
{
- finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid));
+ finfo[i].argtypes = pg_malloc_array(Oid, finfo[i].nargs);
parseOidArray(PQgetvalue(res, i, i_proargtypes),
finfo[i].argtypes, finfo[i].nargs);
}
(relkind == RELKIND_MATVIEW ||
relkind == RELKIND_FOREIGN_TABLE))
{
- RelStatsInfo *info = pg_malloc0(sizeof(RelStatsInfo));
+ RelStatsInfo *info = pg_malloc0_object(RelStatsInfo);
DumpableObject *dobj = &info->dobj;
dobj->objType = DO_REL_STATS;
dobj->catId.tableoid = 0;
dobj->catId.oid = 0;
AssignDumpId(dobj);
- dobj->dependencies = (DumpId *) pg_malloc(sizeof(DumpId));
+ dobj->dependencies = pg_malloc_object(DumpId);
dobj->dependencies[0] = rel->dumpId;
dobj->nDeps = 1;
dobj->allocDeps = 1;
* only one, because we don't yet know which tables might be inheritance
* ancestors of the target table.
*/
- tblinfo = (TableInfo *) pg_malloc0(ntups * sizeof(TableInfo));
+ tblinfo = pg_malloc0_array(TableInfo, ntups);
i_reltableoid = PQfnumber(res, "tableoid");
i_reloid = PQfnumber(res, "oid");
*numInherits = ntups;
- inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
+ inhinfo = pg_malloc_array(InhInfo, ntups);
i_inhrelid = PQfnumber(res, "inhrelid");
i_inhparent = PQfnumber(res, "inhparent");
i_indstatcols = PQfnumber(res, "indstatcols");
i_indstatvals = PQfnumber(res, "indstatvals");
- indxinfo = (IndxInfo *) pg_malloc(ntups * sizeof(IndxInfo));
+ indxinfo = pg_malloc_array(IndxInfo, ntups);
/*
* Outer loop iterates once per table, not once per row. Incrementing of
indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions));
indxinfo[j].indstatcols = pg_strdup(PQgetvalue(res, j, i_indstatcols));
indxinfo[j].indstatvals = pg_strdup(PQgetvalue(res, j, i_indstatvals));
- indxinfo[j].indkeys = (Oid *) pg_malloc(indxinfo[j].indnattrs * sizeof(Oid));
+ indxinfo[j].indkeys = pg_malloc_array(Oid, indxinfo[j].indnattrs);
parseOidArray(PQgetvalue(res, j, i_indkey),
indxinfo[j].indkeys, indxinfo[j].indnattrs);
indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
*/
ConstraintInfo *constrinfo;
- constrinfo = (ConstraintInfo *) pg_malloc(sizeof(ConstraintInfo));
+ constrinfo = pg_malloc_object(ConstraintInfo);
constrinfo->dobj.objType = DO_CONSTRAINT;
constrinfo->dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
constrinfo->dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
i_stxrelid = PQfnumber(res, "stxrelid");
i_stattarget = PQfnumber(res, "stxstattarget");
- statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
+ statsextinfo = pg_malloc_array(StatsExtInfo, ntups);
for (i = 0; i < ntups; i++)
{
i_conindid = PQfnumber(res, "conindid");
i_condef = PQfnumber(res, "condef");
- constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
+ constrinfo = pg_malloc_array(ConstraintInfo, ntups);
curtblindx = -1;
for (int j = 0; j < ntups; j++)
i_convalidated = PQfnumber(res, "convalidated");
i_contype = PQfnumber(res, "contype");
- constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
+ constrinfo = pg_malloc_array(ConstraintInfo, ntups);
tyinfo->domChecks = constrinfo;
/* 'i' tracks result rows; 'j' counts CHECK constraints */
ntups = PQntuples(res);
- ruleinfo = (RuleInfo *) pg_malloc(ntups * sizeof(RuleInfo));
+ ruleinfo = pg_malloc_array(RuleInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
i_tgispartition = PQfnumber(res, "tgispartition");
i_tgdef = PQfnumber(res, "tgdef");
- tginfo = (TriggerInfo *) pg_malloc(ntups * sizeof(TriggerInfo));
+ tginfo = pg_malloc_array(TriggerInfo, ntups);
/*
* Outer loop iterates once per table, not once per row. Incrementing of
ntups = PQntuples(res);
- evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
+ evtinfo = pg_malloc_array(EventTriggerInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
ntups = PQntuples(res);
- planginfo = (ProcLangInfo *) pg_malloc(ntups * sizeof(ProcLangInfo));
+ planginfo = pg_malloc_array(ProcLangInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
ntups = PQntuples(res);
- castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
+ castinfo = pg_malloc_array(CastInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
ntups = PQntuples(res);
- transforminfo = (TransformInfo *) pg_malloc(ntups * sizeof(TransformInfo));
+ transforminfo = pg_malloc_array(TransformInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
/* Save data for this table */
tbinfo->numatts = numatts;
- tbinfo->attnames = (char **) pg_malloc(numatts * sizeof(char *));
- tbinfo->atttypnames = (char **) pg_malloc(numatts * sizeof(char *));
- tbinfo->attstattarget = (int *) pg_malloc(numatts * sizeof(int));
- tbinfo->attstorage = (char *) pg_malloc(numatts * sizeof(char));
- tbinfo->typstorage = (char *) pg_malloc(numatts * sizeof(char));
- tbinfo->attidentity = (char *) pg_malloc(numatts * sizeof(char));
- tbinfo->attgenerated = (char *) pg_malloc(numatts * sizeof(char));
- tbinfo->attisdropped = (bool *) pg_malloc(numatts * sizeof(bool));
- tbinfo->attlen = (int *) pg_malloc(numatts * sizeof(int));
- tbinfo->attalign = (char *) pg_malloc(numatts * sizeof(char));
- tbinfo->attislocal = (bool *) pg_malloc(numatts * sizeof(bool));
- tbinfo->attoptions = (char **) pg_malloc(numatts * sizeof(char *));
- tbinfo->attcollation = (Oid *) pg_malloc(numatts * sizeof(Oid));
- tbinfo->attcompression = (char *) pg_malloc(numatts * sizeof(char));
- tbinfo->attfdwoptions = (char **) pg_malloc(numatts * sizeof(char *));
- tbinfo->attmissingval = (char **) pg_malloc(numatts * sizeof(char *));
- tbinfo->notnull_constrs = (char **) pg_malloc(numatts * sizeof(char *));
- tbinfo->notnull_comment = (char **) pg_malloc(numatts * sizeof(char *));
- tbinfo->notnull_invalid = (bool *) pg_malloc(numatts * sizeof(bool));
- tbinfo->notnull_noinh = (bool *) pg_malloc(numatts * sizeof(bool));
- tbinfo->notnull_islocal = (bool *) pg_malloc(numatts * sizeof(bool));
- tbinfo->attrdefs = (AttrDefInfo **) pg_malloc(numatts * sizeof(AttrDefInfo *));
+ tbinfo->attnames = pg_malloc_array(char *, numatts);
+ tbinfo->atttypnames = pg_malloc_array(char *, numatts);
+ tbinfo->attstattarget = pg_malloc_array(int, numatts);
+ tbinfo->attstorage = pg_malloc_array(char, numatts);
+ tbinfo->typstorage = pg_malloc_array(char, numatts);
+ tbinfo->attidentity = pg_malloc_array(char, numatts);
+ tbinfo->attgenerated = pg_malloc_array(char, numatts);
+ tbinfo->attisdropped = pg_malloc_array(bool, numatts);
+ tbinfo->attlen = pg_malloc_array(int, numatts);
+ tbinfo->attalign = pg_malloc_array(char, numatts);
+ tbinfo->attislocal = pg_malloc_array(bool, numatts);
+ tbinfo->attoptions = pg_malloc_array(char *, numatts);
+ tbinfo->attcollation = pg_malloc_array(Oid, numatts);
+ tbinfo->attcompression = pg_malloc_array(char, numatts);
+ tbinfo->attfdwoptions = pg_malloc_array(char *, numatts);
+ tbinfo->attmissingval = pg_malloc_array(char *, numatts);
+ tbinfo->notnull_constrs = pg_malloc_array(char *, numatts);
+ tbinfo->notnull_comment = pg_malloc_array(char *, numatts);
+ tbinfo->notnull_invalid = pg_malloc_array(bool, numatts);
+ tbinfo->notnull_noinh = pg_malloc_array(bool, numatts);
+ tbinfo->notnull_islocal = pg_malloc_array(bool, numatts);
+ tbinfo->attrdefs = pg_malloc_array(AttrDefInfo *, numatts);
hasdefaults = false;
for (int j = 0; j < numatts; j++, r++)
res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK);
numDefaults = PQntuples(res);
- attrdefs = (AttrDefInfo *) pg_malloc(numDefaults * sizeof(AttrDefInfo));
+ attrdefs = pg_malloc_array(AttrDefInfo, numDefaults);
curtblindx = -1;
for (int j = 0; j < numDefaults; j++)
res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK);
numConstrs = PQntuples(res);
- constrs = (ConstraintInfo *) pg_malloc(numConstrs * sizeof(ConstraintInfo));
+ constrs = pg_malloc_array(ConstraintInfo, numConstrs);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK);
numConstrs = PQntuples(res);
- constrs = (ConstraintInfo *) pg_malloc(numConstrs * sizeof(ConstraintInfo));
+ constrs = pg_malloc_array(ConstraintInfo, numConstrs);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
ntups = PQntuples(res);
- prsinfo = (TSParserInfo *) pg_malloc(ntups * sizeof(TSParserInfo));
+ prsinfo = pg_malloc_array(TSParserInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
ntups = PQntuples(res);
- dictinfo = (TSDictInfo *) pg_malloc(ntups * sizeof(TSDictInfo));
+ dictinfo = pg_malloc_array(TSDictInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
ntups = PQntuples(res);
- tmplinfo = (TSTemplateInfo *) pg_malloc(ntups * sizeof(TSTemplateInfo));
+ tmplinfo = pg_malloc_array(TSTemplateInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
ntups = PQntuples(res);
- cfginfo = (TSConfigInfo *) pg_malloc(ntups * sizeof(TSConfigInfo));
+ cfginfo = pg_malloc_array(TSConfigInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
ntups = PQntuples(res);
- fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
+ fdwinfo = pg_malloc_array(FdwInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
ntups = PQntuples(res);
- srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo));
+ srvinfo = pg_malloc_array(ForeignServerInfo, ntups);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
ntups = PQntuples(res);
- daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
+ daclinfo = pg_malloc_array(DefaultACLInfo, ntups);
i_oid = PQfnumber(res, "oid");
i_tableoid = PQfnumber(res, "tableoid");
nrolenames = PQntuples(res);
- rolenames = (RoleNameItem *) pg_malloc(nrolenames * sizeof(RoleNameItem));
+ rolenames = pg_malloc_array(RoleNameItem, nrolenames);
for (i = 0; i < nrolenames; i++)
{
ntups = PQntuples(res);
- comments = (CommentItem *) pg_malloc(ntups * sizeof(CommentItem));
+ comments = pg_malloc_array(CommentItem, ntups);
ncomments = 0;
dobj = NULL;
if (*protrftypes)
{
- Oid *typeids = pg_malloc(FUNC_MAX_ARGS * sizeof(Oid));
+ Oid *typeids = pg_malloc_array(Oid, FUNC_MAX_ARGS);
int i;
appendPQExpBufferStr(q, " TRANSFORM ");
ntups = PQntuples(res);
- seclabels = (SecLabelItem *) pg_malloc(ntups * sizeof(SecLabelItem));
+ seclabels = pg_malloc_array(SecLabelItem, ntups);
nseclabels = 0;
dobj = NULL;
res = ExecuteSqlQuery(fout, query, PGRES_TUPLES_OK);
nsequences = PQntuples(res);
- sequences = (SequenceItem *) pg_malloc(nsequences * sizeof(SequenceItem));
+ sequences = pg_malloc_array(SequenceItem, nsequences);
for (int i = 0; i < nsequences; i++)
{
PQntuples(res)),
tbinfo->dobj.name, PQntuples(res));
- seq = pg_malloc0(sizeof(SequenceItem));
+ seq = pg_malloc0_object(SequenceItem);
seq->seqtype = parse_sequence_type(PQgetvalue(res, 0, 0));
seq->startv = strtoi64(PQgetvalue(res, 0, 1), NULL, 10);
seq->incby = strtoi64(PQgetvalue(res, 0, 2), NULL, 10);
{
DumpableObject *dobjs;
- dobjs = (DumpableObject *) pg_malloc(2 * sizeof(DumpableObject));
+ dobjs = pg_malloc_array(DumpableObject, 2);
dobjs[0].objType = DO_PRE_DATA_BOUNDARY;
dobjs[0].catId = nilCatalogId;
continue;
/* Set up work array */
allocDeps = 64;
- dependencies = (DumpId *) pg_malloc(allocDeps * sizeof(DumpId));
+ dependencies = pg_malloc_array(DumpId, allocDeps);
nDeps = 0;
/* Recursively find all dumpable dependencies */
findDumpableDependencies(AH, dobj,
/* And save 'em ... */
if (nDeps > 0)
{
- dependencies = (DumpId *) pg_realloc(dependencies,
- nDeps * sizeof(DumpId));
+ dependencies = pg_realloc_array(dependencies, DumpId, nDeps);
te->dependencies = dependencies;
te->nDeps = nDeps;
}
if (*nDeps >= *allocDeps)
{
*allocDeps *= 2;
- *dependencies = (DumpId *) pg_realloc(*dependencies,
- *allocDeps * sizeof(DumpId));
+ *dependencies = pg_realloc_array(*dependencies, DumpId, *allocDeps);
}
(*dependencies)[*nDeps] = depid;
(*nDeps)++;