Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m1CyE-000175-OL for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Jul 2021 19:12:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m1CyD-0005JC-NK for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Jul 2021 19:12:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m1CyC-0005J4-6C for pgsql-hackers@lists.postgresql.org; Wed, 07 Jul 2021 19:12:29 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m1Cy8-0005sK-Pq for pgsql-hackers@lists.postgresql.org; Wed, 07 Jul 2021 19:12:27 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id ACA485C00E8 for ; Wed, 7 Jul 2021 15:12:22 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 07 Jul 2021 15:12:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilmari.org; h= from:to:subject:date:message-id:mime-version:content-type; s= fm2; bh=aWmxZydXBDcD1k4keuHHQred+4fxTihGZfu6GE/1tuI=; b=g7hN6mUb ouImZj8m+0xxZMBfAQl+OXo7va0IHvC92tqFoyoBtBdGc98gQv3MPWftBEvkmYTS HpjyUaV739dKWUqWFt+d/e0OH0vwAAsdmBc3Tl3r2ncX1V5gpJwiXvBJWUDzRkx2 yb8Kxyq+1K5NsU4kj32ISCNXwetX5n6zpMfACJP9AlxMtBZBfn7TGmwuKbGFAg0a jc2yr/rGgxOHTepHbLeEG1kXK+n/5xNs4LSlumdE9GiiR73Mf2bGA5ZqAF0bCTG2 IopE49403fuZ5DtgKRXYaL/btY1zGUIwgJjeE+NPJKLhvo1FZbXpKBQDdw9MnaPW ySWa+b9M6y68dQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=aWmxZydXBDcD1k4keuHHQred+4fxT ihGZfu6GE/1tuI=; b=qFEZPyAl7pcC9rBErPX2LGEw1vOFDsGghP5jY1q+oH07o GJTOJ3AoRtsKvRqo6Mh5Ms0/3twpRYlOedpZWD+g8+7iTQoI+q2xf9oLYVGbMBBN 8wVt6DFi9HC5y9xDwQ9c7I8B+jdgOA7kovI5+e3Hsqex3ZDkfdup//uGNW/TV+Fl DdD+PYN4d/oFCbzaZ6leRWxWygR7kboMb92LK46d0+uonYVDYPNdD6Zb/ze6jTex a0hNnz7vKKSAEtTCqybwKYsJxXXNr3Ws4GgBOMZ2rqhQtPLUVgcv9qZ3c30vbp/f Jrtw294dTO2Yw+bxxLJE7cIMnrDBhBBf87MU3shpg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrtddvgddufedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkfgfgggtsehmtderredtreejnecuhfhrohhmpehilhhmrghrihes ihhlmhgrrhhirdhorhhgucdlffgrghhfihhnnhcukfhlmhgrrhhiucforghnnhhsnohkvg hrmdenucggtffrrghtthgvrhhnpeeliefguddtuefgueethfdvvdduvdetieevvddtgfdt ffeivdeivdehieehvdevffenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehilhhmrghrihesihhlmhgrrhhirdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 7 Jul 2021 15:12:21 -0400 (EDT) From: ilmari@ilmari.org (Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker?=) To: PostgreSQL Hackers Subject: Replace remaining =?utf-8?Q?castNode=28=E2=80=A6=2C_lfirst=28?= =?utf-8?Q?=E2=80=A6=29=29?= and friends calls with l*_node() Date: Wed, 07 Jul 2021 20:12:20 +0100 Message-ID: <87eecahraj.fsf@wibble.ilmari.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=-=-= Content-Type: text/plain Hi hackers, We've had node-casting versions of the list extraction macros since 2017, but several cases of the written-out version have been added since then (even by Tom, who added the l*_node() macros). Here's a patch to convert the remaining ones. The macros were back-patched to all supported branches, so this won't create any new back-patching hazards. - ilmari --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=0001-Use-l-_node-family-of-functions-where-appropriate.patch Content-Transfer-Encoding: 8bit From be3556361bcba2f332f51b75aa13946359335ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= Date: Wed, 7 Jul 2021 11:44:23 +0100 Subject: [PATCH] Use l*_node() family of functions where appropriate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of castNode(…, lfoo(…)) --- src/backend/commands/publicationcmds.c | 2 +- src/backend/commands/tablecmds.c | 8 ++++---- src/backend/executor/execPartition.c | 2 +- src/backend/executor/nodeValuesscan.c | 2 +- src/backend/optimizer/util/paramassign.c | 2 +- src/backend/parser/parse_clause.c | 2 +- src/backend/parser/parse_utilcmd.c | 8 ++++---- src/backend/partitioning/partbounds.c | 18 +++++++++--------- src/backend/rewrite/rewriteSearchCycle.c | 8 ++++---- src/backend/tcop/postgres.c | 2 +- src/backend/utils/adt/ruleutils.c | 6 +++--- src/pl/plpgsql/src/pl_exec.c | 2 +- src/test/modules/test_predtest/test_predtest.c | 4 ++-- 13 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/backend/commands/publicationcmds.c b/src/backend/commands/publicationcmds.c index 95c253c8e0..08f94fa324 100644 --- a/src/backend/commands/publicationcmds.c +++ b/src/backend/commands/publicationcmds.c @@ -515,7 +515,7 @@ OpenTableList(List *tables) */ foreach(lc, tables) { - RangeVar *rv = castNode(RangeVar, lfirst(lc)); + RangeVar *rv = lfirst_node(RangeVar, lc); bool recurse = rv->inh; Relation rel; Oid myrelid; diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 97a9725df7..ba71ceed64 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -4770,7 +4770,7 @@ ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode, foreach(lcmd, subcmds) ATExecCmd(wqueue, tab, - castNode(AlterTableCmd, lfirst(lcmd)), + lfirst_node(AlterTableCmd, lcmd), lockmode, pass, context); /* @@ -12753,7 +12753,7 @@ ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId, char *cmd, foreach(lcmd, stmt->cmds) { - AlterTableCmd *cmd = castNode(AlterTableCmd, lfirst(lcmd)); + AlterTableCmd *cmd = lfirst_node(AlterTableCmd, lcmd); if (cmd->subtype == AT_AddIndex) { @@ -16571,7 +16571,7 @@ transformPartitionSpec(Relation rel, PartitionSpec *partspec, char *strategy) /* take care of any partition expressions */ foreach(l, partspec->partParams) { - PartitionElem *pelem = castNode(PartitionElem, lfirst(l)); + PartitionElem *pelem = lfirst_node(PartitionElem, l); if (pelem->expr) { @@ -16608,7 +16608,7 @@ ComputePartitionAttrs(ParseState *pstate, Relation rel, List *partParams, AttrNu attn = 0; foreach(lc, partParams) { - PartitionElem *pelem = castNode(PartitionElem, lfirst(lc)); + PartitionElem *pelem = lfirst_node(PartitionElem, lc); Oid atttype; Oid attcollation; diff --git a/src/backend/executor/execPartition.c b/src/backend/executor/execPartition.c index 606c920b06..5c723bc54e 100644 --- a/src/backend/executor/execPartition.c +++ b/src/backend/executor/execPartition.c @@ -585,7 +585,7 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, EState *estate, foreach(ll, wcoList) { - WithCheckOption *wco = castNode(WithCheckOption, lfirst(ll)); + WithCheckOption *wco = lfirst_node(WithCheckOption, ll); ExprState *wcoExpr = ExecInitQual(castNode(List, wco->qual), &mtstate->ps); diff --git a/src/backend/executor/nodeValuesscan.c b/src/backend/executor/nodeValuesscan.c index 5de1429fda..00bd1271e4 100644 --- a/src/backend/executor/nodeValuesscan.c +++ b/src/backend/executor/nodeValuesscan.c @@ -285,7 +285,7 @@ ExecInitValuesScan(ValuesScan *node, EState *estate, int eflags) i = 0; foreach(vtl, node->values_lists) { - List *exprs = castNode(List, lfirst(vtl)); + List *exprs = lfirst_node(List, vtl); scanstate->exprlists[i] = exprs; diff --git a/src/backend/optimizer/util/paramassign.c b/src/backend/optimizer/util/paramassign.c index ebb424112b..61b856a959 100644 --- a/src/backend/optimizer/util/paramassign.c +++ b/src/backend/optimizer/util/paramassign.c @@ -431,7 +431,7 @@ process_subquery_nestloop_params(PlannerInfo *root, List *subplan_params) foreach(lc, subplan_params) { - PlannerParamItem *pitem = castNode(PlannerParamItem, lfirst(lc)); + PlannerParamItem *pitem = lfirst_node(PlannerParamItem, lc); if (IsA(pitem->item, Var)) { diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index 71c360bea5..b3f151d33b 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -2807,7 +2807,7 @@ transformWindowDefinitions(ParseState *pstate, (errcode(ERRCODE_WINDOWING_ERROR), errmsg("RANGE with offset PRECEDING/FOLLOWING requires exactly one ORDER BY column"), parser_errposition(pstate, windef->location))); - sortcl = castNode(SortGroupClause, linitial(wc->orderClause)); + sortcl = linitial_node(SortGroupClause, wc->orderClause); sortkey = get_sortgroupclause_expr(sortcl, *targetlist); /* Find the sort operator in pg_amop */ if (!get_ordering_op_properties(sortcl->sortop, diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index 81d3e7990c..16abacd76c 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -2425,7 +2425,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt) /* Make sure referenced column exists. */ foreach(columns, cxt->columns) { - column = castNode(ColumnDef, lfirst(columns)); + column = lfirst_node(ColumnDef, columns); if (strcmp(column->colname, key) == 0) { found = true; @@ -2463,7 +2463,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt) foreach(inher, cxt->inhRelations) { - RangeVar *inh = castNode(RangeVar, lfirst(inher)); + RangeVar *inh = lfirst_node(RangeVar, inher); Relation rel; int count; @@ -4089,7 +4089,7 @@ transformPartitionBound(ParseState *pstate, Relation parent, duplicate = false; foreach(cell2, result_spec->listdatums) { - Const *value2 = castNode(Const, lfirst(cell2)); + Const *value2 = lfirst_node(Const, cell2); if (equal(value, value2)) { @@ -4268,7 +4268,7 @@ validateInfiniteBounds(ParseState *pstate, List *blist) foreach(lc, blist) { - PartitionRangeDatum *prd = castNode(PartitionRangeDatum, lfirst(lc)); + PartitionRangeDatum *prd = lfirst_node(PartitionRangeDatum, lc); if (kind == prd->kind) continue; diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c index 38baaefcda..be35068384 100644 --- a/src/backend/partitioning/partbounds.c +++ b/src/backend/partitioning/partbounds.c @@ -453,7 +453,7 @@ get_non_null_list_datum_count(PartitionBoundSpec **boundspecs, int nparts) foreach(lc, boundspecs[i]->listdatums) { - Const *val = castNode(Const, lfirst(lc)); + Const *val = lfirst_node(Const, lc); if (!val->constisnull) count++; @@ -514,7 +514,7 @@ create_list_bounds(PartitionBoundSpec **boundspecs, int nparts, foreach(c, spec->listdatums) { - Const *val = castNode(Const, lfirst(c)); + Const *val = lfirst_node(Const, c); if (!val->constisnull) { @@ -3015,7 +3015,7 @@ check_new_partition_bound(char *relname, Relation parent, foreach(cell, spec->listdatums) { - Const *val = castNode(Const, lfirst(cell)); + Const *val = lfirst_node(Const, cell); overlap_location = val->location; if (!val->constisnull) @@ -3400,7 +3400,7 @@ make_one_partition_rbound(PartitionKey key, int index, List *datums, bool lower) i = 0; foreach(lc, datums) { - PartitionRangeDatum *datum = castNode(PartitionRangeDatum, lfirst(lc)); + PartitionRangeDatum *datum = lfirst_node(PartitionRangeDatum, lc); /* What's contained in this range datum? */ bound->kind[i] = datum->kind; @@ -4104,7 +4104,7 @@ get_qual_for_list(Relation parent, PartitionBoundSpec *spec) */ foreach(cell, spec->listdatums) { - Const *val = castNode(Const, lfirst(cell)); + Const *val = lfirst_node(Const, cell); if (val->constisnull) list_has_null = true; @@ -4359,8 +4359,8 @@ get_qual_for_range(Relation parent, PartitionBoundSpec *spec, Datum test_result; bool isNull; - ldatum = castNode(PartitionRangeDatum, lfirst(cell1)); - udatum = castNode(PartitionRangeDatum, lfirst(cell2)); + ldatum = lfirst_node(PartitionRangeDatum, cell1); + udatum = lfirst_node(PartitionRangeDatum, cell2); /* * Since get_range_key_properties() modifies partexprs_item, and we @@ -4441,11 +4441,11 @@ get_qual_for_range(Relation parent, PartitionBoundSpec *spec, PartitionRangeDatum *ldatum_next = NULL, *udatum_next = NULL; - ldatum = castNode(PartitionRangeDatum, lfirst(cell1)); + ldatum = lfirst_node(PartitionRangeDatum, cell1); if (lnext(spec->lowerdatums, cell1)) ldatum_next = castNode(PartitionRangeDatum, lfirst(lnext(spec->lowerdatums, cell1))); - udatum = castNode(PartitionRangeDatum, lfirst(cell2)); + udatum = lfirst_node(PartitionRangeDatum, cell2); if (lnext(spec->upperdatums, cell2)) udatum_next = castNode(PartitionRangeDatum, lfirst(lnext(spec->upperdatums, cell2))); diff --git a/src/backend/rewrite/rewriteSearchCycle.c b/src/backend/rewrite/rewriteSearchCycle.c index 599fe8e735..c50ebdba24 100644 --- a/src/backend/rewrite/rewriteSearchCycle.c +++ b/src/backend/rewrite/rewriteSearchCycle.c @@ -307,8 +307,8 @@ rewriteSearchAndCycle(CommonTableExpr *cte) list_nth_oid(cte->ctecolcollations, i), 0); tle = makeTargetEntry((Expr *) var, i + 1, strVal(list_nth(cte->ctecolnames, i)), false); - tle->resorigtbl = castNode(TargetEntry, list_nth(rte1->subquery->targetList, i))->resorigtbl; - tle->resorigcol = castNode(TargetEntry, list_nth(rte1->subquery->targetList, i))->resorigcol; + tle->resorigtbl = list_nth_node(TargetEntry, rte1->subquery->targetList, i)->resorigtbl; + tle->resorigcol = list_nth_node(TargetEntry, rte1->subquery->targetList, i)->resorigcol; newq1->targetList = lappend(newq1->targetList, tle); } @@ -482,8 +482,8 @@ rewriteSearchAndCycle(CommonTableExpr *cte) list_nth_oid(cte->ctecolcollations, i), 0); tle = makeTargetEntry((Expr *) var, i + 1, strVal(list_nth(cte->ctecolnames, i)), false); - tle->resorigtbl = castNode(TargetEntry, list_nth(rte2->subquery->targetList, i))->resorigtbl; - tle->resorigcol = castNode(TargetEntry, list_nth(rte2->subquery->targetList, i))->resorigcol; + tle->resorigtbl = list_nth_node(TargetEntry, rte2->subquery->targetList, i)->resorigtbl; + tle->resorigcol = list_nth_node(TargetEntry, rte2->subquery->targetList, i)->resorigcol; newq2->targetList = lappend(newq2->targetList, tle); } diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 8cea10c901..530caa520b 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -785,7 +785,7 @@ pg_rewrite_query(Query *query) */ foreach(lc, querytree_list) { - Query *query = castNode(Query, lfirst(lc)); + Query *query = lfirst_node(Query, lc); if (query->commandType != CMD_UTILITY) { diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 3719755a0d..5e7108f903 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -7793,7 +7793,7 @@ find_param_referent(Param *param, deparse_context *context, */ foreach(lc2, ((Plan *) ancestor)->initPlan) { - SubPlan *subplan = castNode(SubPlan, lfirst(lc2)); + SubPlan *subplan = lfirst_node(SubPlan, lc2); if (child_plan != (Plan *) list_nth(dpns->subplans, subplan->plan_id - 1)) @@ -9407,7 +9407,7 @@ get_rule_expr(Node *node, deparse_context *context, sep = ""; foreach(cell, spec->listdatums) { - Const *val = castNode(Const, lfirst(cell)); + Const *val = lfirst_node(Const, cell); appendStringInfoString(buf, sep); get_const_expr(val, context, -1); @@ -11990,7 +11990,7 @@ get_range_partbound_string(List *bound_datums) foreach(cell, bound_datums) { PartitionRangeDatum *datum = - castNode(PartitionRangeDatum, lfirst(cell)); + lfirst_node(PartitionRangeDatum, cell); appendStringInfoString(buf, sep); if (datum->kind == PARTITION_RANGE_DATUM_MINVALUE) diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c index 96bb77e0b1..b5c208d83d 100644 --- a/src/pl/plpgsql/src/pl_exec.c +++ b/src/pl/plpgsql/src/pl_exec.c @@ -7996,7 +7996,7 @@ exec_save_simple_expr(PLpgSQL_expr *expr, CachedPlan *cplan) { /* Extract the single tlist expression */ Assert(list_length(plan->targetlist) == 1); - tle_expr = castNode(TargetEntry, linitial(plan->targetlist))->expr; + tle_expr = linitial_node(TargetEntry, plan->targetlist)->expr; if (IsA(plan, Result)) { diff --git a/src/test/modules/test_predtest/test_predtest.c b/src/test/modules/test_predtest/test_predtest.c index 9c0aadd61c..0301d48443 100644 --- a/src/test/modules/test_predtest/test_predtest.c +++ b/src/test/modules/test_predtest/test_predtest.c @@ -131,8 +131,8 @@ test_predtest(PG_FUNCTION_ARGS) elog(ERROR, "failed to decipher query plan"); plan = stmt->planTree; Assert(list_length(plan->targetlist) >= 2); - clause1 = castNode(TargetEntry, linitial(plan->targetlist))->expr; - clause2 = castNode(TargetEntry, lsecond(plan->targetlist))->expr; + clause1 = linitial_node(TargetEntry, plan->targetlist)->expr; + clause2 = lsecond_node(TargetEntry, plan->targetlist)->expr; /* * Because the clauses are in the SELECT list, preprocess_expression did -- 2.30.2 --=-=-=--