1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Use the new castNode() macro in a number of places.

This is far from a pervasive conversion, but it's a good starting
point.

Author: Peter Eisentraut, with some minor changes by me
Reviewed-By: Tom Lane
Discussion: https://postgr.es/m/c5d387d9-3440-f5e0-f9d4-71d53b9fbe52@2ndquadrant.com
This commit is contained in:
Andres Freund
2017-01-26 16:47:03 -08:00
parent 5bcab11142
commit 9ba8a9ce45
32 changed files with 77 additions and 131 deletions

View File

@ -403,11 +403,12 @@ ExecSupportsMarkRestore(Path *pathnode)
return true;
case T_CustomScan:
Assert(IsA(pathnode, CustomPath));
if (((CustomPath *) pathnode)->flags & CUSTOMPATH_SUPPORT_MARK_RESTORE)
{
CustomPath *customPath = castNode(CustomPath, pathnode);
if (customPath->flags & CUSTOMPATH_SUPPORT_MARK_RESTORE)
return true;
return false;
}
case T_Result:
/*

View File

@ -4640,10 +4640,9 @@ ExecInitExpr(Expr *node, PlanState *parent)
cstate->arg = ExecInitExpr(caseexpr->arg, parent);
foreach(l, caseexpr->args)
{
CaseWhen *when = (CaseWhen *) lfirst(l);
CaseWhen *when = castNode(CaseWhen, lfirst(l));
CaseWhenState *wstate = makeNode(CaseWhenState);
Assert(IsA(when, CaseWhen));
wstate->xprstate.evalfunc = NULL; /* not used */
wstate->xprstate.expr = (Expr *) when;
wstate->expr = ExecInitExpr(when->expr, parent);
@ -5137,9 +5136,8 @@ ExecCleanTargetListLength(List *targetlist)
foreach(tl, targetlist)
{
TargetEntry *curTle = (TargetEntry *) lfirst(tl);
TargetEntry *curTle = castNode(TargetEntry, lfirst(tl));
Assert(IsA(curTle, TargetEntry));
if (!curTle->resjunk)
len++;
}

View File

@ -160,10 +160,7 @@ ExecResetTupleTable(List *tupleTable, /* tuple table */
foreach(lc, tupleTable)
{
TupleTableSlot *slot = (TupleTableSlot *) lfirst(lc);
/* Sanity checks */
Assert(IsA(slot, TupleTableSlot));
TupleTableSlot *slot = castNode(TupleTableSlot, lfirst(lc));
/* Always release resources and reset the slot to empty */
ExecClearTuple(slot);

View File

@ -479,19 +479,17 @@ init_execution_state(List *queryTree_list,
foreach(lc1, queryTree_list)
{
List *qtlist = (List *) lfirst(lc1);
List *qtlist = castNode(List, lfirst(lc1));
execution_state *firstes = NULL;
execution_state *preves = NULL;
ListCell *lc2;
foreach(lc2, qtlist)
{
Query *queryTree = (Query *) lfirst(lc2);
Query *queryTree = castNode(Query, lfirst(lc2));
PlannedStmt *stmt;
execution_state *newes;
Assert(IsA(queryTree, Query));
/* Plan the query if needed */
if (queryTree->commandType == CMD_UTILITY)
{

View File

@ -2572,9 +2572,8 @@ ExecInitAgg(Agg *node, EState *estate, int eflags)
if (phase > 0)
{
aggnode = list_nth(node->chain, phase - 1);
sortnode = (Sort *) aggnode->plan.lefttree;
Assert(IsA(sortnode, Sort));
aggnode = castNode(Agg, list_nth(node->chain, phase - 1));
sortnode = castNode(Sort, aggnode->plan.lefttree);
}
else
{
@ -3010,10 +3009,9 @@ ExecInitAgg(Agg *node, EState *estate, int eflags)
*/
foreach(arg, pertrans->aggref->args)
{
TargetEntry *source_tle = (TargetEntry *) lfirst(arg);
TargetEntry *source_tle = castNode(TargetEntry, lfirst(arg));
TargetEntry *tle;
Assert(IsA(source_tle, TargetEntry));
tle = flatCopyTargetEntry(source_tle);
tle->resno += column_offset;

View File

@ -210,7 +210,7 @@ ExecInitCteScan(CteScan *node, EState *estate, int eflags)
prmdata = &(estate->es_param_exec_vals[node->cteParam]);
Assert(prmdata->execPlan == NULL);
Assert(!prmdata->isnull);
scanstate->leader = (CteScanState *) DatumGetPointer(prmdata->value);
scanstate->leader = castNode(CteScanState, DatumGetPointer(prmdata->value));
if (scanstate->leader == NULL)
{
/* I am the leader */
@ -223,7 +223,6 @@ ExecInitCteScan(CteScan *node, EState *estate, int eflags)
else
{
/* Not the leader */
Assert(IsA(scanstate->leader, CteScanState));
/* Create my own read pointer, and ensure it is at start */
scanstate->readptr =
tuplestore_alloc_read_pointer(scanstate->leader->cte_table,

View File

@ -35,8 +35,8 @@ ExecInitCustomScan(CustomScan *cscan, EState *estate, int eflags)
* methods field correctly at this time. Other standard fields should be
* set to zero.
*/
css = (CustomScanState *) cscan->methods->CreateCustomScanState(cscan);
Assert(IsA(css, CustomScanState));
css = castNode(CustomScanState,
cscan->methods->CreateCustomScanState(cscan));
/* ensure flags is filled correctly */
css->flags = cscan->flags;

View File

@ -519,12 +519,9 @@ ExecInitHashJoin(HashJoin *node, EState *estate, int eflags)
hoperators = NIL;
foreach(l, hjstate->hashclauses)
{
FuncExprState *fstate = (FuncExprState *) lfirst(l);
OpExpr *hclause;
FuncExprState *fstate = castNode(FuncExprState, lfirst(l));
OpExpr *hclause = castNode(OpExpr, fstate->xprstate.expr);
Assert(IsA(fstate, FuncExprState));
hclause = (OpExpr *) fstate->xprstate.expr;
Assert(IsA(hclause, OpExpr));
lclauses = lappend(lclauses, linitial(fstate->args));
rclauses = lappend(rclauses, lsecond(fstate->args));
hoperators = lappend_oid(hoperators, hclause->opno);

View File

@ -401,12 +401,10 @@ ExecInitLockRows(LockRows *node, EState *estate, int eflags)
epq_arowmarks = NIL;
foreach(lc, node->rowMarks)
{
PlanRowMark *rc = (PlanRowMark *) lfirst(lc);
PlanRowMark *rc = castNode(PlanRowMark, lfirst(lc));
ExecRowMark *erm;
ExecAuxRowMark *aerm;
Assert(IsA(rc, PlanRowMark));
/* ignore "parent" rowmarks; they are irrelevant at runtime */
if (rc->isParent)
continue;

View File

@ -1958,11 +1958,9 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
*/
foreach(l, node->rowMarks)
{
PlanRowMark *rc = (PlanRowMark *) lfirst(l);
PlanRowMark *rc = castNode(PlanRowMark, lfirst(l));
ExecRowMark *erm;
Assert(IsA(rc, PlanRowMark));
/* ignore "parent" rowmarks; they are irrelevant at runtime */
if (rc->isParent)
continue;

View File

@ -808,8 +808,7 @@ ExecInitSubPlan(SubPlan *subplan, PlanState *parent)
else if (and_clause((Node *) sstate->testexpr->expr))
{
/* multiple combining operators */
Assert(IsA(sstate->testexpr, BoolExprState));
oplist = ((BoolExprState *) sstate->testexpr)->args;
oplist = castNode(BoolExprState, sstate->testexpr)->args;
}
else
{
@ -829,8 +828,8 @@ ExecInitSubPlan(SubPlan *subplan, PlanState *parent)
i = 1;
foreach(l, oplist)
{
FuncExprState *fstate = (FuncExprState *) lfirst(l);
OpExpr *opexpr = (OpExpr *) fstate->xprstate.expr;
FuncExprState *fstate = castNode(FuncExprState, lfirst(l));
OpExpr *opexpr = castNode(OpExpr, fstate->xprstate.expr);
ExprState *exstate;
Expr *expr;
TargetEntry *tle;
@ -839,8 +838,6 @@ ExecInitSubPlan(SubPlan *subplan, PlanState *parent)
Oid left_hashfn;
Oid right_hashfn;
Assert(IsA(fstate, FuncExprState));
Assert(IsA(opexpr, OpExpr));
Assert(list_length(fstate->args) == 2);
/* Process lefthand argument */
@ -1218,10 +1215,8 @@ ExecAlternativeSubPlan(AlternativeSubPlanState *node,
bool *isNull)
{
/* Just pass control to the active subplan */
SubPlanState *activesp = (SubPlanState *) list_nth(node->subplans,
node->active);
Assert(IsA(activesp, SubPlanState));
SubPlanState *activesp = castNode(SubPlanState,
list_nth(node->subplans, node->active));
return ExecSubPlan(activesp, econtext, isNull);
}

View File

@ -95,8 +95,8 @@ ExecWorkTableScan(WorkTableScanState *node)
param = &(estate->es_param_exec_vals[plan->wtParam]);
Assert(param->execPlan == NULL);
Assert(!param->isnull);
node->rustate = (RecursiveUnionState *) DatumGetPointer(param->value);
Assert(node->rustate && IsA(node->rustate, RecursiveUnionState));
node->rustate = castNode(RecursiveUnionState, DatumGetPointer(param->value));
Assert(node->rustate);
/*
* The scan tuple type (ie, the rowtype we expect to find in the work