usr.bin/make MACROfy some tiny functions.

Max Okumoto okumoto at ucsd.edu
Wed Dec 1 16:04:24 PST 2004


PatchSet 385
Date: 2004/11/30 10:35:04
Author: harti
Log:
Change a couple of the primitve list functions to be macros. This 
changes the semantic of Lst_Datum which formerly returned NULL
when the argument node was NULL. There was only one place in the
source that relied on this so change that place.
Members:
        Makefile:1.37->1.38
        dir.c:1.32->1.33
        lst.h:1.17->1.18
        lst.lib/lstAtEnd.c:1.11->1.12(DEAD)
        lst.lib/lstAtFront.c:1.11->1.12(DEAD)
        lst.lib/lstDatum.c:1.11->1.12(DEAD)
        lst.lib/lstEnQueue.c:1.11->1.12(DEAD)
        lst.lib/lstFind.c:1.14->1.15(DEAD)
        lst.lib/lstFirst.c:1.10->1.11(DEAD)
        lst.lib/lstForEach.c:1.13->1.14(DEAD)
        lst.lib/lstLast.c:1.9->1.10(DEAD)
        lst.lib/lstReplace.c:1.11->1.12(DEAD)
        lst.lib/lstSucc.c:1.10->1.11(DEAD)
---------------------
PatchSet 385
Date: 2004/11/30 10:35:04
Author: harti
Log:
Change a couple of the primitve list functions to be macros. This changes
the semantic of Lst_Datum which formerly returned NULL when the argument
node was NULL. There was only one place in the source that relied on this
so change that place.

Members: 
	Makefile:1.37->1.38 
	dir.c:1.32->1.33 
	lst.h:1.17->1.18 
	lst.lib/lstAtEnd.c:1.11->1.12(DEAD) 
	lst.lib/lstAtFront.c:1.11->1.12(DEAD) 
	lst.lib/lstDatum.c:1.11->1.12(DEAD) 
	lst.lib/lstEnQueue.c:1.11->1.12(DEAD) 
	lst.lib/lstFind.c:1.14->1.15(DEAD) 
	lst.lib/lstFirst.c:1.10->1.11(DEAD) 
	lst.lib/lstForEach.c:1.13->1.14(DEAD) 
	lst.lib/lstLast.c:1.9->1.10(DEAD) 
	lst.lib/lstReplace.c:1.11->1.12(DEAD) 
	lst.lib/lstSucc.c:1.10->1.11(DEAD) 

Index: Makefile
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/Makefile,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- Makefile	29 Nov 2004 08:38:16 -0000	1.37
+++ Makefile	30 Nov 2004 10:35:04 -0000	1.38
@@ -1,13 +1,11 @@
 
 PROG=	make
 CFLAGS+=-I${.CURDIR}
 SRCS=	arch.c buf.c compat.c cond.c dir.c for.c hash.c job.c main.c \
 	make.c parse.c str.c suff.c targ.c util.c var.c var_modify.c
-SRCS+=	lstAppend.c lstAtEnd.c lstAtFront.c lstClose.c lstConcat.c \
-	lstDatum.c lstDeQueue.c lstDestroy.c lstDupl.c lstEnQueue.c \
-	lstFind.c lstFindFrom.c lstFirst.c lstForEach.c lstForEachFrom.c \
-	lstInit.c lstInsert.c lstIsAtEnd.c lstLast.c \
-	lstMember.c lstNext.c lstOpen.c lstRemove.c lstReplace.c lstSucc.c
+SRCS+=	lstAppend.c lstClose.c lstConcat.c lstDeQueue.c lstDestroy.c \
+	lstDupl.c lstFindFrom.c lstForEachFrom.c lstInit.c lstInsert.c \
+	lstIsAtEnd.c lstMember.c lstNext.c lstOpen.c lstRemove.c
 .PATH:	${.CURDIR}/lst.lib
 
 WARNS?=	3
Index: dir.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/dir.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- dir.c	2 Oct 2003 21:30:30 -0000	1.32
+++ dir.c	30 Nov 2004 10:35:04 -0000	1.33
@@ -231,10 +231,12 @@
 void
 Dir_InitDot (void)
 {
+    LstNode ln;
+
     Dir_AddDir (openDirectories, ".");
-    dot = (Path *)Lst_Datum(Lst_Last(openDirectories));
-    if (dot == (Path *) NULL)
+    if ((ln = Lst_Last(openDirectories)) == NULL)
 	err(1, "cannot open current directory");
+    dot = Lst_Datum(ln);
 
     /*
      * We always need to have dot around, so we increment its reference count
Index: lst.h
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- lst.h	29 Nov 2004 12:17:12 -0000	1.17
+++ lst.h	30 Nov 2004 10:35:04 -0000	1.18
@@ -127,13 +127,14 @@
 /* Insert an element after another */
 ReturnStatus	Lst_Append(Lst, LstNode, void *);
 /* Place an element at the front of a lst. */
-ReturnStatus	Lst_AtFront(Lst, void *);
+#define	Lst_AtFront(LST, D)	(Lst_Insert((LST), Lst_First(LST), (D)))
 /* Place an element at the end of a lst. */
-ReturnStatus	Lst_AtEnd(Lst, void *);
+#define	Lst_AtEnd(LST, D) 	(Lst_Append((LST), Lst_Last(LST), (D)))
 /* Remove an element */
 ReturnStatus	Lst_Remove(Lst, LstNode);
 /* Replace a node with a new value */
-ReturnStatus	Lst_Replace(LstNode, void *);
+#define	Lst_Replace(NODE, D)	(((NODE) == NULL) ? FAILURE : \
+				    (((NODE)->datum = (D)), SUCCESS))
 /* Concatenate two lists */
 ReturnStatus	Lst_Concat(Lst, Lst, int);
 
@@ -141,19 +142,21 @@
  * Node-specific functions
  */
 /* Return first element in list */
-LstNode		Lst_First(Lst);
+#define	Lst_First(LST)	((Lst_Valid(LST) && !Lst_IsEmpty(LST)) \
+			    ? (LST)->firstPtr : NULL)
 /* Return last element in list */
-LstNode		Lst_Last(Lst);
+#define	Lst_Last(LST)	((Lst_Valid(LST) && !Lst_IsEmpty(LST)) \
+			    ? (LST)->lastPtr : NULL)
 /* Return successor to given element */
-LstNode		Lst_Succ(LstNode);
+#define	Lst_Succ(NODE)	(((NODE) == NULL) ? NULL : (NODE)->nextPtr)
 /* Get datum from LstNode */
-void *	Lst_Datum(LstNode);
+#define	Lst_Datum(NODE)	((NODE)->datum)
 
 /*
  * Functions for entire lists
  */
 /* Find an element in a list */
-LstNode		Lst_Find(Lst, void *, CompareProc *);
+#define	Lst_Find(LST, D, FN)	(Lst_FindFrom((LST), Lst_First(LST), (D), (FN)))
 /* Find an element starting from somewhere */
 LstNode		Lst_FindFrom(Lst, LstNode, void *, CompareProc *);
 /*
@@ -163,6 +166,8 @@
 LstNode		Lst_Member(Lst, void *);
 /* Apply a function to all elements of a lst */
 void		Lst_ForEach(Lst, DoProc *, void *);
+#define	Lst_ForEach(LST, FN, D)	(Lst_ForEachFrom((LST), Lst_First(LST), \
+				    (FN), (D)))
 /*
  * Apply a function to all elements of a lst starting from a certain point.
  * If the list is circular, the application will wrap around to the
@@ -187,7 +192,9 @@
  * for using the list as a queue
  */
 /* Place an element at tail of queue */
-ReturnStatus	Lst_EnQueue(Lst, void *);
+#define	Lst_EnQueue(LST, D)	(Lst_Valid(LST) \
+				    ? Lst_Append((LST), Lst_Last(LST), (D)) \
+				    : FAILURE)
 /* Remove an element from head of queue */
 void *	Lst_DeQueue(Lst);
 




More information about the Submit mailing list