aboutsummaryrefslogtreecommitdiff
path: root/src/backend/nodes
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/nodes')
-rw-r--r--src/backend/nodes/copyfuncs.c62
-rw-r--r--src/backend/nodes/equalfuncs.c15
-rw-r--r--src/backend/nodes/list.c145
-rw-r--r--src/backend/nodes/outfuncs.c6
-rw-r--r--src/backend/nodes/readfuncs.c8
5 files changed, 142 insertions, 94 deletions
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
index ba7f48bc200..4be727d2aba 100644
--- a/src/backend/nodes/copyfuncs.c
+++ b/src/backend/nodes/copyfuncs.c
@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.241 2003/02/09 00:30:39 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.242 2003/02/09 06:56:27 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -47,6 +47,10 @@
#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))
@@ -69,31 +73,38 @@
* 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, which is
- * grotty but unlikely to break --- it could fail if sizeof(pointer)
- * is less than sizeof(int), but I don't know any such machines...
+ * 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!
+ * of integers or Oids!
*/
List *
listCopy(List *list)
{
List *newlist,
- *l,
- *nl;
+ *oldl,
+ *newcell,
+ *prev;
/* rather ugly coding for speed... */
if (list == NIL)
return NIL;
- newlist = nl = makeList1(lfirst(list));
+ newcell = makeNode(List);
+ newcell->elem = list->elem;
+
+ newlist = prev = newcell;
- foreach(l, lnext(list))
+ foreach(oldl, lnext(list))
{
- lnext(nl) = makeList1(lfirst(l));
- nl = lnext(nl);
+ newcell = makeNode(List);
+ newcell->elem = oldl->elem;
+ prev->next = newcell;
+ prev = newcell;
}
+ prev->next = NIL;
+
return newlist;
}
@@ -248,7 +259,7 @@ _copyIndexScan(IndexScan *from)
/*
* copy remainder of node
*/
- COPY_INTLIST_FIELD(indxid);
+ COPY_OIDLIST_FIELD(indxid);
COPY_NODE_FIELD(indxqual);
COPY_NODE_FIELD(indxqualorig);
COPY_SCALAR_FIELD(indxorderdir);
@@ -816,7 +827,7 @@ _copySubLink(SubLink *from)
COPY_SCALAR_FIELD(useOr);
COPY_NODE_FIELD(lefthand);
COPY_NODE_FIELD(operName);
- COPY_INTLIST_FIELD(operOids);
+ COPY_OIDLIST_FIELD(operOids);
COPY_NODE_FIELD(subselect);
return newnode;
@@ -1523,7 +1534,7 @@ _copySetOperationStmt(SetOperationStmt *from)
COPY_SCALAR_FIELD(all);
COPY_NODE_FIELD(larg);
COPY_NODE_FIELD(rarg);
- COPY_INTLIST_FIELD(colTypes);
+ COPY_OIDLIST_FIELD(colTypes);
return newnode;
}
@@ -2271,7 +2282,7 @@ _copyPrepareStmt(PrepareStmt *from)
COPY_STRING_FIELD(name);
COPY_NODE_FIELD(argtypes);
- COPY_INTLIST_FIELD(argtype_oids);
+ COPY_OIDLIST_FIELD(argtype_oids);
COPY_NODE_FIELD(query);
return newnode;
@@ -2527,19 +2538,26 @@ copyObject(void *from)
case T_List:
{
List *list = from,
- *l,
- *nl;
+ *oldl,
+ *newcell,
+ *prev;
/* rather ugly coding for speed... */
/* Note the input list cannot be NIL if we got here. */
- nl = makeList1(copyObject(lfirst(list)));
- retval = nl;
+ newcell = makeNode(List);
+ lfirst(newcell) = copyObject(lfirst(list));
+
+ retval = (void *) newcell;
+ prev = newcell;
- foreach(l, lnext(list))
+ foreach(oldl, lnext(list))
{
- lnext(nl) = makeList1(copyObject(lfirst(l)));
- nl = lnext(nl);
+ newcell = makeNode(List);
+ lfirst(newcell) = copyObject(lfirst(oldl));
+ prev->next = newcell;
+ prev = newcell;
}
+ prev->next = NIL;
}
break;
diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c
index b347f779bd5..d33c4f52732 100644
--- a/src/backend/nodes/equalfuncs.c
+++ b/src/backend/nodes/equalfuncs.c
@@ -18,7 +18,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.184 2003/02/08 20:20:53 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.185 2003/02/09 06:56:27 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -59,6 +59,13 @@
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 { \
@@ -297,7 +304,7 @@ _equalSubLink(SubLink *a, SubLink *b)
COMPARE_SCALAR_FIELD(useOr);
COMPARE_NODE_FIELD(lefthand);
COMPARE_NODE_FIELD(operName);
- COMPARE_INTLIST_FIELD(operOids);
+ COMPARE_OIDLIST_FIELD(operOids);
COMPARE_NODE_FIELD(subselect);
return true;
@@ -611,7 +618,7 @@ _equalSetOperationStmt(SetOperationStmt *a, SetOperationStmt *b)
COMPARE_SCALAR_FIELD(all);
COMPARE_NODE_FIELD(larg);
COMPARE_NODE_FIELD(rarg);
- COMPARE_INTLIST_FIELD(colTypes);
+ COMPARE_OIDLIST_FIELD(colTypes);
return true;
}
@@ -1237,7 +1244,7 @@ _equalPrepareStmt(PrepareStmt *a, PrepareStmt *b)
{
COMPARE_STRING_FIELD(name);
COMPARE_NODE_FIELD(argtypes);
- COMPARE_INTLIST_FIELD(argtype_oids);
+ COMPARE_OIDLIST_FIELD(argtype_oids);
COMPARE_NODE_FIELD(query);
return true;
diff --git a/src/backend/nodes/list.c b/src/backend/nodes/list.c
index 7fe3eedb2f7..0a379a753b1 100644
--- a/src/backend/nodes/list.c
+++ b/src/backend/nodes/list.c
@@ -1,14 +1,15 @@
/*-------------------------------------------------------------------------
*
* list.c
- * various list handling routines
+ * POSTGRES generic list package
+ *
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/list.c,v 1.47 2003/02/08 20:20:54 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/list.c,v 1.48 2003/02/09 06:56:27 tgl Exp $
*
* NOTES
* XXX a few of the following functions are duplicated to handle
@@ -118,6 +119,21 @@ lconsi(int datum, List *list)
}
/*
+ * lconso
+ *
+ * Same as lcons, but for Oid data
+ */
+List *
+lconso(Oid datum, List *list)
+{
+ List *l = makeNode(List);
+
+ lfirsto(l) = datum;
+ lnext(l) = list;
+ return l;
+}
+
+/*
* lappend
*
* Add obj to the end of list, or make a new list if 'list' is NIL
@@ -142,6 +158,17 @@ lappendi(List *list, int datum)
}
/*
+ * lappendo
+ *
+ * Same as lappend, but for Oids
+ */
+List *
+lappendo(List *list, Oid datum)
+{
+ return nconc(list, makeListo1(datum));
+}
+
+/*
* nconc
*
* Concat l2 on to the end of l1
@@ -159,7 +186,7 @@ nconc(List *l1, List *l2)
if (l2 == NIL)
return l1;
if (l1 == l2)
- elog(ERROR, "tryout to nconc a list to itself");
+ elog(ERROR, "can't nconc a list to itself");
for (temp = l1; lnext(temp) != NIL; temp = lnext(temp))
;
@@ -177,45 +204,14 @@ void *
nth(int n, List *l)
{
/* XXX assume list is long enough */
- while (n > 0)
+ while (n-- > 0)
{
l = lnext(l);
- n--;
}
return lfirst(l);
}
/*
- * nthi
- *
- * Same as nthi, but for integers
- */
-int
-nthi(int n, List *l)
-{
- /* XXX assume list is long enough */
- while (n > 0)
- {
- l = lnext(l);
- n--;
- }
- return lfirsti(l);
-}
-
-/* this is here solely for rt_store. Get rid of me some day! */
-void
-set_nth(List *l, int n, void *elem)
-{
- /* XXX assume list is long enough */
- while (n > 0)
- {
- l = lnext(l);
- n--;
- }
- lfirst(l) = elem;
-}
-
-/*
* length
*
* Get the length of l
@@ -253,7 +249,7 @@ llast(List *l)
*
* Free the List nodes of a list
* The pointed-to nodes, if any, are NOT freed.
- * This works for integer lists too.
+ * This works for integer and Oid lists too.
*/
void
freeList(List *list)
@@ -290,6 +286,28 @@ equali(List *list1, List *list2)
}
/*
+ * equalo
+ * compares two lists of Oids
+ */
+bool
+equalo(List *list1, List *list2)
+{
+ List *l;
+
+ foreach(l, list1)
+ {
+ if (list2 == NIL)
+ return false;
+ if (lfirsto(l) != lfirsto(list2))
+ return false;
+ list2 = lnext(list2);
+ }
+ if (list2 != NIL)
+ return false;
+ return true;
+}
+
+/*
* Generate the union of two lists,
* ie, l1 plus all members of l2 that are not already in l1.
*
@@ -313,17 +331,17 @@ set_union(List *l1, List *l2)
return retval;
}
-/* set_union for integer lists */
+/* set_union for Oid lists */
List *
-set_unioni(List *l1, List *l2)
+set_uniono(List *l1, List *l2)
{
List *retval = listCopy(l1);
List *i;
foreach(i, l2)
{
- if (!intMember(lfirsti(i), retval))
- retval = lappendi(retval, lfirsti(i));
+ if (!oidMember(lfirsto(i), retval))
+ retval = lappendo(retval, lfirsto(i));
}
return retval;
}
@@ -353,6 +371,7 @@ set_ptrUnion(List *l1, List *l2)
* The result is a fresh List, but it points to the same member nodes
* as were in the inputs.
*/
+#ifdef NOT_USED
List *
set_intersect(List *l1, List *l2)
{
@@ -366,20 +385,7 @@ set_intersect(List *l1, List *l2)
}
return retval;
}
-
-List *
-set_intersecti(List *l1, List *l2)
-{
- List *retval = NIL;
- List *i;
-
- foreach(i, l1)
- {
- if (intMember(lfirsti(i), l2))
- retval = lappendi(retval, lfirsti(i));
- }
- return retval;
-}
+#endif
/*
* member()
@@ -408,7 +414,7 @@ ptrMember(void *l1, List *l2)
foreach(i, l2)
{
- if (l1 == ((void *) lfirst(i)))
+ if (l1 == lfirst(i))
return true;
}
return false;
@@ -431,8 +437,25 @@ intMember(int l1, List *l2)
}
/*
+ * membership test for Oid lists
+ */
+bool
+oidMember(Oid l1, List *l2)
+{
+ List *i;
+
+ foreach(i, l2)
+ {
+ if (l1 == lfirsto(i))
+ return true;
+ }
+ return false;
+}
+
+/*
* lremove
* 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 simple pointer comparison.
* See also LispRemove.
@@ -464,9 +487,9 @@ lremove(void *elem, List *list)
/*
* 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().
- * (If there is more than one equal list member, the first is removed.)
* See also lremove.
*/
List *
@@ -572,12 +595,12 @@ set_difference(List *l1, List *l2)
}
/*
- * set_differencei
+ * set_differenceo
*
- * Same as set_difference, but for integers
+ * Same as set_difference, but for Oid lists
*/
List *
-set_differencei(List *l1, List *l2)
+set_differenceo(List *l1, List *l2)
{
List *result = NIL;
List *i;
@@ -587,8 +610,8 @@ set_differencei(List *l1, List *l2)
foreach(i, l1)
{
- if (!intMember(lfirsti(i), l2))
- result = lappendi(result, lfirsti(i));
+ if (!oidMember(lfirsto(i), l2))
+ result = lappendo(result, lfirsto(i));
}
return result;
}
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
index 9d4f977f22d..c42f2639df1 100644
--- a/src/backend/nodes/outfuncs.c
+++ b/src/backend/nodes/outfuncs.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.197 2003/02/09 00:30:39 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.198 2003/02/09 06:56:27 tgl Exp $
*
* NOTES
* Every node type that can appear in stored rules' parsetrees *must*
@@ -173,7 +173,7 @@ _outOidList(StringInfo str, List *list)
appendStringInfoChar(str, '(');
foreach(l, list)
- appendStringInfo(str, " %u", (Oid) lfirsti(l));
+ appendStringInfo(str, " %u", lfirsto(l));
appendStringInfoChar(str, ')');
}
@@ -689,7 +689,7 @@ _outSubLink(StringInfo str, SubLink *node)
WRITE_BOOL_FIELD(useOr);
WRITE_NODE_FIELD(lefthand);
WRITE_NODE_FIELD(operName);
- WRITE_INTLIST_FIELD(operOids);
+ WRITE_OIDLIST_FIELD(operOids);
WRITE_NODE_FIELD(subselect);
}
diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c
index fe4831ee9f6..f37856728b1 100644
--- a/src/backend/nodes/readfuncs.c
+++ b/src/backend/nodes/readfuncs.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.147 2003/02/03 21:15:44 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.148 2003/02/09 06:56:27 tgl Exp $
*
* NOTES
* Path and Plan nodes do not have any readfuncs support, because we
@@ -170,12 +170,12 @@ toOidList(List *list)
*/
if (IsA(v, Integer))
{
- lfirsti(l) = (Oid) intVal(v);
+ lfirsto(l) = (Oid) intVal(v);
pfree(v);
}
else if (IsA(v, Float))
{
- lfirsti(l) = atooid(strVal(v));
+ lfirsto(l) = atooid(strVal(v));
pfree(strVal(v));
pfree(v);
}
@@ -534,7 +534,7 @@ _readSubLink(void)
READ_BOOL_FIELD(useOr);
READ_NODE_FIELD(lefthand);
READ_NODE_FIELD(operName);
- READ_INTLIST_FIELD(operOids);
+ READ_OIDLIST_FIELD(operOids);
READ_NODE_FIELD(subselect);
READ_DONE();