summaryrefslogtreecommitdiff
path: root/src/backend/commands/tablecmds.c
diff options
context:
space:
mode:
authorMichael Paquier2025-12-09 22:36:46 +0000
committerMichael Paquier2025-12-09 22:36:46 +0000
commit1b105f9472bdb9a68f709778afafb494997267bd (patch)
tree205727d30b0dd4f3060bc1f49a9efa724ee3ff80 /src/backend/commands/tablecmds.c
parentc507ba55f5bfae900baa94f1c657e1d99da5c6dc (diff)
Use palloc_object() and palloc_array() in backend code
The idea is to encourage more the use of these new routines across the tree, as these offer stronger type safety guarantees than palloc(). This batch of changes includes most of the trivial changes suggested by the author for src/backend/. A total of 334 files are updated here. Among these files, 48 of them have their build change slightly; these are caused by line number changes as the new allocation formulas are simpler, shaving around 100 lines of code in total. Similar work has been done in 0c3c5c3b06a3 and 31d3847a37be. Author: David Geier <geidav.pg@gmail.com> Discussion: https://postgr.es/m/ad0748d4-3080-436e-b0bc-ac8f86a3466a@gmail.com
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r--src/backend/commands/tablecmds.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 07e5b95782e..1c9ef53be20 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -999,7 +999,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
Assert(colDef->cooked_default == NULL);
- rawEnt = (RawColumnDefault *) palloc(sizeof(RawColumnDefault));
+ rawEnt = palloc_object(RawColumnDefault);
rawEnt->attnum = attnum;
rawEnt->raw_default = colDef->raw_default;
rawEnt->generated = colDef->generated;
@@ -1009,7 +1009,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
{
CookedConstraint *cooked;
- cooked = (CookedConstraint *) palloc(sizeof(CookedConstraint));
+ cooked = palloc_object(CookedConstraint);
cooked->contype = CONSTR_DEFAULT;
cooked->conoid = InvalidOid; /* until created */
cooked->name = NULL;
@@ -6568,7 +6568,7 @@ ATGetQueueEntry(List **wqueue, Relation rel)
* Not there, so add it. Note that we make a copy of the relation's
* existing descriptor before anything interesting can happen to it.
*/
- tab = (AlteredTableInfo *) palloc0(sizeof(AlteredTableInfo));
+ tab = palloc0_object(AlteredTableInfo);
tab->relid = relid;
tab->rel = NULL; /* set later */
tab->relkind = rel->rd_rel->relkind;
@@ -7406,7 +7406,7 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
{
RawColumnDefault *rawEnt;
- rawEnt = (RawColumnDefault *) palloc(sizeof(RawColumnDefault));
+ rawEnt = palloc_object(RawColumnDefault);
rawEnt->attnum = attribute->attnum;
rawEnt->raw_default = copyObject(colDef->raw_default);
rawEnt->generated = colDef->generated;
@@ -7507,7 +7507,7 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
defval = expression_planner(defval);
/* Add the new default to the newvals list */
- newval = (NewColumnValue *) palloc0(sizeof(NewColumnValue));
+ newval = palloc0_object(NewColumnValue);
newval->attnum = attribute->attnum;
newval->expr = defval;
newval->is_generated = (colDef->generated != '\0');
@@ -8176,7 +8176,7 @@ ATExecColumnDefault(Relation rel, const char *colName,
/* SET DEFAULT */
RawColumnDefault *rawEnt;
- rawEnt = (RawColumnDefault *) palloc(sizeof(RawColumnDefault));
+ rawEnt = palloc_object(RawColumnDefault);
rawEnt->attnum = attnum;
rawEnt->raw_default = newDefault;
rawEnt->generated = '\0';
@@ -8704,7 +8704,7 @@ ATExecSetExpression(AlteredTableInfo *tab, Relation rel, const char *colName,
false, false);
/* Prepare to store the new expression, in the catalogs */
- rawEnt = (RawColumnDefault *) palloc(sizeof(RawColumnDefault));
+ rawEnt = palloc_object(RawColumnDefault);
rawEnt->attnum = attnum;
rawEnt->raw_default = newExpr;
rawEnt->generated = attgenerated;
@@ -8721,7 +8721,7 @@ ATExecSetExpression(AlteredTableInfo *tab, Relation rel, const char *colName,
/* Prepare for table rewrite */
defval = (Expr *) build_column_default(rel, attnum);
- newval = (NewColumnValue *) palloc0(sizeof(NewColumnValue));
+ newval = palloc0_object(NewColumnValue);
newval->attnum = attnum;
newval->expr = expression_planner(defval);
newval->is_generated = true;
@@ -9949,7 +9949,7 @@ ATAddCheckNNConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
{
NewConstraint *newcon;
- newcon = (NewConstraint *) palloc0(sizeof(NewConstraint));
+ newcon = palloc0_object(NewConstraint);
newcon->name = ccon->name;
newcon->contype = ccon->contype;
newcon->qual = ccon->expr;
@@ -10946,7 +10946,7 @@ addFkRecurseReferenced(Constraint *fkconstraint, Relation rel,
false);
if (map)
{
- mapped_pkattnum = palloc(sizeof(AttrNumber) * numfks);
+ mapped_pkattnum = palloc_array(AttrNumber, numfks);
for (int j = 0; j < numfks; j++)
mapped_pkattnum[j] = map->attnums[pkattnum[j] - 1];
}
@@ -11081,7 +11081,7 @@ addFkRecurseReferencing(List **wqueue, Constraint *fkconstraint, Relation rel,
tab = ATGetQueueEntry(wqueue, rel);
- newcon = (NewConstraint *) palloc0(sizeof(NewConstraint));
+ newcon = palloc0_object(NewConstraint);
newcon->name = get_constraint_name(parentConstr);
newcon->contype = CONSTR_FOREIGN;
newcon->refrelid = RelationGetRelid(pkrel);
@@ -12503,7 +12503,7 @@ ATExecAlterConstrEnforceability(List **wqueue, ATAlterConstraint *cmdcon,
AlteredTableInfo *tab;
NewConstraint *newcon;
- newcon = (NewConstraint *) palloc0(sizeof(NewConstraint));
+ newcon = palloc0_object(NewConstraint);
newcon->name = fkconstraint->conname;
newcon->contype = CONSTR_FOREIGN;
newcon->refrelid = currcon->confrelid;
@@ -13019,7 +13019,7 @@ QueueFKConstraintValidation(List **wqueue, Relation conrel, Relation fkrel,
/* for now this is all we need */
fkconstraint->conname = pstrdup(NameStr(con->conname));
- newcon = (NewConstraint *) palloc0(sizeof(NewConstraint));
+ newcon = palloc0_object(NewConstraint);
newcon->name = fkconstraint->conname;
newcon->contype = CONSTR_FOREIGN;
newcon->refrelid = con->confrelid;
@@ -13167,7 +13167,7 @@ QueueCheckConstraintValidation(List **wqueue, Relation conrel, Relation rel,
}
/* Queue validation for phase 3 */
- newcon = (NewConstraint *) palloc0(sizeof(NewConstraint));
+ newcon = palloc0_object(NewConstraint);
newcon->name = constrName;
newcon->contype = CONSTR_CHECK;
newcon->refrelid = InvalidOid;
@@ -14522,7 +14522,7 @@ ATPrepAlterColumnType(List **wqueue,
* Add a work queue item to make ATRewriteTable update the column
* contents.
*/
- newval = (NewColumnValue *) palloc0(sizeof(NewColumnValue));
+ newval = palloc0_object(NewColumnValue);
newval->attnum = attnum;
newval->expr = (Expr *) transform;
newval->is_generated = false;
@@ -19262,7 +19262,7 @@ register_on_commit_action(Oid relid, OnCommitAction action)
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
- oc = (OnCommitItem *) palloc(sizeof(OnCommitItem));
+ oc = palloc_object(OnCommitItem);
oc->relid = relid;
oc->oncommit = action;
oc->creating_subid = GetCurrentSubTransactionId();
@@ -20575,8 +20575,8 @@ AttachPartitionEnsureIndexes(List **wqueue, Relation rel, Relation attachrel)
idxes = RelationGetIndexList(rel);
attachRelIdxs = RelationGetIndexList(attachrel);
- attachrelIdxRels = palloc(sizeof(Relation) * list_length(attachRelIdxs));
- attachInfos = palloc(sizeof(IndexInfo *) * list_length(attachRelIdxs));
+ attachrelIdxRels = palloc_array(Relation, list_length(attachRelIdxs));
+ attachInfos = palloc_array(IndexInfo *, list_length(attachRelIdxs));
/* Build arrays of all existing indexes and their IndexInfos */
foreach_oid(cldIdxId, attachRelIdxs)