Index: src/backend/parser/analyze.c
===================================================================
RCS file: /Users/neilc/local/cvs/pgsql-server/src/backend/parser/analyze.c,v
retrieving revision 1.311
diff -c -r1.311 analyze.c
*** src/backend/parser/analyze.c	29 Aug 2004 05:06:44 -0000	1.311
--- src/backend/parser/analyze.c	25 Sep 2004 09:14:45 -0000
***************
*** 2273,2297 ****
  static void
  applyColumnNames(List *dst, List *src)
  {
! 	ListCell   *dst_item = list_head(dst);
! 	ListCell   *src_item = list_head(src);
  
  	if (list_length(src) > list_length(dst))
  		ereport(ERROR,
  				(errcode(ERRCODE_SYNTAX_ERROR),
  			 errmsg("CREATE TABLE AS specifies too many column names")));
  
! 	while (src_item != NULL && dst_item != NULL)
  	{
  		TargetEntry *d = (TargetEntry *) lfirst(dst_item);
  		ColumnDef  *s = (ColumnDef *) lfirst(src_item);
  
  		Assert(d->resdom && !d->resdom->resjunk);
- 
  		d->resdom->resname = pstrdup(s->colname);
- 
- 		dst_item = lnext(dst_item);
- 		src_item = lnext(src_item);
  	}
  }
  
--- 2273,2293 ----
  static void
  applyColumnNames(List *dst, List *src)
  {
! 	ListCell   *dst_item;
! 	ListCell   *src_item;
  
  	if (list_length(src) > list_length(dst))
  		ereport(ERROR,
  				(errcode(ERRCODE_SYNTAX_ERROR),
  			 errmsg("CREATE TABLE AS specifies too many column names")));
  
! 	forboth(dst_item, dst, src_item, src)
  	{
  		TargetEntry *d = (TargetEntry *) lfirst(dst_item);
  		ColumnDef  *s = (ColumnDef *) lfirst(src_item);
  
  		Assert(d->resdom && !d->resdom->resjunk);
  		d->resdom->resname = pstrdup(s->colname);
  	}
  }
  
Index: src/backend/utils/cache/catcache.c
===================================================================
RCS file: /Users/neilc/local/cvs/pgsql-server/src/backend/utils/cache/catcache.c,v
retrieving revision 1.116
diff -c -r1.116 catcache.c
*** src/backend/utils/cache/catcache.c	29 Aug 2004 05:06:50 -0000	1.116
--- src/backend/utils/cache/catcache.c	25 Sep 2004 10:35:47 -0000
***************
*** 1501,1507 ****
  		 * worth fixing.
  		 */
  		ct->refcount++;
! 		ctlist = lcons(ct, ctlist);
  		nmembers++;
  	}
  
--- 1501,1507 ----
  		 * worth fixing.
  		 */
  		ct->refcount++;
! 		ctlist = lappend(ctlist, ct);
  		nmembers++;
  	}
  
***************
*** 1522,1537 ****
  
  	cl->cl_magic = CL_MAGIC;
  	cl->my_cache = cache;
! 	DLInitElem(&cl->cache_elem, (void *) cl);
  	cl->refcount = 0;			/* for the moment */
  	cl->dead = false;
  	cl->ordered = ordered;
  	cl->nkeys = nkeys;
  	cl->hash_value = lHashValue;
  	cl->n_members = nmembers;
! 	/* The list is backwards because we built it with lcons */
  	ctlist_item = list_head(ctlist);
! 	for (i = nmembers; --i >= 0;)
  	{
  		cl->members[i] = ct = (CatCTup *) lfirst(ctlist_item);
  		Assert(ct->c_list == NULL);
--- 1522,1538 ----
  
  	cl->cl_magic = CL_MAGIC;
  	cl->my_cache = cache;
! 	DLInitElem(&cl->cache_elem, cl);
  	cl->refcount = 0;			/* for the moment */
  	cl->dead = false;
  	cl->ordered = ordered;
  	cl->nkeys = nkeys;
  	cl->hash_value = lHashValue;
  	cl->n_members = nmembers;
! 
! 	Assert(nmembers == list_length(ctlist));
  	ctlist_item = list_head(ctlist);
! 	for (i = 0; i < nmembers; i++)
  	{
  		cl->members[i] = ct = (CatCTup *) lfirst(ctlist_item);
  		Assert(ct->c_list == NULL);
Index: src/include/nodes/pg_list.h
===================================================================
RCS file: /Users/neilc/local/cvs/pgsql-server/src/include/nodes/pg_list.h,v
retrieving revision 1.49
diff -c -r1.49 pg_list.h
*** src/include/nodes/pg_list.h	29 Aug 2004 05:06:57 -0000	1.49
--- src/include/nodes/pg_list.h	25 Sep 2004 09:32:52 -0000
***************
*** 167,174 ****
   *	  a convenience macro which loops through a list starting from a
   *	  specified cell
   */
! #define for_each_cell(cell, l)	\
! 	for ((cell) = (l); (cell) != NULL; (cell) = lnext(cell))
  
  /*
   * forboth -
--- 167,174 ----
   *	  a convenience macro which loops through a list starting from a
   *	  specified cell
   */
! #define for_each_cell(cell, initcell)	\
! 	for ((cell) = (initcell); (cell) != NULL; (cell) = lnext(cell))
  
  /*
   * forboth -
