Skip to content

Commit 9ba8a9c

Browse files
committed
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
1 parent 5bcab11 commit 9ba8a9c

32 files changed

+77
-131
lines changed

contrib/pg_stat_statements/pg_stat_statements.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,9 +2382,8 @@ JumbleRangeTable(pgssJumbleState *jstate, List *rtable)
23822382

23832383
foreach(lc, rtable)
23842384
{
2385-
RangeTblEntry *rte = (RangeTblEntry *) lfirst(lc);
2385+
RangeTblEntry *rte = castNode(RangeTblEntry, lfirst(lc));
23862386

2387-
Assert(IsA(rte, RangeTblEntry));
23882387
APP_JUMB(rte->rtekind);
23892388
switch (rte->rtekind)
23902389
{
@@ -2570,7 +2569,7 @@ JumbleExpr(pgssJumbleState *jstate, Node *node)
25702569
APP_JUMB(sublink->subLinkType);
25712570
APP_JUMB(sublink->subLinkId);
25722571
JumbleExpr(jstate, (Node *) sublink->testexpr);
2573-
JumbleQuery(jstate, (Query *) sublink->subselect);
2572+
JumbleQuery(jstate, castNode(Query, sublink->subselect));
25742573
}
25752574
break;
25762575
case T_FieldSelect:
@@ -2636,9 +2635,8 @@ JumbleExpr(pgssJumbleState *jstate, Node *node)
26362635
JumbleExpr(jstate, (Node *) caseexpr->arg);
26372636
foreach(temp, caseexpr->args)
26382637
{
2639-
CaseWhen *when = (CaseWhen *) lfirst(temp);
2638+
CaseWhen *when = castNode(CaseWhen, lfirst(temp));
26402639

2641-
Assert(IsA(when, CaseWhen));
26422640
JumbleExpr(jstate, (Node *) when->expr);
26432641
JumbleExpr(jstate, (Node *) when->result);
26442642
}
@@ -2850,7 +2848,7 @@ JumbleExpr(pgssJumbleState *jstate, Node *node)
28502848

28512849
/* we store the string name because RTE_CTE RTEs need it */
28522850
APP_JUMB_STRING(cte->ctename);
2853-
JumbleQuery(jstate, (Query *) cte->ctequery);
2851+
JumbleQuery(jstate, castNode(Query, cte->ctequery));
28542852
}
28552853
break;
28562854
case T_SetOperationStmt:

contrib/postgres_fdw/deparse.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,10 +1315,7 @@ deparseExplicitTargetList(List *tlist, List **retrieved_attrs,
13151315

13161316
foreach(lc, tlist)
13171317
{
1318-
TargetEntry *tle = (TargetEntry *) lfirst(lc);
1319-
1320-
/* Extract expression if TargetEntry node */
1321-
Assert(IsA(tle, TargetEntry));
1318+
TargetEntry *tle = castNode(TargetEntry, lfirst(lc));
13221319

13231320
if (i > 0)
13241321
appendStringInfoString(buf, ", ");

contrib/postgres_fdw/postgres_fdw.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,9 +1159,7 @@ postgresGetForeignPlan(PlannerInfo *root,
11591159
*/
11601160
foreach(lc, scan_clauses)
11611161
{
1162-
RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
1163-
1164-
Assert(IsA(rinfo, RestrictInfo));
1162+
RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(lc));
11651163

11661164
/* Ignore any pseudoconstants, they're dealt with elsewhere */
11671165
if (rinfo->pseudoconstant)
@@ -4958,14 +4956,12 @@ conversion_error_callback(void *arg)
49584956
{
49594957
/* error occurred in a scan against a foreign join */
49604958
ForeignScanState *fsstate = errpos->fsstate;
4961-
ForeignScan *fsplan = (ForeignScan *) fsstate->ss.ps.plan;
4959+
ForeignScan *fsplan = castNode(ForeignScan, fsstate->ss.ps.plan);
49624960
EState *estate = fsstate->ss.ps.state;
49634961
TargetEntry *tle;
49644962

4965-
Assert(IsA(fsplan, ForeignScan));
4966-
tle = (TargetEntry *) list_nth(fsplan->fdw_scan_tlist,
4967-
errpos->cur_attno - 1);
4968-
Assert(IsA(tle, TargetEntry));
4963+
tle = castNode(TargetEntry, list_nth(fsplan->fdw_scan_tlist,
4964+
errpos->cur_attno - 1));
49694965

49704966
/*
49714967
* Target list can have Vars and expressions. For Vars, we can get

src/backend/catalog/pg_proc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,7 @@ ProcedureCreate(const char *procedureName,
510510
Anum_pg_proc_proargdefaults,
511511
&isnull);
512512
Assert(!isnull);
513-
oldDefaults = (List *) stringToNode(TextDatumGetCString(proargdefaults));
514-
Assert(IsA(oldDefaults, List));
513+
oldDefaults = castNode(List, stringToNode(TextDatumGetCString(proargdefaults)));
515514
Assert(list_length(oldDefaults) == oldproc->pronargdefaults);
516515

517516
/* new list can have more defaults than old, advance over 'em */

src/backend/commands/aggregatecmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ DefineAggregate(ParseState *pstate, List *name, List *args, bool oldstyle, List
109109
aggKind = AGGKIND_ORDERED_SET;
110110
else
111111
numDirectArgs = 0;
112-
args = (List *) linitial(args);
112+
args = castNode(List, linitial(args));
113113
}
114114

115115
/* Examine aggregate's definition clauses */
116116
foreach(pl, parameters)
117117
{
118-
DefElem *defel = (DefElem *) lfirst(pl);
118+
DefElem *defel = castNode(DefElem, lfirst(pl));
119119

120120
/*
121121
* sfunc1, stype1, and initcond1 are accepted as obsolete spellings

src/backend/commands/analyze.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,9 @@ compute_index_stats(Relation onerel, double totalrows,
722722
econtext->ecxt_scantuple = slot;
723723

724724
/* Set up execution state for predicate. */
725-
predicate = (List *)
726-
ExecPrepareExpr((Expr *) indexInfo->ii_Predicate,
727-
estate);
725+
predicate = castNode(List,
726+
ExecPrepareExpr((Expr *) indexInfo->ii_Predicate,
727+
estate));
728728

729729
/* Compute and save index expression values */
730730
exprvals = (Datum *) palloc(numrows * attr_cnt * sizeof(Datum));

src/backend/commands/async.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ AtSubCommit_Notify(void)
16361636
List *parentPendingActions;
16371637
List *parentPendingNotifies;
16381638

1639-
parentPendingActions = (List *) linitial(upperPendingActions);
1639+
parentPendingActions = castNode(List, linitial(upperPendingActions));
16401640
upperPendingActions = list_delete_first(upperPendingActions);
16411641

16421642
Assert(list_length(upperPendingActions) ==
@@ -1647,7 +1647,7 @@ AtSubCommit_Notify(void)
16471647
*/
16481648
pendingActions = list_concat(parentPendingActions, pendingActions);
16491649

1650-
parentPendingNotifies = (List *) linitial(upperPendingNotifies);
1650+
parentPendingNotifies = castNode(List, linitial(upperPendingNotifies));
16511651
upperPendingNotifies = list_delete_first(upperPendingNotifies);
16521652

16531653
Assert(list_length(upperPendingNotifies) ==
@@ -1679,13 +1679,13 @@ AtSubAbort_Notify(void)
16791679
*/
16801680
while (list_length(upperPendingActions) > my_level - 2)
16811681
{
1682-
pendingActions = (List *) linitial(upperPendingActions);
1682+
pendingActions = castNode(List, linitial(upperPendingActions));
16831683
upperPendingActions = list_delete_first(upperPendingActions);
16841684
}
16851685

16861686
while (list_length(upperPendingNotifies) > my_level - 2)
16871687
{
1688-
pendingNotifies = (List *) linitial(upperPendingNotifies);
1688+
pendingNotifies = castNode(List, linitial(upperPendingNotifies));
16891689
upperPendingNotifies = list_delete_first(upperPendingNotifies);
16901690
}
16911691
}

src/backend/commands/collationcmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ DefineCollation(ParseState *pstate, List *names, List *parameters)
6161

6262
foreach(pl, parameters)
6363
{
64-
DefElem *defel = (DefElem *) lfirst(pl);
64+
DefElem *defel = castNode(DefElem, lfirst(pl));
6565
DefElem **defelp;
6666

6767
if (pg_strcasecmp(defel->defname, "from") == 0)

src/backend/commands/constraint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
Datum
3838
unique_key_recheck(PG_FUNCTION_ARGS)
3939
{
40-
TriggerData *trigdata = (TriggerData *) fcinfo->context;
40+
TriggerData *trigdata = castNode(TriggerData, fcinfo->context);
4141
const char *funcname = "unique_key_recheck";
4242
HeapTuple new_row;
4343
ItemPointerData tmptid;

src/backend/commands/copy.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ ProcessCopyOptions(ParseState *pstate,
10261026
/* Extract options from the statement node tree */
10271027
foreach(option, options)
10281028
{
1029-
DefElem *defel = (DefElem *) lfirst(option);
1029+
DefElem *defel = castNode(DefElem, lfirst(option));
10301030

10311031
if (strcmp(defel->defname, "format") == 0)
10321032
{
@@ -1139,7 +1139,7 @@ ProcessCopyOptions(ParseState *pstate,
11391139
errmsg("conflicting or redundant options"),
11401140
parser_errposition(pstate, defel->location)));
11411141
if (defel->arg && IsA(defel->arg, List))
1142-
cstate->force_notnull = (List *) defel->arg;
1142+
cstate->force_notnull = castNode(List, defel->arg);
11431143
else
11441144
ereport(ERROR,
11451145
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
@@ -1154,7 +1154,7 @@ ProcessCopyOptions(ParseState *pstate,
11541154
(errcode(ERRCODE_SYNTAX_ERROR),
11551155
errmsg("conflicting or redundant options")));
11561156
if (defel->arg && IsA(defel->arg, List))
1157-
cstate->force_null = (List *) defel->arg;
1157+
cstate->force_null = castNode(List, defel->arg);
11581158
else
11591159
ereport(ERROR,
11601160
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
@@ -1176,7 +1176,7 @@ ProcessCopyOptions(ParseState *pstate,
11761176
parser_errposition(pstate, defel->location)));
11771177
cstate->convert_selectively = true;
11781178
if (defel->arg == NULL || IsA(defel->arg, List))
1179-
cstate->convert_select = (List *) defel->arg;
1179+
cstate->convert_select = castNode(List, defel->arg);
11801180
else
11811181
ereport(ERROR,
11821182
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
@@ -1479,7 +1479,7 @@ BeginCopy(ParseState *pstate,
14791479
/* examine queries to determine which error message to issue */
14801480
foreach(lc, rewritten)
14811481
{
1482-
Query *q = (Query *) lfirst(lc);
1482+
Query *q = castNode(Query, lfirst(lc));
14831483

14841484
if (q->querySource == QSRC_QUAL_INSTEAD_RULE)
14851485
ereport(ERROR,
@@ -1496,7 +1496,7 @@ BeginCopy(ParseState *pstate,
14961496
errmsg("multi-statement DO INSTEAD rules are not supported for COPY")));
14971497
}
14981498

1499-
query = (Query *) linitial(rewritten);
1499+
query = castNode(Query, linitial(rewritten));
15001500

15011501
/* The grammar allows SELECT INTO, but we don't support that */
15021502
if (query->utilityStmt != NULL &&

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy