Module Name:    src
Committed By:   rillig
Date:           Sat Aug 22 14:39:12 UTC 2020

Modified Files:
        src/usr.bin/make: arch.c compat.c dir.c lst.c lst.h make.c parse.c
            suff.c

Log Message:
make(1): convert Lst_Enqueue and Lst_Dequeue to nonnull variants

Except for once instance in parse.c, the usage pattern for Lst_Dequeue
was to first test whether the list is empty.  This pattern allowed the
implementation of Lst_Dequeue to become simpler since the null check is
not needed anymore.

The calls to Lst_Enqueue never pass an invalid list or a null pointer,
therefore making them strict was trivial.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/make/arch.c
cvs rdiff -u -r1.122 -r1.123 src/usr.bin/make/compat.c
cvs rdiff -u -r1.101 -r1.102 src/usr.bin/make/dir.c
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/make/lst.c
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/make/lst.h
cvs rdiff -u -r1.114 -r1.115 src/usr.bin/make/make.c
cvs rdiff -u -r1.255 -r1.256 src/usr.bin/make/parse.c
cvs rdiff -u -r1.103 -r1.104 src/usr.bin/make/suff.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/arch.c
diff -u src/usr.bin/make/arch.c:1.87 src/usr.bin/make/arch.c:1.88
--- src/usr.bin/make/arch.c:1.87	Sat Aug 22 11:35:00 2020
+++ src/usr.bin/make/arch.c	Sat Aug 22 14:39:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.87 2020/08/22 11:35:00 rillig Exp $	*/
+/*	$NetBSD: arch.c,v 1.88 2020/08/22 14:39:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: arch.c,v 1.87 2020/08/22 11:35:00 rillig Exp $";
+static char rcsid[] = "$NetBSD: arch.c,v 1.88 2020/08/22 14:39:12 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)arch.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: arch.c,v 1.87 2020/08/22 11:35:00 rillig Exp $");
+__RCSID("$NetBSD: arch.c,v 1.88 2020/08/22 14:39:12 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -393,13 +393,12 @@ Arch_ParseArchive(char **linePtr, Lst no
 	    free(buf);
 	} else if (Dir_HasWildcards(memName)) {
 	    Lst	  members = Lst_Init();
-	    char  *member;
 	    size_t sz = MAXPATHLEN, nsz;
 	    nameBuf = bmake_malloc(sz);
 
 	    Dir_Expand(memName, dirSearchPath, members);
 	    while (!Lst_IsEmpty(members)) {
-		member = (char *)Lst_DeQueue(members);
+		char *member = Lst_DequeueS(members);
 		nsz = strlen(libName) + strlen(member) + 3;
 		if (sz > nsz)
 		    nameBuf = bmake_realloc(nameBuf, sz = nsz * 2);

Index: src/usr.bin/make/compat.c
diff -u src/usr.bin/make/compat.c:1.122 src/usr.bin/make/compat.c:1.123
--- src/usr.bin/make/compat.c:1.122	Sat Aug 22 11:35:00 2020
+++ src/usr.bin/make/compat.c	Sat Aug 22 14:39:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat.c,v 1.122 2020/08/22 11:35:00 rillig Exp $	*/
+/*	$NetBSD: compat.c,v 1.123 2020/08/22 14:39:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: compat.c,v 1.122 2020/08/22 11:35:00 rillig Exp $";
+static char rcsid[] = "$NetBSD: compat.c,v 1.123 2020/08/22 14:39:12 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)compat.c	8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: compat.c,v 1.122 2020/08/22 11:35:00 rillig Exp $");
+__RCSID("$NetBSD: compat.c,v 1.123 2020/08/22 14:39:12 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -746,8 +746,8 @@ Compat_Run(Lst targs)
      *	    	  	    could not be made due to errors.
      */
     errors = 0;
-    while (!Lst_IsEmpty (targs)) {
-	gn = (GNode *)Lst_DeQueue(targs);
+    while (!Lst_IsEmpty(targs)) {
+	gn = Lst_DequeueS(targs);
 	Compat_Make(gn, gn);
 
 	if (gn->made == UPTODATE) {

Index: src/usr.bin/make/dir.c
diff -u src/usr.bin/make/dir.c:1.101 src/usr.bin/make/dir.c:1.102
--- src/usr.bin/make/dir.c:1.101	Sat Aug 22 14:04:22 2020
+++ src/usr.bin/make/dir.c	Sat Aug 22 14:39:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.101 2020/08/22 14:04:22 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.102 2020/08/22 14:39:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: dir.c,v 1.101 2020/08/22 14:04:22 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.102 2020/08/22 14:39:12 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.101 2020/08/22 14:04:22 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.102 2020/08/22 14:39:12 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1732,9 +1732,8 @@ Dir_Destroy(void *pp)
 void
 Dir_ClearPath(Lst path)
 {
-    Path *p;
     while (!Lst_IsEmpty(path)) {
-	p = (Path *)Lst_DeQueue(path);
+	Path *p = Lst_DequeueS(path);
 	Dir_Destroy(p);
     }
 }

Index: src/usr.bin/make/lst.c
diff -u src/usr.bin/make/lst.c:1.24 src/usr.bin/make/lst.c:1.25
--- src/usr.bin/make/lst.c:1.24	Sat Aug 22 13:49:40 2020
+++ src/usr.bin/make/lst.c	Sat Aug 22 14:39:12 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.24 2020/08/22 13:49:40 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.25 2020/08/22 14:39:12 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -37,11 +37,11 @@
 #include "make.h"
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: lst.c,v 1.24 2020/08/22 13:49:40 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.25 2020/08/22 14:39:12 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.24 2020/08/22 13:49:40 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.25 2020/08/22 14:39:12 rillig Exp $");
 #endif /* not lint */
 #endif
 
@@ -786,30 +786,23 @@ Lst_CloseS(Lst list)
  */
 
 /* Add the datum to the tail of the given list. */
-ReturnStatus
-Lst_EnQueue(Lst list, void *datum)
+void
+Lst_EnqueueS(Lst list, void *datum)
 {
-    if (!LstIsValid(list)) {
-	return FAILURE;
-    }
-
-    return Lst_InsertAfter(list, Lst_Last(list), datum);
+    Lst_AppendS(list, datum);
 }
 
-/* Remove and return the datum at the head of the given list, or NULL if the
- * list is empty. */
+/* Remove and return the datum at the head of the given list. */
 void *
-Lst_DeQueue(Lst list)
+Lst_DequeueS(Lst list)
 {
-    LstNode head;
     void *datum;
 
-    head = Lst_First(list);
-    if (head == NULL) {
-	return NULL;
-    }
+    assert(LstIsValid(list));
+    assert(!LstIsEmpty(list));
 
-    datum = head->datum;
-    Lst_RemoveS(list, head);
+    datum = list->first->datum;
+    Lst_RemoveS(list, list->first);
+    assert(datum != NULL);
     return datum;
 }

Index: src/usr.bin/make/lst.h
diff -u src/usr.bin/make/lst.h:1.30 src/usr.bin/make/lst.h:1.31
--- src/usr.bin/make/lst.h:1.30	Sat Aug 22 13:28:20 2020
+++ src/usr.bin/make/lst.h	Sat Aug 22 14:39:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lst.h,v 1.30 2020/08/22 13:28:20 rillig Exp $	*/
+/*	$NetBSD: lst.h,v 1.31 2020/08/22 14:39:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -180,8 +180,8 @@ void		Lst_CloseS(Lst);
  * for using the list as a queue
  */
 /* Place an element at tail of queue */
-ReturnStatus	Lst_EnQueue(Lst, void *);
+void		Lst_EnqueueS(Lst, void *);
 /* Remove an element from head of queue */
-void		*Lst_DeQueue(Lst);
+void		*Lst_DequeueS(Lst);
 
 #endif /* MAKE_LST_H */

Index: src/usr.bin/make/make.c
diff -u src/usr.bin/make/make.c:1.114 src/usr.bin/make/make.c:1.115
--- src/usr.bin/make/make.c:1.114	Sat Aug 22 13:44:17 2020
+++ src/usr.bin/make/make.c	Sat Aug 22 14:39:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.c,v 1.114 2020/08/22 13:44:17 rillig Exp $	*/
+/*	$NetBSD: make.c,v 1.115 2020/08/22 14:39:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: make.c,v 1.114 2020/08/22 13:44:17 rillig Exp $";
+static char rcsid[] = "$NetBSD: make.c,v 1.115 2020/08/22 14:39:12 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)make.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: make.c,v 1.114 2020/08/22 13:44:17 rillig Exp $");
+__RCSID("$NetBSD: make.c,v 1.115 2020/08/22 14:39:12 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -378,7 +378,7 @@ MakeAddChild(void *gnp, void *lp)
 	if (DEBUG(MAKE))
 	    fprintf(debug_file, "MakeAddChild: need to examine %s%s\n",
 		gn->name, gn->cohort_num);
-	(void)Lst_EnQueue(l, gn);
+	Lst_EnqueueS(l, gn);
     }
     return 0;
 }
@@ -794,7 +794,7 @@ Make_Update(GNode *cgn)
 	    }
 	    /* Ok, we can schedule the parent again */
 	    pgn->made = REQUESTED;
-	    (void)Lst_EnQueue(toBeMade, pgn);
+	    Lst_EnqueueS(toBeMade, pgn);
 	}
 	Lst_CloseS(parents);
     }
@@ -1050,13 +1050,13 @@ MakeStartJobs(void)
     GNode	*gn;
     int		have_token = 0;
 
-    while (!Lst_IsEmpty (toBeMade)) {
+    while (!Lst_IsEmpty(toBeMade)) {
 	/* Get token now to avoid cycling job-list when we only have 1 token */
 	if (!have_token && !Job_TokenWithdraw())
 	    break;
 	have_token = 1;
 
-	gn = (GNode *)Lst_DeQueue(toBeMade);
+	gn = Lst_DequeueS(toBeMade);
 	if (DEBUG(MAKE))
 	    fprintf(debug_file, "Examining %s%s...\n",
 		    gn->name, gn->cohort_num);
@@ -1269,8 +1269,8 @@ Make_ExpandUse(Lst targs)
      * be looked at in a minute, otherwise we add its children to our queue
      * and go on about our business.
      */
-    while (!Lst_IsEmpty (examine)) {
-	gn = (GNode *)Lst_DeQueue(examine);
+    while (!Lst_IsEmpty(examine)) {
+	gn = Lst_DequeueS(examine);
 
 	if (gn->flags & REMAKE)
 	    /* We've looked at this one already */
@@ -1405,8 +1405,8 @@ Make_ProcessWait(Lst targs)
     examine = Lst_Init();
     Lst_AppendS(examine, pgn);
 
-    while (!Lst_IsEmpty (examine)) {
-	pgn = Lst_DeQueue(examine);
+    while (!Lst_IsEmpty(examine)) {
+	pgn = Lst_DequeueS(examine);
 
 	/* We only want to process each child-list once */
 	if (pgn->flags & DONE_WAIT)

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.255 src/usr.bin/make/parse.c:1.256
--- src/usr.bin/make/parse.c:1.255	Sat Aug 22 13:44:17 2020
+++ src/usr.bin/make/parse.c	Sat Aug 22 14:39:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.255 2020/08/22 13:44:17 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.256 2020/08/22 14:39:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.255 2020/08/22 13:44:17 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.256 2020/08/22 14:39:12 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.255 2020/08/22 13:44:17 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.256 2020/08/22 14:39:12 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1447,7 +1447,7 @@ ParseDoDependency(char *line)
 	    /* Apply the targets. */
 
 	    while(!Lst_IsEmpty(curTargs)) {
-		char	*targName = (char *)Lst_DeQueue(curTargs);
+		char *targName = Lst_DequeueS(curTargs);
 
 		if (!Suff_IsTransform (targName)) {
 		    gn = Targ_FindNode(targName, TARG_CREATE);
@@ -1721,8 +1721,8 @@ ParseDoDependency(char *line)
 		    goto out;
 		}
 
-		while (!Lst_IsEmpty (sources)) {
-		    gn = (GNode *)Lst_DeQueue(sources);
+		while (!Lst_IsEmpty(sources)) {
+		    gn = Lst_DequeueS(sources);
 		    ParseDoSrc(tOp, gn->name);
 		}
 		Lst_Destroy(sources, NULL);
@@ -2745,9 +2745,8 @@ ParseEOF(void)
     free(curFile->P_str);
     free(curFile);
 
-    curFile = Lst_DeQueue(includes);
-
-    if (curFile == NULL) {
+    if (Lst_IsEmpty(includes)) {
+        curFile = NULL;
 	/* We've run out of input */
 	Var_Delete(".PARSEDIR", VAR_GLOBAL);
 	Var_Delete(".PARSEFILE", VAR_GLOBAL);
@@ -2756,6 +2755,7 @@ ParseEOF(void)
 	return DONE;
     }
 
+    curFile = Lst_DequeueS(includes);
     if (DEBUG(PARSE))
 	fprintf(debug_file, "ParseEOF: returning to file %s, line %d\n",
 	    curFile->fname, curFile->lineno);

Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.103 src/usr.bin/make/suff.c:1.104
--- src/usr.bin/make/suff.c:1.103	Sat Aug 22 13:28:20 2020
+++ src/usr.bin/make/suff.c	Sat Aug 22 14:39:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.103 2020/08/22 13:28:20 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.104 2020/08/22 14:39:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.103 2020/08/22 13:28:20 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.104 2020/08/22 14:39:12 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)suff.c	8.4 (Berkeley) 3/21/94";
 #else
-__RCSID("$NetBSD: suff.c,v 1.103 2020/08/22 13:28:20 rillig Exp $");
+__RCSID("$NetBSD: suff.c,v 1.104 2020/08/22 14:39:12 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1358,7 +1358,7 @@ SuffFindThem(Lst srcs, Lst slst)
     rs = NULL;
 
     while (!Lst_IsEmpty (srcs)) {
-	s = (Src *)Lst_DeQueue(srcs);
+	s = Lst_DequeueS(srcs);
 
 	if (DEBUG(SUFF)) {
 	    fprintf(debug_file, "\ttrying %s...", s->file);
@@ -1640,7 +1640,7 @@ SuffExpandChildren(LstNode cln, GNode *p
 	 * Add all elements of the members list to the parent node.
 	 */
 	while(!Lst_IsEmpty(members)) {
-	    gn = (GNode *)Lst_DeQueue(members);
+	    gn = Lst_DequeueS(members);
 
 	    if (DEBUG(SUFF)) {
 		fprintf(debug_file, "%s...", gn->name);
@@ -1693,7 +1693,7 @@ SuffExpandWildcards(LstNode cln, GNode *
 	/*
 	 * Fetch next expansion off the list and find its GNode
 	 */
-	cp = (char *)Lst_DeQueue(explist);
+	cp = Lst_DequeueS(explist);
 
 	if (DEBUG(SUFF)) {
 	    fprintf(debug_file, "%s...", cp);

Reply via email to