From d0b4399d81f39decccb23fa38f772b71b51bf96a Mon Sep 17 00:00:00 2001 From: Neil Conway Date: Wed, 26 May 2004 04:41:50 +0000 Subject: [PATCH] Reimplement the linked list data structure used throughout the backend. In the past, we used a 'Lispy' linked list implementation: a "list" was merely a pointer to the head node of the list. The problem with that design is that it makes lappend() and length() linear time. This patch fixes that problem (and others) by maintaining a count of the list length and a pointer to the tail node along with each head node pointer. A "list" is now a pointer to a structure containing some meta-data about the list; the head and tail pointers in that structure refer to ListCell structures that maintain the actual linked list of nodes. The function names of the list API have also been changed to, I hope, be more logically consistent. By default, the old function names are still available; they will be disabled-by-default once the rest of the tree has been updated to use the new API names. --- src/backend/access/common/printtup.c | 17 +- src/backend/access/common/tupdesc.c | 10 +- src/backend/access/nbtree/nbtxlog.c | 6 +- src/backend/bootstrap/bootparse.y | 6 +- src/backend/catalog/aclchk.c | 34 +- src/backend/catalog/dependency.c | 42 +- src/backend/catalog/heap.c | 34 +- src/backend/catalog/index.c | 30 +- src/backend/catalog/namespace.c | 160 +-- src/backend/catalog/pg_proc.c | 12 +- src/backend/commands/aggregatecmds.c | 4 +- src/backend/commands/alter.c | 6 +- src/backend/commands/analyze.c | 14 +- src/backend/commands/async.c | 4 +- src/backend/commands/cluster.c | 14 +- src/backend/commands/comment.c | 60 +- src/backend/commands/copy.c | 51 +- src/backend/commands/dbcommands.c | 4 +- src/backend/commands/define.c | 6 +- src/backend/commands/explain.c | 44 +- src/backend/commands/functioncmds.c | 20 +- src/backend/commands/indexcmds.c | 40 +- src/backend/commands/lockcmds.c | 4 +- src/backend/commands/opclasscmds.c | 12 +- src/backend/commands/operatorcmds.c | 14 +- src/backend/commands/portalcmds.c | 10 +- src/backend/commands/prepare.c | 36 +- src/backend/commands/schemacmds.c | 12 +- src/backend/commands/sequence.c | 4 +- src/backend/commands/tablecmds.c | 224 ++-- src/backend/commands/trigger.c | 40 +- src/backend/commands/typecmds.c | 16 +- src/backend/commands/user.c | 46 +- src/backend/commands/vacuum.c | 24 +- src/backend/commands/variable.c | 8 +- src/backend/commands/view.c | 8 +- src/backend/executor/execAmi.c | 14 +- src/backend/executor/execJunk.c | 6 +- src/backend/executor/execMain.c | 32 +- src/backend/executor/execProcnode.c | 14 +- src/backend/executor/execQual.c | 73 +- src/backend/executor/execScan.c | 11 +- src/backend/executor/execTuples.c | 6 +- src/backend/executor/execUtils.c | 15 +- src/backend/executor/functions.c | 4 +- src/backend/executor/nodeAgg.c | 8 +- src/backend/executor/nodeAppend.c | 4 +- src/backend/executor/nodeFunctionscan.c | 4 +- src/backend/executor/nodeHash.c | 6 +- src/backend/executor/nodeHashjoin.c | 10 +- src/backend/executor/nodeIndexscan.c | 68 +- src/backend/executor/nodeMergejoin.c | 29 +- src/backend/executor/nodeSubplan.c | 60 +- src/backend/executor/nodeTidscan.c | 8 +- src/backend/executor/spi.c | 22 +- src/backend/libpq/crypt.c | 8 +- src/backend/libpq/hba.c | 304 ++--- src/backend/nodes/copyfuncs.c | 186 ++- src/backend/nodes/equalfuncs.c | 121 +- src/backend/nodes/list.c | 1302 ++++++++++++++------- src/backend/nodes/outfuncs.c | 134 +-- src/backend/nodes/print.c | 24 +- src/backend/nodes/read.c | 3 +- src/backend/nodes/readfuncs.c | 37 +- src/backend/optimizer/geqo/geqo_eval.c | 12 +- src/backend/optimizer/path/allpaths.c | 51 +- src/backend/optimizer/path/clausesel.c | 14 +- src/backend/optimizer/path/costsize.c | 12 +- src/backend/optimizer/path/indxpath.c | 87 +- src/backend/optimizer/path/joinpath.c | 28 +- src/backend/optimizer/path/joinrels.c | 56 +- src/backend/optimizer/path/orindxpath.c | 20 +- src/backend/optimizer/path/pathkeys.c | 132 +-- src/backend/optimizer/path/tidpath.c | 28 +- src/backend/optimizer/plan/createplan.c | 103 +- src/backend/optimizer/plan/initsplan.c | 21 +- src/backend/optimizer/plan/planner.c | 63 +- src/backend/optimizer/plan/setrefs.c | 25 +- src/backend/optimizer/plan/subselect.c | 75 +- src/backend/optimizer/prep/prepjointree.c | 50 +- src/backend/optimizer/prep/prepqual.c | 50 +- src/backend/optimizer/prep/preptlist.c | 17 +- src/backend/optimizer/prep/prepunion.c | 63 +- src/backend/optimizer/util/clauses.c | 78 +- src/backend/optimizer/util/joininfo.c | 8 +- src/backend/optimizer/util/pathnode.c | 43 +- src/backend/optimizer/util/plancat.c | 12 +- src/backend/optimizer/util/relnode.c | 46 +- src/backend/optimizer/util/restrictinfo.c | 22 +- src/backend/optimizer/util/tlist.c | 12 +- src/backend/optimizer/util/var.c | 8 +- src/backend/parser/analyze.c | 217 ++-- src/backend/parser/gram.y | 22 +- src/backend/parser/parse_agg.c | 18 +- src/backend/parser/parse_clause.c | 81 +- src/backend/parser/parse_coerce.c | 14 +- src/backend/parser/parse_expr.c | 114 +- src/backend/parser/parse_func.c | 116 +- src/backend/parser/parse_node.c | 4 +- src/backend/parser/parse_relation.c | 91 +- src/backend/parser/parse_target.c | 16 +- src/backend/parser/parse_type.c | 16 +- src/backend/rewrite/rewriteDefine.c | 12 +- src/backend/rewrite/rewriteHandler.c | 30 +- src/backend/rewrite/rewriteManip.c | 10 +- src/backend/tcop/postgres.c | 58 +- src/backend/tcop/pquery.c | 25 +- src/backend/tcop/utility.c | 22 +- src/backend/utils/adt/name.c | 13 +- src/backend/utils/adt/regproc.c | 4 +- src/backend/utils/adt/ri_triggers.c | 24 +- src/backend/utils/adt/ruleutils.c | 150 +-- src/backend/utils/adt/selfuncs.c | 30 +- src/backend/utils/adt/tid.c | 4 +- src/backend/utils/adt/varlena.c | 4 +- src/backend/utils/cache/catcache.c | 8 +- src/backend/utils/cache/relcache.c | 25 +- src/backend/utils/cache/typcache.c | 4 +- src/backend/utils/init/miscinit.c | 4 +- src/backend/utils/misc/guc.c | 10 +- src/include/nodes/nodes.h | 4 +- src/include/nodes/pg_list.h | 378 ++++-- src/include/parser/parsetree.h | 6 +- src/pl/plpgsql/src/pl_exec.c | 8 +- src/pl/tcl/pltcl.c | 8 +- 125 files changed, 3438 insertions(+), 2837 deletions(-) diff --git a/src/backend/access/common/printtup.c b/src/backend/access/common/printtup.c index 664c884a71..eb05c994b4 100644 --- a/src/backend/access/common/printtup.c +++ b/src/backend/access/common/printtup.c @@ -9,7 +9,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/common/printtup.c,v 1.80 2004/01/07 18:56:23 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/access/common/printtup.c,v 1.81 2004/05/26 04:41:03 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -138,7 +138,7 @@ printtup_startup(DestReceiver *self, int operation, TupleDesc typeinfo) List *targetlist; if (portal->strategy == PORTAL_ONE_SELECT) - targetlist = ((Query *) lfirst(portal->parseTrees))->targetList; + targetlist = ((Query *) linitial(portal->parseTrees))->targetList; else targetlist = NIL; @@ -176,6 +176,7 @@ SendRowDescriptionMessage(TupleDesc typeinfo, List *targetlist, int16 *formats) int proto = PG_PROTOCOL_MAJOR(FrontendProtocol); int i; StringInfoData buf; + ListCell *tlist_item = list_head(targetlist); pq_beginmessage(&buf, 'T'); /* tuple descriptor message type */ pq_sendint(&buf, natts, 2); /* # of attrs in tuples */ @@ -191,16 +192,16 @@ SendRowDescriptionMessage(TupleDesc typeinfo, List *targetlist, int16 *formats) if (proto >= 3) { /* Do we have a non-resjunk tlist item? */ - while (targetlist && - ((TargetEntry *) lfirst(targetlist))->resdom->resjunk) - targetlist = lnext(targetlist); - if (targetlist) + while (tlist_item && + ((TargetEntry *) lfirst(tlist_item))->resdom->resjunk) + tlist_item = lnext(tlist_item); + if (tlist_item) { - Resdom *res = ((TargetEntry *) lfirst(targetlist))->resdom; + Resdom *res = ((TargetEntry *) lfirst(tlist_item))->resdom; pq_sendint(&buf, res->resorigtbl, 4); pq_sendint(&buf, res->resorigcol, 2); - targetlist = lnext(targetlist); + tlist_item = lnext(tlist_item); } else { diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c index 1a016d86f8..4a3c2721c7 100644 --- a/src/backend/access/common/tupdesc.c +++ b/src/backend/access/common/tupdesc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/common/tupdesc.c,v 1.102 2004/04/01 21:28:43 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/access/common/tupdesc.c,v 1.103 2004/05/26 04:41:03 neilc Exp $ * * NOTES * some of the executor utility code such as "ExecTypeFromTL" should be @@ -472,7 +472,7 @@ BuildDescForRelation(List *schema) { int natts; AttrNumber attnum; - List *p; + ListCell *l; TupleDesc desc; AttrDefault *attrdef = NULL; TupleConstr *constr = (TupleConstr *) palloc0(sizeof(TupleConstr)); @@ -490,9 +490,9 @@ BuildDescForRelation(List *schema) attnum = 0; - foreach(p, schema) + foreach(l, schema) { - ColumnDef *entry = lfirst(p); + ColumnDef *entry = lfirst(l); /* * for each entry in the list, get the name and type information @@ -661,7 +661,7 @@ TypeGetTupleDesc(Oid typeoid, List *colaliases) errmsg("number of aliases does not match number of columns"))); /* OK, get the column alias */ - attname = strVal(lfirst(colaliases)); + attname = strVal(linitial(colaliases)); tupdesc = CreateTemplateTupleDesc(1, false); TupleDescInitEntry(tupdesc, diff --git a/src/backend/access/nbtree/nbtxlog.c b/src/backend/access/nbtree/nbtxlog.c index 02dbd33341..693279f12a 100644 --- a/src/backend/access/nbtree/nbtxlog.c +++ b/src/backend/access/nbtree/nbtxlog.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtxlog.c,v 1.10 2004/01/07 18:56:24 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtxlog.c,v 1.11 2004/05/26 04:41:05 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -59,7 +59,7 @@ forget_matching_split(Relation reln, RelFileNode node, Page page; BTItem btitem; BlockNumber rightblk; - List *l; + ListCell *l; /* Get downlink TID from page */ buffer = XLogReadBuffer(false, reln, insertblk); @@ -964,7 +964,7 @@ btree_xlog_startup(void) void btree_xlog_cleanup(void) { - List *l; + ListCell *l; foreach(l, incomplete_splits) { diff --git a/src/backend/bootstrap/bootparse.y b/src/backend/bootstrap/bootparse.y index debf24e892..4047958b1d 100644 --- a/src/backend/bootstrap/bootparse.y +++ b/src/backend/bootstrap/bootparse.y @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.67 2004/05/21 05:07:56 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.68 2004/05/26 04:41:05 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -271,7 +271,7 @@ Boot_BuildIndsStmt: boot_index_params: boot_index_params COMMA boot_index_param { $$ = lappend($1, $3); } - | boot_index_param { $$ = makeList1($1); } + | boot_index_param { $$ = list_make1($1); } ; boot_index_param: @@ -280,7 +280,7 @@ boot_index_param: IndexElem *n = makeNode(IndexElem); n->name = LexIDStr($1); n->expr = NULL; - n->opclass = makeList1(makeString(LexIDStr($2))); + n->opclass = list_make1(makeString(LexIDStr($2))); $$ = n; } ; diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c index 8e27f10d39..cabeb69088 100644 --- a/src/backend/catalog/aclchk.c +++ b/src/backend/catalog/aclchk.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.98 2004/05/11 17:36:12 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.99 2004/05/26 04:41:06 neilc Exp $ * * NOTES * See acl.h. @@ -110,7 +110,7 @@ merge_acl_with_grant(Acl *old_acl, bool is_grant, AclId grantor_uid, AclId owner_uid) { unsigned modechg; - List *j; + ListCell *j; Acl *new_acl; modechg = is_grant ? ACL_MODECHG_ADD : ACL_MODECHG_DEL; @@ -221,16 +221,16 @@ static void ExecuteGrantStmt_Relation(GrantStmt *stmt) { AclMode privileges; - List *i; + ListCell *i; - if (lfirsti(stmt->privileges) == ACL_ALL_RIGHTS) + if (linitial_int(stmt->privileges) == ACL_ALL_RIGHTS) privileges = ACL_ALL_RIGHTS_RELATION; else { privileges = ACL_NO_RIGHTS; foreach(i, stmt->privileges) { - AclMode priv = lfirsti(i); + AclMode priv = lfirst_int(i); if (priv & ~((AclMode) ACL_ALL_RIGHTS_RELATION)) ereport(ERROR, @@ -328,16 +328,16 @@ static void ExecuteGrantStmt_Database(GrantStmt *stmt) { AclMode privileges; - List *i; + ListCell *i; - if (lfirsti(stmt->privileges) == ACL_ALL_RIGHTS) + if (linitial_int(stmt->privileges) == ACL_ALL_RIGHTS) privileges = ACL_ALL_RIGHTS_DATABASE; else { privileges = ACL_NO_RIGHTS; foreach(i, stmt->privileges) { - AclMode priv = lfirsti(i); + AclMode priv = lfirst_int(i); if (priv & ~((AclMode) ACL_ALL_RIGHTS_DATABASE)) ereport(ERROR, @@ -433,16 +433,16 @@ static void ExecuteGrantStmt_Function(GrantStmt *stmt) { AclMode privileges; - List *i; + ListCell *i; - if (lfirsti(stmt->privileges) == ACL_ALL_RIGHTS) + if (linitial_int(stmt->privileges) == ACL_ALL_RIGHTS) privileges = ACL_ALL_RIGHTS_FUNCTION; else { privileges = ACL_NO_RIGHTS; foreach(i, stmt->privileges) { - AclMode priv = lfirsti(i); + AclMode priv = lfirst_int(i); if (priv & ~((AclMode) ACL_ALL_RIGHTS_FUNCTION)) ereport(ERROR, @@ -534,16 +534,16 @@ static void ExecuteGrantStmt_Language(GrantStmt *stmt) { AclMode privileges; - List *i; + ListCell *i; - if (lfirsti(stmt->privileges) == ACL_ALL_RIGHTS) + if (linitial_int(stmt->privileges) == ACL_ALL_RIGHTS) privileges = ACL_ALL_RIGHTS_LANGUAGE; else { privileges = ACL_NO_RIGHTS; foreach(i, stmt->privileges) { - AclMode priv = lfirsti(i); + AclMode priv = lfirst_int(i); if (priv & ~((AclMode) ACL_ALL_RIGHTS_LANGUAGE)) ereport(ERROR, @@ -643,16 +643,16 @@ static void ExecuteGrantStmt_Namespace(GrantStmt *stmt) { AclMode privileges; - List *i; + ListCell *i; - if (lfirsti(stmt->privileges) == ACL_ALL_RIGHTS) + if (linitial_int(stmt->privileges) == ACL_ALL_RIGHTS) privileges = ACL_ALL_RIGHTS_NAMESPACE; else { privileges = ACL_NO_RIGHTS; foreach(i, stmt->privileges) { - AclMode priv = lfirsti(i); + AclMode priv = lfirst_int(i); if (priv & ~((AclMode) ACL_ALL_RIGHTS_NAMESPACE)) ereport(ERROR, diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c index 5f2b2ea28a..9d4e1c6a5c 100644 --- a/src/backend/catalog/dependency.c +++ b/src/backend/catalog/dependency.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/catalog/dependency.c,v 1.35 2004/05/05 04:48:45 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/dependency.c,v 1.36 2004/05/26 04:41:06 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -841,7 +841,7 @@ recordDependencyOnExpr(const ObjectAddress *depender, init_object_addresses(&context.addrs); /* Set up interpretation for Vars at varlevelsup = 0 */ - context.rtables = makeList1(rtable); + context.rtables = list_make1(rtable); /* Scan the expression tree for referenceable objects */ find_expr_references_walker(expr, &context); @@ -883,7 +883,7 @@ recordDependencyOnSingleRelExpr(const ObjectAddress *depender, rte.rtekind = RTE_RELATION; rte.relid = relId; - context.rtables = makeList1(makeList1(&rte)); + context.rtables = list_make1(list_make1(&rte)); /* Scan the expression tree for referenceable objects */ find_expr_references_walker(expr, &context); @@ -960,24 +960,14 @@ find_expr_references_walker(Node *node, if (IsA(node, Var)) { Var *var = (Var *) node; - int levelsup; - List *rtable, - *rtables; + List *rtable; RangeTblEntry *rte; /* Find matching rtable entry, or complain if not found */ - levelsup = var->varlevelsup; - rtables = context->rtables; - while (levelsup--) - { - if (rtables == NIL) - break; - rtables = lnext(rtables); - } - if (rtables == NIL) + if (var->varlevelsup >= list_length(context->rtables)) elog(ERROR, "invalid varlevelsup %d", var->varlevelsup); - rtable = lfirst(rtables); - if (var->varno <= 0 || var->varno > length(rtable)) + rtable = (List *) list_nth(context->rtables, var->varlevelsup); + if (var->varno <= 0 || var->varno > list_length(rtable)) elog(ERROR, "invalid varno %d", var->varno); rte = rt_fetch(var->varno, rtable); if (rte->rtekind == RTE_RELATION) @@ -994,13 +984,15 @@ find_expr_references_walker(Node *node, /* We must make the context appropriate for join's level */ save_rtables = context->rtables; - context->rtables = rtables; + context->rtables = list_copy_tail(context->rtables, + var->varlevelsup); if (var->varattno <= 0 || - var->varattno > length(rte->joinaliasvars)) + var->varattno > list_length(rte->joinaliasvars)) elog(ERROR, "invalid varattno %d", var->varattno); - find_expr_references_walker((Node *) nth(var->varattno - 1, - rte->joinaliasvars), + find_expr_references_walker((Node *) list_nth(rte->joinaliasvars, + var->varattno - 1), context); + list_free(context->rtables); context->rtables = save_rtables; } return false; @@ -1056,11 +1048,11 @@ find_expr_references_walker(Node *node, if (IsA(node, SubLink)) { SubLink *sublink = (SubLink *) node; - List *opid; + ListCell *opid; foreach(opid, sublink->operOids) { - add_object_address(OCLASS_OPERATOR, lfirsto(opid), 0, + add_object_address(OCLASS_OPERATOR, lfirst_oid(opid), 0, &context->addrs); } /* fall through to examine arguments */ @@ -1074,7 +1066,7 @@ find_expr_references_walker(Node *node, { /* Recurse into RTE subquery or not-yet-planned sublink subquery */ Query *query = (Query *) node; - List *rtable; + ListCell *rtable; bool result; /* @@ -1099,7 +1091,7 @@ find_expr_references_walker(Node *node, find_expr_references_walker, (void *) context, QTW_IGNORE_JOINALIASES); - context->rtables = lnext(context->rtables); + context->rtables = list_delete_first(context->rtables); return result; } return expression_tree_walker(node, find_expr_references_walker, diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 94f1fd2a13..a7ffe38b53 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.264 2004/05/08 19:09:24 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.265 2004/05/26 04:41:07 neilc Exp $ * * * INTERFACE ROUTINES @@ -1379,11 +1379,11 @@ StoreRelCheck(Relation rel, char *ccname, char *ccbin) * contents of subselects. */ varList = pull_var_clause(expr, false); - keycount = length(varList); + keycount = list_length(varList); if (keycount > 0) { - List *vl; + ListCell *vl; int i = 0; attNos = (int16 *) palloc(keycount * sizeof(int16)); @@ -1505,7 +1505,7 @@ AddRelationRawConstraints(Relation rel, RangeTblEntry *rte; int numchecks; int constr_name_ctr = 0; - List *listptr; + ListCell *cell; Node *expr; CookedConstraint *cooked; @@ -1540,9 +1540,9 @@ AddRelationRawConstraints(Relation rel, /* * Process column default expressions. */ - foreach(listptr, rawColDefaults) + foreach(cell, rawColDefaults) { - RawColumnDefault *colDef = (RawColumnDefault *) lfirst(listptr); + RawColumnDefault *colDef = (RawColumnDefault *) lfirst(cell); Form_pg_attribute atp = rel->rd_att->attrs[colDef->attnum - 1]; expr = cookDefault(pstate, colDef->raw_default, @@ -1563,9 +1563,9 @@ AddRelationRawConstraints(Relation rel, * Process constraint expressions. */ numchecks = numoldchecks; - foreach(listptr, rawConstraints) + foreach(cell, rawConstraints) { - Constraint *cdef = (Constraint *) lfirst(listptr); + Constraint *cdef = (Constraint *) lfirst(cell); char *ccname; if (cdef->contype != CONSTR_CHECK || cdef->raw_expr == NULL) @@ -1575,7 +1575,7 @@ AddRelationRawConstraints(Relation rel, /* Check name uniqueness, or generate a new name */ if (cdef->name != NULL) { - List *listptr2; + ListCell *cell2; ccname = cdef->name; /* Check against pre-existing constraints */ @@ -1589,9 +1589,9 @@ AddRelationRawConstraints(Relation rel, ccname, RelationGetRelationName(rel)))); /* Check against other new constraints */ /* Needed because we don't do CommandCounterIncrement in loop */ - foreach(listptr2, rawConstraints) + foreach(cell2, rawConstraints) { - Constraint *cdef2 = (Constraint *) lfirst(listptr2); + Constraint *cdef2 = (Constraint *) lfirst(cell2); if (cdef2 == cdef || cdef2->contype != CONSTR_CHECK || @@ -1611,7 +1611,7 @@ AddRelationRawConstraints(Relation rel, do { - List *listptr2; + ListCell *cell2; /* * Generate a name that does not conflict with @@ -1629,9 +1629,9 @@ AddRelationRawConstraints(Relation rel, * name. */ success = true; - foreach(listptr2, rawConstraints) + foreach(cell2, rawConstraints) { - Constraint *cdef2 = (Constraint *) lfirst(listptr2); + Constraint *cdef2 = (Constraint *) lfirst(cell2); if (cdef2 == cdef || cdef2->contype != CONSTR_CHECK || @@ -1660,7 +1660,7 @@ AddRelationRawConstraints(Relation rel, /* * Make sure no outside relations are referred to. */ - if (length(pstate->p_rtable) != 1) + if (list_length(pstate->p_rtable) != 1) ereport(ERROR, (errcode(ERRCODE_INVALID_COLUMN_REFERENCE), errmsg("only table \"%s\" can be referenced in check constraint", @@ -1949,7 +1949,7 @@ static void RelationTruncateIndexes(Oid heapId) { Relation heapRelation; - List *indlist; + ListCell *indlist; /* * Open the heap rel. We need grab no lock because we assume @@ -1960,7 +1960,7 @@ RelationTruncateIndexes(Oid heapId) /* Ask the relcache to produce a list of the indexes of the rel */ foreach(indlist, RelationGetIndexList(heapRelation)) { - Oid indexId = lfirsto(indlist); + Oid indexId = lfirst_oid(indlist); Relation currentIndex; IndexInfo *indexInfo; diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index d6d38795df..0ccecac668 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.231 2004/05/08 19:09:24 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.232 2004/05/26 04:41:07 neilc Exp $ * * * INTERFACE ROUTINES @@ -88,7 +88,7 @@ ConstructTupleDescriptor(Relation heapRelation, Oid *classObjectId) { int numatts = indexInfo->ii_NumIndexAttrs; - List *indexprs = indexInfo->ii_Expressions; + ListCell *indexpr_item = list_head(indexInfo->ii_Expressions); TupleDesc heapTupDesc; TupleDesc indexTupDesc; int natts; /* #atts in heap rel --- for error checks */ @@ -165,10 +165,10 @@ ConstructTupleDescriptor(Relation heapRelation, /* Expressional index */ Node *indexkey; - if (indexprs == NIL) /* shouldn't happen */ + if (indexpr_item == NULL) /* shouldn't happen */ elog(ERROR, "too few entries in indexprs list"); - indexkey = (Node *) lfirst(indexprs); - indexprs = lnext(indexprs); + indexkey = (Node *) lfirst(indexpr_item); + indexpr_item = lnext(indexpr_item); /* * Make the attribute's name "pg_expresssion_nnn" (maybe think @@ -928,7 +928,7 @@ FormIndexDatum(IndexInfo *indexInfo, Datum *datum, char *nullv) { - List *indexprs; + ListCell *indexpr_item; int i; if (indexInfo->ii_Expressions != NIL && @@ -941,7 +941,7 @@ FormIndexDatum(IndexInfo *indexInfo, /* Check caller has set up context correctly */ Assert(GetPerTupleExprContext(estate)->ecxt_scantuple->val == heapTuple); } - indexprs = indexInfo->ii_ExpressionsState; + indexpr_item = list_head(indexInfo->ii_ExpressionsState); for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++) { @@ -962,19 +962,19 @@ FormIndexDatum(IndexInfo *indexInfo, /* * Index expression --- need to evaluate it. */ - if (indexprs == NIL) + if (indexpr_item == NULL) elog(ERROR, "wrong number of index expressions"); - iDatum = ExecEvalExprSwitchContext((ExprState *) lfirst(indexprs), + iDatum = ExecEvalExprSwitchContext((ExprState *) lfirst(indexpr_item), GetPerTupleExprContext(estate), &isNull, NULL); - indexprs = lnext(indexprs); + indexpr_item = lnext(indexpr_item); } datum[i] = iDatum; nullv[i] = (isNull) ? 'n' : ' '; } - if (indexprs != NIL) + if (indexpr_item != NULL) elog(ERROR, "wrong number of index expressions"); } @@ -1738,8 +1738,8 @@ reindex_relation(Oid relid, bool toast_too) bool is_pg_class; bool result; List *indexIds, - *doneIndexes, - *indexId; + *doneIndexes; + ListCell *indexId; /* * Ensure to hold an exclusive lock throughout the transaction. The @@ -1780,7 +1780,7 @@ reindex_relation(Oid relid, bool toast_too) /* Reindex all the indexes. */ foreach(indexId, indexIds) { - Oid indexOid = lfirsto(indexId); + Oid indexOid = lfirst_oid(indexId); if (is_pg_class) RelationSetIndexList(rel, doneIndexes); @@ -1790,7 +1790,7 @@ reindex_relation(Oid relid, bool toast_too) CommandCounterIncrement(); if (is_pg_class) - doneIndexes = lappendo(doneIndexes, indexOid); + doneIndexes = lappend_oid(doneIndexes, indexOid); } if (is_pg_class) diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c index 91a604eac7..e9b5a35ba7 100644 --- a/src/backend/catalog/namespace.c +++ b/src/backend/catalog/namespace.c @@ -13,7 +13,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.63 2004/02/13 01:08:20 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.64 2004/05/26 04:41:07 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -276,13 +276,13 @@ Oid RelnameGetRelid(const char *relname) { Oid relid; - List *lptr; + ListCell *l; recomputeNamespacePath(); - foreach(lptr, namespaceSearchPath) + foreach(l, namespaceSearchPath) { - Oid namespaceId = lfirsto(lptr); + Oid namespaceId = lfirst_oid(l); relid = get_relname_relid(relname, namespaceId); if (OidIsValid(relid)) @@ -320,11 +320,11 @@ RelationIsVisible(Oid relid) /* * Quick check: if it ain't in the path at all, it ain't visible. * Items in the system namespace are surely in the path and so we - * needn't even do oidMember() for them. + * needn't even do list_member_oid() for them. */ relnamespace = relform->relnamespace; if (relnamespace != PG_CATALOG_NAMESPACE && - !oidMember(relnamespace, namespaceSearchPath)) + !list_member_oid(namespaceSearchPath, relnamespace)) visible = false; else { @@ -356,13 +356,13 @@ Oid TypenameGetTypid(const char *typname) { Oid typid; - List *lptr; + ListCell *l; recomputeNamespacePath(); - foreach(lptr, namespaceSearchPath) + foreach(l, namespaceSearchPath) { - Oid namespaceId = lfirsto(lptr); + Oid namespaceId = lfirst_oid(l); typid = GetSysCacheOid(TYPENAMENSP, PointerGetDatum(typname), @@ -402,11 +402,11 @@ TypeIsVisible(Oid typid) /* * Quick check: if it ain't in the path at all, it ain't visible. * Items in the system namespace are surely in the path and so we - * needn't even do oidMember() for them. + * needn't even do list_member_oid() for them. */ typnamespace = typform->typnamespace; if (typnamespace != PG_CATALOG_NAMESPACE && - !oidMember(typnamespace, namespaceSearchPath)) + !list_member_oid(namespaceSearchPath, typnamespace)) visible = false; else { @@ -496,15 +496,15 @@ FuncnameGetCandidates(List *names, int nargs) else { /* Consider only procs that are in the search path */ - List *nsp; + ListCell *nsp; foreach(nsp, namespaceSearchPath) { - if (procform->pronamespace == lfirsto(nsp)) + if (procform->pronamespace == lfirst_oid(nsp)) break; pathpos++; } - if (nsp == NIL) + if (nsp == NULL) continue; /* proc is not in search path */ /* @@ -603,11 +603,11 @@ FunctionIsVisible(Oid funcid) /* * Quick check: if it ain't in the path at all, it ain't visible. * Items in the system namespace are surely in the path and so we - * needn't even do oidMember() for them. + * needn't even do list_member_oid() for them. */ pronamespace = procform->pronamespace; if (pronamespace != PG_CATALOG_NAMESPACE && - !oidMember(pronamespace, namespaceSearchPath)) + !list_member_oid(namespaceSearchPath, pronamespace)) visible = false; else { @@ -623,7 +623,7 @@ FunctionIsVisible(Oid funcid) visible = false; - clist = FuncnameGetCandidates(makeList1(makeString(proname)), nargs); + clist = FuncnameGetCandidates(list_make1(makeString(proname)), nargs); for (; clist; clist = clist->next) { @@ -727,15 +727,15 @@ OpernameGetCandidates(List *names, char oprkind) else { /* Consider only opers that are in the search path */ - List *nsp; + ListCell *nsp; foreach(nsp, namespaceSearchPath) { - if (operform->oprnamespace == lfirsto(nsp)) + if (operform->oprnamespace == lfirst_oid(nsp)) break; pathpos++; } - if (nsp == NIL) + if (nsp == NULL) continue; /* oper is not in search path */ /* @@ -832,11 +832,11 @@ OperatorIsVisible(Oid oprid) /* * Quick check: if it ain't in the path at all, it ain't visible. * Items in the system namespace are surely in the path and so we - * needn't even do oidMember() for them. + * needn't even do list_member_oid() for them. */ oprnamespace = oprform->oprnamespace; if (oprnamespace != PG_CATALOG_NAMESPACE && - !oidMember(oprnamespace, namespaceSearchPath)) + !list_member_oid(namespaceSearchPath, oprnamespace)) visible = false; else { @@ -852,7 +852,7 @@ OperatorIsVisible(Oid oprid) visible = false; - clist = OpernameGetCandidates(makeList1(makeString(oprname)), + clist = OpernameGetCandidates(list_make1(makeString(oprname)), oprform->oprkind); for (; clist; clist = clist->next) @@ -903,16 +903,16 @@ OpclassGetCandidates(Oid amid) Form_pg_opclass opcform = (Form_pg_opclass) GETSTRUCT(opctup); int pathpos = 0; OpclassCandidateList newResult; - List *nsp; + ListCell *nsp; /* Consider only opclasses that are in the search path */ foreach(nsp, namespaceSearchPath) { - if (opcform->opcnamespace == lfirsto(nsp)) + if (opcform->opcnamespace == lfirst_oid(nsp)) break; pathpos++; } - if (nsp == NIL) + if (nsp == NULL) continue; /* opclass is not in search path */ /* @@ -998,13 +998,13 @@ Oid OpclassnameGetOpcid(Oid amid, const char *opcname) { Oid opcid; - List *lptr; + ListCell *l; recomputeNamespacePath(); - foreach(lptr, namespaceSearchPath) + foreach(l, namespaceSearchPath) { - Oid namespaceId = lfirsto(lptr); + Oid namespaceId = lfirst_oid(l); opcid = GetSysCacheOid(CLAAMNAMENSP, ObjectIdGetDatum(amid), @@ -1045,11 +1045,11 @@ OpclassIsVisible(Oid opcid) /* * Quick check: if it ain't in the path at all, it ain't visible. * Items in the system namespace are surely in the path and so we - * needn't even do oidMember() for them. + * needn't even do list_member_oid() for them. */ opcnamespace = opcform->opcnamespace; if (opcnamespace != PG_CATALOG_NAMESPACE && - !oidMember(opcnamespace, namespaceSearchPath)) + !list_member_oid(namespaceSearchPath, opcnamespace)) visible = false; else { @@ -1080,13 +1080,13 @@ Oid ConversionGetConid(const char *conname) { Oid conid; - List *lptr; + ListCell *l; recomputeNamespacePath(); - foreach(lptr, namespaceSearchPath) + foreach(l, namespaceSearchPath) { - Oid namespaceId = lfirsto(lptr); + Oid namespaceId = lfirst_oid(l); conid = GetSysCacheOid(CONNAMENSP, PointerGetDatum(conname), @@ -1126,11 +1126,11 @@ ConversionIsVisible(Oid conid) /* * Quick check: if it ain't in the path at all, it ain't visible. * Items in the system namespace are surely in the path and so we - * needn't even do oidMember() for them. + * needn't even do list_member_oid() for them. */ connamespace = conform->connamespace; if (connamespace != PG_CATALOG_NAMESPACE && - !oidMember(connamespace, namespaceSearchPath)) + !list_member_oid(namespaceSearchPath, connamespace)) visible = false; else { @@ -1166,17 +1166,17 @@ DeconstructQualifiedName(List *names, char *schemaname = NULL; char *objname = NULL; - switch (length(names)) + switch (list_length(names)) { case 1: - objname = strVal(lfirst(names)); + objname = strVal(linitial(names)); break; case 2: - schemaname = strVal(lfirst(names)); + schemaname = strVal(linitial(names)); objname = strVal(lsecond(names)); break; case 3: - catalogname = strVal(lfirst(names)); + catalogname = strVal(linitial(names)); schemaname = strVal(lsecond(names)); objname = strVal(lthird(names)); @@ -1287,17 +1287,17 @@ makeRangeVarFromNameList(List *names) { RangeVar *rel = makeRangeVar(NULL, NULL); - switch (length(names)) + switch (list_length(names)) { case 1: - rel->relname = strVal(lfirst(names)); + rel->relname = strVal(linitial(names)); break; case 2: - rel->schemaname = strVal(lfirst(names)); + rel->schemaname = strVal(linitial(names)); rel->relname = strVal(lsecond(names)); break; case 3: - rel->catalogname = strVal(lfirst(names)); + rel->catalogname = strVal(linitial(names)); rel->schemaname = strVal(lsecond(names)); rel->relname = strVal(lthird(names)); break; @@ -1323,13 +1323,13 @@ char * NameListToString(List *names) { StringInfoData string; - List *l; + ListCell *l; initStringInfo(&string); foreach(l, names) { - if (l != names) + if (l != list_head(names)) appendStringInfoChar(&string, '.'); appendStringInfoString(&string, strVal(lfirst(l))); } @@ -1348,13 +1348,13 @@ char * NameListToQuotedString(List *names) { StringInfoData string; - List *l; + ListCell *l; initStringInfo(&string); foreach(l, names) { - if (l != names) + if (l != list_head(names)) appendStringInfoChar(&string, '.'); appendStringInfoString(&string, quote_identifier(strVal(lfirst(l)))); } @@ -1435,7 +1435,7 @@ FindConversionByName(List *name) char *conversion_name; Oid namespaceId; Oid conoid; - List *lptr; + ListCell *l; /* deconstruct the name list */ DeconstructQualifiedName(name, &schemaname, &conversion_name); @@ -1451,9 +1451,9 @@ FindConversionByName(List *name) /* search for it in search path */ recomputeNamespacePath(); - foreach(lptr, namespaceSearchPath) + foreach(l, namespaceSearchPath) { - namespaceId = lfirsto(lptr); + namespaceId = lfirst_oid(l); conoid = FindConversion(conversion_name, namespaceId); if (OidIsValid(conoid)) return conoid; @@ -1471,13 +1471,13 @@ Oid FindDefaultConversionProc(int4 for_encoding, int4 to_encoding) { Oid proc; - List *lptr; + ListCell *l; recomputeNamespacePath(); - foreach(lptr, namespaceSearchPath) + foreach(l, namespaceSearchPath) { - Oid namespaceId = lfirsto(lptr); + Oid namespaceId = lfirst_oid(l); proc = FindDefaultConversion(namespaceId, for_encoding, to_encoding); if (OidIsValid(proc)) @@ -1499,7 +1499,7 @@ recomputeNamespacePath(void) List *namelist; List *oidlist; List *newpath; - List *l; + ListCell *l; Oid firstNS; MemoryContext oldcxt; @@ -1550,10 +1550,10 @@ recomputeNamespacePath(void) 0, 0, 0); ReleaseSysCache(tuple); if (OidIsValid(namespaceId) && - !oidMember(namespaceId, oidlist) && + !list_member_oid(oidlist, namespaceId) && pg_namespace_aclcheck(namespaceId, userId, ACL_USAGE) == ACLCHECK_OK) - oidlist = lappendo(oidlist, namespaceId); + oidlist = lappend_oid(oidlist, namespaceId); } } else @@ -1563,10 +1563,10 @@ recomputeNamespacePath(void) CStringGetDatum(curname), 0, 0, 0); if (OidIsValid(namespaceId) && - !oidMember(namespaceId, oidlist) && + !list_member_oid(oidlist, namespaceId) && pg_namespace_aclcheck(namespaceId, userId, ACL_USAGE) == ACLCHECK_OK) - oidlist = lappendo(oidlist, namespaceId); + oidlist = lappend_oid(oidlist, namespaceId); } } @@ -1576,34 +1576,34 @@ recomputeNamespacePath(void) if (oidlist == NIL) firstNS = InvalidOid; else - firstNS = lfirsto(oidlist); + firstNS = linitial_oid(oidlist); /* * Add any implicitly-searched namespaces to the list. Note these go * on the front, not the back; also notice that we do not check USAGE * permissions for these. */ - if (!oidMember(PG_CATALOG_NAMESPACE, oidlist)) - oidlist = lconso(PG_CATALOG_NAMESPACE, oidlist); + if (!list_member_oid(oidlist, PG_CATALOG_NAMESPACE)) + oidlist = lcons_oid(PG_CATALOG_NAMESPACE, oidlist); if (OidIsValid(myTempNamespace) && - !oidMember(myTempNamespace, oidlist)) - oidlist = lconso(myTempNamespace, oidlist); + !list_member_oid(oidlist, myTempNamespace)) + oidlist = lcons_oid(myTempNamespace, oidlist); if (OidIsValid(mySpecialNamespace) && - !oidMember(mySpecialNamespace, oidlist)) - oidlist = lconso(mySpecialNamespace, oidlist); + !list_member_oid(oidlist, mySpecialNamespace)) + oidlist = lcons_oid(mySpecialNamespace, oidlist); /* * Now that we've successfully built the new list of namespace OIDs, * save it in permanent storage. */ oldcxt = MemoryContextSwitchTo(TopMemoryContext); - newpath = listCopy(oidlist); + newpath = list_copy(oidlist); MemoryContextSwitchTo(oldcxt); /* Now safe to assign to state variable. */ - freeList(namespaceSearchPath); + list_free(namespaceSearchPath); namespaceSearchPath = newpath; /* @@ -1621,8 +1621,8 @@ recomputeNamespacePath(void) /* Clean up. */ pfree(rawname); - freeList(namelist); - freeList(oidlist); + list_free(namelist); + list_free(oidlist); } /* @@ -1783,7 +1783,7 @@ assign_search_path(const char *newval, bool doit, GucSource source) { char *rawname; List *namelist; - List *l; + ListCell *l; /* Need a modifiable copy of string */ rawname = pstrdup(newval); @@ -1793,7 +1793,7 @@ assign_search_path(const char *newval, bool doit, GucSource source) { /* syntax error in name list */ pfree(rawname); - freeList(namelist); + list_free(namelist); return NULL; } @@ -1831,7 +1831,7 @@ assign_search_path(const char *newval, bool doit, GucSource source) } pfree(rawname); - freeList(namelist); + list_free(namelist); /* * We mark the path as needing recomputation, but don't do anything @@ -1862,7 +1862,7 @@ InitializeSearchPath(void) MemoryContext oldcxt; oldcxt = MemoryContextSwitchTo(TopMemoryContext); - namespaceSearchPath = makeListo1(PG_CATALOG_NAMESPACE); + namespaceSearchPath = list_make1_oid(PG_CATALOG_NAMESPACE); MemoryContextSwitchTo(oldcxt); defaultCreationNamespace = PG_CATALOG_NAMESPACE; firstExplicitNamespace = PG_CATALOG_NAMESPACE; @@ -1895,12 +1895,12 @@ NamespaceCallback(Datum arg, Oid relid) } /* - * Fetch the active search path, expressed as a List of OIDs. + * Fetch the active search path. The return value is a palloc'ed list + * of OIDs; the caller is responsible for freeing this storage as + * appropriate. * * The returned list includes the implicitly-prepended namespaces only if * includeImplicit is true. - * - * NB: caller must treat the list as read-only! */ List * fetch_search_path(bool includeImplicit) @@ -1909,11 +1909,11 @@ fetch_search_path(bool includeImplicit) recomputeNamespacePath(); - result = namespaceSearchPath; + result = list_copy(namespaceSearchPath); if (!includeImplicit) { - while (result && lfirsto(result) != firstExplicitNamespace) - result = lnext(result); + while (result && linitial_oid(result) != firstExplicitNamespace) + result = list_delete_first(result); } return result; diff --git a/src/backend/catalog/pg_proc.c b/src/backend/catalog/pg_proc.c index 749ad44127..3a184182b8 100644 --- a/src/backend/catalog/pg_proc.c +++ b/src/backend/catalog/pg_proc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/catalog/pg_proc.c,v 1.115 2004/04/02 23:14:05 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/pg_proc.c,v 1.116 2004/05/26 04:41:08 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -374,7 +374,7 @@ check_sql_fn_retval(Oid rettype, char fn_typtype, List *queryTreeList) Query *parse; int cmd; List *tlist; - List *tlistitem; + ListCell *tlistitem; int tlistlen; Oid typerelid; Oid restype; @@ -396,7 +396,7 @@ check_sql_fn_retval(Oid rettype, char fn_typtype, List *queryTreeList) } /* find the final query */ - parse = (Query *) llast(queryTreeList); + parse = (Query *) lfirst(list_tail(queryTreeList)); cmd = parse->commandType; tlist = parse->targetList; @@ -448,7 +448,7 @@ check_sql_fn_retval(Oid rettype, char fn_typtype, List *queryTreeList) format_type_be(rettype)), errdetail("Final SELECT must return exactly one column."))); - restype = ((TargetEntry *) lfirst(tlist))->resdom->restype; + restype = ((TargetEntry *) linitial(tlist))->resdom->restype; if (!IsBinaryCoercible(restype, rettype)) ereport(ERROR, (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), @@ -471,7 +471,7 @@ check_sql_fn_retval(Oid rettype, char fn_typtype, List *queryTreeList) */ if (tlistlen == 1) { - restype = ((TargetEntry *) lfirst(tlist))->resdom->restype; + restype = ((TargetEntry *) linitial(tlist))->resdom->restype; if (IsBinaryCoercible(restype, rettype)) return false; /* NOT returning whole tuple */ } @@ -556,7 +556,7 @@ check_sql_fn_retval(Oid rettype, char fn_typtype, List *queryTreeList) */ if (tlistlen == 1) { - restype = ((TargetEntry *) lfirst(tlist))->resdom->restype; + restype = ((TargetEntry *) linitial(tlist))->resdom->restype; if (IsBinaryCoercible(restype, rettype)) return false; /* NOT returning whole tuple */ } diff --git a/src/backend/commands/aggregatecmds.c b/src/backend/commands/aggregatecmds.c index d587245ef9..c8865b3dbd 100644 --- a/src/backend/commands/aggregatecmds.c +++ b/src/backend/commands/aggregatecmds.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/aggregatecmds.c,v 1.17 2004/05/07 00:24:57 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/aggregatecmds.c,v 1.18 2004/05/26 04:41:09 neilc Exp $ * * DESCRIPTION * The "DefineFoo" routines take the parse tree and pick out the @@ -56,7 +56,7 @@ DefineAggregate(List *names, List *parameters) char *initval = NULL; Oid baseTypeId; Oid transTypeId; - List *pl; + ListCell *pl; /* Convert list of names to a name and namespace */ aggNamespace = QualifiedNameGetCreationNamespace(names, &aggName); diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c index 5bb3c51dd3..40a28103c7 100644 --- a/src/backend/commands/alter.c +++ b/src/backend/commands/alter.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/alter.c,v 1.6 2003/11/29 19:51:47 pgsql Exp $ + * $PostgreSQL: pgsql/src/backend/commands/alter.c,v 1.7 2004/05/26 04:41:09 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -41,7 +41,9 @@ ExecRenameStmt(RenameStmt *stmt) switch (stmt->renameType) { case OBJECT_AGGREGATE: - RenameAggregate(stmt->object, (TypeName *) lfirst(stmt->objarg), stmt->newname); + RenameAggregate(stmt->object, + (TypeName *) linitial(stmt->objarg), + stmt->newname); break; case OBJECT_CONVERSION: diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 0f6ff2d37e..4efaf653ed 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.72 2004/05/23 21:24:02 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.73 2004/05/26 04:41:09 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -207,9 +207,9 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt) */ if (vacstmt->va_cols != NIL) { - List *le; + ListCell *le; - vacattrstats = (VacAttrStats **) palloc(length(vacstmt->va_cols) * + vacattrstats = (VacAttrStats **) palloc(list_length(vacstmt->va_cols) * sizeof(VacAttrStats *)); tcnt = 0; foreach(le, vacstmt->va_cols) @@ -260,7 +260,7 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt) thisdata->tupleFract = 1.0; /* fix later if partial */ if (indexInfo->ii_Expressions != NIL && vacstmt->va_cols == NIL) { - List *indexprs = indexInfo->ii_Expressions; + ListCell *indexpr_item = list_head(indexInfo->ii_Expressions); thisdata->vacattrstats = (VacAttrStats **) palloc(indexInfo->ii_NumIndexAttrs * sizeof(VacAttrStats *)); @@ -274,10 +274,10 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt) /* Found an index expression */ Node *indexkey; - if (indexprs == NIL) /* shouldn't happen */ + if (indexpr_item == NULL) /* shouldn't happen */ elog(ERROR, "too few entries in indexprs list"); - indexkey = (Node *) lfirst(indexprs); - indexprs = lnext(indexprs); + indexkey = (Node *) lfirst(indexpr_item); + indexpr_item = lnext(indexpr_item); /* * Can't analyze if the opclass uses a storage type diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c index 15d7c0aae5..847f73ff06 100644 --- a/src/backend/commands/async.c +++ b/src/backend/commands/async.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/async.c,v 1.111 2004/05/23 03:50:45 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/async.c,v 1.112 2004/05/26 04:41:10 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -932,7 +932,7 @@ NotifyMyFrontEnd(char *relname, int32 listenerPID) static bool AsyncExistsPendingNotify(const char *relname) { - List *p; + ListCell *p; foreach(p, pendingNotifies) { diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 168ae749fa..d9c4397176 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.123 2004/05/08 00:34:49 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.124 2004/05/26 04:41:10 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -103,7 +103,7 @@ cluster(ClusterStmt *stmt) if (stmt->indexname == NULL) { - List *index; + ListCell *index; /* We need to find the index that has indisclustered set. */ foreach(index, RelationGetIndexList(rel)) @@ -111,7 +111,7 @@ cluster(ClusterStmt *stmt) HeapTuple idxtuple; Form_pg_index indexForm; - indexOid = lfirsto(index); + indexOid = lfirst_oid(index); idxtuple = SearchSysCache(INDEXRELID, ObjectIdGetDatum(indexOid), 0, 0, 0); @@ -165,8 +165,8 @@ cluster(ClusterStmt *stmt) * tables that have some index with indisclustered set. */ MemoryContext cluster_context; - List *rv, - *rvs; + List *rvs; + ListCell *rv; /* * We cannot run this form of CLUSTER inside a user transaction @@ -408,7 +408,7 @@ mark_index_clustered(Relation rel, Oid indexOid) HeapTuple indexTuple; Form_pg_index indexForm; Relation pg_index; - List *index; + ListCell *index; /* * If the index is already marked clustered, no need to do anything. @@ -438,7 +438,7 @@ mark_index_clustered(Relation rel, Oid indexOid) foreach(index, RelationGetIndexList(rel)) { - Oid thisIndexOid = lfirsto(index); + Oid thisIndexOid = lfirst_oid(index); indexTuple = SearchSysCacheCopy(INDEXRELID, ObjectIdGetDatum(thisIndexOid), diff --git a/src/backend/commands/comment.c b/src/backend/commands/comment.c index 423ab97570..4c0d65038b 100644 --- a/src/backend/commands/comment.c +++ b/src/backend/commands/comment.c @@ -7,7 +7,7 @@ * Copyright (c) 1996-2003, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/comment.c,v 1.76 2004/03/08 21:35:59 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/commands/comment.c,v 1.77 2004/05/26 04:41:10 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -379,11 +379,11 @@ CommentAttribute(List *qualname, char *comment) AttrNumber attnum; /* Separate relname and attr name */ - nnames = length(qualname); + nnames = list_length(qualname); if (nnames < 2) /* parser messed up */ elog(ERROR, "must specify relation and attribute"); - relname = ltruncate(nnames - 1, listCopy(qualname)); - attrname = strVal(llast(qualname)); + relname = list_truncate(list_copy(qualname), nnames - 1); + attrname = strVal(lfirst(list_tail(qualname))); /* Open the containing relation to ensure it won't go away meanwhile */ rel = makeRangeVarFromNameList(relname); @@ -429,11 +429,11 @@ CommentDatabase(List *qualname, char *comment) char *database; Oid oid; - if (length(qualname) != 1) + if (list_length(qualname) != 1) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("database name may not be qualified"))); - database = strVal(lfirst(qualname)); + database = strVal(linitial(qualname)); /* * We cannot currently support cross-database comments (since other @@ -493,11 +493,11 @@ CommentNamespace(List *qualname, char *comment) Oid classoid; char *namespace; - if (length(qualname) != 1) + if (list_length(qualname) != 1) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("schema name may not be qualified"))); - namespace = strVal(lfirst(qualname)); + namespace = strVal(linitial(qualname)); oid = GetSysCacheOid(NAMESPACENAME, CStringGetDatum(namespace), @@ -548,7 +548,7 @@ CommentRule(List *qualname, char *comment) AclResult aclcheck; /* Separate relname and trig name */ - nnames = length(qualname); + nnames = list_length(qualname); if (nnames == 1) { /* Old-style: only a rule name is given */ @@ -556,7 +556,7 @@ CommentRule(List *qualname, char *comment) HeapScanDesc scanDesc; ScanKeyData scanKeyData; - rulename = strVal(lfirst(qualname)); + rulename = strVal(linitial(qualname)); /* Search pg_rewrite for such a rule */ ScanKeyInit(&scanKeyData, @@ -599,8 +599,8 @@ CommentRule(List *qualname, char *comment) { /* New-style: rule and relname both provided */ Assert(nnames >= 2); - relname = ltruncate(nnames - 1, listCopy(qualname)); - rulename = strVal(llast(qualname)); + relname = list_truncate(list_copy(qualname), nnames - 1); + rulename = strVal(lfirst(list_tail(qualname))); /* Open the owning relation to ensure it won't go away meanwhile */ rel = makeRangeVarFromNameList(relname); @@ -683,7 +683,7 @@ CommentType(List *typename, char *comment) static void CommentAggregate(List *aggregate, List *arguments, char *comment) { - TypeName *aggtype = (TypeName *) lfirst(arguments); + TypeName *aggtype = (TypeName *) linitial(arguments); Oid baseoid, oid; @@ -750,7 +750,7 @@ CommentProc(List *function, List *arguments, char *comment) static void CommentOperator(List *opername, List *arguments, char *comment) { - TypeName *typenode1 = (TypeName *) lfirst(arguments); + TypeName *typenode1 = (TypeName *) linitial(arguments); TypeName *typenode2 = (TypeName *) lsecond(arguments); Oid oid; Oid classoid; @@ -794,11 +794,11 @@ CommentTrigger(List *qualname, char *comment) Oid oid; /* Separate relname and trig name */ - nnames = length(qualname); + nnames = list_length(qualname); if (nnames < 2) /* parser messed up */ elog(ERROR, "must specify relation and trigger"); - relname = ltruncate(nnames - 1, listCopy(qualname)); - trigname = strVal(llast(qualname)); + relname = list_truncate(list_copy(qualname), nnames - 1); + trigname = strVal(lfirst(list_tail(qualname))); /* Open the owning relation to ensure it won't go away meanwhile */ rel = makeRangeVarFromNameList(relname); @@ -872,11 +872,11 @@ CommentConstraint(List *qualname, char *comment) Oid conOid = InvalidOid; /* Separate relname and constraint name */ - nnames = length(qualname); + nnames = list_length(qualname); if (nnames < 2) /* parser messed up */ elog(ERROR, "must specify relation and constraint"); - relName = ltruncate(nnames - 1, listCopy(qualname)); - conName = strVal(llast(qualname)); + relName = list_truncate(list_copy(qualname), nnames - 1); + conName = strVal(lfirst(list_tail(qualname))); /* Open the owning relation to ensure it won't go away meanwhile */ rel = makeRangeVarFromNameList(relName); @@ -985,11 +985,11 @@ CommentLanguage(List *qualname, char *comment) Oid classoid; char *language; - if (length(qualname) != 1) + if (list_length(qualname) != 1) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("language name may not be qualified"))); - language = strVal(lfirst(qualname)); + language = strVal(linitial(qualname)); oid = GetSysCacheOid(LANGNAME, CStringGetDatum(language), @@ -1032,8 +1032,8 @@ CommentOpClass(List *qualname, List *arguments, char *comment) Oid classoid; HeapTuple tuple; - Assert(length(arguments) == 1); - amname = strVal(lfirst(arguments)); + Assert(list_length(arguments) == 1); + amname = strVal(linitial(arguments)); /* * Get the access method's OID. @@ -1118,8 +1118,8 @@ CommentLargeObject(List *qualname, char *comment) Oid classoid; Node *node; - Assert(length(qualname) == 1); - node = (Node *) lfirst(qualname); + Assert(list_length(qualname) == 1); + node = (Node *) linitial(qualname); switch (nodeTag(node)) { @@ -1176,11 +1176,11 @@ CommentCast(List *qualname, List *arguments, char *comment) Oid castOid; Oid classoid; - Assert(length(qualname) == 1); - sourcetype = (TypeName *) lfirst(qualname); + Assert(list_length(qualname) == 1); + sourcetype = (TypeName *) linitial(qualname); Assert(IsA(sourcetype, TypeName)); - Assert(length(arguments) == 1); - targettype = (TypeName *) lfirst(arguments); + Assert(list_length(arguments) == 1); + targettype = (TypeName *) linitial(arguments); Assert(IsA(targettype, TypeName)); sourcetypeid = typenameTypeId(sourcetype); diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 74025ad041..a666516fb3 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.223 2004/04/21 00:34:18 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.224 2004/05/26 04:41:10 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -685,7 +685,7 @@ DoCopy(const CopyStmt *stmt) char *filename = stmt->filename; bool is_from = stmt->is_from; bool pipe = (stmt->filename == NULL); - List *option; + ListCell *option; List *attnamelist = stmt->attlist; List *attnumlist; bool binary = false; @@ -934,15 +934,15 @@ DoCopy(const CopyStmt *stmt) { TupleDesc tupDesc = RelationGetDescr(rel); Form_pg_attribute *attr = tupDesc->attrs; - List *cur; + ListCell *cur; force_quote_atts = CopyGetAttnums(rel, force_quote); foreach(cur, force_quote_atts) { - int attnum = lfirsti(cur); + int attnum = lfirst_int(cur); - if (!intMember(attnum, attnumlist)) + if (!list_member_int(attnumlist, attnum)) ereport(ERROR, (errcode(ERRCODE_INVALID_COLUMN_REFERENCE), errmsg("FORCE QUOTE column \"%s\" not referenced by COPY", @@ -955,7 +955,7 @@ DoCopy(const CopyStmt *stmt) */ if (force_notnull) { - List *cur; + ListCell *cur; TupleDesc tupDesc = RelationGetDescr(rel); Form_pg_attribute *attr = tupDesc->attrs; @@ -963,9 +963,9 @@ DoCopy(const CopyStmt *stmt) foreach(cur, force_notnull_atts) { - int attnum = lfirsti(cur); + int attnum = lfirst_int(cur); - if (!intMember(attnum, attnumlist)) + if (!list_member_int(attnumlist, attnum)) ereport(ERROR, (errcode(ERRCODE_INVALID_COLUMN_REFERENCE), errmsg("FORCE NOT NULL column \"%s\" not referenced by COPY", @@ -1011,7 +1011,7 @@ DoCopy(const CopyStmt *stmt) if (pipe) { if (whereToSendOutput == Remote) - ReceiveCopyBegin(binary, length(attnumlist)); + ReceiveCopyBegin(binary, list_length(attnumlist)); else copy_file = stdin; } @@ -1062,7 +1062,7 @@ DoCopy(const CopyStmt *stmt) if (pipe) { if (whereToSendOutput == Remote) - SendCopyBegin(binary, length(attnumlist)); + SendCopyBegin(binary, list_length(attnumlist)); else copy_file = stdout; } @@ -1147,14 +1147,14 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids, bool *isvarlena; char *string; Snapshot mySnapshot; - List *cur; + ListCell *cur; MemoryContext oldcontext; MemoryContext mycontext; tupDesc = rel->rd_att; attr = tupDesc->attrs; num_phys_attrs = tupDesc->natts; - attr_count = length(attnumlist); + attr_count = list_length(attnumlist); /* * Get info about the columns we need to process. @@ -1167,7 +1167,7 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids, force_quote = (bool *) palloc((num_phys_attrs + 1) * sizeof(bool)); foreach(cur, attnumlist) { - int attnum = lfirsti(cur); + int attnum = lfirst_int(cur); Oid out_func_oid; if (binary) @@ -1180,7 +1180,7 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids, &isvarlena[attnum - 1]); fmgr_info(out_func_oid, &out_functions[attnum - 1]); - if (intMember(attnum, force_quote_atts)) + if (list_member_int(force_quote_atts, attnum)) force_quote[attnum - 1] = true; else force_quote[attnum - 1] = false; @@ -1266,7 +1266,7 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids, foreach(cur, attnumlist) { - int attnum = lfirsti(cur); + int attnum = lfirst_int(cur); Datum value; bool isnull; @@ -1451,7 +1451,6 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, bool hasConstraints = false; int attnum; int i; - List *cur; Oid in_func_oid; Datum *values; char *nulls; @@ -1471,7 +1470,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, tupDesc = RelationGetDescr(rel); attr = tupDesc->attrs; num_phys_attrs = tupDesc->natts; - attr_count = length(attnumlist); + attr_count = list_length(attnumlist); num_defaults = 0; /* @@ -1526,13 +1525,13 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, &in_func_oid, &elements[attnum - 1]); fmgr_info(in_func_oid, &in_functions[attnum - 1]); - if (intMember(attnum, force_notnull_atts)) + if (list_member_int(force_notnull_atts, attnum)) force_notnull[attnum - 1] = true; else force_notnull[attnum - 1] = false; /* Get default info if needed */ - if (!intMember(attnum, attnumlist)) + if (!list_member_int(attnumlist, attnum)) { /* attribute is NOT to be copied from input */ /* use default value if one exists */ @@ -1681,6 +1680,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, { CopyReadResult result = NORMAL_ATTR; char *string; + ListCell *cur; /* Actually read the line into memory here */ done = CopyReadLine(); @@ -1722,7 +1722,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, */ foreach(cur, attnumlist) { - int attnum = lfirsti(cur); + int attnum = lfirst_int(cur); int m = attnum - 1; /* @@ -1783,6 +1783,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, { /* binary */ int16 fld_count; + ListCell *cur; fld_count = CopyGetInt16(); if (CopyGetEof() || fld_count == -1) @@ -1815,7 +1816,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, i = 0; foreach(cur, attnumlist) { - int attnum = lfirsti(cur); + int attnum = lfirst_int(cur); int m = attnum - 1; copy_attname = NameStr(attr[m]->attname); @@ -2642,13 +2643,13 @@ CopyGetAttnums(Relation rel, List *attnamelist) { if (attr[i]->attisdropped) continue; - attnums = lappendi(attnums, i + 1); + attnums = lappend_int(attnums, i + 1); } } else { /* Validate the user-supplied list and extract attnums */ - List *l; + ListCell *l; foreach(l, attnamelist) { @@ -2659,12 +2660,12 @@ CopyGetAttnums(Relation rel, List *attnamelist) /* Note we disallow system columns here */ attnum = attnameAttNum(rel, name, false); /* Check for duplicates */ - if (intMember(attnum, attnums)) + if (list_member_int(attnums, attnum)) ereport(ERROR, (errcode(ERRCODE_DUPLICATE_COLUMN), errmsg("column \"%s\" specified more than once", name))); - attnums = lappendi(attnums, attnum); + attnums = lappend_int(attnums, attnum); } } diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index 038db4de70..9114983e75 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.132 2004/04/19 17:42:57 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.133 2004/05/26 04:41:10 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -82,7 +82,7 @@ createdb(const CreatedbStmt *stmt) char new_record_nulls[Natts_pg_database]; Oid dboid; AclId datdba; - List *option; + ListCell *option; DefElem *downer = NULL; DefElem *dpath = NULL; DefElem *dtemplate = NULL; diff --git a/src/backend/commands/define.c b/src/backend/commands/define.c index e4a62b7730..1a12674fa7 100644 --- a/src/backend/commands/define.c +++ b/src/backend/commands/define.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/define.c,v 1.88 2004/05/14 16:11:25 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/define.c,v 1.89 2004/05/26 04:41:10 neilc Exp $ * * DESCRIPTION * The "DefineFoo" routines take the parse tree and pick out the @@ -190,7 +190,7 @@ defGetQualifiedName(DefElem *def) return (List *) def->arg; case T_String: /* Allow quoted name for backwards compatibility */ - return makeList1(def->arg); + return list_make1(def->arg); default: ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -223,7 +223,7 @@ defGetTypeName(DefElem *def) /* Allow quoted typename for backwards compatibility */ TypeName *n = makeNode(TypeName); - n->names = makeList1(def->arg); + n->names = list_make1(def->arg); n->typmod = -1; return n; } diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index e2f3d4aa81..3658a00ea2 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994-5, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.120 2004/04/01 21:28:44 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.121 2004/05/26 04:41:10 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -72,7 +72,7 @@ ExplainQuery(ExplainStmt *stmt, DestReceiver *dest) Query *query = stmt->query; TupOutputState *tstate; List *rewritten; - List *l; + ListCell *l; /* prepare for projection of tuples */ tstate = begin_tup_output_tupdesc(dest, ExplainResultDesc(stmt)); @@ -104,7 +104,7 @@ ExplainQuery(ExplainStmt *stmt, DestReceiver *dest) { ExplainOneQuery(lfirst(l), stmt, tstate); /* put a blank line between plans */ - if (lnext(l) != NIL) + if (lnext(l) != NULL) do_text_output_oneline(tstate, ""); } } @@ -156,9 +156,9 @@ ExplainOneQuery(Query *query, ExplainStmt *stmt, TupOutputState *tstate) /* Still need to rewrite cursor command */ Assert(query->commandType == CMD_SELECT); rewritten = QueryRewrite(query); - if (length(rewritten) != 1) + if (list_length(rewritten) != 1) elog(ERROR, "unexpected rewrite result"); - query = (Query *) lfirst(rewritten); + query = (Query *) linitial(rewritten); Assert(query->commandType == CMD_SELECT); /* do not actually execute the underlying query! */ stmt->analyze = false; @@ -317,7 +317,7 @@ explain_outNode(StringInfo str, Plan *outer_plan, int indent, ExplainState *es) { - List *l; + ListCell *l; char *pname; int i; @@ -491,7 +491,7 @@ explain_outNode(StringInfo str, { Relation relation; - relation = index_open(lfirsto(l)); + relation = index_open(lfirst_oid(l)); appendStringInfo(str, "%s%s", (++i > 1) ? ", " : "", quote_identifier(RelationGetRelationName(relation))); @@ -699,7 +699,7 @@ explain_outNode(StringInfo str, if (plan->initPlan) { List *saved_rtable = es->rtable; - List *lst; + ListCell *lst; for (i = 0; i < indent; i++) appendStringInfo(str, " "); @@ -749,7 +749,7 @@ explain_outNode(StringInfo str, { Append *appendplan = (Append *) plan; AppendState *appendstate = (AppendState *) planstate; - List *lst; + ListCell *lst; int j; j = 0; @@ -797,7 +797,7 @@ explain_outNode(StringInfo str, if (planstate->subPlan) { List *saved_rtable = es->rtable; - List *lst; + ListCell *lst; for (i = 0; i < indent; i++) appendStringInfo(str, " "); @@ -839,11 +839,8 @@ show_scan_qual(List *qual, bool is_or_qual, const char *qlabel, /* No work if empty qual */ if (qual == NIL) return; - if (is_or_qual) - { - if (lfirst(qual) == NIL && lnext(qual) == NIL) - return; - } + if (is_or_qual && list_length(qual) == 1 && linitial(qual) == NIL) + return; /* Fix qual --- indexqual requires different processing */ if (is_or_qual) @@ -852,7 +849,7 @@ show_scan_qual(List *qual, bool is_or_qual, const char *qlabel, node = (Node *) make_ands_explicit(qual); /* Generate deparse context */ - Assert(scanrelid > 0 && scanrelid <= length(es->rtable)); + Assert(scanrelid > 0 && scanrelid <= list_length(es->rtable)); rte = rt_fetch(scanrelid, es->rtable); scancontext = deparse_context_for_rte(rte); @@ -984,7 +981,7 @@ show_sort_keys(List *tlist, int nkeys, AttrNumber *keycols, context = deparse_context_for_plan(0, NULL, 0, NULL, es->rtable); - useprefix = length(es->rtable) > 1; + useprefix = list_length(es->rtable) > 1; } bms_free(varnos); @@ -1017,17 +1014,16 @@ make_ors_ands_explicit(List *orclauses) { if (orclauses == NIL) return NULL; /* probably can't happen */ - else if (lnext(orclauses) == NIL) - return (Node *) make_ands_explicit(lfirst(orclauses)); + else if (list_length(orclauses) == 1) + return (Node *) make_ands_explicit(linitial(orclauses)); else { - FastList args; - List *orptr; + List *args = NIL; + ListCell *orptr; - FastListInit(&args); foreach(orptr, orclauses) - FastAppend(&args, make_ands_explicit(lfirst(orptr))); + args = lappend(args, make_ands_explicit(lfirst(orptr))); - return (Node *) make_orclause(FastListValue(&args)); + return (Node *) make_orclause(args); } } diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c index c118e8e3b5..757869a925 100644 --- a/src/backend/commands/functioncmds.c +++ b/src/backend/commands/functioncmds.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.46 2004/05/14 16:11:25 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.47 2004/05/26 04:41:11 neilc Exp $ * * DESCRIPTION * These routines take the parse tree and pick out the @@ -137,7 +137,7 @@ examine_parameter_list(List *parameter, Oid languageOid, Oid *parameterTypes, const char *parameterNames[]) { int parameterCount = 0; - List *x; + ListCell *x; MemSet(parameterTypes, 0, FUNC_MAX_ARGS * sizeof(Oid)); MemSet(parameterNames, 0, FUNC_MAX_ARGS * sizeof(char *)); @@ -202,14 +202,14 @@ examine_parameter_list(List *parameter, Oid languageOid, */ static void -compute_attributes_sql_style(const List *options, +compute_attributes_sql_style(List *options, List **as, char **language, char *volatility_p, bool *strict_p, bool *security_definer) { - const List *option; + ListCell *option; DefElem *as_item = NULL; DefElem *language_item = NULL; DefElem *volatility_item = NULL; @@ -322,7 +322,7 @@ compute_attributes_sql_style(const List *options, static void compute_attributes_with_style(List *parameters, bool *isStrict_p, char *volatility_p) { - List *pl; + ListCell *pl; foreach(pl, parameters) { @@ -357,7 +357,7 @@ compute_attributes_with_style(List *parameters, bool *isStrict_p, char *volatili */ static void -interpret_AS_clause(Oid languageOid, const char *languageName, const List *as, +interpret_AS_clause(Oid languageOid, const char *languageName, List *as, char **prosrc_str_p, char **probin_str_p) { Assert(as != NIL); @@ -368,8 +368,8 @@ interpret_AS_clause(Oid languageOid, const char *languageName, const List *as, * For "C" language, store the file name in probin and, when * given, the link symbol name in prosrc. */ - *probin_str_p = strVal(lfirst(as)); - if (lnext(as) == NULL) + *probin_str_p = strVal(linitial(as)); + if (list_length(as) == 1) *prosrc_str_p = "-"; else *prosrc_str_p = strVal(lsecond(as)); @@ -377,10 +377,10 @@ interpret_AS_clause(Oid languageOid, const char *languageName, const List *as, else { /* Everything else wants the given string in prosrc. */ - *prosrc_str_p = strVal(lfirst(as)); + *prosrc_str_p = strVal(linitial(as)); *probin_str_p = "-"; - if (lnext(as) != NIL) + if (list_length(as) != 1) ereport(ERROR, (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), errmsg("only one AS item needed for language \"%s\"", diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 448f99e1d3..1fe8e58e58 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.119 2004/05/08 00:34:49 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.120 2004/05/26 04:41:11 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -109,7 +109,7 @@ DefineIndex(RangeVar *heapRelation, /* * count attributes in index */ - numberOfAttributes = length(attributeList); + numberOfAttributes = list_length(attributeList); if (numberOfAttributes <= 0) ereport(ERROR, (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), @@ -165,7 +165,7 @@ DefineIndex(RangeVar *heapRelation, namespaceId); else { - IndexElem *iparam = (IndexElem *) lfirst(attributeList); + IndexElem *iparam = (IndexElem *) linitial(attributeList); indexRelationName = CreateIndexName(RelationGetRelationName(rel), iparam->name, @@ -208,7 +208,7 @@ DefineIndex(RangeVar *heapRelation, */ if (rangetable != NIL) { - if (length(rangetable) != 1 || getrelid(1, rangetable) != relationId) + if (list_length(rangetable) != 1 || getrelid(1, rangetable) != relationId) ereport(ERROR, (errcode(ERRCODE_INVALID_COLUMN_REFERENCE), errmsg("index expressions and predicates may refer only to the table being indexed"))); @@ -226,7 +226,7 @@ DefineIndex(RangeVar *heapRelation, if (primary) { List *cmds; - List *keys; + ListCell *keys; /* * If ALTER TABLE, check that there isn't already a PRIMARY KEY. @@ -399,7 +399,7 @@ ComputeIndexAttrs(IndexInfo *indexInfo, Oid accessMethodId, bool isconstraint) { - List *rest; + ListCell *rest; int attn = 0; /* @@ -516,9 +516,9 @@ GetIndexOpClass(List *opclass, Oid attrType, * Release 7.5 removes bigbox_ops (which was dead code for a long while * anyway). tgl 2003/11/11 */ - if (length(opclass) == 1) + if (list_length(opclass) == 1) { - char *claname = strVal(lfirst(opclass)); + char *claname = strVal(linitial(opclass)); if (strcmp(claname, "network_ops") == 0 || strcmp(claname, "timespan_ops") == 0 || @@ -697,8 +697,8 @@ static bool relationHasPrimaryKey(Relation rel) { bool result = false; - List *indexoidlist, - *indexoidscan; + List *indexoidlist; + ListCell *indexoidscan; /* * Get the list of index OIDs for the table from the relcache, and @@ -709,7 +709,7 @@ relationHasPrimaryKey(Relation rel) foreach(indexoidscan, indexoidlist) { - Oid indexoid = lfirsto(indexoidscan); + Oid indexoid = lfirst_oid(indexoidscan); HeapTuple indexTuple; indexTuple = SearchSysCache(INDEXRELID, @@ -723,7 +723,7 @@ relationHasPrimaryKey(Relation rel) break; } - freeList(indexoidlist); + list_free(indexoidlist); return result; } @@ -843,12 +843,13 @@ void ReindexDatabase(const char *dbname, bool force /* currently unused */, bool all) { - Relation relationRelation; + Relation relationRelation; HeapScanDesc scan; - HeapTuple tuple; + HeapTuple tuple; MemoryContext private_context; MemoryContext old; - List *relids = NIL; + List *relids = NIL; + ListCell *l; AssertArg(dbname); @@ -887,7 +888,7 @@ ReindexDatabase(const char *dbname, bool force /* currently unused */, * reindexing itself will try to update pg_class. */ old = MemoryContextSwitchTo(private_context); - relids = lappendo(relids, RelOid_pg_class); + relids = lappend_oid(relids, RelOid_pg_class); MemoryContextSwitchTo(old); /* @@ -921,7 +922,7 @@ ReindexDatabase(const char *dbname, bool force /* currently unused */, continue; /* got it already */ old = MemoryContextSwitchTo(private_context); - relids = lappendo(relids, HeapTupleGetOid(tuple)); + relids = lappend_oid(relids, HeapTupleGetOid(tuple)); MemoryContextSwitchTo(old); } heap_endscan(scan); @@ -929,9 +930,9 @@ ReindexDatabase(const char *dbname, bool force /* currently unused */, /* Now reindex each rel in a separate transaction */ CommitTransactionCommand(); - while (relids) + foreach(l, relids) { - Oid relid = lfirsto(relids); + Oid relid = lfirst_oid(l); StartTransactionCommand(); SetQuerySnapshot(); /* might be needed for functions in @@ -941,7 +942,6 @@ ReindexDatabase(const char *dbname, bool force /* currently unused */, (errmsg("table \"%s\" was reindexed", get_rel_name(relid)))); CommitTransactionCommand(); - relids = lnext(relids); } StartTransactionCommand(); diff --git a/src/backend/commands/lockcmds.c b/src/backend/commands/lockcmds.c index 58bee42f8f..7ab0687e98 100644 --- a/src/backend/commands/lockcmds.c +++ b/src/backend/commands/lockcmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/lockcmds.c,v 1.9 2004/03/11 01:47:35 ishii Exp $ + * $PostgreSQL: pgsql/src/backend/commands/lockcmds.c,v 1.10 2004/05/26 04:41:11 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -28,7 +28,7 @@ void LockTableCommand(LockStmt *lockstmt) { - List *p; + ListCell *p; /* * Iterate over the list and open, lock, and close the relations one diff --git a/src/backend/commands/opclasscmds.c b/src/backend/commands/opclasscmds.c index d3551a7349..db5c2ccabc 100644 --- a/src/backend/commands/opclasscmds.c +++ b/src/backend/commands/opclasscmds.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.24 2003/11/29 19:51:47 pgsql Exp $ + * $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.25 2004/05/26 04:41:11 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -77,7 +77,7 @@ DefineOpClass(CreateOpClassStmt *stmt) numProcs; /* amsupport value */ List *operators; /* OpClassMember list for operators */ List *procedures; /* OpClassMember list for support procs */ - List *l; + ListCell *l; Relation rel; HeapTuple tup; Datum values[Natts_pg_opclass]; @@ -168,7 +168,7 @@ DefineOpClass(CreateOpClassStmt *stmt) item->number, numOperators))); if (item->args != NIL) { - TypeName *typeName1 = (TypeName *) lfirst(item->args); + TypeName *typeName1 = (TypeName *) linitial(item->args); TypeName *typeName2 = (TypeName *) lsecond(item->args); operOid = LookupOperNameTypeNames(item->name, @@ -506,7 +506,7 @@ assignProcSubtype(Oid amoid, Oid typeoid, Oid procOid) static void addClassMember(List **list, OpClassMember *member, bool isProc) { - List *l; + ListCell *l; foreach(l, *list) { @@ -540,7 +540,7 @@ storeOperators(Oid opclassoid, List *operators) Datum values[Natts_pg_amop]; char nulls[Natts_pg_amop]; HeapTuple tup; - List *l; + ListCell *l; int i; rel = heap_openr(AccessMethodOperatorRelationName, RowExclusiveLock); @@ -584,7 +584,7 @@ storeProcedures(Oid opclassoid, List *procedures) Datum values[Natts_pg_amproc]; char nulls[Natts_pg_amproc]; HeapTuple tup; - List *l; + ListCell *l; int i; rel = heap_openr(AccessMethodProcedureRelationName, RowExclusiveLock); diff --git a/src/backend/commands/operatorcmds.c b/src/backend/commands/operatorcmds.c index a198f51eee..d2ffae2ce5 100644 --- a/src/backend/commands/operatorcmds.c +++ b/src/backend/commands/operatorcmds.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/operatorcmds.c,v 1.15 2004/05/14 16:11:25 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/operatorcmds.c,v 1.16 2004/05/26 04:41:11 neilc Exp $ * * DESCRIPTION * The "DefineFoo" routines take the parse tree and pick out the @@ -79,7 +79,7 @@ DefineOperator(List *names, List *parameters) List *rightSortName = NIL; /* optional right sort operator */ List *ltCompareName = NIL; /* optional < compare operator */ List *gtCompareName = NIL; /* optional > compare operator */ - List *pl; + ListCell *pl; /* Convert list of names to a name and namespace */ oprNamespace = QualifiedNameGetCreationNamespace(names, &oprName); @@ -167,13 +167,13 @@ DefineOperator(List *names, List *parameters) if (canMerge) { if (!leftSortName) - leftSortName = makeList1(makeString("<")); + leftSortName = list_make1(makeString("<")); if (!rightSortName) - rightSortName = makeList1(makeString("<")); + rightSortName = list_make1(makeString("<")); if (!ltCompareName) - ltCompareName = makeList1(makeString("<")); + ltCompareName = list_make1(makeString("<")); if (!gtCompareName) - gtCompareName = makeList1(makeString(">")); + gtCompareName = list_make1(makeString(">")); } /* @@ -206,7 +206,7 @@ void RemoveOperator(RemoveOperStmt *stmt) { List *operatorName = stmt->opname; - TypeName *typeName1 = (TypeName *) lfirst(stmt->args); + TypeName *typeName1 = (TypeName *) linitial(stmt->args); TypeName *typeName2 = (TypeName *) lsecond(stmt->args); Oid operOid; HeapTuple tup; diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c index 855c9391c1..d2fa894a76 100644 --- a/src/backend/commands/portalcmds.c +++ b/src/backend/commands/portalcmds.c @@ -14,7 +14,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.26 2004/03/21 22:29:10 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.27 2004/05/26 04:41:11 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -68,9 +68,9 @@ PerformCursorOpen(DeclareCursorStmt *stmt) * strange. */ rewritten = QueryRewrite((Query *) stmt->query); - if (length(rewritten) != 1 || !IsA(lfirst(rewritten), Query)) + if (list_length(rewritten) != 1 || !IsA(linitial(rewritten), Query)) elog(ERROR, "unexpected rewrite result"); - query = (Query *) lfirst(rewritten); + query = (Query *) linitial(rewritten); if (query->commandType != CMD_SELECT) elog(ERROR, "unexpected rewrite result"); @@ -100,8 +100,8 @@ PerformCursorOpen(DeclareCursorStmt *stmt) PortalDefineQuery(portal, NULL, /* unfortunately don't have sourceText */ "SELECT", /* cursor's query is always a SELECT */ - makeList1(query), - makeList1(plan), + list_make1(query), + list_make1(plan), PortalGetHeapMemory(portal)); MemoryContextSwitchTo(oldContext); diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c index d85d41c1ec..083ad2af5e 100644 --- a/src/backend/commands/prepare.c +++ b/src/backend/commands/prepare.c @@ -10,7 +10,7 @@ * Copyright (c) 2002-2003, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.26 2004/04/22 02:58:20 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.27 2004/05/26 04:41:11 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -125,7 +125,7 @@ ExecuteQuery(ExecuteStmt *stmt, DestReceiver *dest, char *completionTag) plan_list = entry->plan_list; qcontext = entry->context; - Assert(length(query_list) == length(plan_list)); + Assert(list_length(query_list) == list_length(plan_list)); /* Evaluate parameters, if any */ if (entry->argtype_list != NIL) @@ -162,11 +162,11 @@ ExecuteQuery(ExecuteStmt *stmt, DestReceiver *dest, char *completionTag) plan_list = copyObject(plan_list); qcontext = PortalGetHeapMemory(portal); - if (length(query_list) != 1) + if (list_length(query_list) != 1) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("prepared statement is not a SELECT"))); - query = (Query *) lfirst(query_list); + query = (Query *) linitial(query_list); if (query->commandType != CMD_SELECT) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), @@ -208,14 +208,14 @@ ExecuteQuery(ExecuteStmt *stmt, DestReceiver *dest, char *completionTag) static ParamListInfo EvaluateParams(EState *estate, List *params, List *argtypes) { - int nargs = length(argtypes); + int nargs = list_length(argtypes); ParamListInfo paramLI; List *exprstates; - List *l; + ListCell *l; int i = 0; /* Parser should have caught this error, but check for safety */ - if (length(params) != nargs) + if (list_length(params) != nargs) elog(ERROR, "wrong number of arguments"); exprstates = (List *) ExecPrepareExpr((Expr *) params, estate); @@ -326,7 +326,7 @@ StorePreparedStatement(const char *stmt_name, qstring = query_string ? pstrdup(query_string) : NULL; query_list = (List *) copyObject(query_list); plan_list = (List *) copyObject(plan_list); - argtype_list = listCopy(argtype_list); + argtype_list = list_copy(argtype_list); /* Now we can add entry to hash table */ entry = (PreparedStatement *) hash_search(prepared_queries, @@ -419,11 +419,11 @@ FetchPreparedStatementResultDesc(PreparedStatement *stmt) switch (ChoosePortalStrategy(stmt->query_list)) { case PORTAL_ONE_SELECT: - query = (Query *) lfirst(stmt->query_list); + query = (Query *) linitial(stmt->query_list); return ExecCleanTypeFromTL(query->targetList, false); case PORTAL_UTIL_SELECT: - query = (Query *) lfirst(stmt->query_list); + query = (Query *) linitial(stmt->query_list); return UtilityTupleDescriptor(query->utilityStmt); case PORTAL_MULTI_QUERY: @@ -478,8 +478,9 @@ ExplainExecuteQuery(ExplainStmt *stmt, TupOutputState *tstate) { ExecuteStmt *execstmt = (ExecuteStmt *) stmt->query->utilityStmt; PreparedStatement *entry; - List *l, - *query_list, + ListCell *q, + *p; + List *query_list, *plan_list; ParamListInfo paramLI = NULL; EState *estate = NULL; @@ -493,7 +494,7 @@ ExplainExecuteQuery(ExplainStmt *stmt, TupOutputState *tstate) query_list = entry->query_list; plan_list = entry->plan_list; - Assert(length(query_list) == length(plan_list)); + Assert(list_length(query_list) == list_length(plan_list)); /* Evaluate parameters, if any */ if (entry->argtype_list != NIL) @@ -508,14 +509,13 @@ ExplainExecuteQuery(ExplainStmt *stmt, TupOutputState *tstate) } /* Explain each query */ - foreach(l, query_list) + forboth (q, query_list, p, plan_list) { - Query *query = (Query *) lfirst(l); - Plan *plan = (Plan *) lfirst(plan_list); + Query *query = (Query *) lfirst(q); + Plan *plan = (Plan *) lfirst(p); bool is_last_query; - plan_list = lnext(plan_list); - is_last_query = (plan_list == NIL); + is_last_query = (lnext(p) == NULL); if (query->commandType == CMD_UTILITY) { diff --git a/src/backend/commands/schemacmds.c b/src/backend/commands/schemacmds.c index 8af564cf74..18a212271e 100644 --- a/src/backend/commands/schemacmds.c +++ b/src/backend/commands/schemacmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/schemacmds.c,v 1.17 2003/11/29 19:51:47 pgsql Exp $ + * $PostgreSQL: pgsql/src/backend/commands/schemacmds.c,v 1.18 2004/05/26 04:41:11 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -42,7 +42,7 @@ CreateSchemaCommand(CreateSchemaStmt *stmt) const char *authId = stmt->authid; Oid namespaceId; List *parsetree_list; - List *parsetree_item; + ListCell *parsetree_item; const char *owner_name; AclId owner_userid; AclId saved_userid; @@ -129,8 +129,8 @@ CreateSchemaCommand(CreateSchemaStmt *stmt) foreach(parsetree_item, parsetree_list) { Node *parsetree = (Node *) lfirst(parsetree_item); - List *querytree_list, - *querytree_item; + List *querytree_list; + ListCell *querytree_item; querytree_list = parse_analyze(parsetree, NULL, 0); @@ -166,11 +166,11 @@ RemoveSchema(List *names, DropBehavior behavior) Oid namespaceId; ObjectAddress object; - if (length(names) != 1) + if (list_length(names) != 1) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("schema name may not be qualified"))); - namespaceName = strVal(lfirst(names)); + namespaceName = strVal(linitial(names)); namespaceId = GetSysCacheOid(NAMESPACENAME, CStringGetDatum(namespaceName), diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c index 0ff1b386b5..351813b5de 100644 --- a/src/backend/commands/sequence.c +++ b/src/backend/commands/sequence.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.110 2004/05/08 19:09:24 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.111 2004/05/26 04:41:11 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -862,7 +862,7 @@ init_params(List *options, Form_pg_sequence new, bool isInit) DefElem *min_value = NULL; DefElem *cache_value = NULL; DefElem *is_cycled = NULL; - List *option; + ListCell *option; foreach(option, options) { diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index bf308141fa..431c4ac742 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.107 2004/05/08 22:46:29 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.108 2004/05/26 04:41:12 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -262,7 +262,7 @@ DefineRelation(CreateStmt *stmt, char relkind) bool localHasOids; int parentOidCount; List *rawDefaults; - List *listptr; + ListCell *listptr; int i; AttrNumber attnum; @@ -320,7 +320,7 @@ DefineRelation(CreateStmt *stmt, char relkind) if (old_constraints != NIL) { - ConstrCheck *check = (ConstrCheck *) palloc(length(old_constraints) * + ConstrCheck *check = (ConstrCheck *) palloc(list_length(old_constraints) * sizeof(ConstrCheck)); int ncheck = 0; int constr_name_ctr = 0; @@ -634,7 +634,7 @@ static List * MergeAttributes(List *schema, List *supers, bool istemp, List **supOids, List **supconstr, int *supOidCount) { - List *entry; + ListCell *entry; List *inhSchema = NIL; List *parentOids = NIL; List *constraints = NIL; @@ -654,9 +654,9 @@ MergeAttributes(List *schema, List *supers, bool istemp, foreach(entry, schema) { ColumnDef *coldef = lfirst(entry); - List *rest; + ListCell *rest; - foreach(rest, lnext(entry)) + for_each_cell(rest, lnext(entry)) { ColumnDef *restdef = lfirst(rest); @@ -708,13 +708,13 @@ MergeAttributes(List *schema, List *supers, bool istemp, /* * Reject duplications in the list of parents. */ - if (oidMember(RelationGetRelid(relation), parentOids)) + if (list_member_oid(parentOids, RelationGetRelid(relation))) ereport(ERROR, (errcode(ERRCODE_DUPLICATE_TABLE), errmsg("inherited relation \"%s\" duplicated", parent->relname))); - parentOids = lappendo(parentOids, RelationGetRelid(relation)); + parentOids = lappend_oid(parentOids, RelationGetRelid(relation)); if (relation->rd_rel->relhasoids) parentsWithOids++; @@ -767,7 +767,7 @@ MergeAttributes(List *schema, List *supers, bool istemp, ereport(NOTICE, (errmsg("merging multiple inherited definitions of column \"%s\"", attributeName))); - def = (ColumnDef *) nth(exist_attno - 1, inhSchema); + def = (ColumnDef *) list_nth(inhSchema, exist_attno - 1); if (typenameTypeId(def->typename) != attribute->atttypid || def->typename->typmod != attribute->atttypmod) ereport(ERROR, @@ -922,7 +922,7 @@ MergeAttributes(List *schema, List *supers, bool istemp, ereport(NOTICE, (errmsg("merging column \"%s\" with inherited definition", attributeName))); - def = (ColumnDef *) nth(exist_attno - 1, inhSchema); + def = (ColumnDef *) list_nth(inhSchema, exist_attno - 1); if (typenameTypeId(def->typename) != typenameTypeId(newdef->typename) || def->typename->typmod != newdef->typename->typmod) ereport(ERROR, @@ -1033,7 +1033,7 @@ StoreCatalogInheritance(Oid relationId, List *supers) Relation relation; TupleDesc desc; int16 seqNumber; - List *entry; + ListCell *entry; HeapTuple tuple; /* @@ -1059,7 +1059,7 @@ StoreCatalogInheritance(Oid relationId, List *supers) seqNumber = 1; foreach(entry, supers) { - Oid parentOid = lfirsto(entry); + Oid parentOid = lfirst_oid(entry); Datum datum[Natts_pg_inherits]; char nullarr[Natts_pg_inherits]; ObjectAddress childobject, @@ -1113,16 +1113,17 @@ StoreCatalogInheritance(Oid relationId, List *supers) static int findAttrByName(const char *attributeName, List *schema) { - List *s; - int i = 0; + ListCell *s; + int i = 1; foreach(s, schema) { ColumnDef *def = lfirst(s); - ++i; if (strcmp(attributeName, def->colname) == 0) return i; + + i++; } return 0; } @@ -1198,7 +1199,7 @@ renameatt(Oid myrelid, Form_pg_attribute attform; int attnum; List *indexoidlist; - List *indexoidscan; + ListCell *indexoidscan; /* * Grab an exclusive lock on the target table, which we will NOT @@ -1232,8 +1233,8 @@ renameatt(Oid myrelid, */ if (recurse) { - List *child, - *children; + ListCell *child; + List *children; /* this routine is actually in the planner */ children = find_all_inheritors(myrelid); @@ -1245,7 +1246,7 @@ renameatt(Oid myrelid, */ foreach(child, children) { - Oid childrelid = lfirsto(child); + Oid childrelid = lfirst_oid(child); if (childrelid == myrelid) continue; @@ -1322,7 +1323,7 @@ renameatt(Oid myrelid, foreach(indexoidscan, indexoidlist) { - Oid indexoid = lfirsto(indexoidscan); + Oid indexoid = lfirst_oid(indexoidscan); HeapTuple indextup; Form_pg_index indexform; int i; @@ -1370,7 +1371,7 @@ renameatt(Oid myrelid, ReleaseSysCache(indextup); } - freeList(indexoidlist); + list_free(indexoidlist); heap_close(attrelation, RowExclusiveLock); @@ -1765,7 +1766,7 @@ static void ATController(Relation rel, List *cmds, bool recurse) { List *wqueue = NIL; - List *lcmd; + ListCell *lcmd; /* Phase 1: preliminary examination of commands, create work queue */ foreach(lcmd, cmds) @@ -1962,7 +1963,7 @@ static void ATRewriteCatalogs(List **wqueue) { int pass; - List *ltab; + ListCell *ltab; /* * We process all the tables "in parallel", one pass at a time. This @@ -1979,7 +1980,7 @@ ATRewriteCatalogs(List **wqueue) AlteredTableInfo *tab = (AlteredTableInfo *) lfirst(ltab); List *subcmds = tab->subcmds[pass]; Relation rel; - List *lcmd; + ListCell *lcmd; if (subcmds == NIL) continue; @@ -2107,7 +2108,7 @@ ATExecCmd(AlteredTableInfo *tab, Relation rel, AlterTableCmd *cmd) static void ATRewriteTables(List **wqueue) { - List *ltab; + ListCell *ltab; /* Go through each table that needs to be checked or rewritten */ foreach(ltab, *wqueue) @@ -2215,7 +2216,7 @@ ATRewriteTables(List **wqueue) { AlteredTableInfo *tab = (AlteredTableInfo *) lfirst(ltab); Relation rel = NULL; - List *lcon; + ListCell *lcon; foreach(lcon, tab->constraints) { @@ -2259,7 +2260,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap) TupleDesc newTupDesc; bool needscan = false; int i; - List *l; + ListCell *l; EState *estate; /* @@ -2473,7 +2474,7 @@ ATGetQueueEntry(List **wqueue, Relation rel) { Oid relid = RelationGetRelid(rel); AlteredTableInfo *tab; - List *ltab; + ListCell *ltab; foreach(ltab, *wqueue) { @@ -2554,8 +2555,8 @@ ATSimpleRecursion(List **wqueue, Relation rel, if (recurse && rel->rd_rel->relkind == RELKIND_RELATION) { Oid relid = RelationGetRelid(rel); - List *child, - *children; + ListCell *child; + List *children; /* this routine is actually in the planner */ children = find_all_inheritors(relid); @@ -2567,7 +2568,7 @@ ATSimpleRecursion(List **wqueue, Relation rel, */ foreach(child, children) { - Oid childrelid = lfirsto(child); + Oid childrelid = lfirst_oid(child); Relation childrel; if (childrelid == relid) @@ -2592,15 +2593,15 @@ ATOneLevelRecursion(List **wqueue, Relation rel, AlterTableCmd *cmd) { Oid relid = RelationGetRelid(rel); - List *child, - *children; + ListCell *child; + List *children; /* this routine is actually in the planner */ children = find_inheritance_children(relid); foreach(child, children) { - Oid childrelid = lfirsto(child); + Oid childrelid = lfirst_oid(child); Relation childrel; childrel = relation_open(childrelid, AccessExclusiveLock); @@ -2764,7 +2765,7 @@ ATExecAddColumn(AlteredTableInfo *tab, Relation rel, attribute->atttypmod = colDef->typename->typmod; attribute->attnum = i; attribute->attbyval = tform->typbyval; - attribute->attndims = length(colDef->typename->arrayBounds); + attribute->attndims = list_length(colDef->typename->arrayBounds); attribute->attstorage = tform->typstorage; attribute->attalign = tform->typalign; attribute->attnotnull = colDef->is_not_null; @@ -2814,7 +2815,7 @@ ATExecAddColumn(AlteredTableInfo *tab, Relation rel, * This function is intended for CREATE TABLE, so it processes a * _list_ of defaults, but we just do one. */ - AddRelationRawConstraints(rel, makeList1(rawEnt), NIL); + AddRelationRawConstraints(rel, list_make1(rawEnt), NIL); /* Make the additional catalog changes visible */ CommandCounterIncrement(); @@ -2880,7 +2881,7 @@ ATExecDropNotNull(Relation rel, const char *colName) AttrNumber attnum; Relation attr_rel; List *indexoidlist; - List *indexoidscan; + ListCell *indexoidscan; /* * lookup the attribute @@ -2913,7 +2914,7 @@ ATExecDropNotNull(Relation rel, const char *colName) foreach(indexoidscan, indexoidlist) { - Oid indexoid = lfirsto(indexoidscan); + Oid indexoid = lfirst_oid(indexoidscan); HeapTuple indexTuple; Form_pg_index indexStruct; int i; @@ -2945,7 +2946,7 @@ ATExecDropNotNull(Relation rel, const char *colName) ReleaseSysCache(indexTuple); } - freeList(indexoidlist); + list_free(indexoidlist); /* * Okay, actually perform the catalog change ... if needed @@ -3067,7 +3068,7 @@ ATExecColumnDefault(Relation rel, const char *colName, * This function is intended for CREATE TABLE, so it processes a * _list_ of defaults, but we just do one. */ - AddRelationRawConstraints(rel, makeList1(rawEnt), NIL); + AddRelationRawConstraints(rel, list_make1(rawEnt), NIL); } } @@ -3292,12 +3293,12 @@ ATExecDropColumn(Relation rel, const char *colName, if (children) { Relation attr_rel; - List *child; + ListCell *child; attr_rel = heap_openr(AttributeRelationName, RowExclusiveLock); foreach(child, children) { - Oid childrelid = lfirsto(child); + Oid childrelid = lfirst_oid(child); Relation childrel; Form_pg_attribute childatt; @@ -3464,14 +3465,14 @@ ATExecAddConstraint(AlteredTableInfo *tab, Relation rel, Node *newConstraint) case CONSTR_CHECK: { List *newcons; - List *lcon; + ListCell *lcon; /* * Call AddRelationRawConstraints to do the work. * It returns a list of cooked constraints. */ newcons = AddRelationRawConstraints(rel, NIL, - makeList1(constr)); + list_make1(constr)); /* Add each constraint to Phase 3's queue */ foreach(lcon, newcons) { @@ -3676,7 +3677,7 @@ ATAddForeignKeyConstraint(AlteredTableInfo *tab, Relation rel, * get the right answer from the test below on opclass membership * unless we select the proper operator.) */ - Operator o = oper(makeList1(makeString("=")), + Operator o = oper(list_make1(makeString("=")), pktypoid[i], fktypoid[i], true); if (o == NULL) @@ -3687,8 +3688,8 @@ ATAddForeignKeyConstraint(AlteredTableInfo *tab, Relation rel, fkconstraint->constr_name), errdetail("Key columns \"%s\" and \"%s\" " "are of incompatible types: %s and %s.", - strVal(nth(i, fkconstraint->fk_attrs)), - strVal(nth(i, fkconstraint->pk_attrs)), + strVal(list_nth(fkconstraint->fk_attrs, i)), + strVal(list_nth(fkconstraint->pk_attrs, i)), format_type_be(fktypoid[i]), format_type_be(pktypoid[i])))); @@ -3704,8 +3705,8 @@ ATAddForeignKeyConstraint(AlteredTableInfo *tab, Relation rel, fkconstraint->constr_name), errdetail("Key columns \"%s\" and \"%s\" " "are of different types: %s and %s.", - strVal(nth(i, fkconstraint->fk_attrs)), - strVal(nth(i, fkconstraint->pk_attrs)), + strVal(list_nth(fkconstraint->fk_attrs, i)), + strVal(list_nth(fkconstraint->pk_attrs, i)), format_type_be(fktypoid[i]), format_type_be(pktypoid[i])))); @@ -3774,7 +3775,7 @@ static int transformColumnNameList(Oid relId, List *colList, int16 *attnums, Oid *atttypids) { - List *l; + ListCell *l; int attnum; attnum = 0; @@ -3821,8 +3822,8 @@ transformFkeyGetPrimaryKey(Relation pkrel, Oid *indexOid, int16 *attnums, Oid *atttypids, Oid *opclasses) { - List *indexoidlist, - *indexoidscan; + List *indexoidlist; + ListCell *indexoidscan; HeapTuple indexTuple = NULL; Form_pg_index indexStruct = NULL; int i; @@ -3836,7 +3837,7 @@ transformFkeyGetPrimaryKey(Relation pkrel, Oid *indexOid, foreach(indexoidscan, indexoidlist) { - Oid indexoid = lfirsto(indexoidscan); + Oid indexoid = lfirst_oid(indexoidscan); indexTuple = SearchSysCache(INDEXRELID, ObjectIdGetDatum(indexoid), @@ -3853,7 +3854,7 @@ transformFkeyGetPrimaryKey(Relation pkrel, Oid *indexOid, indexStruct = NULL; } - freeList(indexoidlist); + list_free(indexoidlist); /* * Check that we found it @@ -3900,8 +3901,8 @@ transformFkeyCheckAttrs(Relation pkrel, { Oid indexoid = InvalidOid; bool found = false; - List *indexoidlist, - *indexoidscan; + List *indexoidlist; + ListCell *indexoidscan; /* * Get the list of index OIDs for the table from the relcache, and @@ -3917,7 +3918,7 @@ transformFkeyCheckAttrs(Relation pkrel, int i, j; - indexoid = lfirsto(indexoidscan); + indexoid = lfirst_oid(indexoidscan); indexTuple = SearchSysCache(INDEXRELID, ObjectIdGetDatum(indexoid), 0, 0, 0); @@ -3982,7 +3983,7 @@ transformFkeyCheckAttrs(Relation pkrel, errmsg("there is no unique constraint matching given keys for referenced table \"%s\"", RelationGetRelationName(pkrel)))); - freeList(indexoidlist); + list_free(indexoidlist); return indexoid; } @@ -4001,7 +4002,7 @@ validateForeignKeyConstraint(FkConstraint *fkconstraint, HeapScanDesc scan; HeapTuple tuple; Trigger trig; - List *list; + ListCell *list; int count; /* @@ -4026,8 +4027,8 @@ validateForeignKeyConstraint(FkConstraint *fkconstraint, trig.tginitdeferred = FALSE; trig.tgargs = (char **) palloc(sizeof(char *) * - (4 + length(fkconstraint->fk_attrs) - + length(fkconstraint->pk_attrs))); + (4 + list_length(fkconstraint->fk_attrs) + + list_length(fkconstraint->pk_attrs))); trig.tgargs[0] = trig.tgname; trig.tgargs[1] = RelationGetRelationName(rel); @@ -4094,8 +4095,8 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint, { RangeVar *myRel; CreateTrigStmt *fk_trigger; - List *fk_attr; - List *pk_attr; + ListCell *fk_attr; + ListCell *pk_attr; ObjectAddress trigobj, constrobj; @@ -4146,19 +4147,16 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint, makeString(fkconstraint->pktable->relname)); fk_trigger->args = lappend(fk_trigger->args, makeString(fkMatchTypeToString(fkconstraint->fk_matchtype))); - fk_attr = fkconstraint->fk_attrs; - pk_attr = fkconstraint->pk_attrs; - if (length(fk_attr) != length(pk_attr)) + if (list_length(fkconstraint->fk_attrs) != list_length(fkconstraint->pk_attrs)) ereport(ERROR, (errcode(ERRCODE_INVALID_FOREIGN_KEY), errmsg("number of referencing and referenced columns for foreign key disagree"))); - while (fk_attr != NIL) + forboth(fk_attr, fkconstraint->fk_attrs, + pk_attr, fkconstraint->pk_attrs) { fk_trigger->args = lappend(fk_trigger->args, lfirst(fk_attr)); fk_trigger->args = lappend(fk_trigger->args, lfirst(pk_attr)); - fk_attr = lnext(fk_attr); - pk_attr = lnext(pk_attr); } trigobj.objectId = CreateTrigger(fk_trigger, true); @@ -4219,14 +4217,11 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint, makeString(fkconstraint->pktable->relname)); fk_trigger->args = lappend(fk_trigger->args, makeString(fkMatchTypeToString(fkconstraint->fk_matchtype))); - fk_attr = fkconstraint->fk_attrs; - pk_attr = fkconstraint->pk_attrs; - while (fk_attr != NIL) + forboth(fk_attr, fkconstraint->fk_attrs, + pk_attr, fkconstraint->pk_attrs) { fk_trigger->args = lappend(fk_trigger->args, lfirst(fk_attr)); fk_trigger->args = lappend(fk_trigger->args, lfirst(pk_attr)); - fk_attr = lnext(fk_attr); - pk_attr = lnext(pk_attr); } trigobj.objectId = CreateTrigger(fk_trigger, true); @@ -4286,14 +4281,11 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint, makeString(fkconstraint->pktable->relname)); fk_trigger->args = lappend(fk_trigger->args, makeString(fkMatchTypeToString(fkconstraint->fk_matchtype))); - fk_attr = fkconstraint->fk_attrs; - pk_attr = fkconstraint->pk_attrs; - while (fk_attr != NIL) + forboth(fk_attr, fkconstraint->fk_attrs, + pk_attr, fkconstraint->pk_attrs) { fk_trigger->args = lappend(fk_trigger->args, lfirst(fk_attr)); fk_trigger->args = lappend(fk_trigger->args, lfirst(pk_attr)); - fk_attr = lnext(fk_attr); - pk_attr = lnext(pk_attr); } trigobj.objectId = CreateTrigger(fk_trigger, true); @@ -4626,9 +4618,9 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel, if (relKind == RELKIND_INDEX) { Assert(foundObject.objectSubId == 0); - if (!oidMember(foundObject.objectId, tab->changedIndexOids)) + if (!list_member_oid(tab->changedIndexOids, foundObject.objectId)) { - tab->changedIndexOids = lappendo(tab->changedIndexOids, + tab->changedIndexOids = lappend_oid(tab->changedIndexOids, foundObject.objectId); tab->changedIndexDefs = lappend(tab->changedIndexDefs, pg_get_indexdef_string(foundObject.objectId)); @@ -4653,9 +4645,9 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel, case OCLASS_CONSTRAINT: Assert(foundObject.objectSubId == 0); - if (!oidMember(foundObject.objectId, tab->changedConstraintOids)) + if (!list_member_oid(tab->changedConstraintOids, foundObject.objectId)) { - tab->changedConstraintOids = lappendo(tab->changedConstraintOids, + tab->changedConstraintOids = lappend_oid(tab->changedConstraintOids, foundObject.objectId); tab->changedConstraintDefs = lappend(tab->changedConstraintDefs, pg_get_constraintdef_string(foundObject.objectId)); @@ -4750,7 +4742,7 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel, */ attTup->atttypid = targettype; attTup->atttypmod = typename->typmod; - attTup->attndims = length(typename->arrayBounds); + attTup->attndims = list_length(typename->arrayBounds); attTup->attlen = tform->typlen; attTup->attbyval = tform->typbyval; attTup->attalign = tform->typalign; @@ -4805,7 +4797,7 @@ static void ATPostAlterTypeCleanup(List **wqueue, AlteredTableInfo *tab) { ObjectAddress obj; - List *l; + ListCell *l; /* * Re-parse the index and constraint definitions, and attach them to @@ -4835,7 +4827,7 @@ ATPostAlterTypeCleanup(List **wqueue, AlteredTableInfo *tab) obj.classId = get_system_catalog_relid(ConstraintRelationName); foreach(l, tab->changedConstraintOids) { - obj.objectId = lfirsto(l); + obj.objectId = lfirst_oid(l); obj.objectSubId = 0; performDeletion(&obj, DROP_RESTRICT); } @@ -4843,7 +4835,7 @@ ATPostAlterTypeCleanup(List **wqueue, AlteredTableInfo *tab) obj.classId = RelOid_pg_class; foreach(l, tab->changedIndexOids) { - obj.objectId = lfirsto(l); + obj.objectId = lfirst_oid(l); obj.objectSubId = 0; performDeletion(&obj, DROP_RESTRICT); } @@ -4859,7 +4851,7 @@ ATPostAlterTypeParse(char *cmd, List **wqueue) { List *raw_parsetree_list; List *querytree_list; - List *list_item; + ListCell *list_item; /* * We expect that we only have to do raw parsing and parse analysis, not @@ -4871,7 +4863,7 @@ ATPostAlterTypeParse(char *cmd, List **wqueue) { Node *parsetree = (Node *) lfirst(list_item); - querytree_list = nconc(querytree_list, + querytree_list = list_concat(querytree_list, parse_analyze(parsetree, NULL, 0)); } @@ -4907,7 +4899,7 @@ ATPostAlterTypeParse(char *cmd, List **wqueue) case T_AlterTableStmt: { AlterTableStmt *stmt = (AlterTableStmt *) query->utilityStmt; - List *lcmd; + ListCell *lcmd; rel = relation_openrv(stmt->relation, AccessExclusiveLock); tab = ATGetQueueEntry(wqueue, rel); @@ -5002,17 +4994,17 @@ ATExecChangeOwner(Oid relationOid, int32 newOwnerSysId) if (tuple_class->relkind == RELKIND_RELATION || tuple_class->relkind == RELKIND_TOASTVALUE) { - List *index_oid_list, - *i; + List *index_oid_list; + ListCell *i; /* Find all the indexes belonging to this relation */ index_oid_list = RelationGetIndexList(target_rel); /* For each index, recursively change its ownership */ foreach(i, index_oid_list) - ATExecChangeOwner(lfirsto(i), newOwnerSysId); + ATExecChangeOwner(lfirst_oid(i), newOwnerSysId); - freeList(index_oid_list); + list_free(index_oid_list); } if (tuple_class->relkind == RELKIND_RELATION) @@ -5362,7 +5354,7 @@ register_on_commit_action(Oid relid, OnCommitAction action) void remove_on_commit_action(Oid relid) { - List *l; + ListCell *l; foreach(l, on_commits) { @@ -5385,7 +5377,7 @@ remove_on_commit_action(Oid relid) void PreCommit_on_commit_actions(void) { - List *l; + ListCell *l; foreach(l, on_commits) { @@ -5437,40 +5429,34 @@ PreCommit_on_commit_actions(void) void AtEOXact_on_commit_actions(bool isCommit) { - List *l, - *prev; + ListCell *cur_item; + ListCell *prev_item; - prev = NIL; - l = on_commits; - while (l != NIL) + prev_item = NULL; + cur_item = list_head(on_commits); + + while (cur_item != NULL) { - OnCommitItem *oc = (OnCommitItem *) lfirst(l); + OnCommitItem *oc = (OnCommitItem *) lfirst(cur_item); if (isCommit ? oc->deleted_in_cur_xact : oc->created_in_cur_xact) { - /* This entry must be removed */ - if (prev != NIL) - { - lnext(prev) = lnext(l); - pfree(l); - l = lnext(prev); - } - else - { - on_commits = lnext(l); - pfree(l); - l = on_commits; - } + /* cur_item must be removed */ + on_commits = list_delete_cell(on_commits, cur_item, prev_item); pfree(oc); + if (prev_item) + cur_item = lnext(prev_item); + else + cur_item = list_head(on_commits); } else { - /* This entry must be preserved */ - oc->created_in_cur_xact = false; + /* cur_item must be preserved */ oc->deleted_in_cur_xact = false; - prev = l; - l = lnext(l); + oc->created_in_cur_xact = false; + prev_item = cur_item; + cur_item = lnext(prev_item); } } } diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index bddf3f5ad6..cfbd58e428 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.164 2004/02/10 01:55:25 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.165 2004/05/26 04:41:12 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -111,19 +111,19 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint) bool needconstrrelid = false; void *elem = NULL; - if (strncmp(strVal(llast(stmt->funcname)), "RI_FKey_check_", 14) == 0) + if (strncmp(strVal(lfirst(list_tail((stmt->funcname)))), "RI_FKey_check_", 14) == 0) { /* A trigger on FK table. */ needconstrrelid = true; - if (length(stmt->args) > RI_PK_RELNAME_ARGNO) - elem = nth(RI_PK_RELNAME_ARGNO, stmt->args); + if (list_length(stmt->args) > RI_PK_RELNAME_ARGNO) + elem = list_nth(stmt->args, RI_PK_RELNAME_ARGNO); } - else if (strncmp(strVal(llast(stmt->funcname)), "RI_FKey_", 8) == 0) + else if (strncmp(strVal(lfirst(list_tail((stmt->funcname)))), "RI_FKey_", 8) == 0) { /* A trigger on PK table. */ needconstrrelid = true; - if (length(stmt->args) > RI_FK_RELNAME_ARGNO) - elem = nth(RI_FK_RELNAME_ARGNO, stmt->args); + if (list_length(stmt->args) > RI_FK_RELNAME_ARGNO) + elem = list_nth(stmt->args, RI_FK_RELNAME_ARGNO); } if (elem != NULL) { @@ -318,9 +318,9 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint) if (stmt->args) { - List *le; + ListCell *le; char *args; - int16 nargs = length(stmt->args); + int16 nargs = list_length(stmt->args); int len = 0; foreach(le, stmt->args) @@ -1691,7 +1691,7 @@ static bool deferredTriggerCheckState(Oid tgoid, int32 itemstate) { MemoryContext oldcxt; - List *sl; + ListCell *sl; DeferredTriggerStatus trigstate; /* @@ -2193,7 +2193,7 @@ DeferredTriggerAbortXact(void) void DeferredTriggerSetState(ConstraintsSetStmt *stmt) { - List *l; + ListCell *l; /* * Ignore call if we aren't in a transaction. @@ -2210,15 +2210,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) * Drop all per-transaction information about individual trigger * states. */ - l = deferredTriggers->deftrig_trigstates; - while (l != NIL) - { - List *next = lnext(l); - - pfree(lfirst(l)); - pfree(l); - l = next; - } + list_free_deep(deferredTriggers->deftrig_trigstates); deferredTriggers->deftrig_trigstates = NIL; /* @@ -2233,7 +2225,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) MemoryContext oldcxt; bool found; DeferredTriggerStatus state; - List *ls; + ListCell *ls; List *loid = NIL; /* ---------- @@ -2293,7 +2285,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) cname))); constr_oid = HeapTupleGetOid(htup); - loid = lappendo(loid, constr_oid); + loid = lappend_oid(loid, constr_oid); found = true; } @@ -2321,7 +2313,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) foreach(ls, deferredTriggers->deftrig_trigstates) { state = (DeferredTriggerStatus) lfirst(ls); - if (state->dts_tgoid == lfirsto(l)) + if (state->dts_tgoid == lfirst_oid(l)) { state->dts_tgisdeferred = stmt->deferred; found = true; @@ -2332,7 +2324,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) { state = (DeferredTriggerStatus) palloc(sizeof(DeferredTriggerStatusData)); - state->dts_tgoid = lfirsto(l); + state->dts_tgoid = lfirst_oid(l); state->dts_tgisdeferred = stmt->deferred; deferredTriggers->deftrig_trigstates = diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c index 03428369ff..d8a2a5b20f 100644 --- a/src/backend/commands/typecmds.c +++ b/src/backend/commands/typecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.56 2004/05/14 16:11:25 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.57 2004/05/26 04:41:12 neilc Exp $ * * DESCRIPTION * The "DefineFoo" routines take the parse tree and pick out the @@ -114,7 +114,7 @@ DefineType(List *names, List *parameters) Oid sendOid = InvalidOid; Oid analyzeOid = InvalidOid; char *shadow_type; - List *pl; + ListCell *pl; Oid typoid; Oid resulttype; @@ -502,10 +502,10 @@ DefineDomain(CreateDomainStmt *stmt) bool typNotNull = false; bool nullDefined = false; Oid basetypelem; - int32 typNDims = length(stmt->typename->arrayBounds); + int32 typNDims = list_length(stmt->typename->arrayBounds); HeapTuple typeTup; List *schema = stmt->constraints; - List *listptr; + ListCell *listptr; Oid basetypeoid; Oid domainoid; Form_pg_type baseType; @@ -1304,7 +1304,7 @@ AlterDomainNotNull(List *names, bool notNull) if (notNull) { List *rels; - List *rt; + ListCell *rt; /* Fetch relation list with attributes based on this domain */ /* ShareLock is sufficient to prevent concurrent data changes */ @@ -1461,7 +1461,7 @@ AlterDomainAddConstraint(List *names, Node *newConstraint) HeapTuple tup; Form_pg_type typTup; List *rels; - List *rt; + ListCell *rt; EState *estate; ExprContext *econtext; char *ccbin; @@ -1681,7 +1681,7 @@ get_rels_with_domain(Oid domainOid, LOCKMODE lockmode) { Form_pg_depend pg_depend = (Form_pg_depend) GETSTRUCT(depTup); RelToCheck *rtc = NULL; - List *rellist; + ListCell *rellist; Form_pg_attribute pg_att; int ptr; @@ -1848,7 +1848,7 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid, /* * Make sure no outside relations are referred to. */ - if (length(pstate->p_rtable) != 0) + if (list_length(pstate->p_rtable) != 0) ereport(ERROR, (errcode(ERRCODE_INVALID_COLUMN_REFERENCE), errmsg("cannot use table references in domain check constraint"))); diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c index 476e7e1865..255428fadc 100644 --- a/src/backend/commands/user.c +++ b/src/backend/commands/user.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.140 2004/05/06 16:59:16 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.141 2004/05/26 04:41:12 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -491,8 +491,8 @@ CreateUser(CreateUserStmt *stmt) sysid_exists = false, havesysid = false; int max_id; - List *item, - *option; + ListCell *item; + ListCell *option; char *password = NULL; /* PostgreSQL user password */ bool encrypt_password = Password_encryption; /* encrypt password? */ char encrypted_password[MD5_PASSWD_LEN + 1]; @@ -715,7 +715,7 @@ CreateUser(CreateUserStmt *stmt) ags.name = strVal(lfirst(item)); /* the group name to add * this in */ ags.action = +1; - ags.listUsers = makeList1(makeInteger(sysid)); + ags.listUsers = list_make1(makeInteger(sysid)); AlterGroup(&ags, "CREATE USER"); } @@ -746,7 +746,7 @@ AlterUser(AlterUserStmt *stmt) TupleDesc pg_shadow_dsc; HeapTuple tuple, new_tuple; - List *option; + ListCell *option; char *password = NULL; /* PostgreSQL user password */ bool encrypt_password = Password_encryption; /* encrypt password? */ char encrypted_password[MD5_PASSWD_LEN + 1]; @@ -1017,7 +1017,7 @@ DropUser(DropUserStmt *stmt) { Relation pg_shadow_rel; TupleDesc pg_shadow_dsc; - List *item; + ListCell *item; if (!superuser()) ereport(ERROR, @@ -1122,7 +1122,7 @@ DropUser(DropUserStmt *stmt) /* the group name from which to try to drop the user: */ ags.name = pstrdup(NameStr(((Form_pg_group) GETSTRUCT(tmp_tuple))->groname)); ags.action = -1; - ags.listUsers = makeList1(makeInteger(usesysid)); + ags.listUsers = list_make1(makeInteger(usesysid)); AlterGroup(&ags, "DROP USER"); } heap_endscan(scan); @@ -1283,9 +1283,9 @@ CreateGroup(CreateGroupStmt *stmt) int max_id; Datum new_record[Natts_pg_group]; char new_record_nulls[Natts_pg_group]; - List *item, - *option, - *newlist = NIL; + ListCell *item; + ListCell *option; + List *newlist = NIL; IdList *grolist; int sysid = 0; List *userElts = NIL; @@ -1397,8 +1397,8 @@ CreateGroup(CreateGroupStmt *stmt) const char *groupuser = strVal(lfirst(item)); int32 userid = get_usesysid(groupuser); - if (!intMember(userid, newlist)) - newlist = lappendi(newlist, userid); + if (!list_member_int(newlist, userid)) + newlist = lappend_int(newlist, userid); } /* build an array to insert */ @@ -1454,8 +1454,8 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag) IdList *oldarray; Datum datum; bool null; - List *newlist, - *item; + List *newlist; + ListCell *item; /* * Make sure the user can do this. @@ -1525,8 +1525,8 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag) sysid = 0; /* keep compiler quiet */ } - if (!intMember(sysid, newlist)) - newlist = lappendi(newlist, sysid); + if (!list_member_int(newlist, sysid)) + newlist = lappend_int(newlist, sysid); } /* Do the update */ @@ -1565,8 +1565,8 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag) /* for dropuser we already know the uid */ sysid = intVal(lfirst(item)); } - if (intMember(sysid, newlist)) - newlist = lremovei(sysid, newlist); + if (list_member_int(newlist, sysid)) + newlist = list_delete_int(newlist, sysid); else if (!is_dropuser) ereport(WARNING, (errcode(ERRCODE_WARNING), @@ -1636,9 +1636,9 @@ UpdateGroupMembership(Relation group_rel, HeapTuple group_tuple, static IdList * IdListToArray(List *members) { - int nmembers = length(members); + int nmembers = list_length(members); IdList *newarray; - List *item; + ListCell *item; int i; newarray = palloc(ARR_OVERHEAD(1) + nmembers * sizeof(int32)); @@ -1650,7 +1650,7 @@ IdListToArray(List *members) ARR_DIMS(newarray)[0] = nmembers; /* axis is this long */ i = 0; foreach(item, members) - ((int *) ARR_DATA_PTR(newarray))[i++] = lfirsti(item); + ((int *) ARR_DATA_PTR(newarray))[i++] = lfirst_int(item); return newarray; } @@ -1679,8 +1679,8 @@ IdArrayToList(IdList *oldarray) sysid = ((int32 *) ARR_DATA_PTR(oldarray))[i]; /* filter out any duplicates --- probably a waste of time */ - if (!intMember(sysid, newlist)) - newlist = lappendi(newlist, sysid); + if (!list_member_int(newlist, sysid)) + newlist = lappend_int(newlist, sysid); } return newlist; diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index 5822b7f210..b2ebda8e97 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -13,7 +13,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.277 2004/05/22 23:14:38 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.278 2004/05/26 04:41:12 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -164,8 +164,8 @@ vacuum(VacuumStmt *vacstmt) bool all_rels, in_outer_xact, use_own_xacts; - List *relations, - *cur; + List *relations; + ListCell *cur; if (vacstmt->verbose) elevel = INFO; @@ -276,7 +276,7 @@ vacuum(VacuumStmt *vacstmt) Assert(vacstmt->analyze); if (in_outer_xact) use_own_xacts = false; - else if (length(relations) > 1) + else if (list_length(relations) > 1) use_own_xacts = true; else use_own_xacts = false; @@ -312,7 +312,7 @@ vacuum(VacuumStmt *vacstmt) */ foreach(cur, relations) { - Oid relid = lfirsto(cur); + Oid relid = lfirst_oid(cur); if (vacstmt->vacuum) { @@ -431,7 +431,7 @@ get_rel_oids(const RangeVar *vacrel, const char *stmttype) /* Make a relation list entry for this guy */ oldcontext = MemoryContextSwitchTo(vac_context); - oid_list = lappendo(oid_list, relid); + oid_list = lappend_oid(oid_list, relid); MemoryContextSwitchTo(oldcontext); } else @@ -455,7 +455,7 @@ get_rel_oids(const RangeVar *vacrel, const char *stmttype) { /* Make a relation list entry for this guy */ oldcontext = MemoryContextSwitchTo(vac_context); - oid_list = lappendo(oid_list, HeapTupleGetOid(tuple)); + oid_list = lappend_oid(oid_list, HeapTupleGetOid(tuple)); MemoryContextSwitchTo(oldcontext); } @@ -3061,13 +3061,13 @@ vac_cmp_vtlinks(const void *left, const void *right) void vac_open_indexes(Relation relation, int *nindexes, Relation **Irel) { - List *indexoidlist, - *indexoidscan; + List *indexoidlist; + ListCell *indexoidscan; int i; indexoidlist = RelationGetIndexList(relation); - *nindexes = length(indexoidlist); + *nindexes = list_length(indexoidlist); if (*nindexes > 0) *Irel = (Relation *) palloc(*nindexes * sizeof(Relation)); @@ -3077,13 +3077,13 @@ vac_open_indexes(Relation relation, int *nindexes, Relation **Irel) i = 0; foreach(indexoidscan, indexoidlist) { - Oid indexoid = lfirsto(indexoidscan); + Oid indexoid = lfirst_oid(indexoidscan); (*Irel)[i] = index_open(indexoid); i++; } - freeList(indexoidlist); + list_free(indexoidlist); } diff --git a/src/backend/commands/variable.c b/src/backend/commands/variable.c index 58cf97408f..4a58419079 100644 --- a/src/backend/commands/variable.c +++ b/src/backend/commands/variable.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/variable.c,v 1.96 2004/05/23 23:12:11 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/variable.c,v 1.97 2004/05/26 04:41:13 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -48,7 +48,7 @@ assign_datestyle(const char *value, bool doit, GucSource source) char *rawstring; char *result; List *elemlist; - List *l; + ListCell *l; /* Need a modifiable copy of string */ rawstring = pstrdup(value); @@ -58,7 +58,7 @@ assign_datestyle(const char *value, bool doit, GucSource source) { /* syntax error in list */ pfree(rawstring); - freeList(elemlist); + list_free(elemlist); if (source >= PGC_S_INTERACTIVE) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), @@ -159,7 +159,7 @@ assign_datestyle(const char *value, bool doit, GucSource source) ok = false; pfree(rawstring); - freeList(elemlist); + list_free(elemlist); if (!ok) { diff --git a/src/backend/commands/view.c b/src/backend/commands/view.c index a8c3cb5ce0..4c27bd6719 100644 --- a/src/backend/commands/view.c +++ b/src/backend/commands/view.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/view.c,v 1.81 2004/01/14 23:01:54 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/view.c,v 1.82 2004/05/26 04:41:13 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -47,8 +47,8 @@ DefineVirtualRelation(const RangeVar *relation, List *tlist, bool replace) Oid viewOid, namespaceId; CreateStmt *createStmt = makeNode(CreateStmt); - List *attrList, - *t; + List *attrList; + ListCell *t; /* * create a list of ColumnDef nodes based on the names and types of @@ -217,7 +217,7 @@ FormViewRetrieveRule(const RangeVar *view, Query *viewParse, bool replace) rule->whereClause = NULL; rule->event = CMD_SELECT; rule->instead = true; - rule->actions = makeList1(viewParse); + rule->actions = list_make1(viewParse); rule->replace = replace; return rule; diff --git a/src/backend/executor/execAmi.c b/src/backend/executor/execAmi.c index 8bbd1942eb..fdf55b31c0 100644 --- a/src/backend/executor/execAmi.c +++ b/src/backend/executor/execAmi.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/executor/execAmi.c,v 1.78 2004/03/02 18:56:15 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/execAmi.c,v 1.79 2004/05/26 04:41:14 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -64,11 +64,11 @@ ExecReScan(PlanState *node, ExprContext *exprCtxt) /* If we have changed parameters, propagate that info */ if (node->chgParam != NULL) { - List *lst; + ListCell *l; - foreach(lst, node->initPlan) + foreach(l, node->initPlan) { - SubPlanState *sstate = (SubPlanState *) lfirst(lst); + SubPlanState *sstate = (SubPlanState *) lfirst(l); PlanState *splan = sstate->planstate; if (splan->plan->extParam != NULL) /* don't care about child @@ -77,9 +77,9 @@ ExecReScan(PlanState *node, ExprContext *exprCtxt) if (splan->chgParam != NULL) ExecReScanSetParamPlan(sstate, node); } - foreach(lst, node->subPlan) + foreach(l, node->subPlan) { - SubPlanState *sstate = (SubPlanState *) lfirst(lst); + SubPlanState *sstate = (SubPlanState *) lfirst(l); PlanState *splan = sstate->planstate; if (splan->plan->extParam != NULL) @@ -315,7 +315,7 @@ ExecSupportsBackwardScan(Plan *node) case T_Append: { - List *l; + ListCell *l; foreach(l, ((Append *) node)->appendplans) { diff --git a/src/backend/executor/execJunk.c b/src/backend/executor/execJunk.c index 0411e2e553..20c385134b 100644 --- a/src/backend/executor/execJunk.c +++ b/src/backend/executor/execJunk.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/execJunk.c,v 1.39 2004/04/07 18:46:12 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/execJunk.c,v 1.40 2004/05/26 04:41:14 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -68,7 +68,7 @@ ExecInitJunkFilter(List *targetList, TupleDesc tupType, int len, cleanLength; TupleDesc cleanTupType; - List *t; + ListCell *t; TargetEntry *tle; Resdom *resdom, *cleanResdom; @@ -184,7 +184,7 @@ ExecGetJunkAttribute(JunkFilter *junkfilter, bool *isNull) { List *targetList; - List *t; + ListCell *t; AttrNumber resno; TupleDesc tupType; HeapTuple tuple; diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index e8ed4ce5cc..5ee954ab4d 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -26,7 +26,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.231 2004/05/11 17:36:12 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.232 2004/05/26 04:41:14 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -353,11 +353,11 @@ ExecutorRewind(QueryDesc *queryDesc) void ExecCheckRTPerms(List *rangeTable) { - List *lp; + ListCell *l; - foreach(lp, rangeTable) + foreach(l, rangeTable) { - RangeTblEntry *rte = lfirst(lp); + RangeTblEntry *rte = lfirst(l); ExecCheckRTEPerms(rte); } @@ -427,7 +427,7 @@ ExecCheckRTEPerms(RangeTblEntry *rte) static void ExecCheckXactReadOnly(Query *parsetree) { - List *lp; + ListCell *l; /* * CREATE TABLE AS or SELECT INTO? @@ -438,9 +438,9 @@ ExecCheckXactReadOnly(Query *parsetree) goto fail; /* Fail if write permissions are requested on any non-temp table */ - foreach(lp, parsetree->rtable) + foreach(l, parsetree->rtable) { - RangeTblEntry *rte = lfirst(lp); + RangeTblEntry *rte = lfirst(l); if (rte->rtekind == RTE_SUBQUERY) { @@ -521,20 +521,20 @@ InitPlan(QueryDesc *queryDesc, bool explainOnly) * Multiple result relations (due to inheritance) * parseTree->resultRelations identifies them all */ - ResultRelInfo *resultRelInfo; + ResultRelInfo *resultRelInfo; + ListCell *l; numResultRelations = length(resultRelations); resultRelInfos = (ResultRelInfo *) palloc(numResultRelations * sizeof(ResultRelInfo)); resultRelInfo = resultRelInfos; - while (resultRelations != NIL) + foreach(l, resultRelations) { initResultRelInfo(resultRelInfo, - lfirsti(resultRelations), + lfirst_int(l), rangeTable, operation); resultRelInfo++; - resultRelations = lnext(resultRelations); } } else @@ -586,7 +586,7 @@ InitPlan(QueryDesc *queryDesc, bool explainOnly) estate->es_rowMark = NIL; if (parseTree->rowMarks != NIL) { - List *l; + ListCell *l; foreach(l, parseTree->rowMarks) { @@ -651,7 +651,7 @@ InitPlan(QueryDesc *queryDesc, bool explainOnly) */ { bool junk_filter_needed = false; - List *tlist; + ListCell *tlist; switch (operation) { @@ -950,7 +950,7 @@ ExecEndPlan(PlanState *planstate, EState *estate) { ResultRelInfo *resultRelInfo; int i; - List *l; + ListCell *l; /* * shut down any PlanQual processing we were doing @@ -1132,7 +1132,7 @@ lnext: ; } else if (estate->es_rowMark != NIL) { - List *l; + ListCell *l; lmark: ; foreach(l, estate->es_rowMark) @@ -1785,7 +1785,7 @@ EvalPlanQual(EState *estate, Index rti, ItemPointer tid) relation = estate->es_result_relation_info->ri_RelationDesc; else { - List *l; + ListCell *l; relation = NULL; foreach(l, estate->es_rowMark) diff --git a/src/backend/executor/execProcnode.c b/src/backend/executor/execProcnode.c index 4a50c4bc90..dbe1b9b9fd 100644 --- a/src/backend/executor/execProcnode.c +++ b/src/backend/executor/execProcnode.c @@ -12,7 +12,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/execProcnode.c,v 1.42 2004/03/02 22:17:34 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/execProcnode.c,v 1.43 2004/05/26 04:41:15 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -119,7 +119,7 @@ ExecInitNode(Plan *node, EState *estate) { PlanState *result; List *subps; - List *subp; + ListCell *l; /* * do nothing when we get to the end of a leaf on tree. @@ -224,9 +224,9 @@ ExecInitNode(Plan *node, EState *estate) * them in a separate list for us. */ subps = NIL; - foreach(subp, node->initPlan) + foreach(l, node->initPlan) { - SubPlan *subplan = (SubPlan *) lfirst(subp); + SubPlan *subplan = (SubPlan *) lfirst(l); SubPlanState *sstate; Assert(IsA(subplan, SubPlan)); @@ -242,9 +242,9 @@ ExecInitNode(Plan *node, EState *estate) * do this after initializing initPlans, in case their arguments * contain subPlans (is that actually possible? perhaps not). */ - foreach(subp, result->subPlan) + foreach(l, result->subPlan) { - SubPlanState *sstate = (SubPlanState *) lfirst(subp); + SubPlanState *sstate = (SubPlanState *) lfirst(l); Assert(IsA(sstate, SubPlanState)); ExecInitSubPlan(sstate, estate); @@ -483,7 +483,7 @@ ExecCountSlotsNode(Plan *node) void ExecEndNode(PlanState *node) { - List *subp; + ListCell *subp; /* * do nothing when we get to the end of a leaf on tree. diff --git a/src/backend/executor/execQual.c b/src/backend/executor/execQual.c index d44f580be0..9308848964 100644 --- a/src/backend/executor/execQual.c +++ b/src/backend/executor/execQual.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.159 2004/05/10 22:44:43 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.160 2004/05/26 04:41:15 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -217,7 +217,7 @@ ExecEvalArrayRef(ArrayRefExprState *astate, ArrayType *array_source; ArrayType *resultArray; bool isAssignment = (arrayRef->refassgnexpr != NULL); - List *elt; + ListCell *l; int i = 0, j = 0; IntArray upper, @@ -258,9 +258,9 @@ ExecEvalArrayRef(ArrayRefExprState *astate, array_source = NULL; } - foreach(elt, astate->refupperindexpr) + foreach(l, astate->refupperindexpr) { - ExprState *eltstate = (ExprState *) lfirst(elt); + ExprState *eltstate = (ExprState *) lfirst(l); if (i >= MAXDIM) ereport(ERROR, @@ -284,9 +284,9 @@ ExecEvalArrayRef(ArrayRefExprState *astate, if (astate->reflowerindexpr != NIL) { - foreach(elt, astate->reflowerindexpr) + foreach(l, astate->reflowerindexpr) { - ExprState *eltstate = (ExprState *) lfirst(elt); + ExprState *eltstate = (ExprState *) lfirst(l); if (j >= MAXDIM) ereport(ERROR, @@ -798,7 +798,7 @@ ExecEvalFuncArgs(FunctionCallInfo fcinfo, { ExprDoneCond argIsDone; int i; - List *arg; + ListCell *arg; argIsDone = ExprSingleResult; /* default assumption */ @@ -1070,7 +1070,7 @@ ExecMakeFunctionResultNoSets(FuncExprState *fcache, bool *isNull, ExprDoneCond *isDone) { - List *arg; + ListCell *arg; Datum result; FunctionCallInfoData fcinfo; int i; @@ -1703,7 +1703,7 @@ static Datum ExecEvalNot(BoolExprState *notclause, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone) { - ExprState *clause = lfirst(notclause->args); + ExprState *clause = linitial(notclause->args); Datum expr_value; if (isDone) @@ -1734,7 +1734,7 @@ ExecEvalOr(BoolExprState *orExpr, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone) { List *clauses = orExpr->args; - List *clause; + ListCell *clause; bool AnyNull; if (isDone) @@ -1786,7 +1786,7 @@ ExecEvalAnd(BoolExprState *andExpr, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone) { List *clauses = andExpr->args; - List *clause; + ListCell *clause; bool AnyNull; if (isDone) @@ -1802,6 +1802,7 @@ ExecEvalAnd(BoolExprState *andExpr, ExprContext *econtext, * when you interpret NULL as "don't know", using the same sort of * reasoning as for OR, above. */ + foreach(clause, clauses) { ExprState *clausestate = (ExprState *) lfirst(clause); @@ -1838,7 +1839,7 @@ ExecEvalCase(CaseExprState *caseExpr, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone) { List *clauses = caseExpr->args; - List *clause; + ListCell *clause; Datum save_datum; bool save_isNull; @@ -1938,7 +1939,7 @@ ExecEvalArray(ArrayExprState *astate, ExprContext *econtext, { ArrayExpr *arrayExpr = (ArrayExpr *) astate->xprstate.expr; ArrayType *result; - List *element; + ListCell *element; Oid element_type = arrayExpr->element_typeid; int ndims = 0; int dims[MAXDIM]; @@ -2118,7 +2119,7 @@ ExecEvalRow(RowExprState *rstate, Datum *values; char *nulls; int nargs; - List *arg; + ListCell *arg; int i; /* Set default values for result flags: non-null, not a set result */ @@ -2161,7 +2162,7 @@ static Datum ExecEvalCoalesce(CoalesceExprState *coalesceExpr, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone) { - List *arg; + ListCell *arg; if (isDone) *isDone = ExprSingleResult; @@ -2390,7 +2391,7 @@ ExecEvalCoerceToDomain(CoerceToDomainState *cstate, ExprContext *econtext, { CoerceToDomain *ctest = (CoerceToDomain *) cstate->xprstate.expr; Datum result; - List *l; + ListCell *l; result = ExecEvalExpr(cstate->arg, econtext, isNull, isDone); @@ -2826,14 +2827,14 @@ ExecInitExpr(Expr *node, PlanState *parent) CaseExpr *caseexpr = (CaseExpr *) node; CaseExprState *cstate = makeNode(CaseExprState); FastList outlist; - List *inlist; + ListCell *l; cstate->xprstate.evalfunc = (ExprStateEvalFunc) ExecEvalCase; cstate->arg = ExecInitExpr(caseexpr->arg, parent); FastListInit(&outlist); - foreach(inlist, caseexpr->args) + foreach(l, caseexpr->args) { - CaseWhen *when = (CaseWhen *) lfirst(inlist); + CaseWhen *when = (CaseWhen *) lfirst(l); CaseWhenState *wstate = makeNode(CaseWhenState); Assert(IsA(when, CaseWhen)); @@ -2853,13 +2854,13 @@ ExecInitExpr(Expr *node, PlanState *parent) ArrayExpr *arrayexpr = (ArrayExpr *) node; ArrayExprState *astate = makeNode(ArrayExprState); FastList outlist; - List *inlist; + ListCell *l; astate->xprstate.evalfunc = (ExprStateEvalFunc) ExecEvalArray; FastListInit(&outlist); - foreach(inlist, arrayexpr->elements) + foreach(l, arrayexpr->elements) { - Expr *e = (Expr *) lfirst(inlist); + Expr *e = (Expr *) lfirst(l); ExprState *estate; estate = ExecInitExpr(e, parent); @@ -2879,13 +2880,13 @@ ExecInitExpr(Expr *node, PlanState *parent) RowExpr *rowexpr = (RowExpr *) node; RowExprState *rstate = makeNode(RowExprState); List *outlist; - List *inlist; + ListCell *l; rstate->xprstate.evalfunc = (ExprStateEvalFunc) ExecEvalRow; outlist = NIL; - foreach(inlist, rowexpr->args) + foreach(l, rowexpr->args) { - Expr *e = (Expr *) lfirst(inlist); + Expr *e = (Expr *) lfirst(l); ExprState *estate; estate = ExecInitExpr(e, parent); @@ -2912,13 +2913,13 @@ ExecInitExpr(Expr *node, PlanState *parent) CoalesceExpr *coalesceexpr = (CoalesceExpr *) node; CoalesceExprState *cstate = makeNode(CoalesceExprState); FastList outlist; - List *inlist; + ListCell *l; cstate->xprstate.evalfunc = (ExprStateEvalFunc) ExecEvalCoalesce; FastListInit(&outlist); - foreach(inlist, coalesceexpr->args) + foreach(l, coalesceexpr->args) { - Expr *e = (Expr *) lfirst(inlist); + Expr *e = (Expr *) lfirst(l); ExprState *estate; estate = ExecInitExpr(e, parent); @@ -2984,13 +2985,13 @@ ExecInitExpr(Expr *node, PlanState *parent) case T_List: { FastList outlist; - List *inlist; + ListCell *l; FastListInit(&outlist); - foreach(inlist, (List *) node) + foreach(l, (List *) node) { FastAppend(&outlist, - ExecInitExpr((Expr *) lfirst(inlist), + ExecInitExpr((Expr *) lfirst(l), parent)); } /* Don't fall through to the "common" code below */ @@ -3101,7 +3102,7 @@ ExecQual(List *qual, ExprContext *econtext, bool resultForNull) { bool result; MemoryContext oldContext; - List *qlist; + ListCell *l; /* * debugging stuff @@ -3131,9 +3132,9 @@ ExecQual(List *qual, ExprContext *econtext, bool resultForNull) */ result = true; - foreach(qlist, qual) + foreach(l, qual) { - ExprState *clause = (ExprState *) lfirst(qlist); + ExprState *clause = (ExprState *) lfirst(l); Datum expr_value; bool isNull; @@ -3179,7 +3180,7 @@ int ExecCleanTargetListLength(List *targetlist) { int len = 0; - List *tl; + ListCell *tl; foreach(tl, targetlist) { @@ -3219,7 +3220,7 @@ ExecTargetList(List *targetlist, ExprDoneCond *isDone) { MemoryContext oldContext; - List *tl; + ListCell *tl; bool isNull; bool haveDoneSets; diff --git a/src/backend/executor/execScan.c b/src/backend/executor/execScan.c index 2508a9f2b1..9564dd1674 100644 --- a/src/backend/executor/execScan.c +++ b/src/backend/executor/execScan.c @@ -12,7 +12,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/execScan.c,v 1.30 2004/01/22 02:23:21 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/execScan.c,v 1.31 2004/05/26 04:41:15 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -195,6 +195,7 @@ tlist_matches_tupdesc(PlanState *ps, List *tlist, Index varno, TupleDesc tupdesc int numattrs = tupdesc->natts; int attrno; bool hasoid; + ListCell *tlist_item = list_head(tlist); /* Check the tlist attributes */ for (attrno = 1; attrno <= numattrs; attrno++) @@ -202,9 +203,9 @@ tlist_matches_tupdesc(PlanState *ps, List *tlist, Index varno, TupleDesc tupdesc Form_pg_attribute att_tup = tupdesc->attrs[attrno - 1]; Var *var; - if (tlist == NIL) + if (tlist_item == NULL) return false; /* tlist too short */ - var = (Var *) ((TargetEntry *) lfirst(tlist))->expr; + var = (Var *) ((TargetEntry *) lfirst(tlist_item))->expr; if (!var || !IsA(var, Var)) return false; /* tlist item not a Var */ Assert(var->varno == varno); @@ -216,10 +217,10 @@ tlist_matches_tupdesc(PlanState *ps, List *tlist, Index varno, TupleDesc tupdesc Assert(var->vartype == att_tup->atttypid); Assert(var->vartypmod == att_tup->atttypmod); - tlist = lnext(tlist); + tlist_item = lnext(tlist_item); } - if (tlist) + if (tlist_item) return false; /* tlist too long */ /* diff --git a/src/backend/executor/execTuples.c b/src/backend/executor/execTuples.c index 725b8fea0f..a28735c0f1 100644 --- a/src/backend/executor/execTuples.c +++ b/src/backend/executor/execTuples.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/execTuples.c,v 1.77 2004/05/10 22:44:44 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/execTuples.c,v 1.78 2004/05/26 04:41:15 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -569,7 +569,7 @@ static TupleDesc ExecTypeFromTLInternal(List *targetList, bool hasoid, bool skipjunk) { TupleDesc typeInfo; - List *l; + ListCell *l; int len; int cur_resno = 1; @@ -606,7 +606,7 @@ TupleDesc ExecTypeFromExprList(List *exprList) { TupleDesc typeInfo; - List *l; + ListCell *l; int cur_resno = 1; char fldname[NAMEDATALEN]; diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c index 9702b1cf0a..811ec513e0 100644 --- a/src/backend/executor/execUtils.c +++ b/src/backend/executor/execUtils.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/execUtils.c,v 1.110 2004/03/17 20:48:42 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/execUtils.c,v 1.111 2004/05/26 04:41:15 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -248,7 +248,10 @@ FreeExecutorState(EState *estate) */ while (estate->es_exprcontexts) { - FreeExprContext((ExprContext *) lfirst(estate->es_exprcontexts)); + /* XXX: seems there ought to be a faster way to implement this + * than repeated lremove(), no? + */ + FreeExprContext((ExprContext *) linitial(estate->es_exprcontexts)); /* FreeExprContext removed the list link for us */ } @@ -636,8 +639,8 @@ void ExecOpenIndices(ResultRelInfo *resultRelInfo) { Relation resultRelation = resultRelInfo->ri_RelationDesc; - List *indexoidlist, - *indexoidscan; + List *indexoidlist; + ListCell *l; int len, i; RelationPtr relationDescs; @@ -671,9 +674,9 @@ ExecOpenIndices(ResultRelInfo *resultRelInfo) * For each index, open the index relation and save pg_index info. */ i = 0; - foreach(indexoidscan, indexoidlist) + foreach(l, indexoidlist) { - Oid indexOid = lfirsto(indexoidscan); + Oid indexOid = lfirsto(l); Relation indexDesc; IndexInfo *ii; diff --git a/src/backend/executor/functions.c b/src/backend/executor/functions.c index c07eac5faf..2e75813a2a 100644 --- a/src/backend/executor/functions.c +++ b/src/backend/executor/functions.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.80 2004/04/02 23:14:08 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.81 2004/05/26 04:41:15 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -92,7 +92,7 @@ init_execution_state(List *queryTree_list) { execution_state *firstes = NULL; execution_state *preves = NULL; - List *qtl_item; + ListCell *qtl_item; foreach(qtl_item, queryTree_list) { diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c index 0a87222127..9884cfecd3 100644 --- a/src/backend/executor/nodeAgg.c +++ b/src/backend/executor/nodeAgg.c @@ -45,7 +45,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeAgg.c,v 1.119 2004/03/13 00:54:10 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeAgg.c,v 1.120 2004/05/26 04:41:15 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -1033,7 +1033,7 @@ ExecInitAgg(Agg *node, EState *estate) ExprContext *econtext; int numaggs, aggno; - List *alist; + ListCell *l; /* * create state structure @@ -1187,9 +1187,9 @@ ExecInitAgg(Agg *node, EState *estate) * result entry by giving them duplicate aggno values. */ aggno = -1; - foreach(alist, aggstate->aggs) + foreach(l, aggstate->aggs) { - AggrefExprState *aggrefstate = (AggrefExprState *) lfirst(alist); + AggrefExprState *aggrefstate = (AggrefExprState *) lfirst(l); Aggref *aggref = (Aggref *) aggrefstate->xprstate.expr; AggStatePerAgg peraggstate; Oid inputType; diff --git a/src/backend/executor/nodeAppend.c b/src/backend/executor/nodeAppend.c index c0d74c4778..f23554e0bc 100644 --- a/src/backend/executor/nodeAppend.c +++ b/src/backend/executor/nodeAppend.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeAppend.c,v 1.56 2004/01/22 02:23:21 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeAppend.c,v 1.57 2004/05/26 04:41:15 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -237,7 +237,7 @@ ExecInitAppend(Append *node, EState *estate) int ExecCountSlotsAppend(Append *node) { - List *plan; + ListCell *plan; int nSlots = 0; foreach(plan, node->appendplans) diff --git a/src/backend/executor/nodeFunctionscan.c b/src/backend/executor/nodeFunctionscan.c index 7847b24ffe..55aa120ec9 100644 --- a/src/backend/executor/nodeFunctionscan.c +++ b/src/backend/executor/nodeFunctionscan.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeFunctionscan.c,v 1.24 2004/04/01 21:28:44 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeFunctionscan.c,v 1.25 2004/05/26 04:41:15 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -201,7 +201,7 @@ ExecInitFunctionScan(FunctionScan *node, EState *estate) else if (functyptype == 'b' || functyptype == 'd') { /* Must be a base data type, i.e. scalar */ - char *attname = strVal(lfirst(rte->eref->colnames)); + char *attname = strVal(linitial(rte->eref->colnames)); tupdesc = CreateTemplateTupleDesc(1, false); TupleDescInitEntry(tupdesc, diff --git a/src/backend/executor/nodeHash.c b/src/backend/executor/nodeHash.c index a6a386f97f..bf9ed89e94 100644 --- a/src/backend/executor/nodeHash.c +++ b/src/backend/executor/nodeHash.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeHash.c,v 1.83 2004/03/17 01:02:23 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeHash.c,v 1.84 2004/05/26 04:41:15 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -202,7 +202,7 @@ ExecHashTableCreate(Hash *node, List *hashOperators) int nbatch; int nkeys; int i; - List *ho; + ListCell *ho; MemoryContext oldcxt; /* @@ -518,7 +518,7 @@ ExecHashGetBucket(HashJoinTable hashtable, { uint32 hashkey = 0; int bucketno; - List *hk; + ListCell *hk; int i = 0; MemoryContext oldContext; diff --git a/src/backend/executor/nodeHashjoin.c b/src/backend/executor/nodeHashjoin.c index f0c1ee69e6..da2f6cdac8 100644 --- a/src/backend/executor/nodeHashjoin.c +++ b/src/backend/executor/nodeHashjoin.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeHashjoin.c,v 1.60 2004/01/07 18:56:26 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeHashjoin.c,v 1.61 2004/05/26 04:41:15 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -311,7 +311,7 @@ ExecInitHashJoin(HashJoin *node, EState *estate) List *lclauses; List *rclauses; List *hoperators; - List *hcl; + ListCell *l; /* * create state structure @@ -419,15 +419,15 @@ ExecInitHashJoin(HashJoin *node, EState *estate) lclauses = NIL; rclauses = NIL; hoperators = NIL; - foreach(hcl, hjstate->hashclauses) + foreach(l, hjstate->hashclauses) { - FuncExprState *fstate = (FuncExprState *) lfirst(hcl); + FuncExprState *fstate = (FuncExprState *) lfirst(l); OpExpr *hclause; Assert(IsA(fstate, FuncExprState)); hclause = (OpExpr *) fstate->xprstate.expr; Assert(IsA(hclause, OpExpr)); - lclauses = lappend(lclauses, lfirst(fstate->args)); + lclauses = lappend(lclauses, linitial(fstate->args)); rclauses = lappend(rclauses, lsecond(fstate->args)); hoperators = lappendo(hoperators, hclause->opno); } diff --git a/src/backend/executor/nodeIndexscan.c b/src/backend/executor/nodeIndexscan.c index a68dbf1dca..c306e4563b 100644 --- a/src/backend/executor/nodeIndexscan.c +++ b/src/backend/executor/nodeIndexscan.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeIndexscan.c,v 1.93 2004/04/21 18:24:26 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeIndexscan.c,v 1.94 2004/05/26 04:41:16 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -146,7 +146,7 @@ IndexNext(IndexScanState *node) if (estate->es_evTuple != NULL && estate->es_evTuple[scanrelid - 1] != NULL) { - List *qual; + ListCell *qual; if (estate->es_evTupleNull[scanrelid - 1]) return slot; /* return empty slot */ @@ -164,7 +164,7 @@ IndexNext(IndexScanState *node) if (ExecQual((List *) lfirst(qual), econtext, false)) break; } - if (qual == NIL) /* would not be returned by indices */ + if (qual == NULL) /* would not be returned by indices */ slot->val = NULL; /* Flag for the next call that no more tuples */ @@ -283,11 +283,11 @@ IndexNext(IndexScanState *node) { bool prev_matches = false; int prev_index; - List *qual; + ListCell *qual; econtext->ecxt_scantuple = slot; ResetExprContext(econtext); - qual = node->indxqualorig; + qual = list_head(node->indxqualorig); for (prev_index = 0; prev_index < node->iss_IndexPtr; prev_index++) @@ -641,11 +641,11 @@ IndexScanState * ExecInitIndexScan(IndexScan *node, EState *estate) { IndexScanState *indexstate; - List *indxqual; - List *indxstrategy; - List *indxsubtype; - List *indxlossy; - List *indxid; + ListCell *indxqual; + ListCell *indxstrategy; + ListCell *indxsubtype; + ListCell *indxlossy; + ListCell *indxid_item; int i; int numIndices; int indexPtr; @@ -719,8 +719,8 @@ ExecInitIndexScan(IndexScan *node, EState *estate) /* * get the index node information */ - indxid = node->indxid; - numIndices = length(indxid); + indxid_item = list_head(node->indxid); + numIndices = length(node->indxid); indexPtr = -1; CXT1_printf("ExecInitIndexScan: context is %d\n", CurrentMemoryContext); @@ -745,28 +745,32 @@ ExecInitIndexScan(IndexScan *node, EState *estate) /* * build the index scan keys from the index qualification */ - indxqual = node->indxqual; - indxstrategy = node->indxstrategy; - indxsubtype = node->indxsubtype; - indxlossy = node->indxlossy; + indxqual = list_head(node->indxqual); + indxstrategy = list_head(node->indxstrategy); + indxsubtype = list_head(node->indxsubtype); + indxlossy = list_head(node->indxlossy); for (i = 0; i < numIndices; i++) { List *quals; List *strategies; List *subtypes; List *lossyflags; + ListCell *qual_cell; + ListCell *strategy_cell; + ListCell *subtype_cell; + ListCell *lossyflag_cell; int n_keys; ScanKey scan_keys; ExprState **run_keys; int j; - quals = lfirst(indxqual); + quals = (List *) lfirst(indxqual); indxqual = lnext(indxqual); - strategies = lfirst(indxstrategy); + strategies = (List *) lfirst(indxstrategy); indxstrategy = lnext(indxstrategy); - subtypes = lfirst(indxsubtype); + subtypes = (List *) lfirst(indxsubtype); indxsubtype = lnext(indxsubtype); - lossyflags = lfirst(indxlossy); + lossyflags = (List *) lfirst(indxlossy); indxlossy = lnext(indxlossy); n_keys = length(quals); scan_keys = (n_keys <= 0) ? NULL : @@ -778,6 +782,10 @@ ExecInitIndexScan(IndexScan *node, EState *estate) * for each opclause in the given qual, convert each qual's * opclause into a single scan key */ + qual_cell = list_head(quals); + strategy_cell = list_head(strategies); + subtype_cell = list_head(subtypes); + lossyflag_cell = list_head(lossyflags); for (j = 0; j < n_keys; j++) { OpExpr *clause; /* one clause of index qual */ @@ -794,14 +802,14 @@ ExecInitIndexScan(IndexScan *node, EState *estate) /* * extract clause information from the qualification */ - clause = (OpExpr *) lfirst(quals); - quals = lnext(quals); - strategy = lfirsti(strategies); - strategies = lnext(strategies); - subtype = lfirsto(subtypes); - subtypes = lnext(subtypes); - lossy = lfirsti(lossyflags); - lossyflags = lnext(lossyflags); + clause = (OpExpr *) lfirst(qual_cell); + qual_cell = lnext(qual_cell); + strategy = lfirsti(strategy_cell); + strategy_cell = lnext(strategy_cell); + subtype = lfirsto(subtype_cell); + subtype_cell = lnext(subtype_cell); + lossy = lfirsti(lossyflag_cell); + lossyflag_cell = lnext(lossyflag_cell); if (!IsA(clause, OpExpr)) elog(ERROR, "indxqual is not an OpExpr"); @@ -972,7 +980,7 @@ ExecInitIndexScan(IndexScan *node, EState *estate) */ for (i = 0; i < numIndices; i++) { - Oid indexOid = lfirsto(indxid); + Oid indexOid = lfirsto(indxid_item); indexDescs[i] = index_open(indexOid); scanDescs[i] = index_beginscan(currentRelation, @@ -980,7 +988,7 @@ ExecInitIndexScan(IndexScan *node, EState *estate) estate->es_snapshot, numScanKeys[i], scanKeys[i]); - indxid = lnext(indxid); + indxid_item = lnext(indxid_item); } indexstate->iss_RelationDescs = indexDescs; diff --git a/src/backend/executor/nodeMergejoin.c b/src/backend/executor/nodeMergejoin.c index 9c44102611..e9ca17317e 100644 --- a/src/backend/executor/nodeMergejoin.c +++ b/src/backend/executor/nodeMergejoin.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeMergejoin.c,v 1.64 2004/03/17 01:02:23 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeMergejoin.c,v 1.65 2004/05/26 04:41:16 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -104,10 +104,10 @@ static void MJFormSkipQuals(List *qualList, List **ltQuals, List **gtQuals, PlanState *parent) { - List *ltexprs, - *gtexprs, - *ltcdr, - *gtcdr; + List *ltexprs, + *gtexprs; + ListCell *ltcdr, + *gtcdr; /* * Make modifiable copies of the qualList. @@ -119,8 +119,7 @@ MJFormSkipQuals(List *qualList, List **ltQuals, List **gtQuals, * Scan both lists in parallel, so that we can update the operators * with the minimum number of syscache searches. */ - ltcdr = ltexprs; - foreach(gtcdr, gtexprs) + forboth(ltcdr, ltexprs, gtcdr, gtexprs) { OpExpr *ltop = (OpExpr *) lfirst(ltcdr); OpExpr *gtop = (OpExpr *) lfirst(gtcdr); @@ -140,8 +139,6 @@ MJFormSkipQuals(List *qualList, List **ltQuals, List **gtQuals, >op->opno, <op->opfuncid, >op->opfuncid); - - ltcdr = lnext(ltcdr); } /* @@ -173,8 +170,8 @@ MergeCompare(List *eqQual, List *compareQual, ExprContext *econtext) { bool result; MemoryContext oldContext; - List *clause; - List *eqclause; + ListCell *clause; + ListCell *eqclause; /* * Do expression eval in short-lived context. @@ -188,8 +185,12 @@ MergeCompare(List *eqQual, List *compareQual, ExprContext *econtext) */ result = false; /* assume 'false' result */ - eqclause = eqQual; - foreach(clause, compareQual) + /* + * We can't run out of one list before the other + */ + Assert(length(compareQual) == length(eqQual)); + + forboth(clause, compareQual, eqclause, eqQual) { ExprState *clauseexpr = (ExprState *) lfirst(clause); ExprState *eqclauseexpr = (ExprState *) lfirst(eqclause); @@ -220,8 +221,6 @@ MergeCompare(List *eqQual, List *compareQual, ExprContext *econtext) if (!DatumGetBool(const_value) || isNull) break; /* return false */ - - eqclause = lnext(eqclause); } MemoryContextSwitchTo(oldContext); diff --git a/src/backend/executor/nodeSubplan.c b/src/backend/executor/nodeSubplan.c index 8c667b70e7..d7db23b2c3 100644 --- a/src/backend/executor/nodeSubplan.c +++ b/src/backend/executor/nodeSubplan.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeSubplan.c,v 1.61 2004/03/17 01:02:23 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeSubplan.c,v 1.62 2004/05/26 04:41:16 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -212,8 +212,8 @@ ExecScanSubPlan(SubPlanState *node, TupleTableSlot *slot; Datum result; bool found = false; /* TRUE if got at least one subplan tuple */ - List *pvar; - List *lst; + ListCell *pvar; + ListCell *l; ArrayBuildState *astate = NULL; /* @@ -228,21 +228,19 @@ ExecScanSubPlan(SubPlanState *node, * calculation we have to do is done in the parent econtext, since the * Param values don't need to have per-query lifetime.) */ - pvar = node->args; - foreach(lst, subplan->parParam) + Assert(length(subplan->parParam) == length(node->args)); + + forboth(l, subplan->parParam, pvar, node->args) { - int paramid = lfirsti(lst); + int paramid = lfirst_int(l); ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]); - Assert(pvar != NIL); prm->value = ExecEvalExprSwitchContext((ExprState *) lfirst(pvar), econtext, &(prm->isnull), NULL); - pvar = lnext(pvar); planstate->chgParam = bms_add_member(planstate->chgParam, paramid); } - Assert(pvar == NIL); ExecReScan(planstate, NULL); @@ -278,7 +276,7 @@ ExecScanSubPlan(SubPlanState *node, Datum rowresult = BoolGetDatum(!useOr); bool rownull = false; int col = 1; - List *plst; + ListCell *plst; if (subLinkType == EXISTS_SUBLINK) { @@ -343,11 +341,12 @@ ExecScanSubPlan(SubPlanState *node, * For ALL, ANY, and MULTIEXPR sublinks, iterate over combining * operators for columns of tuple. */ - plst = subplan->paramIds; - foreach(lst, node->exprs) + Assert(length(node->exprs) == length(subplan->paramIds)); + + forboth(l, node->exprs, plst, subplan->paramIds) { - ExprState *exprstate = (ExprState *) lfirst(lst); - int paramid = lfirsti(plst); + ExprState *exprstate = (ExprState *) lfirst(l); + int paramid = lfirst_int(plst); ParamExecData *prmdata; Datum expresult; bool expnull; @@ -400,7 +399,6 @@ ExecScanSubPlan(SubPlanState *node, } } - plst = lnext(plst); col++; } @@ -559,7 +557,7 @@ buildSubPlanHash(SubPlanState *node) HeapTuple tup = slot->val; TupleDesc tdesc = slot->ttc_tupleDescriptor; int col = 1; - List *plst; + ListCell *plst; bool isnew; /* @@ -737,7 +735,7 @@ ExecInitSubPlan(SubPlanState *node, EState *estate) */ if (subplan->setParam != NIL) { - List *lst; + ListCell *lst; foreach(lst, subplan->setParam) { @@ -762,8 +760,8 @@ ExecInitSubPlan(SubPlanState *node, EState *estate) List *lefttlist, *righttlist, *leftptlist, - *rightptlist, - *lexpr; + *rightptlist; + ListCell *lexpr; /* We need a memory context to hold the hash table(s) */ node->tablecxt = @@ -815,7 +813,7 @@ ExecInitSubPlan(SubPlanState *node, EState *estate) Assert(length(fstate->args) == 2); /* Process lefthand argument */ - exstate = (ExprState *) lfirst(fstate->args); + exstate = (ExprState *) linitial(fstate->args); expr = exstate->expr; tle = makeTargetEntry(makeResdom(i, exprType((Node *) expr), @@ -914,7 +912,7 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext) SubLinkType subLinkType = subplan->subLinkType; MemoryContext oldcontext; TupleTableSlot *slot; - List *lst; + ListCell *l; bool found = false; ArrayBuildState *astate = NULL; @@ -941,7 +939,7 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext) if (subLinkType == EXISTS_SUBLINK) { /* There can be only one param... */ - int paramid = lfirsti(subplan->setParam); + int paramid = linitial_int(subplan->setParam); ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]); prm->execPlan = NULL; @@ -992,9 +990,9 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext) /* * Now set all the setParam params from the columns of the tuple */ - foreach(lst, subplan->setParam) + foreach(l, subplan->setParam) { - int paramid = lfirsti(lst); + int paramid = lfirsti(l); ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]); prm->execPlan = NULL; @@ -1008,7 +1006,7 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext) if (subLinkType == EXISTS_SUBLINK) { /* There can be only one param... */ - int paramid = lfirsti(subplan->setParam); + int paramid = linitial_int(subplan->setParam); ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]); prm->execPlan = NULL; @@ -1017,9 +1015,9 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext) } else { - foreach(lst, subplan->setParam) + foreach(l, subplan->setParam) { - int paramid = lfirsti(lst); + int paramid = lfirsti(l); ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]); prm->execPlan = NULL; @@ -1031,7 +1029,7 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext) else if (subLinkType == ARRAY_SUBLINK) { /* There can be only one param... */ - int paramid = lfirsti(subplan->setParam); + int paramid = linitial_int(subplan->setParam); ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]); Assert(astate != NULL); @@ -1074,7 +1072,7 @@ ExecReScanSetParamPlan(SubPlanState *node, PlanState *parent) PlanState *planstate = node->planstate; SubPlan *subplan = (SubPlan *) node->xprstate.expr; EState *estate = parent->state; - List *lst; + ListCell *l; /* sanity checks */ if (subplan->parParam != NIL) @@ -1091,9 +1089,9 @@ ExecReScanSetParamPlan(SubPlanState *node, PlanState *parent) /* * Mark this subplan's output parameters as needing recalculation */ - foreach(lst, subplan->setParam) + foreach(l, subplan->setParam) { - int paramid = lfirsti(lst); + int paramid = lfirsti(l); ParamExecData *prm = &(estate->es_param_exec_vals[paramid]); prm->execPlan = node; diff --git a/src/backend/executor/nodeTidscan.c b/src/backend/executor/nodeTidscan.c index ee928deff5..0d321b0866 100644 --- a/src/backend/executor/nodeTidscan.c +++ b/src/backend/executor/nodeTidscan.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeTidscan.c,v 1.37 2004/04/21 18:24:26 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeTidscan.c,v 1.38 2004/05/26 04:41:16 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -45,18 +45,18 @@ TidListCreate(TidScanState *tidstate) ExprContext *econtext = tidstate->ss.ps.ps_ExprContext; ItemPointerData *tidList; int numTids = 0; - List *lst; + ListCell *l; tidList = (ItemPointerData *) palloc(length(tidstate->tss_tideval) * sizeof(ItemPointerData)); - foreach(lst, evalList) + foreach(l, evalList) { ItemPointer itemptr; bool isNull; itemptr = (ItemPointer) - DatumGetPointer(ExecEvalExprSwitchContext(lfirst(lst), + DatumGetPointer(ExecEvalExprSwitchContext(lfirst(l), econtext, &isNull, NULL)); diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index bcf7f8d52b..4d8fade3d6 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.113 2004/04/01 21:28:44 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.114 2004/05/26 04:41:16 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -744,8 +744,8 @@ SPI_cursor_open(const char *name, void *plan, Datum *Values, const char *Nulls) ereport(ERROR, (errcode(ERRCODE_INVALID_CURSOR_DEFINITION), errmsg("cannot open multi-query plan as cursor"))); - queryTree = (Query *) lfirst((List *) lfirst(qtlist)); - planTree = (Plan *) lfirst(ptlist); + queryTree = (Query *) linitial((List *) linitial(qtlist)); + planTree = (Plan *) linitial(ptlist); if (queryTree->commandType != CMD_SELECT) ereport(ERROR, @@ -953,7 +953,7 @@ SPI_is_cursor_plan(void *plan) qtlist = spiplan->qtlist; if (length(spiplan->ptlist) == 1 && length(qtlist) == 1) { - Query *queryTree = (Query *) lfirst((List *) lfirst(qtlist)); + Query *queryTree = (Query *) linitial((List *) linitial(qtlist)); if (queryTree->commandType == CMD_SELECT && queryTree->into == NULL) return true; @@ -1062,7 +1062,7 @@ _SPI_execute(const char *src, int tcount, _SPI_plan *plan) List *raw_parsetree_list; List *query_list_list; List *plan_list; - List *list_item; + ListCell *list_item; ErrorContextCallback spierrcontext; int nargs = 0; Oid *argtypes = NULL; @@ -1110,7 +1110,7 @@ _SPI_execute(const char *src, int tcount, _SPI_plan *plan) { Node *parsetree = (Node *) lfirst(list_item); List *query_list; - List *query_list_item; + ListCell *query_list_item; query_list = pg_analyze_and_rewrite(parsetree, argtypes, nargs); @@ -1207,8 +1207,8 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, const char *Nulls, bool useCurrentSnapshot, int tcount) { List *query_list_list = plan->qtlist; - List *plan_list = plan->ptlist; - List *query_list_list_item; + ListCell *plan_list_item = list_head(plan->ptlist); + ListCell *query_list_list_item; ErrorContextCallback spierrcontext; int nargs = plan->nargs; int res = 0; @@ -1254,7 +1254,7 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, const char *Nulls, foreach(query_list_list_item, query_list_list) { List *query_list = lfirst(query_list_list_item); - List *query_list_item; + ListCell *query_list_item; /* Reset state for each original parsetree */ /* (at most one of its querytrees will be marked canSetTag) */ @@ -1270,8 +1270,8 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, const char *Nulls, QueryDesc *qdesc; DestReceiver *dest; - planTree = lfirst(plan_list); - plan_list = lnext(plan_list); + planTree = lfirst(plan_list_item); + plan_list_item = lnext(plan_list_item); dest = CreateDestReceiver(queryTree->canSetTag ? SPI : None, NULL); if (queryTree->commandType == CMD_UTILITY) diff --git a/src/backend/libpq/crypt.c b/src/backend/libpq/crypt.c index 8b8fa6abf9..dda111fc68 100644 --- a/src/backend/libpq/crypt.c +++ b/src/backend/libpq/crypt.c @@ -9,7 +9,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/libpq/crypt.c,v 1.58 2003/11/29 19:51:49 pgsql Exp $ + * $PostgreSQL: pgsql/src/backend/libpq/crypt.c,v 1.59 2004/05/26 04:41:18 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -36,14 +36,14 @@ md5_crypt_verify(const Port *port, const char *user, char *client_pass) *crypt_pwd; int retval = STATUS_ERROR; List **line; - List *token; + ListCell *token; char *crypt_client_pass = client_pass; if ((line = get_user_line(user)) == NULL) return STATUS_ERROR; - /* Skip over line number and username */ - token = lnext(lnext(*line)); + /* Skip over username */ + token = lnext(list_head(*line)); if (token) { shadow_pass = lfirst(token); diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c index d4204acfd5..25666af690 100644 --- a/src/backend/libpq/hba.c +++ b/src/backend/libpq/hba.c @@ -10,12 +10,14 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.122 2004/05/25 19:11:14 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.123 2004/05/26 04:41:18 neilc Exp $ * *------------------------------------------------------------------------- */ #include "postgres.h" +#define DISABLE_LIST_COMPAT + #include #include #include @@ -63,11 +65,19 @@ * one string per token on the line. Note there will always be at least * one token, since blank lines are not entered in the data structure. */ -static List *hba_lines = NIL; /* pre-parsed contents of hba file */ -static List *ident_lines = NIL; /* pre-parsed contents of ident file */ -static List *group_lines = NIL; /* pre-parsed contents of group file */ -static List *user_lines = NIL; /* pre-parsed contents of user password - * file */ + +/* pre-parsed content of CONF_FILE and corresponding line #s */ +static List *hba_lines = NIL; +static List *hba_line_nums = NIL; +/* pre-parsed content of USERMAP_FILE and corresponding line #s */ +static List *ident_lines = NIL; +static List *ident_line_nums = NIL; +/* pre-parsed content of group file and corresponding line #s */ +static List *group_lines = NIL; +static List *group_line_nums = NIL; +/* pre-parsed content of user passwd file and corresponding line #s */ +static List *user_lines = NIL; +static List *user_line_nums = NIL; /* sorted entries so we can do binary search lookups */ static List **user_sorted = NULL; /* sorted user list, for bsearch() */ @@ -76,7 +86,7 @@ static List **group_sorted = NULL; /* sorted group list, for static int user_length; static int group_length; -static List *tokenize_file(FILE *file); +static void tokenize_file(FILE *file, List **lines, List **line_nums); static char *tokenize_inc_file(const char *inc_filename); /* @@ -250,28 +260,45 @@ next_token_expand(FILE *file) * Free memory used by lines/tokens (i.e., structure built by tokenize_file) */ static void -free_lines(List **lines) +free_lines(List **lines, List **line_nums) { + /* + * Either both must be non-NULL, or both must be NULL + */ + Assert((*lines != NIL && *line_nums != NIL) || + (*lines == NIL && *line_nums == NIL)); + if (*lines) { - List *line, - *token; + /* + * "lines" is a list of lists; each of those sublists consists + * of palloc'ed tokens, so we want to free each pointed-to + * token in a sublist, followed by the sublist itself, and + * finally the whole list. + */ + ListCell *line; foreach(line, *lines) { List *ln = lfirst(line); + ListCell *token; - /* free the pstrdup'd tokens (don't try it on the line number) */ - foreach(token, lnext(ln)) + foreach(token, ln) pfree(lfirst(token)); /* free the sublist structure itself */ - freeList(ln); + list_free(ln); } /* free the list structure itself */ - freeList(*lines); + list_free(*lines); /* clear the static variable */ *lines = NIL; } + + if (*line_nums) + { + list_free(*line_nums); + *line_nums = NIL; + } } @@ -281,7 +308,8 @@ tokenize_inc_file(const char *inc_filename) char *inc_fullname; FILE *inc_file; List *inc_lines; - List *line; + List *inc_line_nums; + ListCell *line; char *comma_str = pstrdup(""); inc_fullname = (char *) palloc(strlen(DataDir) + 1 + @@ -305,17 +333,16 @@ tokenize_inc_file(const char *inc_filename) pfree(inc_fullname); /* There is possible recursion here if the file contains @ */ - inc_lines = tokenize_file(inc_file); + tokenize_file(inc_file, &inc_lines, &inc_line_nums); FreeFile(inc_file); /* Create comma-separate string from List */ foreach(line, inc_lines) { - List *ln = lfirst(line); - List *token; + List *token_list = (List *) lfirst(line); + ListCell *token; - /* First entry is line number */ - foreach(token, lnext(ln)) + foreach(token, token_list) { if (strlen(comma_str)) { @@ -328,24 +355,26 @@ tokenize_inc_file(const char *inc_filename) } } - free_lines(&inc_lines); + free_lines(&inc_lines, &inc_line_nums); return comma_str; } - /* - * Read the given file and create a list of line sublists. + * Tokenize the given file, storing the resulting data into two lists: + * a list of sublists, each sublist containing the tokens in a line of + * the file, and a list of line numbers. */ -static List * -tokenize_file(FILE *file) +static void +tokenize_file(FILE *file, List **lines, List **line_nums) { - List *lines = NIL; - List *next_line = NIL; + List *current_line = NIL; int line_number = 1; char *buf; + *lines = *line_nums = NIL; + while (!feof(file)) { buf = next_token_expand(file); @@ -353,27 +382,27 @@ tokenize_file(FILE *file) /* add token to list, unless we are at EOL or comment start */ if (buf[0] != '\0') { - if (next_line == NIL) + if (current_line == NIL) + { + /* make a new line List, record its line number */ + current_line = lappend(current_line, buf); + *lines = lappend(*lines, current_line); + *line_nums = lappend_int(*line_nums, line_number); + } + else { - /* make a new line List */ - next_line = makeListi1(line_number); - lines = lappend(lines, next_line); + /* append token to current line's list */ + current_line = lappend(current_line, buf); } - /* append token to current line's list */ - next_line = lappend(next_line, buf); } else { /* we are at real or logical EOL, so force a new line List */ - next_line = NIL; - } - - /* Advance line number whenever we reach EOL */ - if (next_line == NIL) + current_line = NIL; + /* Advance line number whenever we reach EOL */ line_number++; + } } - - return lines; } @@ -385,9 +414,8 @@ tokenize_file(FILE *file) static int user_group_qsort_cmp(const void *list1, const void *list2) { - /* first node is line number */ - char *user1 = lfirst(lnext(*(List **) list1)); - char *user2 = lfirst(lnext(*(List **) list2)); + char *user1 = linitial(*(List **) list1); + char *user2 = linitial(*(List **) list2); return strcmp(user1, user2); } @@ -401,8 +429,7 @@ user_group_qsort_cmp(const void *list1, const void *list2) static int user_group_bsearch_cmp(const void *user, const void *list) { - /* first node is line number */ - char *user2 = lfirst(lnext(*(List **) list)); + char *user2 = linitial(*(List **) list); return strcmp(user, user2); } @@ -450,14 +477,18 @@ get_user_line(const char *user) static bool check_group(char *group, char *user) { - List **line, - *l; + List **line; if ((line = get_group_line(group)) != NULL) { - foreach(l, lnext(lnext(*line))) - if (strcmp(lfirst(l), user) == 0) - return true; + ListCell *line_item; + + /* skip over the group name */ + for_each_cell(line_item, lnext(list_head(*line))) + { + if (strcmp(lfirst(line_item), user) == 0) + return true; + } } return false; @@ -518,24 +549,24 @@ check_db(char *dbname, char *user, char *param_str) /* * Scan the rest of a host record (after the mask field) * and return the interpretation of it as *userauth_p, *auth_arg_p, and - * *error_p. *line points to the next token of the line, and is + * *error_p. *line_item points to the next token of the line, and is * advanced over successfully-read tokens. */ static void -parse_hba_auth(List **line, UserAuth *userauth_p, char **auth_arg_p, - bool *error_p) +parse_hba_auth(ListCell **line_item, UserAuth *userauth_p, + char **auth_arg_p, bool *error_p) { char *token; *auth_arg_p = NULL; - /* Get authentication type token. */ - if (!*line) + if (!*line_item) { *error_p = true; return; } - token = lfirst(*line); + + token = lfirst(*line_item); if (strcmp(token, "trust") == 0) *userauth_p = uaTrust; else if (strcmp(token, "ident") == 0) @@ -561,16 +592,16 @@ parse_hba_auth(List **line, UserAuth *userauth_p, char **auth_arg_p, *error_p = true; return; } - *line = lnext(*line); + *line_item = lnext(*line_item); /* Get the authentication argument token, if any */ - if (*line) + if (*line_item) { - token = lfirst(*line); + token = lfirst(*line_item); *auth_arg_p = pstrdup(token); - *line = lnext(*line); + *line_item = lnext(*line_item); /* If there is more on the line, it is an error */ - if (*line) + if (*line_item) *error_p = true; } } @@ -587,9 +618,9 @@ parse_hba_auth(List **line, UserAuth *userauth_p, char **auth_arg_p, * leave *error_p as it was. */ static void -parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p) +parse_hba(List *line, int line_num, hbaPort *port, + bool *found_p, bool *error_p) { - int line_number; char *token; char *db; char *user; @@ -599,33 +630,32 @@ parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p) struct sockaddr_storage addr; struct sockaddr_storage mask; char *cidr_slash; + ListCell *line_item; - Assert(line != NIL); - line_number = lfirsti(line); - line = lnext(line); - Assert(line != NIL); + line_item = list_head(line); /* Check the record type. */ - token = lfirst(line); + token = lfirst(line_item); if (strcmp(token, "local") == 0) { /* Get the database. */ - line = lnext(line); - if (!line) + line_item = lnext(line_item); + if (!line_item) goto hba_syntax; - db = lfirst(line); + db = lfirst(line_item); /* Get the user. */ - line = lnext(line); - if (!line) + line_item = lnext(line_item); + if (!line_item) goto hba_syntax; - user = lfirst(line); + user = lfirst(line_item); - line = lnext(line); - if (!line) + line_item = lnext(line_item); + if (!line_item) goto hba_syntax; /* Read the rest of the line. */ - parse_hba_auth(&line, &port->auth_method, &port->auth_arg, error_p); + parse_hba_auth(&line_item, &port->auth_method, + &port->auth_arg, error_p); if (*error_p) goto hba_syntax; @@ -669,22 +699,22 @@ parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p) #endif /* Get the database. */ - line = lnext(line); - if (!line) + line_item = lnext(line_item); + if (!line_item) goto hba_syntax; - db = lfirst(line); + db = lfirst(line_item); /* Get the user. */ - line = lnext(line); - if (!line) + line_item = lnext(line_item); + if (!line_item) goto hba_syntax; - user = lfirst(line); + user = lfirst(line_item); /* Read the IP address field. (with or without CIDR netmask) */ - line = lnext(line); - if (!line) + line_item = lnext(line_item); + if (!line_item) goto hba_syntax; - token = lfirst(line); + token = lfirst(line_item); /* Check if it has a CIDR suffix and if so isolate it */ cidr_slash = strchr(token, '/'); @@ -707,7 +737,7 @@ parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p) ereport(LOG, (errcode(ERRCODE_CONFIG_FILE_ERROR), errmsg("invalid IP address \"%s\" in pg_hba.conf file line %d: %s", - token, line_number, gai_strerror(ret)))); + token, line_num, gai_strerror(ret)))); if (cidr_slash) *cidr_slash = '/'; if (gai_result) @@ -730,10 +760,10 @@ parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p) else { /* Read the mask field. */ - line = lnext(line); - if (!line) + line_item = lnext(line_item); + if (!line_item) goto hba_syntax; - token = lfirst(line); + token = lfirst(line_item); ret = getaddrinfo_all(token, NULL, &hints, &gai_result); if (ret || !gai_result) @@ -741,7 +771,7 @@ parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p) ereport(LOG, (errcode(ERRCODE_CONFIG_FILE_ERROR), errmsg("invalid IP mask \"%s\" in pg_hba.conf file line %d: %s", - token, line_number, gai_strerror(ret)))); + token, line_num, gai_strerror(ret)))); if (gai_result) freeaddrinfo_all(hints.ai_family, gai_result); goto hba_other_error; @@ -755,7 +785,7 @@ parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p) ereport(LOG, (errcode(ERRCODE_CONFIG_FILE_ERROR), errmsg("IP address and mask do not match in pg_hba.conf file line %d", - line_number))); + line_num))); goto hba_other_error; } } @@ -787,10 +817,11 @@ parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p) return; /* Read the rest of the line. */ - line = lnext(line); - if (!line) + line_item = lnext(line_item); + if (!line_item) goto hba_syntax; - parse_hba_auth(&line, &port->auth_method, &port->auth_arg, error_p); + parse_hba_auth(&line_item, &port->auth_method, + &port->auth_arg, error_p); if (*error_p) goto hba_syntax; } @@ -808,16 +839,16 @@ parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p) return; hba_syntax: - if (line) + if (line_item) ereport(LOG, (errcode(ERRCODE_CONFIG_FILE_ERROR), errmsg("invalid entry in pg_hba.conf file at line %d, token \"%s\"", - line_number, (const char *) lfirst(line)))); + line_num, (char *) lfirst(line_item)))); else ereport(LOG, (errcode(ERRCODE_CONFIG_FILE_ERROR), - errmsg("missing field in pg_hba.conf file at end of line %d", - line_number))); + errmsg("missing field in pg_hba.conf file at end of line %d", + line_num))); /* Come here if suitable message already logged */ hba_other_error: @@ -834,11 +865,13 @@ check_hba(hbaPort *port) { bool found_entry = false; bool error = false; - List *line; + ListCell *line; + ListCell *line_num; - foreach(line, hba_lines) + forboth(line, hba_lines, line_num, hba_line_nums) { - parse_hba(lfirst(line), port, &found_entry, &error); + parse_hba(lfirst(line), lfirst_int(line_num), + port, &found_entry, &error); if (found_entry || error) break; } @@ -911,11 +944,10 @@ void load_group(void) { FILE *group_file; - List *line; /* Discard any old data */ - if (group_lines) - free_lines(&group_lines); + if (group_lines || group_line_nums) + free_lines(&group_lines, &group_line_nums); if (group_sorted) pfree(group_sorted); group_sorted = NULL; @@ -924,14 +956,15 @@ load_group(void) group_file = group_openfile(); if (!group_file) return; - group_lines = tokenize_file(group_file); + tokenize_file(group_file, &group_lines, &group_line_nums); FreeFile(group_file); /* create sorted lines for binary searching */ - group_length = length(group_lines); + group_length = list_length(group_lines); if (group_length) { int i = 0; + ListCell *line; group_sorted = palloc(group_length * sizeof(List *)); @@ -953,11 +986,10 @@ void load_user(void) { FILE *user_file; - List *line; /* Discard any old data */ - if (user_lines) - free_lines(&user_lines); + if (user_lines || user_line_nums) + free_lines(&user_lines, &user_line_nums); if (user_sorted) pfree(user_sorted); user_sorted = NULL; @@ -966,14 +998,15 @@ load_user(void) user_file = user_openfile(); if (!user_file) return; - user_lines = tokenize_file(user_file); + tokenize_file(user_file, &user_lines, &user_line_nums); FreeFile(user_file); /* create sorted lines for binary searching */ - user_length = length(user_lines); + user_length = list_length(user_lines); if (user_length) { int i = 0; + ListCell *line; user_sorted = palloc(user_length * sizeof(List *)); @@ -1002,8 +1035,8 @@ load_hba(void) FILE *file; /* The config file we have to read */ char *conf_file; /* The name of the config file */ - if (hba_lines) - free_lines(&hba_lines); + if (hba_lines || hba_line_nums) + free_lines(&hba_lines, &hba_line_nums); /* Put together the full pathname to the config file. */ bufsize = (strlen(DataDir) + strlen(CONF_FILE) + 2) * sizeof(char); @@ -1017,7 +1050,7 @@ load_hba(void) errmsg("could not open configuration file \"%s\": %m", conf_file))); - hba_lines = tokenize_file(file); + tokenize_file(file, &hba_lines, &hba_line_nums); FreeFile(file); pfree(conf_file); } @@ -1030,10 +1063,11 @@ load_hba(void) * *found_p and *error_p are set according to our results. */ static void -parse_ident_usermap(List *line, const char *usermap_name, const char *pg_user, - const char *ident_user, bool *found_p, bool *error_p) +parse_ident_usermap(List *line, int line_number, const char *usermap_name, + const char *pg_user, const char *ident_user, + bool *found_p, bool *error_p) { - int line_number; + ListCell *line_item; char *token; char *file_map; char *file_pguser; @@ -1043,26 +1077,24 @@ parse_ident_usermap(List *line, const char *usermap_name, const char *pg_user, *error_p = false; Assert(line != NIL); - line_number = lfirsti(line); - line = lnext(line); - Assert(line != NIL); + line_item = list_head(line); /* Get the map token (must exist) */ - token = lfirst(line); + token = lfirst(line_item); file_map = token; /* Get the ident user token (must be provided) */ - line = lnext(line); + line_item = lnext(line_item); if (!line) goto ident_syntax; - token = lfirst(line); + token = lfirst(line_item); file_ident_user = token; /* Get the PG username token */ - line = lnext(line); + line_item = lnext(line_item); if (!line) goto ident_syntax; - token = lfirst(line); + token = lfirst(line_item); file_pguser = token; /* Match? */ @@ -1073,11 +1105,11 @@ parse_ident_usermap(List *line, const char *usermap_name, const char *pg_user, return; ident_syntax: - if (line) + if (line_item) ereport(LOG, (errcode(ERRCODE_CONFIG_FILE_ERROR), errmsg("invalid entry in pg_ident.conf file at line %d, token \"%s\"", - line_number, (const char *) lfirst(line)))); + line_number, (const char *) lfirst(line_item)))); else ereport(LOG, (errcode(ERRCODE_CONFIG_FILE_ERROR), @@ -1105,7 +1137,6 @@ check_ident_usermap(const char *usermap_name, const char *pg_user, const char *ident_user) { - List *line; bool found_entry = false, error = false; @@ -1125,10 +1156,13 @@ check_ident_usermap(const char *usermap_name, } else { - foreach(line, ident_lines) + ListCell *line_cell, *num_cell; + + forboth(line_cell, ident_lines, num_cell, ident_line_nums) { - parse_ident_usermap(lfirst(line), usermap_name, pg_user, - ident_user, &found_entry, &error); + parse_ident_usermap(lfirst(line_cell), lfirst_int(num_cell), + usermap_name, pg_user, ident_user, + &found_entry, &error); if (found_entry || error) break; } @@ -1148,8 +1182,8 @@ load_ident(void) * read */ int bufsize; - if (ident_lines) - free_lines(&ident_lines); + if (ident_lines || ident_line_nums) + free_lines(&ident_lines, &ident_line_nums); /* put together the full pathname to the map file */ bufsize = (strlen(DataDir) + strlen(USERMAP_FILE) + 2) * sizeof(char); @@ -1166,7 +1200,7 @@ load_ident(void) } else { - ident_lines = tokenize_file(file); + tokenize_file(file, &ident_lines, &ident_line_nums); FreeFile(file); } pfree(map_file); diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 91fb3b0834..21cef88792 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -15,11 +15,13 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.281 2004/05/10 22:44:44 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.282 2004/05/26 04:41:18 neilc Exp $ * *------------------------------------------------------------------------- */ +#define DISABLE_LIST_COMPAT + #include "postgres.h" #include "nodes/parsenodes.h" @@ -43,14 +45,6 @@ #define COPY_NODE_FIELD(fldname) \ (newnode->fldname = copyObject(from->fldname)) -/* Copy a field that is a pointer to a list of integers */ -#define COPY_INTLIST_FIELD(fldname) \ - (newnode->fldname = listCopy(from->fldname)) - -/* Copy a field that is a pointer to a list of Oids */ -#define COPY_OIDLIST_FIELD(fldname) \ - (newnode->fldname = listCopy(from->fldname)) - /* Copy a field that is a pointer to a Bitmapset */ #define COPY_BITMAPSET_FIELD(fldname) \ (newnode->fldname = bms_copy(from->fldname)) @@ -68,46 +62,6 @@ } while (0) -/* - * listCopy - * This copy function only copies the "cons-cells" of the list, not the - * pointed-to objects. (Use copyObject if you want a "deep" copy.) - * - * We also use this function for copying lists of integers and Oids, - * which is notationally a bit ugly, but perfectly safe. - * - * Note that copyObject will surely coredump if applied to a list - * of integers or Oids! - */ -List * -listCopy(List *list) -{ - List *newlist, - *oldl, - *newcell, - *prev; - - /* rather ugly coding for speed... */ - if (list == NIL) - return NIL; - - newcell = makeNode(List); - newcell->elem = list->elem; - - newlist = prev = newcell; - - foreach(oldl, lnext(list)) - { - newcell = makeNode(List); - newcell->elem = oldl->elem; - prev->next = newcell; - prev = newcell; - } - prev->next = NIL; - - return newlist; -} - /* **************************************************************** * plannodes.h copy functions * **************************************************************** @@ -259,42 +213,12 @@ _copyIndexScan(IndexScan *from) /* * copy remainder of node */ - COPY_OIDLIST_FIELD(indxid); + COPY_NODE_FIELD(indxid); COPY_NODE_FIELD(indxqual); COPY_NODE_FIELD(indxqualorig); - /* this can become COPY_NODE_FIELD when intlists are normal objects: */ - { - List *newstrat = NIL; - List *tmp; - - foreach(tmp, from->indxstrategy) - { - newstrat = lappend(newstrat, listCopy(lfirst(tmp))); - } - newnode->indxstrategy = newstrat; - } - /* this can become COPY_NODE_FIELD when OID lists are normal objects: */ - { - List *newsubtype = NIL; - List *tmp; - - foreach(tmp, from->indxsubtype) - { - newsubtype = lappend(newsubtype, listCopy(lfirst(tmp))); - } - newnode->indxsubtype = newsubtype; - } - /* this can become COPY_NODE_FIELD when intlists are normal objects: */ - { - List *newstrat = NIL; - List *tmp; - - foreach(tmp, from->indxlossy) - { - newstrat = lappend(newstrat, listCopy(lfirst(tmp))); - } - newnode->indxlossy = newstrat; - } + COPY_NODE_FIELD(indxstrategy); + COPY_NODE_FIELD(indxsubtype); + COPY_NODE_FIELD(indxlossy); COPY_SCALAR_FIELD(indxorderdir); return newnode; @@ -876,7 +800,7 @@ _copySubLink(SubLink *from) COPY_SCALAR_FIELD(useOr); COPY_NODE_FIELD(lefthand); COPY_NODE_FIELD(operName); - COPY_OIDLIST_FIELD(operOids); + COPY_NODE_FIELD(operOids); COPY_NODE_FIELD(subselect); return newnode; @@ -893,14 +817,14 @@ _copySubPlan(SubPlan *from) COPY_SCALAR_FIELD(subLinkType); COPY_SCALAR_FIELD(useOr); COPY_NODE_FIELD(exprs); - COPY_INTLIST_FIELD(paramIds); + COPY_NODE_FIELD(paramIds); COPY_NODE_FIELD(plan); COPY_SCALAR_FIELD(plan_id); COPY_NODE_FIELD(rtable); COPY_SCALAR_FIELD(useHashTable); COPY_SCALAR_FIELD(unknownEqFalse); - COPY_INTLIST_FIELD(setParam); - COPY_INTLIST_FIELD(parParam); + COPY_NODE_FIELD(setParam); + COPY_NODE_FIELD(parParam); COPY_NODE_FIELD(args); return newnode; @@ -1582,7 +1506,7 @@ _copyQuery(Query *from) COPY_SCALAR_FIELD(hasSubLinks); COPY_NODE_FIELD(rtable); COPY_NODE_FIELD(jointree); - COPY_INTLIST_FIELD(rowMarks); + COPY_NODE_FIELD(rowMarks); COPY_NODE_FIELD(targetList); COPY_NODE_FIELD(groupClause); COPY_NODE_FIELD(havingQual); @@ -1591,7 +1515,7 @@ _copyQuery(Query *from) COPY_NODE_FIELD(limitOffset); COPY_NODE_FIELD(limitCount); COPY_NODE_FIELD(setOperations); - COPY_INTLIST_FIELD(resultRelations); + COPY_NODE_FIELD(resultRelations); COPY_NODE_FIELD(in_info_list); COPY_SCALAR_FIELD(hasJoinRTEs); @@ -1679,7 +1603,7 @@ _copySetOperationStmt(SetOperationStmt *from) COPY_SCALAR_FIELD(all); COPY_NODE_FIELD(larg); COPY_NODE_FIELD(rarg); - COPY_OIDLIST_FIELD(colTypes); + COPY_NODE_FIELD(colTypes); return newnode; } @@ -1731,7 +1655,7 @@ _copyGrantStmt(GrantStmt *from) COPY_SCALAR_FIELD(is_grant); COPY_SCALAR_FIELD(objtype); COPY_NODE_FIELD(objects); - COPY_INTLIST_FIELD(privileges); + COPY_NODE_FIELD(privileges); COPY_NODE_FIELD(grantees); COPY_SCALAR_FIELD(grant_option); COPY_SCALAR_FIELD(behavior); @@ -2477,7 +2401,7 @@ _copyPrepareStmt(PrepareStmt *from) COPY_STRING_FIELD(name); COPY_NODE_FIELD(argtypes); - COPY_OIDLIST_FIELD(argtype_oids); + COPY_NODE_FIELD(argtype_oids); COPY_NODE_FIELD(query); return newnode; @@ -2511,6 +2435,47 @@ _copyDeallocateStmt(DeallocateStmt *from) * **************************************************************** */ +/* + * Perform a deep copy of the specified list, using copyObject(). The + * list MUST be of type T_List; T_IntList and T_OidList nodes don't + * need deep copies, so they should be copied via list_copy() + */ +#define COPY_NODE_CELL(new, old) \ + (new) = (ListCell *) palloc(sizeof(ListCell)); \ + lfirst(new) = copyObject(lfirst(old)); + +static List * +_copyList(List *from) +{ + List *new; + ListCell *curr_old; + ListCell *prev_new; + + Assert(list_length(from) >= 1); + + new = makeNode(List); + new->length = from->length; + + COPY_NODE_CELL(new->head, from->head); + prev_new = new->head; + curr_old = lnext(from->head); + + while (curr_old) + { + COPY_NODE_CELL(prev_new->next, curr_old); + prev_new = prev_new->next; + curr_old = curr_old->next; + } + prev_new->next = NULL; + new->tail = prev_new; + + return new; +} + +/* **************************************************************** + * value.h copy functions + * **************************************************************** + */ static Value * _copyValue(Value *from) { @@ -2752,30 +2717,21 @@ copyObject(void *from) case T_Null: retval = _copyValue(from); break; + + /* + * LIST NODES + */ case T_List: - { - List *list = from, - *oldl, - *newcell, - *prev; - - /* rather ugly coding for speed... */ - /* Note the input list cannot be NIL if we got here. */ - newcell = makeNode(List); - lfirst(newcell) = copyObject(lfirst(list)); - - retval = (void *) newcell; - prev = newcell; - - foreach(oldl, lnext(list)) - { - newcell = makeNode(List); - lfirst(newcell) = copyObject(lfirst(oldl)); - prev->next = newcell; - prev = newcell; - } - prev->next = NIL; - } + retval = _copyList(from); + break; + /* + * Lists of integers and OIDs don't need to be + * deep-copied, so we perform a shallow copy via + * list_copy() + */ + case T_IntList: + case T_OidList: + retval = list_copy(from); break; /* diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index 19ffbb1be7..236061eee2 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -18,11 +18,13 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.220 2004/05/10 22:44:44 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.221 2004/05/26 04:41:19 neilc Exp $ * *------------------------------------------------------------------------- */ +#define DISABLE_LIST_COMPAT + #include "postgres.h" #include "nodes/params.h" @@ -52,20 +54,6 @@ return false; \ } while (0) -/* Compare a field that is a pointer to a list of integers */ -#define COMPARE_INTLIST_FIELD(fldname) \ - do { \ - if (!equali(a->fldname, b->fldname)) \ - return false; \ - } while (0) - -/* Compare a field that is a pointer to a list of Oids */ -#define COMPARE_OIDLIST_FIELD(fldname) \ - do { \ - if (!equalo(a->fldname, b->fldname)) \ - return false; \ - } while (0) - /* Compare a field that is a pointer to a Bitmapset */ #define COMPARE_BITMAPSET_FIELD(fldname) \ do { \ @@ -328,7 +316,7 @@ _equalSubLink(SubLink *a, SubLink *b) COMPARE_SCALAR_FIELD(useOr); COMPARE_NODE_FIELD(lefthand); COMPARE_NODE_FIELD(operName); - COMPARE_OIDLIST_FIELD(operOids); + COMPARE_NODE_FIELD(operOids); COMPARE_NODE_FIELD(subselect); return true; @@ -340,14 +328,14 @@ _equalSubPlan(SubPlan *a, SubPlan *b) COMPARE_SCALAR_FIELD(subLinkType); COMPARE_SCALAR_FIELD(useOr); COMPARE_NODE_FIELD(exprs); - COMPARE_INTLIST_FIELD(paramIds); + COMPARE_NODE_FIELD(paramIds); /* should compare plans, but have to settle for comparing plan IDs */ COMPARE_SCALAR_FIELD(plan_id); COMPARE_NODE_FIELD(rtable); COMPARE_SCALAR_FIELD(useHashTable); COMPARE_SCALAR_FIELD(unknownEqFalse); - COMPARE_INTLIST_FIELD(setParam); - COMPARE_INTLIST_FIELD(parParam); + COMPARE_NODE_FIELD(setParam); + COMPARE_NODE_FIELD(parParam); COMPARE_NODE_FIELD(args); return true; @@ -636,7 +624,7 @@ _equalQuery(Query *a, Query *b) COMPARE_SCALAR_FIELD(hasSubLinks); COMPARE_NODE_FIELD(rtable); COMPARE_NODE_FIELD(jointree); - COMPARE_INTLIST_FIELD(rowMarks); + COMPARE_NODE_FIELD(rowMarks); COMPARE_NODE_FIELD(targetList); COMPARE_NODE_FIELD(groupClause); COMPARE_NODE_FIELD(havingQual); @@ -645,7 +633,7 @@ _equalQuery(Query *a, Query *b) COMPARE_NODE_FIELD(limitOffset); COMPARE_NODE_FIELD(limitCount); COMPARE_NODE_FIELD(setOperations); - COMPARE_INTLIST_FIELD(resultRelations); + COMPARE_NODE_FIELD(resultRelations); COMPARE_NODE_FIELD(in_info_list); COMPARE_SCALAR_FIELD(hasJoinRTEs); @@ -720,7 +708,7 @@ _equalSetOperationStmt(SetOperationStmt *a, SetOperationStmt *b) COMPARE_SCALAR_FIELD(all); COMPARE_NODE_FIELD(larg); COMPARE_NODE_FIELD(rarg); - COMPARE_OIDLIST_FIELD(colTypes); + COMPARE_NODE_FIELD(colTypes); return true; } @@ -764,7 +752,7 @@ _equalGrantStmt(GrantStmt *a, GrantStmt *b) COMPARE_SCALAR_FIELD(is_grant); COMPARE_SCALAR_FIELD(objtype); COMPARE_NODE_FIELD(objects); - COMPARE_INTLIST_FIELD(privileges); + COMPARE_NODE_FIELD(privileges); COMPARE_NODE_FIELD(grantees); COMPARE_SCALAR_FIELD(grant_option); COMPARE_SCALAR_FIELD(behavior); @@ -1389,7 +1377,7 @@ _equalPrepareStmt(PrepareStmt *a, PrepareStmt *b) { COMPARE_STRING_FIELD(name); COMPARE_NODE_FIELD(argtypes); - COMPARE_OIDLIST_FIELD(argtype_oids); + COMPARE_NODE_FIELD(argtype_oids); COMPARE_NODE_FIELD(query); return true; @@ -1648,6 +1636,65 @@ _equalFkConstraint(FkConstraint *a, FkConstraint *b) * Stuff from pg_list.h */ +static bool +_equalList(List *a, List *b) +{ + ListCell *item_a; + ListCell *item_b; + + /* + * Try to reject by simple scalar checks before grovelling through + * all the list elements... + */ + COMPARE_SCALAR_FIELD(type); + COMPARE_SCALAR_FIELD(length); + + /* + * We place the switch outside the loop for the sake of + * efficiency; this may not be worth doing... + */ + switch (a->type) + { + case T_List: + forboth(item_a, a, item_b, b) + { + if (!equal(lfirst(item_a), lfirst(item_b))) + return false; + } + break; + case T_IntList: + forboth(item_a, a, item_b, b) + { + if (lfirst_int(item_a) != lfirst_int(item_b)) + return false; + } + break; + case T_OidList: + forboth(item_a, a, item_b, b) + { + if (lfirst_oid(item_a) != lfirst_oid(item_b)) + return false; + } + break; + default: + elog(ERROR, "unrecognized list node type: %d", + (int) a->type); + return false; /* keep compiler quiet */ + } + + /* + * If we got here, we should have run out of elements of both lists + */ + Assert(item_a == NULL); + Assert(item_b == NULL); + + return true; +} + +/* + * Stuff from value.h + */ + static bool _equalValue(Value *a, Value *b) { @@ -1818,30 +1865,10 @@ equal(void *a, void *b) case T_InClauseInfo: retval = _equalInClauseInfo(a, b); break; - - /* - * LIST NODES - */ case T_List: - { - List *la = (List *) a; - List *lb = (List *) b; - List *l; - - /* - * Try to reject by length check before we grovel through - * all the elements... - */ - if (length(la) != length(lb)) - return false; - foreach(l, la) - { - if (!equal(lfirst(l), lfirst(lb))) - return false; - lb = lnext(lb); - } - retval = true; - } + case T_IntList: + case T_OidList: + retval = _equalList(a, b); break; case T_Integer: diff --git a/src/backend/nodes/list.c b/src/backend/nodes/list.c index aeda02d170..6fd7b064a6 100644 --- a/src/backend/nodes/list.c +++ b/src/backend/nodes/list.c @@ -9,700 +9,1160 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/list.c,v 1.56 2004/01/07 18:43:36 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/list.c,v 1.57 2004/05/26 04:41:19 neilc Exp $ * *------------------------------------------------------------------------- */ +#define DISABLE_LIST_COMPAT + #include "postgres.h" +#include "nodes/pg_list.h" -#include "nodes/parsenodes.h" +/* + * Routines to simplify writing assertions about the type of a list; a + * NIL list is considered to be an empty list of any type. + */ +#define IsPointerList(l) ((l) == NIL || IsA((l), List)) +#define IsIntegerList(l) ((l) == NIL || IsA((l), IntList)) +#define IsOidList(l) ((l) == NIL || IsA((l), OidList)) +#ifdef USE_ASSERT_CHECKING /* - * lcons - * - * Add obj to the front of list, or make a new list if 'list' is NIL + * Check that the specified List is valid (so far as we can tell). */ -List * -lcons(void *obj, List *list) +static void +check_list_invariants(List *list) { - List *l = makeNode(List); + if (list == NIL) + return; + + Assert(list->length > 0); + Assert(list->head != NULL); + Assert(list->tail != NULL); + + Assert(list->type == T_List || + list->type == T_IntList || + list->type == T_OidList); + + if (list->length == 1) + Assert(list->head == list->tail); + if (list->length == 2) + Assert(list->head->next == list->tail); + Assert(list->tail->next == NULL); +} +#else +#define check_list_invariants(l) +#endif /* USE_ASSERT_CHECKING */ + +/* + * Return a freshly allocated List. Since empty non-NIL lists are + * invalid, new_list() also allocates the head cell of the new list: + * the caller should be sure to fill in that cell's data. + */ +static List * +new_list(NodeTag type) +{ + List *new_list; + ListCell *new_head; + + new_head = (ListCell *) palloc(sizeof(*new_head)); + new_head->next = NULL; + /* new_head->data is left undefined! */ - lfirst(l) = obj; - lnext(l) = list; - return l; + new_list = (List *) palloc(sizeof(*new_list)); + new_list->type = type; + new_list->length = 1; + new_list->head = new_head; + new_list->tail = new_head; + + return new_list; } /* - * lconsi + * Allocate a new cell and make it the head of the specified + * list. Assumes the list it is passed is non-NIL. * - * Same as lcons, but for integer data + * The data in the new head cell is undefined; the caller should be + * sure to fill it in */ -List * -lconsi(int datum, List *list) +static void +new_head_cell(List *list) { - List *l = makeNode(List); + ListCell *new_head; + + new_head = (ListCell *) palloc(sizeof(*new_head)); + new_head->next = list->head; - lfirsti(l) = datum; - lnext(l) = list; - return l; + list->head = new_head; + list->length++; } /* - * lconso + * Allocate a new cell and make it the tail of the specified + * list. Assumes the list it is passed is non-NIL. * - * Same as lcons, but for Oid data + * The data in the new tail cell is undefined; the caller should be + * sure to fill it in */ -List * -lconso(Oid datum, List *list) +static void +new_tail_cell(List *list) { - List *l = makeNode(List); + ListCell *new_tail; + + new_tail = (ListCell *) palloc(sizeof(*new_tail)); + new_tail->next = NULL; - lfirsto(l) = datum; - lnext(l) = list; - return l; + list->tail->next = new_tail; + list->tail = new_tail; + list->length++; } /* - * lappend - * - * Add obj to the end of list, or make a new list if 'list' is NIL - * - * MORE EXPENSIVE THAN lcons + * Append a pointer to the list. A pointer to the modified list is + * returned. Note that this function may or may not destructively + * modify the list; callers should always use this function's return + * value, rather than continuing to use the pointer passed as the + * first argument. */ List * lappend(List *list, void *datum) { - return nconc(list, makeList1(datum)); + Assert(IsPointerList(list)); + + if (list == NIL) + list = new_list(T_List); + else + new_tail_cell(list); + + lfirst(list->tail) = datum; + check_list_invariants(list); + return list; } /* - * lappendi - * - * Same as lappend, but for integers + * Append an integer to the specified list. See lappend() */ -List * -lappendi(List *list, int datum) +List * +lappend_int(List *list, int datum) { - return nconc(list, makeListi1(datum)); + Assert(IsIntegerList(list)); + + if (list == NIL) + list = new_list(T_IntList); + else + new_tail_cell(list); + + lfirst_int(list->tail) = datum; + check_list_invariants(list); + return list; } /* - * lappendo - * - * Same as lappend, but for Oids + * Append an OID to the specified list. See lappend() */ -List * -lappendo(List *list, Oid datum) +List * +lappend_oid(List *list, Oid datum) { - return nconc(list, makeListo1(datum)); + Assert(IsOidList(list)); + + if (list == NIL) + list = new_list(T_OidList); + else + new_tail_cell(list); + + lfirst_oid(list->tail) = datum; + check_list_invariants(list); + return list; } /* - * nconc - * - * Concat l2 on to the end of l1 - * - * NB: l1 is destructively changed! Use nconc(listCopy(l1), l2) - * if you need to make a merged list without touching the original lists. + * Add a new cell to the list, in the position after 'prev_cell'. The + * data in the cell is left undefined, and must be filled in by the + * caller. 'list' is assumed to be non-NIL, and 'prev_cell' is assumed + * to be non-NULL and a member of 'list'. */ -List * -nconc(List *l1, List *l2) +static ListCell * +add_new_cell(List *list, ListCell *prev_cell) { - List *temp; + ListCell *new_cell; - if (l1 == NIL) - return l2; - if (l2 == NIL) - return l1; - if (l1 == l2) - elog(ERROR, "cannot nconc a list to itself"); + new_cell = (ListCell *) palloc(sizeof(*new_cell)); + /* new_cell->data is left undefined! */ + new_cell->next = prev_cell->next; + prev_cell->next = new_cell; - for (temp = l1; lnext(temp) != NIL; temp = lnext(temp)) - ; + if (list->tail == prev_cell) + list->tail = new_cell; + + list->length++; - lnext(temp) = l2; - return l1; /* list1 is now list1+list2 */ + return new_cell; } /* - * FastAppend - append to a FastList. + * Add a new cell to the specified list (which must be non-NIL); + * it will be placed after the list cell 'prev' (which must be + * non-NULL and a member of 'list'). The data placed in the new cell + * is 'datum'. The newly-constructed cell is returned. + */ +ListCell * +lappend_cell(List *list, ListCell *prev, void *datum) +{ + ListCell *new_cell; + + Assert(IsPointerList(list)); + + new_cell = add_new_cell(list, prev); + lfirst(new_cell) = datum; + check_list_invariants(list); + return new_cell; +} + +ListCell * +lappend_cell_int(List *list, ListCell *prev, int datum) +{ + ListCell *new_cell; + + Assert(IsIntegerList(list)); + + new_cell = add_new_cell(list, prev); + lfirst_int(new_cell) = datum; + check_list_invariants(list); + return new_cell; +} + +ListCell * +lappend_cell_oid(List *list, ListCell *prev, Oid datum) +{ + ListCell *new_cell; + + Assert(IsOidList(list)); + + new_cell = add_new_cell(list, prev); + lfirst_oid(new_cell) = datum; + check_list_invariants(list); + return new_cell; +} + +/* + * Prepend a new element to the list. A pointer to the modified list + * is returned. Note that this function may or may not destructively + * modify the list; callers should always use this function's return + * value, rather than continuing to use the pointer passed as the + * second argument. * - * For long lists this is significantly faster than repeated lappend's, - * since we avoid having to chase down the list again each time. + * Caution: before Postgres 7.5, the original List was unmodified and + * could be considered to retain its separate identity. This is no longer + * the case. */ -void -FastAppend(FastList *fl, void *datum) +List * +lcons(void *datum, List *list) { - List *cell = makeList1(datum); + Assert(IsPointerList(list)); - if (fl->tail) - { - lnext(fl->tail) = cell; - fl->tail = cell; - } + if (list == NIL) + list = new_list(T_List); else - { - /* First cell of list */ - Assert(fl->head == NIL); - fl->head = fl->tail = cell; - } + new_head_cell(list); + + lfirst(list->head) = datum; + check_list_invariants(list); + return list; } /* - * FastAppendi - same for integers + * Prepend an integer to the list. See lcons() */ -void -FastAppendi(FastList *fl, int datum) +List * +lcons_int(int datum, List *list) { - List *cell = makeListi1(datum); + Assert(IsIntegerList(list)); - if (fl->tail) - { - lnext(fl->tail) = cell; - fl->tail = cell; - } + if (list == NIL) + list = new_list(T_IntList); else - { - /* First cell of list */ - Assert(fl->head == NIL); - fl->head = fl->tail = cell; - } + new_head_cell(list); + + lfirst_int(list->head) = datum; + check_list_invariants(list); + return list; } /* - * FastAppendo - same for Oids + * Prepend an OID to the list. See lcons() */ -void -FastAppendo(FastList *fl, Oid datum) +List * +lcons_oid(Oid datum, List *list) { - List *cell = makeListo1(datum); + Assert(IsOidList(list)); - if (fl->tail) - { - lnext(fl->tail) = cell; - fl->tail = cell; - } + if (list == NIL) + list = new_list(T_OidList); else - { - /* First cell of list */ - Assert(fl->head == NIL); - fl->head = fl->tail = cell; - } + new_head_cell(list); + + lfirst_oid(list->head) = datum; + check_list_invariants(list); + return list; } /* - * FastConc - nconc() for FastList building + * Concatenate list2 to the end of list1, and return list1. list1 is + * destructively changed. Callers should be sure to use the return + * value as the new pointer to the concatenated list: the 'list1' + * input pointer may or may not be the same as the returned pointer. * - * Note that the cells of the second argument are absorbed into the FastList. + * The nodes in list2 are merely appended to the end of list1 in-place + * (i.e. they aren't copied; the two lists will share some of the same + * storage). Therefore, invoking list_free() on list2 will also + * invalidate a portion of list1. */ -void -FastConc(FastList *fl, List *cells) +List * +list_concat(List *list1, List *list2) { - if (cells == NIL) - return; /* nothing to do */ - if (fl->tail) - lnext(fl->tail) = cells; - else - { - /* First cell of list */ - Assert(fl->head == NIL); - fl->head = cells; - } - while (lnext(cells) != NIL) - cells = lnext(cells); - fl->tail = cells; + if (list1 == NIL) + return list2; + if (list2 == NIL) + return list1; + if (list1 == list2) + elog(ERROR, "cannot list_concat() a list to itself"); + + Assert(list1->type == list2->type); + + list1->length += list2->length; + list1->tail->next = list2->head; + list1->tail = list2->tail; + + check_list_invariants(list1); + return list1; } /* - * FastConcFast - nconc() for FastList building + * Truncate 'list' to contain no more than 'new_size' elements. This + * modifies the list in-place! Despite this, callers should use the + * pointer returned by this function to refer to the newly truncated + * list -- it may or may not be the same as the pointer that was + * passed. * - * Note that the cells of the second argument are absorbed into the first. + * Note that any cells removed by list_truncate() are NOT pfree'd. */ -void -FastConcFast(FastList *fl, FastList *fl2) +List * +list_truncate(List *list, int new_size) { - if (fl2->head == NIL) - return; /* nothing to do */ - if (fl->tail) - lnext(fl->tail) = fl2->head; - else + ListCell *cell; + int n; + + if (new_size <= 0) + return NIL; /* truncate to zero length */ + + /* If asked to effectively extend the list, do nothing */ + if (new_size >= list_length(list)) + return list; + + n = 1; + foreach (cell, list) { - /* First cell of list */ - Assert(fl->head == NIL); - fl->head = fl2->head; + if (n == new_size) + { + cell->next = NULL; + list->tail = cell; + list->length = new_size; + check_list_invariants(list); + return list; + } + n++; } - fl->tail = fl2->tail; + + /* keep the compiler quiet; never reached */ + Assert(false); + return list; } /* - * nth - * - * Get the n'th element of the list. First element is 0th. + * Locate the n'th cell (counting from 0) of the list. It is an assertion + * error if there isn't one. + */ +static ListCell * +list_nth_cell(List *list, int n) +{ + ListCell *match; + + Assert(list != NIL); + Assert(n >= 0); + Assert(n < list->length); + check_list_invariants(list); + + /* Does the caller actually mean to fetch the tail? */ + if (n == list->length - 1) + return list->tail; + + for (match = list->head; n-- > 0; match = match->next) + ; + + return match; +} + +/* + * Return the data value contained in the n'th element of the + * specified list. (List elements begin at 0.) */ void * -nth(int n, List *l) +list_nth(List *list, int n) { - /* XXX assume list is long enough */ - while (n-- > 0) - l = lnext(l); - return lfirst(l); + Assert(IsPointerList(list)); + return lfirst(list_nth_cell(list, n)); } /* - * length - * - * Get the length of l + * Return the integer value contained in the n'th element of the + * specified list. */ int -length(List *l) +list_nth_int(List *list, int n) { - int i = 0; - - while (l != NIL) - { - l = lnext(l); - i++; - } - return i; + Assert(IsIntegerList(list)); + return lfirst_int(list_nth_cell(list, n)); } /* - * llast - * - * Get the last element of l ... error if empty list + * Return the OID value contained in the n'th element of the specified + * list. */ -void * -llast(List *l) +Oid +list_nth_oid(List *list, int n) { - if (l == NIL) - elog(ERROR, "empty list does not have a last item"); - while (lnext(l) != NIL) - l = lnext(l); - return lfirst(l); + Assert(IsOidList(list)); + return lfirst_oid(list_nth_cell(list, n)); } /* - * llastnode - * - * Get the last node of l ... NIL if empty list + * Return true iff 'datum' is a member of the list. Equality is + * determined via equal(), so callers should ensure that they pass a + * Node as 'datum'. */ -List * -llastnode(List *l) +bool +list_member(List *list, void *datum) { - if (l == NIL) - return NIL; - while (lnext(l) != NIL) - l = lnext(l); - return l; + ListCell *cell; + + Assert(IsPointerList(list)); + check_list_invariants(list); + + foreach (cell, list) + { + if (equal(lfirst(cell), datum)) + return true; + } + + return false; } /* - * freeList - * - * Free the List nodes of a list - * The pointed-to nodes, if any, are NOT freed. - * This works for integer and Oid lists too. + * Return true iff 'datum' is a member of the list. Equality is + * determined by using simple pointer comparison. */ -void -freeList(List *list) +bool +list_member_ptr(List *list, void *datum) { - while (list != NIL) - { - List *l = list; + ListCell *cell; - list = lnext(list); - pfree(l); + Assert(IsPointerList(list)); + check_list_invariants(list); + + foreach (cell, list) + { + if (lfirst(cell) == datum) + return true; } + + return false; } /* - * equali - * compares two lists of integers + * Return true iff the integer 'datum' is a member of the list. */ bool -equali(List *list1, List *list2) +list_member_int(List *list, int datum) { - List *l; + ListCell *cell; + + Assert(IsIntegerList(list)); + check_list_invariants(list); - foreach(l, list1) + foreach (cell, list) { - if (list2 == NIL) - return false; - if (lfirsti(l) != lfirsti(list2)) - return false; - list2 = lnext(list2); + if (lfirst_int(cell) == datum) + return true; } - if (list2 != NIL) - return false; - return true; + + return false; } /* - * equalo - * compares two lists of Oids + * Return true iff the OID 'datum' is a member of the list. */ bool -equalo(List *list1, List *list2) +list_member_oid(List *list, Oid datum) { - List *l; + ListCell *cell; + + Assert(IsOidList(list)); + check_list_invariants(list); - foreach(l, list1) + foreach (cell, list) { - if (list2 == NIL) - return false; - if (lfirsto(l) != lfirsto(list2)) - return false; - list2 = lnext(list2); + if (lfirst_oid(cell) == datum) + return true; } - if (list2 != NIL) - return false; - return true; + + return false; } /* - * Generate the union of two lists, - * ie, l1 plus all members of l2 that are not already in l1. - * - * NOTE: if there are duplicates in l1 they will still be duplicate in the - * result; but duplicates in l2 are discarded. + * Delete 'cell' from 'list'; 'prev' is the previous element to 'cell' + * in 'list', if any (i.e. prev == NULL iff list->head == cell) * - * The result is a fresh List, but it points to the same member nodes - * as were in the inputs. + * The cell is pfree'd, as is the List header if this was the last member. */ List * -set_union(List *l1, List *l2) +list_delete_cell(List *list, ListCell *cell, ListCell *prev) { - List *retval = listCopy(l1); - List *i; + check_list_invariants(list); + Assert(prev != NULL ? lnext(prev) == cell : list_head(list) == cell); + + /* + * If we're about to delete the last node from the list, free the + * whole list instead and return NIL, which is the only valid + * representation of a zero-length list. + */ + if (list->length == 1) + { + list_free(list); + return NIL; + } - foreach(i, l2) + /* + * Otherwise, adjust the necessary list links, deallocate the + * particular node we have just removed, and return the list we + * were given. + */ + list->length--; + + if (prev) + prev->next = cell->next; + else + list->head = cell->next; + + if (list->tail == cell) + list->tail = prev; + + pfree(cell); + return list; +} + +/* + * Delete the first cell in list that matches datum, if any. + * Equality is determined via equal(). + */ +List * +list_delete(List *list, void *datum) +{ + ListCell *cell; + ListCell *prev; + + Assert(IsPointerList(list)); + check_list_invariants(list); + + prev = NULL; + foreach (cell, list) { - if (!member(lfirst(i), retval)) - retval = lappend(retval, lfirst(i)); + if (equal(lfirst(cell), datum)) + return list_delete_cell(list, cell, prev); + + prev = cell; } - return retval; + + /* Didn't find a match: return the list unmodified */ + return list; } -/* set_union for Oid lists */ +/* As above, but use simple pointer equality */ List * -set_uniono(List *l1, List *l2) +list_delete_ptr(List *list, void *datum) { - List *retval = listCopy(l1); - List *i; + ListCell *cell; + ListCell *prev; - foreach(i, l2) + Assert(IsPointerList(list)); + check_list_invariants(list); + + prev = NULL; + foreach (cell, list) { - if (!oidMember(lfirsto(i), retval)) - retval = lappendo(retval, lfirsto(i)); + if (lfirst(cell) == datum) + return list_delete_cell(list, cell, prev); + + prev = cell; } - return retval; + + /* Didn't find a match: return the list unmodified */ + return list; } -/* set_union when pointer-equality comparison is sufficient */ +/* As above, but for integers */ List * -set_ptrUnion(List *l1, List *l2) +list_delete_int(List *list, int datum) { - List *retval = listCopy(l1); - List *i; + ListCell *cell; + ListCell *prev; + + Assert(IsIntegerList(list)); + check_list_invariants(list); - foreach(i, l2) + prev = NULL; + foreach (cell, list) { - if (!ptrMember(lfirst(i), retval)) - retval = lappend(retval, lfirst(i)); + if (lfirst_int(cell) == datum) + return list_delete_cell(list, cell, prev); + + prev = cell; } - return retval; + + /* Didn't find a match: return the list unmodified */ + return list; +} + +/* As above, but for OIDs */ +List * +list_delete_oid(List *list, Oid datum) +{ + ListCell *cell; + ListCell *prev; + + Assert(IsOidList(list)); + check_list_invariants(list); + + prev = NULL; + foreach (cell, list) + { + if (lfirst_oid(cell) == datum) + return list_delete_cell(list, cell, prev); + + prev = cell; + } + + /* Didn't find a match: return the list unmodified */ + return list; } /* - * Generate the intersection of two lists, - * ie, all members of both l1 and l2. - * - * NOTE: if there are duplicates in l1 they will still be duplicate in the - * result; but duplicates in l2 are discarded. + * Delete the first element of the list. * - * The result is a fresh List, but it points to the same member nodes - * as were in the inputs. + * This is useful to replace the Lisp-y code "list = lnext(list);" in cases + * where the intent is to alter the list rather than just traverse it. + * Beware that the removed cell is freed, whereas the lnext() coding leaves + * the original list head intact if there's another pointer to it. */ -#ifdef NOT_USED List * -set_intersect(List *l1, List *l2) +list_delete_first(List *list) { - List *retval = NIL; - List *i; + check_list_invariants(list); - foreach(i, l1) - { - if (member(lfirst(i), l2)) - retval = lappend(retval, lfirst(i)); - } - return retval; + if (list == NIL) + return NIL; /* would an error be better? */ + + return list_delete_cell(list, list_head(list), NULL); } -#endif /* - * member() - * nondestructive, returns t iff l1 is a member of the list l2 + * Generate the union of two lists. This is calculated by copying + * list1 via list_copy(), then adding to it all the members of list2 + * that aren't already in list1. + * + * Whether an element is already a member of the list is determined + * via equal(). + * + * The returned list is newly-allocated, although the content of the + * cells is the same (i.e. any pointed-to objects are not copied). + * + * NB: Bizarrely, this function will NOT remove any duplicates that + * are present in list1 (so it is not really a union at all!). Also, + * this function could probably be implemented a lot faster if it is a + * performance bottleneck. */ -bool -member(void *l1, List *l2) +List * +list_union(List *list1, List *list2) { - List *i; + List *result; + ListCell *cell; + + Assert(IsPointerList(list1)); + Assert(IsPointerList(list2)); - foreach(i, l2) + result = list_copy(list1); + foreach(cell, list2) { - if (equal((Node *) l1, (Node *) lfirst(i))) - return true; + if (!list_member(result, lfirst(cell))) + result = lappend(result, lfirst(cell)); } - return false; + + check_list_invariants(result); + return result; } /* - * like member(), but use when pointer-equality comparison is sufficient + * This variant of list_union() determines duplicates via simple + * pointer comparison. */ -bool -ptrMember(void *l1, List *l2) +List * +list_union_ptr(List *list1, List *list2) { - List *i; + List *result; + ListCell *cell; - foreach(i, l2) + Assert(IsPointerList(list1)); + Assert(IsPointerList(list2)); + + result = list_copy(list1); + foreach(cell, list2) { - if (l1 == lfirst(i)) - return true; + if (!list_member_ptr(result, lfirst(cell))) + result = lappend(result, lfirst(cell)); } - return false; + + check_list_invariants(result); + return result; } /* - * membership test for integer lists + * This variant of list_union() operates upon lists of integers. */ -bool -intMember(int l1, List *l2) +List * +list_union_int(List *list1, List *list2) { - List *i; + List *result; + ListCell *cell; + + Assert(IsIntegerList(list1)); + Assert(IsIntegerList(list2)); - foreach(i, l2) + result = list_copy(list1); + foreach(cell, list2) { - if (l1 == lfirsti(i)) - return true; + if (!list_member_int(result, lfirst_int(cell))) + result = lappend_int(result, lfirst_int(cell)); } - return false; + + check_list_invariants(result); + return result; } /* - * membership test for Oid lists + * This variant of list_union() operates upon lists of OIDs. */ -bool -oidMember(Oid l1, List *l2) +List * +list_union_oid(List *list1, List *list2) { - List *i; + List *result; + ListCell *cell; + + Assert(IsOidList(list1)); + Assert(IsOidList(list2)); - foreach(i, l2) + result = list_copy(list1); + foreach(cell, list2) { - if (l1 == lfirsto(i)) - return true; + if (!list_member_oid(result, lfirst_oid(cell))) + result = lappend_oid(result, lfirst_oid(cell)); } - return false; + + check_list_invariants(result); + return result; } /* - * lremove - * Removes 'elem' from the linked list (destructively changing the list!). - * (If there is more than one equal list member, the first is removed.) + * Return a list that contains all the cells in list1 that are not in + * list2. The returned list is freshly allocated via palloc(), but the + * cells themselves point to the same objects as the cells of the + * input lists. * - * This version matches 'elem' using simple pointer comparison. - * See also LispRemove. + * This variant works on lists of pointers, and determines list + * membership via equal() */ List * -lremove(void *elem, List *list) +list_difference(List *list1, List *list2) { - List *l; - List *prev = NIL; - List *result = list; + ListCell *cell; + List *result = NIL; - foreach(l, list) - { - if (elem == lfirst(l)) - break; - prev = l; - } - if (l != NIL) + Assert(IsPointerList(list1)); + Assert(IsPointerList(list2)); + + if (list2 == NIL) + return list_copy(list1); + + foreach (cell, list1) { - if (prev == NIL) - result = lnext(l); - else - lnext(prev) = lnext(l); - pfree(l); + if (!list_member(list2, lfirst(cell))) + result = lappend(result, lfirst(cell)); } + + check_list_invariants(result); return result; } /* - * LispRemove - * Removes 'elem' from the linked list (destructively changing the list!). - * (If there is more than one equal list member, the first is removed.) - * - * This version matches 'elem' using equal(). - * See also lremove. + * This variant of list_difference() determines list membership via + * simple pointer equality. */ List * -LispRemove(void *elem, List *list) +list_difference_ptr(List *list1, List *list2) { - List *l; - List *prev = NIL; - List *result = list; + ListCell *cell; + List *result = NIL; - foreach(l, list) - { - if (equal(elem, lfirst(l))) - break; - prev = l; - } - if (l != NIL) + Assert(IsPointerList(list1)); + Assert(IsPointerList(list2)); + + if (list2 == NIL) + return list_copy(list1); + + foreach (cell, list1) { - if (prev == NIL) - result = lnext(l); - else - lnext(prev) = lnext(l); - pfree(l); + if (!list_member_ptr(list2, lfirst(cell))) + result = lappend(result, lfirst(cell)); } + + check_list_invariants(result); return result; } /* - * lremovei - * lremove() for integer lists. + * This variant of list_difference() operates upon lists of integers. */ List * -lremovei(int elem, List *list) +list_difference_int(List *list1, List *list2) { - List *l; - List *prev = NIL; - List *result = list; + ListCell *cell; + List *result = NIL; - foreach(l, list) - { - if (elem == lfirsti(l)) - break; - prev = l; - } - if (l != NIL) + Assert(IsIntegerList(list1)); + Assert(IsIntegerList(list2)); + + if (list2 == NIL) + return list_copy(list1); + + foreach (cell, list1) { - if (prev == NIL) - result = lnext(l); - else - lnext(prev) = lnext(l); - pfree(l); + if (!list_member_int(list2, lfirst_int(cell))) + result = lappend_int(result, lfirst_int(cell)); } + + check_list_invariants(result); return result; } /* - * ltruncate - * Truncate a list to n elements. - * Does nothing if n >= length(list). - * NB: the list is modified in-place! + * This variant of list_difference() operates upon lists of OIDs. */ List * -ltruncate(int n, List *list) +list_difference_oid(List *list1, List *list2) { - List *ptr; + ListCell *cell; + List *result = NIL; - if (n <= 0) - return NIL; /* truncate to zero length */ + Assert(IsOidList(list1)); + Assert(IsOidList(list2)); - foreach(ptr, list) + if (list2 == NIL) + return list_copy(list1); + + foreach (cell, list1) { - if (--n == 0) - { - lnext(ptr) = NIL; - break; - } + if (!list_member_oid(list2, lfirst_oid(cell))) + result = lappend_oid(result, lfirst_oid(cell)); } - return list; + + check_list_invariants(result); + return result; +} + +/* Free all storage in a list, and optionally the pointed-to elements */ +static void +list_free_private(List *list, bool deep) +{ + ListCell *cell; + + check_list_invariants(list); + + cell = list_head(list); + while (cell != NULL) + { + ListCell *tmp = cell; + + cell = lnext(cell); + if (deep) + pfree(lfirst(tmp)); + pfree(tmp); + } + + if (list) + pfree(list); } /* - * set_difference + * Free all the cells of the list, as well as the list itself. Any + * objects that are pointed-to by the cells of the list are NOT + * free'd. * - * Return l1 without the elements in l2. + * On return, the argument to this function has been freed, so the + * caller would be wise to set it to NIL for safety's sake. + */ +void +list_free(List *list) +{ + list_free_private(list, false); +} + +/* + * Free all the cells of the list, the list itself, and all the + * objects pointed-to by the cells of the list (each element in the + * list must contain a pointer to a palloc()'d region of memory!) * - * The result is a fresh List, but it points to the same member nodes - * as were in l1. + * On return, the argument to this function has been freed, so the + * caller would be wise to set it to NIL for safety's sake. + */ +void +list_free_deep(List *list) +{ + /* + * A "deep" free operation only makes sense on a list of pointers. + */ + Assert(IsPointerList(list)); + list_free_private(list, true); +} + +/* + * Return a shallow copy of the specified list. */ List * -set_difference(List *l1, List *l2) +list_copy(List *oldlist) { - List *result = NIL; - List *i; + List *newlist; + ListCell *newlist_prev; + ListCell *oldlist_cur; + + if (oldlist == NIL) + return NIL; - if (l2 == NIL) - return listCopy(l1); /* slightly faster path for empty l2 */ + newlist = new_list(oldlist->type); + newlist->length = oldlist->length; - foreach(i, l1) + /* + * Copy over the data in the first cell; new_list() has already + * allocated the head cell itself + */ + newlist->head->data = oldlist->head->data; + + newlist_prev = newlist->head; + oldlist_cur = oldlist->head->next; + while (oldlist_cur) { - if (!member(lfirst(i), l2)) - result = lappend(result, lfirst(i)); + ListCell *newlist_cur; + + newlist_cur = (ListCell *) palloc(sizeof(*newlist_cur)); + newlist_cur->data = oldlist_cur->data; + newlist_prev->next = newlist_cur; + + newlist_prev = newlist_cur; + oldlist_cur = oldlist_cur->next; } - return result; + + newlist_prev->next = NULL; + newlist->tail = newlist_prev; + + check_list_invariants(newlist); + return newlist; } /* - * set_differenceo - * - * Same as set_difference, but for Oid lists + * Return a shallow copy of the specified list, without the first N elements. */ List * -set_differenceo(List *l1, List *l2) +list_copy_tail(List *oldlist, int nskip) { - List *result = NIL; - List *i; + List *newlist; + ListCell *newlist_prev; + ListCell *oldlist_cur; + + if (nskip < 0) + nskip = 0; /* would it be better to elog? */ - if (l2 == NIL) - return listCopy(l1); /* slightly faster path for empty l2 */ + if (oldlist == NIL || nskip >= oldlist->length) + return NIL; - foreach(i, l1) + newlist = new_list(oldlist->type); + newlist->length = oldlist->length - nskip; + + /* + * Skip over the unwanted elements. + */ + oldlist_cur = oldlist->head; + while (nskip-- > 0) + oldlist_cur = oldlist_cur->next; + + /* + * Copy over the data in the first remaining cell; new_list() has already + * allocated the head cell itself + */ + newlist->head->data = oldlist_cur->data; + + newlist_prev = newlist->head; + oldlist_cur = oldlist_cur->next; + while (oldlist_cur) { - if (!oidMember(lfirsto(i), l2)) - result = lappendo(result, lfirsto(i)); + ListCell *newlist_cur; + + newlist_cur = (ListCell *) palloc(sizeof(*newlist_cur)); + newlist_cur->data = oldlist_cur->data; + newlist_prev->next = newlist_cur; + + newlist_prev = newlist_cur; + oldlist_cur = oldlist_cur->next; } - return result; + + newlist_prev->next = NULL; + newlist->tail = newlist_prev; + + check_list_invariants(newlist); + return newlist; } /* - * set_ptrDifference + * When using non-GCC compilers, we can't define these as inline + * functions in pg_list.h, so they are defined here. * - * Same as set_difference, when pointer-equality comparison is sufficient + * TODO: investigate supporting inlining for some non-GCC compilers. */ -List * -set_ptrDifference(List *l1, List *l2) +#ifndef __GNUC__ + +ListCell * +list_head(List *l) { - List *result = NIL; - List *i; + return l ? l->head : NULL; +} - if (l2 == NIL) - return listCopy(l1); /* slightly faster path for empty l2 */ +ListCell * +list_tail(List *l) +{ + return l ? l->tail : NULL; +} - foreach(i, l1) - { - if (!ptrMember(lfirst(i), l2)) - result = lappend(result, lfirst(i)); - } - return result; +int +list_length(List *l) +{ + return l ? l->length : 0; } +#endif /* ! __GNUC__ */ + /* - * Reverse a list, non-destructively + * Temporary compatibility functions + * + * In order to avoid warnings for these function definitions, we need + * to include a prototype here as well as in pg_list.h. That's because + * we explicitly disable list API compatibility in list.c, so we + * don't see the prototypes for these functions. */ -#ifdef NOT_USED + +/* + * Given a list, return its length. This is merely defined for the + * sake of backward compatibility: we can't afford to define a macro + * called "length", so it must be a function. New code should use the + * list_length() macro in order to avoid the overhead of a function + * call. + */ +int length(List *list); + +int +length(List *list) +{ + return list_length(list); +} + +/* + * This code implements the old "Fast List" API, making use of the new + * List code to do so. There's no need for FastList anymore, so this + * code is a bit sloppy -- it will be removed soon. + */ +void FastListInit(FastList *fl); + +void +FastListInit(FastList *fl) +{ + fl->list = NIL; +} + +void FastListFromList(FastList *fl, List *l); + +void +FastListFromList(FastList *fl, List *list) +{ + fl->list = list; +} + +List *FastListValue(FastList *fl); + List * -lreverse(List *l) +FastListValue(FastList *fl) +{ + return fl->list; +} + +void makeFastList1(FastList *fl, void *elem); + +void +makeFastList1(FastList *fl, void *elem) { - List *result = NIL; - List *i; + fl->list = list_make1(elem); +} - foreach(i, l) - result = lcons(lfirst(i), result); - return result; +void FastAppend(FastList *fl, void *datum); + +void +FastAppend(FastList *fl, void *datum) +{ + fl->list = lappend(fl->list, datum); } -#endif +void FastAppendi(FastList *fl, int datum); + +void +FastAppendi(FastList *fl, int datum) +{ + fl->list = lappend_int(fl->list, datum); +} + +void FastAppendo(FastList *fl, Oid datum); + +void +FastAppendo(FastList *fl, Oid datum) +{ + fl->list = lappend_oid(fl->list, datum); +} + +void FastConc(FastList *fl, List *cells); + +void +FastConc(FastList *fl, List *cells) +{ + fl->list = list_concat(fl->list, cells); +} + +void FastConcFast(FastList *fl1, FastList *fl2); + +void +FastConcFast(FastList *fl1, FastList *fl2) +{ + fl1->list = list_concat(fl1->list, fl2->list); +} diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index e919a85194..f9e3f7fbcb 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.236 2004/05/10 22:44:44 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.237 2004/05/26 04:41:19 neilc Exp $ * * NOTES * Every node type that can appear in stored rules' parsetrees *must* @@ -19,6 +19,8 @@ * *------------------------------------------------------------------------- */ +#define DISABLE_LIST_COMPAT + #include "postgres.h" #include @@ -85,16 +87,6 @@ (appendStringInfo(str, " :" CppAsString(fldname) " "), \ _outNode(str, node->fldname)) -/* Write an integer-list field */ -#define WRITE_INTLIST_FIELD(fldname) \ - (appendStringInfo(str, " :" CppAsString(fldname) " "), \ - _outIntList(str, node->fldname)) - -/* Write an OID-list field */ -#define WRITE_OIDLIST_FIELD(fldname) \ - (appendStringInfo(str, " :" CppAsString(fldname) " "), \ - _outOidList(str, node->fldname)) - /* Write a bitmapset field */ #define WRITE_BITMAPSET_FIELD(fldname) \ (appendStringInfo(str, " :" CppAsString(fldname) " "), \ @@ -145,35 +137,40 @@ _outToken(StringInfo str, char *s) } } -/* - * _outIntList - - * converts a List of integers - */ static void -_outIntList(StringInfo str, List *list) +_outList(StringInfo str, List *node) { - List *l; + ListCell *lc; appendStringInfoChar(str, '('); - appendStringInfoChar(str, 'i'); - foreach(l, list) - appendStringInfo(str, " %d", lfirsti(l)); - appendStringInfoChar(str, ')'); -} -/* - * _outOidList - - * converts a List of OIDs - */ -static void -_outOidList(StringInfo str, List *list) -{ - List *l; + if (IsA(node, IntList)) + appendStringInfoChar(str, 'i'); + else if (IsA(node, OidList)) + appendStringInfoChar(str, 'o'); + + foreach (lc, node) + { + /* + * For the sake of backward compatibility, we emit a slightly + * different whitespace format for lists of nodes vs. other + * types of lists. XXX: is this necessary? + */ + if (IsA(node, List)) + { + _outNode(str, lfirst(lc)); + if (lnext(lc)) + appendStringInfoChar(str, ' '); + } + else if (IsA(node, IntList)) + appendStringInfo(str, " %d", lfirst_int(lc)); + else if (IsA(node, OidList)) + appendStringInfo(str, " %u", lfirst_oid(lc)); + else + elog(ERROR, "unrecognized list node type: %d", + (int) node->type); + } - appendStringInfoChar(str, '('); - appendStringInfoChar(str, 'o'); - foreach(l, list) - appendStringInfo(str, " %u", lfirsto(l)); appendStringInfoChar(str, ')'); } @@ -336,39 +333,12 @@ _outIndexScan(StringInfo str, IndexScan *node) _outScanInfo(str, (S