Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9ba8a9c

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 startingpoint.Author: Peter Eisentraut, with some minor changes by meReviewed-By: Tom LaneDiscussion:https://postgr.es/m/c5d387d9-3440-f5e0-f9d4-71d53b9fbe52@2ndquadrant.com
1 parent5bcab11 commit9ba8a9c

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
caseT_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
caseT_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
constchar*funcname="unique_key_recheck";
4242
HeapTuplenew_row;
4343
ItemPointerDatatmptid;

‎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&&

‎src/backend/commands/createas.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ ObjectAddress
224224
ExecCreateTableAs(CreateTableAsStmt*stmt,constchar*queryString,
225225
ParamListInfoparams,char*completionTag)
226226
{
227-
Query*query= (Query*)stmt->query;
227+
Query*query=castNode(Query,stmt->query);
228228
IntoClause*into=stmt->into;
229229
boolis_matview= (into->viewQuery!=NULL);
230230
DestReceiver*dest;
@@ -261,11 +261,10 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
261261
* The contained Query could be a SELECT, or an EXECUTE utility command.
262262
* If the latter, we just pass it off to ExecuteQuery.
263263
*/
264-
Assert(IsA(query,Query));
265264
if (query->commandType==CMD_UTILITY&&
266265
IsA(query->utilityStmt,ExecuteStmt))
267266
{
268-
ExecuteStmt*estmt= (ExecuteStmt*)query->utilityStmt;
267+
ExecuteStmt*estmt=castNode(ExecuteStmt,query->utilityStmt);
269268

270269
Assert(!is_matview);/* excluded by syntax */
271270
ExecuteQuery(estmt,into,queryString,params,dest,completionTag);

‎src/backend/commands/dropcmds.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,10 @@ type_in_list_does_not_exist_skipping(List *typenames, const char **msg,
222222

223223
foreach(l,typenames)
224224
{
225-
TypeName*typeName= (TypeName*)lfirst(l);
225+
TypeName*typeName=castNode(TypeName,lfirst(l));
226226

227227
if (typeName!=NULL)
228228
{
229-
Assert(IsA(typeName,TypeName));
230-
231229
if (!OidIsValid(LookupTypeNameOid(NULL,typeName, true)))
232230
{
233231
/* type doesn't exist, try to find why */

‎src/backend/commands/explain.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,25 +1493,25 @@ ExplainNode(PlanState *planstate, List *ancestors,
14931493
planstate,es);
14941494
break;
14951495
caseT_Agg:
1496-
show_agg_keys((AggState*)planstate,ancestors,es);
1496+
show_agg_keys(castNode(AggState,planstate),ancestors,es);
14971497
show_upper_qual(plan->qual,"Filter",planstate,ancestors,es);
14981498
if (plan->qual)
14991499
show_instrumentation_count("Rows Removed by Filter",1,
15001500
planstate,es);
15011501
break;
15021502
caseT_Group:
1503-
show_group_keys((GroupState*)planstate,ancestors,es);
1503+
show_group_keys(castNode(GroupState,planstate),ancestors,es);
15041504
show_upper_qual(plan->qual,"Filter",planstate,ancestors,es);
15051505
if (plan->qual)
15061506
show_instrumentation_count("Rows Removed by Filter",1,
15071507
planstate,es);
15081508
break;
15091509
caseT_Sort:
1510-
show_sort_keys((SortState*)planstate,ancestors,es);
1511-
show_sort_info((SortState*)planstate,es);
1510+
show_sort_keys(castNode(SortState,planstate),ancestors,es);
1511+
show_sort_info(castNode(SortState,planstate),es);
15121512
break;
15131513
caseT_MergeAppend:
1514-
show_merge_append_keys((MergeAppendState*)planstate,
1514+
show_merge_append_keys(castNode(MergeAppendState,planstate),
15151515
ancestors,es);
15161516
break;
15171517
caseT_Result:
@@ -1523,11 +1523,11 @@ ExplainNode(PlanState *planstate, List *ancestors,
15231523
planstate,es);
15241524
break;
15251525
caseT_ModifyTable:
1526-
show_modifytable_info((ModifyTableState*)planstate,ancestors,
1526+
show_modifytable_info(castNode(ModifyTableState,planstate),ancestors,
15271527
es);
15281528
break;
15291529
caseT_Hash:
1530-
show_hash_info((HashState*)planstate,es);
1530+
show_hash_info(castNode(HashState,planstate),es);
15311531
break;
15321532
default:
15331533
break;
@@ -2183,7 +2183,6 @@ show_tablesample(TableSampleClause *tsc, PlanState *planstate,
21832183
staticvoid
21842184
show_sort_info(SortState*sortstate,ExplainState*es)
21852185
{
2186-
Assert(IsA(sortstate,SortState));
21872186
if (es->analyze&&sortstate->sort_Done&&
21882187
sortstate->tuplesortstate!=NULL)
21892188
{
@@ -2217,7 +2216,6 @@ show_hash_info(HashState *hashstate, ExplainState *es)
22172216
{
22182217
HashJoinTablehashtable;
22192218

2220-
Assert(IsA(hashstate,HashState));
22212219
hashtable=hashstate->hashtable;
22222220

22232221
if (hashtable)

‎src/backend/commands/functioncmds.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,8 @@ update_proconfig_value(ArrayType *a, List *set_items)
578578

579579
foreach(l,set_items)
580580
{
581-
VariableSetStmt*sstmt= (VariableSetStmt*)lfirst(l);
581+
VariableSetStmt*sstmt=castNode(VariableSetStmt,lfirst(l));
582582

583-
Assert(IsA(sstmt,VariableSetStmt));
584583
if (sstmt->kind==VAR_RESET_ALL)
585584
a=NULL;
586585
else
@@ -971,9 +970,7 @@ CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
971970
{
972971
ListCell*lc;
973972

974-
Assert(IsA(transformDefElem,List));
975-
976-
foreach(lc, (List*)transformDefElem)
973+
foreach(lc,castNode(List,transformDefElem))
977974
{
978975
Oidtypeid=typenameTypeId(NULL,lfirst(lc));
979976
Oidelt=get_base_element_type(typeid);

‎src/backend/commands/matview.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,7 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
264264
* The stored query was rewritten at the time of the MV definition, but
265265
* has not been scribbled on by the planner.
266266
*/
267-
dataQuery= (Query*)linitial(actions);
268-
Assert(IsA(dataQuery,Query));
267+
dataQuery=castNode(Query,linitial(actions));
269268

270269
/*
271270
* Check for active uses of the relation in the current transaction, such

‎src/backend/commands/opclasscmds.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,12 @@ DefineOpClass(CreateOpClassStmt *stmt)
462462
*/
463463
foreach(l,stmt->items)
464464
{
465-
CreateOpClassItem*item=lfirst(l);
465+
CreateOpClassItem*item=castNode(CreateOpClassItem,lfirst(l));
466466
OidoperOid;
467467
OidfuncOid;
468468
OidsortfamilyOid;
469469
OpFamilyMember*member;
470470

471-
Assert(IsA(item,CreateOpClassItem));
472471
switch (item->itemtype)
473472
{
474473
caseOPCLASS_ITEM_OPERATOR:
@@ -847,13 +846,12 @@ AlterOpFamilyAdd(AlterOpFamilyStmt *stmt, Oid amoid, Oid opfamilyoid,
847846
*/
848847
foreach(l,items)
849848
{
850-
CreateOpClassItem*item=lfirst(l);
849+
CreateOpClassItem*item=castNode(CreateOpClassItem,lfirst(l));
851850
OidoperOid;
852851
OidfuncOid;
853852
OidsortfamilyOid;
854853
OpFamilyMember*member;
855854

856-
Assert(IsA(item,CreateOpClassItem));
857855
switch (item->itemtype)
858856
{
859857
caseOPCLASS_ITEM_OPERATOR:
@@ -981,12 +979,11 @@ AlterOpFamilyDrop(AlterOpFamilyStmt *stmt, Oid amoid, Oid opfamilyoid,
981979
*/
982980
foreach(l,items)
983981
{
984-
CreateOpClassItem*item=lfirst(l);
982+
CreateOpClassItem*item=castNode(CreateOpClassItem,lfirst(l));
985983
Oidlefttype,
986984
righttype;
987985
OpFamilyMember*member;
988986

989-
Assert(IsA(item,CreateOpClassItem));
990987
switch (item->itemtype)
991988
{
992989
caseOPCLASS_ITEM_OPERATOR:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp