Module Name:    src
Committed By:   rillig
Date:           Wed Aug 26 22:55:46 UTC 2020

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

Log Message:
make(1): add stricter variants for remaining Lst functions

In most cases the Lst functions are only called when the arguments are
indeed valid.  It's not guaranteed though, therefore each function call
needs to be analyzed and converted individually.

While here, remove a few statements that were only useful when the Lst
functions handled circular lists.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/usr.bin/make/arch.c
cvs rdiff -u -r1.110 -r1.111 src/usr.bin/make/dir.c
cvs rdiff -u -r1.41 -r1.42 src/usr.bin/make/lst.c
cvs rdiff -u -r1.43 -r1.44 src/usr.bin/make/lst.h
cvs rdiff -u -r1.313 -r1.314 src/usr.bin/make/main.c
cvs rdiff -u -r1.123 -r1.124 src/usr.bin/make/make.c
cvs rdiff -u -r1.99 -r1.100 src/usr.bin/make/meta.c
cvs rdiff -u -r1.262 -r1.263 src/usr.bin/make/parse.c
cvs rdiff -u -r1.115 -r1.116 src/usr.bin/make/suff.c
cvs rdiff -u -r1.72 -r1.73 src/usr.bin/make/targ.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.96 src/usr.bin/make/arch.c:1.97
--- src/usr.bin/make/arch.c:1.96	Sun Aug 23 18:59:01 2020
+++ src/usr.bin/make/arch.c	Wed Aug 26 22:55:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.96 2020/08/23 18:59:01 rillig Exp $	*/
+/*	$NetBSD: arch.c,v 1.97 2020/08/26 22:55:46 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: arch.c,v 1.96 2020/08/23 18:59:01 rillig Exp $";
+static char rcsid[] = "$NetBSD: arch.c,v 1.97 2020/08/26 22:55:46 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.96 2020/08/23 18:59:01 rillig Exp $");
+__RCSID("$NetBSD: arch.c,v 1.97 2020/08/26 22:55:46 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -391,7 +391,7 @@ Arch_ParseArchive(char **linePtr, Lst no
 	     */
 	    free(buf);
 	} else if (Dir_HasWildcards(memName)) {
-	    Lst	  members = Lst_Init();
+	    Lst members = Lst_Init();
 	    Buffer nameBuf;
 
 	    Buf_Init(&nameBuf, 0);
@@ -422,7 +422,7 @@ Arch_ParseArchive(char **linePtr, Lst no
 		    Lst_AppendS(nodeLst, gn);
 		}
 	    }
-	    Lst_Destroy(members, NULL);
+	    Lst_FreeS(members);
 	    Buf_Destroy(&nameBuf, TRUE);
 	} else {
 	    Buffer nameBuf;
@@ -1288,45 +1288,19 @@ Arch_LibOODate(GNode *gn)
     return oodate;
 }
 
-/*-
- *-----------------------------------------------------------------------
- * Arch_Init --
- *	Initialize things for this module.
- *
- * Results:
- *	None.
- *
- * Side Effects:
- *	The 'archives' list is initialized.
- *
- *-----------------------------------------------------------------------
- */
+/* Initialize things for this module. */
 void
 Arch_Init(void)
 {
     archives = Lst_Init();
 }
 
-
-
-/*-
- *-----------------------------------------------------------------------
- * Arch_End --
- *	Cleanup things for this module.
- *
- * Results:
- *	None.
- *
- * Side Effects:
- *	The 'archives' list is freed
- *
- *-----------------------------------------------------------------------
- */
+/* Clean up things for this module. */
 void
 Arch_End(void)
 {
 #ifdef CLEANUP
-    Lst_Destroy(archives, ArchFree);
+    Lst_DestroyS(archives, ArchFree);
 #endif
 }
 

Index: src/usr.bin/make/dir.c
diff -u src/usr.bin/make/dir.c:1.110 src/usr.bin/make/dir.c:1.111
--- src/usr.bin/make/dir.c:1.110	Sun Aug 23 16:58:02 2020
+++ src/usr.bin/make/dir.c	Wed Aug 26 22:55:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.110 2020/08/23 16:58:02 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.111 2020/08/26 22:55:46 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.110 2020/08/23 16:58:02 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.111 2020/08/26 22:55:46 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.110 2020/08/23 16:58:02 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.111 2020/08/26 22:55:46 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -461,9 +461,9 @@ Dir_End(void)
     Dir_Destroy(dotLast);
     Dir_Destroy(dot);
     Dir_ClearPath(dirSearchPath);
-    Lst_Destroy(dirSearchPath, NULL);
+    Lst_FreeS(dirSearchPath);
     Dir_ClearPath(openDirectories);
-    Lst_Destroy(openDirectories, NULL);
+    Lst_FreeS(openDirectories);
     Hash_DeleteTable(&mtimes);
 #endif
 }
@@ -895,7 +895,7 @@ Dir_Expand(const char *word, Lst path, L
 			path = Lst_Init();
 			(void)Dir_AddDir(path, dirpath);
 			DirExpandInt(cp + 1, path, expansions);
-			Lst_Destroy(path, NULL);
+			Lst_FreeS(path);
 		    }
 		} else {
 		    /*

Index: src/usr.bin/make/lst.c
diff -u src/usr.bin/make/lst.c:1.41 src/usr.bin/make/lst.c:1.42
--- src/usr.bin/make/lst.c:1.41	Sun Aug 23 16:58:02 2020
+++ src/usr.bin/make/lst.c	Wed Aug 26 22:55:46 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.41 2020/08/23 16:58:02 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.42 2020/08/26 22:55:46 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.41 2020/08/23 16:58:02 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.42 2020/08/26 22:55:46 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.41 2020/08/23 16:58:02 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.42 2020/08/26 22:55:46 rillig Exp $");
 #endif /* not lint */
 #endif
 
@@ -142,36 +142,38 @@ Lst_CopyS(Lst list, LstCopyProc copyProc
     return newList;
 }
 
+/* Free a list and all its nodes. The list data itself are not freed though. */
+void
+Lst_FreeS(Lst list)
+{
+    LstNode node;
+    LstNode next;
+
+    assert(LstIsValid(list));
+
+    for (node = list->first; node != NULL; node = next) {
+	next = node->next;
+	free(node);
+    }
+
+    free(list);
+}
+
 /* Destroy a list and free all its resources. If the freeProc is given, it is
  * called with the datum from each node in turn before the node is freed. */
 void
-Lst_Destroy(Lst list, LstFreeProc freeProc)
+Lst_DestroyS(Lst list, LstFreeProc freeProc)
 {
     LstNode node;
-    LstNode next = NULL;
+    LstNode next;
 
-    if (list == NULL)
-	return;
+    assert(LstIsValid(list));
+    assert(freeProc != NULL);
 
-    /* To ease scanning */
-    if (list->last != NULL)
-	list->last->next = NULL;
-    else {
-	free(list);
-	return;
-    }
-
-    if (freeProc) {
-	for (node = list->first; node != NULL; node = next) {
-	    next = node->next;
-	    freeProc(node->datum);
-	    free(node);
-	}
-    } else {
-	for (node = list->first; node != NULL; node = next) {
-	    next = node->next;
-	    free(node);
-	}
+    for (node = list->first; node != NULL; node = next) {
+	next = node->next;
+	freeProc(node->datum);
+	free(node);
     }
 
     free(list);
@@ -340,6 +342,15 @@ Lst_First(Lst list)
     }
 }
 
+/* Return the first node from the given list, or NULL if the list is empty. */
+LstNode
+Lst_FirstS(Lst list)
+{
+    assert(LstIsValid(list));
+
+    return list->first;
+}
+
 /* Return the last node from the given list, or NULL if the list is empty or
  * invalid. */
 LstNode
@@ -352,6 +363,15 @@ Lst_Last(Lst list)
     }
 }
 
+/* Return the last node from the given list, or NULL if the list is empty. */
+LstNode
+Lst_LastS(Lst list)
+{
+    assert(LstIsValid(list));
+
+    return list->last;
+}
+
 /* Return the successor to the given node on its list, or NULL. */
 LstNode
 Lst_Succ(LstNode node)
@@ -363,6 +383,15 @@ Lst_Succ(LstNode node)
     }
 }
 
+/* Return the successor to the given node on its list, or NULL. */
+LstNode
+Lst_SuccS(LstNode node)
+{
+    assert(LstNodeIsValid(node));
+
+    return node->next;
+}
+
 /* Return the predecessor to the given node on its list, or NULL. */
 LstNode
 Lst_PrevS(LstNode node)
@@ -391,6 +420,15 @@ Lst_IsEmpty(Lst list)
     return !LstIsValid(list) || LstIsEmpty(list);
 }
 
+/* Return TRUE if the given list is empty. */
+Boolean
+Lst_IsEmptyS(Lst list)
+{
+    assert(LstIsValid(list));
+
+    return LstIsEmpty(list);
+}
+
 /* Return the first node from the given list for which the given comparison
  * function returns 0, or NULL if none of the nodes matches. */
 LstNode
@@ -399,27 +437,45 @@ Lst_Find(Lst list, LstFindProc cmp, cons
     return Lst_FindFrom(list, Lst_First(list), cmp, cmpData);
 }
 
+/* Return the first node from the given list for which the given comparison
+ * function returns 0, or NULL if none of the nodes matches. */
+LstNode
+Lst_FindS(Lst list, LstFindProc cmp, const void *cmpData)
+{
+    if (LstIsEmpty(list))
+	return NULL;
+    return Lst_FindFromS(list, Lst_FirstS(list), cmp, cmpData);
+}
+
 /* Return the first node from the given list, starting at the given node, for
  * which the given comparison function returns 0, or NULL if none of the nodes
  * matches. */
 LstNode
 Lst_FindFrom(Lst list, LstNode node, LstFindProc cmp, const void *cmpData)
 {
-    LstNode tln;
-
-    assert(cmp != NULL);
-
     if (!LstIsValid(list) || LstIsEmpty(list) || !LstNodeIsValid(node)) {
 	return NULL;
     }
 
-    tln = node;
+    return Lst_FindFromS(list, node, cmp, cmpData);
+}
 
-    do {
+/* Return the first node from the given list, starting at the given node, for
+ * which the given comparison function returns 0, or NULL if none of the nodes
+ * matches. */
+LstNode
+Lst_FindFromS(Lst list, LstNode node, LstFindProc cmp, const void *cmpData)
+{
+    LstNode tln;
+
+    assert(LstIsValid(list));
+    assert(LstNodeIsValid(node));
+    assert(cmp != NULL);
+
+    for (tln = node; tln != NULL; tln = tln->next) {
 	if (cmp(tln->datum, cmpData) == 0)
 	    return tln;
-	tln = tln->next;
-    } while (tln != node && tln != NULL);
+    }
 
     return NULL;
 }
@@ -446,26 +502,51 @@ Lst_MemberS(Lst list, void *datum)
  * should return 0 if traversal should continue and non-zero if it should
  * abort. */
 int
-Lst_ForEach(Lst list, int (*proc)(void *, void *), void *procData)
+Lst_ForEach(Lst list, LstActionProc proc, void *procData)
 {
     return Lst_ForEachFrom(list, Lst_First(list), proc, procData);
 }
 
+/* Apply the given function to each element of the given list. The function
+ * should return 0 if traversal should continue and non-zero if it should
+ * abort. */
+int
+Lst_ForEachS(Lst list, LstActionProc proc, void *procData)
+{
+    if (LstIsEmpty(list))
+	return 0;		/* XXX: Document what this value means. */
+    return Lst_ForEachFromS(list, Lst_First(list), proc, procData);
+}
+
 /* Apply the given function to each element of the given list, starting from
  * the given node. The function should return 0 if traversal should continue,
  * and non-zero if it should abort. */
 int
 Lst_ForEachFrom(Lst list, LstNode node,
-		int (*proc)(void *, void *), void *procData)
+		LstActionProc proc, void *procData)
+{
+    if (!LstIsValid(list) || LstIsEmpty(list)) {
+	return 0;
+    }
+
+    return Lst_ForEachFromS(list, node, proc, procData);
+}
+
+/* Apply the given function to each element of the given list, starting from
+ * the given node. The function should return 0 if traversal should continue,
+ * and non-zero if it should abort. */
+int
+Lst_ForEachFromS(Lst list, LstNode node,
+		 LstActionProc proc, void *procData)
 {
     LstNode tln = node;
     LstNode next;
     Boolean done;
     int result;
 
-    if (!LstIsValid(list) || LstIsEmpty(list)) {
-	return 0;
-    }
+    assert(LstIsValid(list));
+    assert(LstNodeIsValid(node));
+    assert(proc != NULL);
 
     do {
 	/*

Index: src/usr.bin/make/lst.h
diff -u src/usr.bin/make/lst.h:1.43 src/usr.bin/make/lst.h:1.44
--- src/usr.bin/make/lst.h:1.43	Sun Aug 23 17:04:21 2020
+++ src/usr.bin/make/lst.h	Wed Aug 26 22:55:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lst.h,v 1.43 2020/08/23 17:04:21 rillig Exp $	*/
+/*	$NetBSD: lst.h,v 1.44 2020/08/26 22:55:46 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -105,9 +105,11 @@ Lst		Lst_Init(void);
 /* Duplicate an existing list */
 Lst		Lst_CopyS(Lst, LstCopyProc);
 /* Destroy an old one */
-void		Lst_Destroy(Lst, LstFreeProc);
+void		Lst_FreeS(Lst);
+void		Lst_DestroyS(Lst, LstFreeProc);
 /* True if list is empty */
 Boolean		Lst_IsEmpty(Lst);
+Boolean		Lst_IsEmptyS(Lst);
 
 /*
  * Functions to modify a list
@@ -123,6 +125,7 @@ void		Lst_RemoveS(Lst, LstNode);
 /* Replace a node with a new value */
 void		LstNode_SetS(LstNode, void *);
 void		LstNode_SetNullS(LstNode);
+
 void		Lst_PrependAllS(Lst, Lst);
 void		Lst_AppendAllS(Lst, Lst);
 void		Lst_MoveAllS(Lst, Lst);
@@ -132,10 +135,13 @@ void		Lst_MoveAllS(Lst, Lst);
  */
 /* Return first element in list */
 LstNode		Lst_First(Lst);
+LstNode		Lst_FirstS(Lst);
 /* Return last element in list */
 LstNode		Lst_Last(Lst);
+LstNode		Lst_LastS(Lst);
 /* Return successor to given element */
 LstNode		Lst_Succ(LstNode);
+LstNode		Lst_SuccS(LstNode);
 /* Return predecessor to given element */
 LstNode		Lst_PrevS(LstNode);
 /* Get datum from LstNode */
@@ -146,8 +152,10 @@ void		*Lst_DatumS(LstNode);
  */
 /* Find an element in a list */
 LstNode		Lst_Find(Lst, LstFindProc, const void *);
+LstNode		Lst_FindS(Lst, LstFindProc, const void *);
 /* Find an element starting from somewhere */
 LstNode		Lst_FindFrom(Lst, LstNode, LstFindProc, const void *);
+LstNode		Lst_FindFromS(Lst, LstNode, LstFindProc, const void *);
 /*
  * See if the given datum is on the list. Returns the LstNode containing
  * the datum
@@ -155,8 +163,10 @@ LstNode		Lst_FindFrom(Lst, LstNode, LstF
 LstNode		Lst_MemberS(Lst, void *);
 /* Apply a function to all elements of a lst */
 int		Lst_ForEach(Lst, LstActionProc, void *);
+int		Lst_ForEachS(Lst, LstActionProc, void *);
 /* Apply a function to all elements of a lst starting from a certain point. */
 int		Lst_ForEachFrom(Lst, LstNode, LstActionProc, void *);
+int		Lst_ForEachFromS(Lst, LstNode, LstActionProc, void *);
 /*
  * these functions are for dealing with a list as a table, of sorts.
  * An idea of the "current element" is kept and used by all the functions

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.313 src/usr.bin/make/main.c:1.314
--- src/usr.bin/make/main.c:1.313	Tue Aug 25 16:50:02 2020
+++ src/usr.bin/make/main.c	Wed Aug 26 22:55:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.313 2020/08/25 16:50:02 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.314 2020/08/26 22:55:46 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.313 2020/08/25 16:50:02 rillig Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.314 2020/08/26 22:55:46 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19
 #if 0
 static char sccsid[] = "@(#)main.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.313 2020/08/25 16:50:02 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.314 2020/08/26 22:55:46 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -905,7 +905,7 @@ runTargets(void)
 	 * we consult the parsing module to find the main target(s)
 	 * to create.
 	 */
-	if (Lst_IsEmpty(create))
+	if (Lst_IsEmptyS(create))
 		targs = Parse_MainName();
 	else
 		targs = Targ_FindList(create, TARG_CREATE);
@@ -933,7 +933,7 @@ runTargets(void)
 		Compat_Run(targs);
 		outOfDate = FALSE;
 	}
-	Lst_Destroy(targs, NULL);
+	Lst_FreeS(targs);
 	return outOfDate;
 }
 
@@ -1467,9 +1467,9 @@ main(int argc, char **argv)
 	}
 
 #ifdef CLEANUP
-	Lst_Destroy(variables, NULL);
-	Lst_Destroy(makefiles, NULL);
-	Lst_Destroy(create, free);
+	Lst_FreeS(variables);
+	Lst_FreeS(makefiles);
+	Lst_DestroyS(create, free);
 #endif
 
 	/* print the graph now it's been processed if the user requested it */

Index: src/usr.bin/make/make.c
diff -u src/usr.bin/make/make.c:1.123 src/usr.bin/make/make.c:1.124
--- src/usr.bin/make/make.c:1.123	Tue Aug 25 16:27:24 2020
+++ src/usr.bin/make/make.c	Wed Aug 26 22:55:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.c,v 1.123 2020/08/25 16:27:24 rillig Exp $	*/
+/*	$NetBSD: make.c,v 1.124 2020/08/26 22:55:46 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: make.c,v 1.123 2020/08/25 16:27:24 rillig Exp $";
+static char rcsid[] = "$NetBSD: make.c,v 1.124 2020/08/26 22:55:46 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.123 2020/08/25 16:27:24 rillig Exp $");
+__RCSID("$NetBSD: make.c,v 1.124 2020/08/26 22:55:46 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1306,7 +1306,7 @@ 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)) {
+    while (!Lst_IsEmptyS(examine)) {
 	gn = Lst_DequeueS(examine);
 
 	if (gn->flags & REMAKE)
@@ -1359,7 +1359,7 @@ Make_ExpandUse(Lst targs)
 	    Lst_ForEach(gn->children, MakeAddChild, examine);
     }
 
-    Lst_Destroy(examine, NULL);
+    Lst_FreeS(examine);
 }
 
 /*-
@@ -1465,7 +1465,7 @@ Make_ProcessWait(Lst targs)
 	Lst_CloseS(pgn->children);
     }
 
-    Lst_Destroy(examine, NULL);
+    Lst_FreeS(examine);
 }
 
 /*-

Index: src/usr.bin/make/meta.c
diff -u src/usr.bin/make/meta.c:1.99 src/usr.bin/make/meta.c:1.100
--- src/usr.bin/make/meta.c:1.99	Sun Aug 23 16:58:02 2020
+++ src/usr.bin/make/meta.c	Wed Aug 26 22:55:46 2020
@@ -1,4 +1,4 @@
-/*      $NetBSD: meta.c,v 1.99 2020/08/23 16:58:02 rillig Exp $ */
+/*      $NetBSD: meta.c,v 1.100 2020/08/26 22:55:46 rillig Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -889,9 +889,11 @@ meta_job_finish(Job *job)
 void
 meta_finish(void)
 {
-    Lst_Destroy(metaBailiwick, NULL);
+    if (metaBailiwick != NULL)
+	Lst_FreeS(metaBailiwick);
     free(metaBailiwickStr);
-    Lst_Destroy(metaIgnorePaths, NULL);
+    if (metaIgnorePaths != NULL)
+	Lst_FreeS(metaIgnorePaths);
     free(metaIgnorePathsStr);
 }
 
@@ -1623,7 +1625,7 @@ meta_oodate(GNode *gn, Boolean oodate)
 	}
     }
 
-    Lst_Destroy(missingFiles, free);
+    Lst_DestroyS(missingFiles, free);
 
     if (oodate && needOODATE) {
 	/*

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.262 src/usr.bin/make/parse.c:1.263
--- src/usr.bin/make/parse.c:1.262	Tue Aug 25 16:50:02 2020
+++ src/usr.bin/make/parse.c	Wed Aug 26 22:55:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.262 2020/08/25 16:50:02 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.263 2020/08/26 22:55:46 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.262 2020/08/25 16:50:02 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.263 2020/08/26 22:55:46 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.262 2020/08/25 16:50:02 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.263 2020/08/26 22:55:46 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -853,7 +853,7 @@ ParseLinkSrc(void *pgnp, void *cgnp)
     GNode          *cgn = (GNode *)cgnp;
 
     if ((pgn->type & OP_DOUBLEDEP) && !Lst_IsEmpty(pgn->cohorts))
-	pgn = Lst_DatumS(Lst_Last(pgn->cohorts));
+	pgn = Lst_DatumS(Lst_LastS(pgn->cohorts));
     Lst_AppendS(pgn->children, cgn);
     if (specType == Not)
 	Lst_AppendS(cgn->parents, pgn);
@@ -1433,7 +1433,7 @@ ParseDoDependency(char *line)
 
 		Dir_Expand(line, emptyPath, curTargs);
 
-		Lst_Destroy(emptyPath, Dir_Destroy);
+		Lst_DestroyS(emptyPath, Dir_Destroy);
 	    } else {
 		/*
 		 * No wildcards, but we want to avoid code duplication,
@@ -1494,7 +1494,7 @@ ParseDoDependency(char *line)
     /*
      * Don't need the list of target names anymore...
      */
-    Lst_Destroy(curTargs, NULL);
+    Lst_FreeS(curTargs);
     curTargs = NULL;
 
     if (!Lst_IsEmpty(targets)) {
@@ -1686,7 +1686,7 @@ ParseDoDependency(char *line)
 	    line = cp;
 	}
 	if (paths) {
-	    Lst_Destroy(paths, NULL);
+	    Lst_FreeS(paths);
 	    paths = NULL;
 	}
 	if (specType == ExPath)
@@ -1723,7 +1723,7 @@ ParseDoDependency(char *line)
 		    gn = Lst_DequeueS(sources);
 		    ParseDoSrc(tOp, gn->name);
 		}
-		Lst_Destroy(sources, NULL);
+		Lst_FreeS(sources);
 		cp = line;
 	    } else {
 		if (*cp) {
@@ -1751,10 +1751,10 @@ ParseDoDependency(char *line)
     }
 
 out:
-    if (paths)
-	Lst_Destroy(paths, NULL);
-    if (curTargs)
-	    Lst_Destroy(curTargs, NULL);
+    if (paths != NULL)
+	Lst_FreeS(paths);
+    if (curTargs != NULL)
+	Lst_FreeS(curTargs);
 }
 
 /*-
@@ -3018,8 +3018,10 @@ static void
 ParseFinishLine(void)
 {
     if (inLine) {
-	Lst_ForEach(targets, Suff_EndTransform, NULL);
-	Lst_Destroy(targets, ParseHasCommands);
+        if (targets != NULL) {
+	    Lst_ForEach(targets, Suff_EndTransform, NULL);
+	    Lst_DestroyS(targets, ParseHasCommands);
+	}
 	targets = NULL;
 	inLine = FALSE;
     }
@@ -3237,8 +3239,8 @@ Parse_File(const char *name, int fd)
 	    /*
 	     * Need a non-circular list for the target nodes
 	     */
-	    if (targets)
-		Lst_Destroy(targets, NULL);
+	    if (targets != NULL)
+		Lst_FreeS(targets);
 
 	    targets = Lst_Init();
 	    inLine = TRUE;
@@ -3295,13 +3297,13 @@ void
 Parse_End(void)
 {
 #ifdef CLEANUP
-    Lst_Destroy(targCmds, free);
+    Lst_DestroyS(targCmds, free);
     if (targets)
-	Lst_Destroy(targets, NULL);
-    Lst_Destroy(defIncPath, Dir_Destroy);
-    Lst_Destroy(sysIncPath, Dir_Destroy);
-    Lst_Destroy(parseIncPath, Dir_Destroy);
-    Lst_Destroy(includes, NULL);	/* Should be empty now */
+	Lst_FreeS(targets);
+    Lst_DestroyS(defIncPath, Dir_Destroy);
+    Lst_DestroyS(sysIncPath, Dir_Destroy);
+    Lst_DestroyS(parseIncPath, Dir_Destroy);
+    Lst_FreeS(includes);	/* Should be empty now */
 #endif
 }
 

Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.115 src/usr.bin/make/suff.c:1.116
--- src/usr.bin/make/suff.c:1.115	Tue Aug 25 16:50:02 2020
+++ src/usr.bin/make/suff.c	Wed Aug 26 22:55:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.115 2020/08/25 16:50:02 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.116 2020/08/26 22:55:46 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.115 2020/08/25 16:50:02 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.116 2020/08/26 22:55:46 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.115 2020/08/25 16:50:02 rillig Exp $");
+__RCSID("$NetBSD: suff.c,v 1.116 2020/08/26 22:55:46 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -441,10 +441,10 @@ SuffFree(void *sp)
 	    s->refCount);
 #endif
 
-    Lst_Destroy(s->ref, NULL);
-    Lst_Destroy(s->children, NULL);
-    Lst_Destroy(s->parents, NULL);
-    Lst_Destroy(s->searchPath, Dir_Destroy);
+    Lst_FreeS(s->ref);
+    Lst_FreeS(s->children);
+    Lst_FreeS(s->parents);
+    Lst_DestroyS(s->searchPath, Dir_Destroy);
 
     free(s->name);
     free(s);
@@ -609,7 +609,7 @@ SuffParseTransform(char *str, Suff **src
      */
     for (;;) {
 	if (srcLn == NULL) {
-	    srcLn = Lst_Find(sufflist, SuffSuffIsPrefix, str);
+	    srcLn = Lst_FindS(sufflist, SuffSuffIsPrefix, str);
 	} else {
 	    srcLn = Lst_FindFrom(sufflist, Lst_Succ(srcLn),
 				 SuffSuffIsPrefix, str);
@@ -640,7 +640,7 @@ SuffParseTransform(char *str, Suff **src
 	    single = src;
 	    singleLn = srcLn;
 	} else {
-	    targLn = Lst_Find(sufflist, SuffSuffHasNameP, str2);
+	    targLn = Lst_FindS(sufflist, SuffSuffHasNameP, str2);
 	    if (targLn != NULL) {
 		*srcPtr = src;
 		*targPtr = Lst_DatumS(targLn);
@@ -716,8 +716,8 @@ Suff_AddTransform(char *line)
 	 * attached to several different transformations.
 	 */
 	gn = Lst_DatumS(ln);
-	Lst_Destroy(gn->commands, NULL);
-	Lst_Destroy(gn->children, NULL);
+	Lst_FreeS(gn->commands);
+	Lst_FreeS(gn->children);
 	gn->commands = Lst_Init();
 	gn->children = Lst_Init();
     }
@@ -849,7 +849,7 @@ SuffRebuildGraph(void *transformp, void 
      */
     cp = UNCONST(SuffStrIsPrefix(s->name, transform->name));
     if (cp != NULL) {
-	ln = Lst_Find(sufflist, SuffSuffHasNameP, cp);
+	ln = Lst_FindS(sufflist, SuffSuffHasNameP, cp);
 	if (ln != NULL) {
 	    /*
 	     * Found target. Link in and return, since it can't be anything
@@ -873,7 +873,7 @@ SuffRebuildGraph(void *transformp, void 
 	 * Null-terminate the source suffix in order to find it.
 	 */
 	cp[1] = '\0';
-	ln = Lst_Find(sufflist, SuffSuffHasNameP, transform->name);
+	ln = Lst_FindS(sufflist, SuffSuffHasNameP, transform->name);
 	/*
 	 * Replace the start of the target suffix
 	 */
@@ -934,7 +934,7 @@ SuffScanTargets(void *targetp, void *gsp
 	    *gs->gn = NULL;
 	    Targ_SetMain(NULL);
 	}
-	Lst_Destroy(target->children, NULL);
+	Lst_FreeS(target->children);
 	target->children = Lst_Init();
 	target->type = OP_TRANSFORM;
 	/*
@@ -976,7 +976,7 @@ Suff_AddSuffix(char *str, GNode **gn)
     LstNode 	  ln;
     GNodeSuff	  gs;
 
-    ln = Lst_Find(sufflist, SuffSuffHasNameP, str);
+    ln = Lst_FindS(sufflist, SuffSuffHasNameP, str);
     if (ln == NULL) {
 	s = bmake_malloc(sizeof(Suff));
 
@@ -1028,7 +1028,7 @@ Suff_GetPath(char *sname)
     LstNode   	  ln;
     Suff    	  *s;
 
-    ln = Lst_Find(sufflist, SuffSuffHasNameP, sname);
+    ln = Lst_FindS(sufflist, SuffSuffHasNameP, sname);
     if (ln == NULL) {
 	return NULL;
     } else {
@@ -1084,7 +1084,7 @@ Suff_DoPaths(void)
 #endif /* LIBRARIES */
 	    Dir_Concat(s->searchPath, dirSearchPath);
 	} else {
-	    Lst_Destroy(s->searchPath, Dir_Destroy);
+	    Lst_DestroyS(s->searchPath, Dir_Destroy);
 	    s->searchPath = Lst_CopyS(dirSearchPath, Dir_CopyDir);
 	}
     }
@@ -1095,8 +1095,8 @@ Suff_DoPaths(void)
     Var_Set(".LIBS", ptr = Dir_MakeFlags("-L", inLibs), VAR_GLOBAL);
     free(ptr);
 
-    Lst_Destroy(inIncludes, Dir_Destroy);
-    Lst_Destroy(inLibs, Dir_Destroy);
+    Lst_DestroyS(inIncludes, Dir_Destroy);
+    Lst_DestroyS(inLibs, Dir_Destroy);
 }
 
 /*-
@@ -1123,7 +1123,7 @@ Suff_AddInclude(char *sname)
     LstNode	  ln;
     Suff	  *s;
 
-    ln = Lst_Find(sufflist, SuffSuffHasNameP, sname);
+    ln = Lst_FindS(sufflist, SuffSuffHasNameP, sname);
     if (ln != NULL) {
 	s = Lst_DatumS(ln);
 	s->flags |= SUFF_INCLUDE;
@@ -1155,7 +1155,7 @@ Suff_AddLib(char *sname)
     LstNode	  ln;
     Suff	  *s;
 
-    ln = Lst_Find(sufflist, SuffSuffHasNameP, sname);
+    ln = Lst_FindS(sufflist, SuffSuffHasNameP, sname);
     if (ln != NULL) {
 	s = Lst_DatumS(ln);
 	s->flags |= SUFF_LIBRARY;
@@ -1308,7 +1308,7 @@ SuffRemoveSrc(Lst l)
 	    }
 #ifdef DEBUG_SRC
 	    fprintf(debug_file, "free: [l=%p] p=%p %d\n", l, s, s->children);
-	    Lst_Destroy(s->cp, NULL);
+	    Lst_FreeS(s->cp);
 #endif
 	    Lst_RemoveS(l, ln);
 	    free(s);
@@ -1460,7 +1460,7 @@ SuffFindCmds(Src *targ, Lst slst)
 	 * The node matches the prefix ok, see if it has a known
 	 * suffix.
 	 */
-	ln = Lst_Find(sufflist, SuffSuffHasNameP, &cp[prefLen]);
+	ln = Lst_FindS(sufflist, SuffSuffHasNameP, &cp[prefLen]);
 	if (ln == NULL)
 	    continue;
 	/*
@@ -1651,7 +1651,7 @@ SuffExpandChildren(LstNode cln, GNode *p
 	    /* Expand wildcards on new node */
 	    SuffExpandWildcards(Lst_PrevS(cln), pgn);
 	}
-	Lst_Destroy(members, NULL);
+	Lst_FreeS(members);
 
 	/*
 	 * Free the result
@@ -1705,10 +1705,7 @@ SuffExpandWildcards(LstNode cln, GNode *
 	pgn->unmade++;
     }
 
-    /*
-     * Nuke what's left of the list
-     */
-    Lst_Destroy(explist, NULL);
+    Lst_FreeS(explist);
 
     if (DEBUG(SUFF)) {
 	fprintf(debug_file, "\n");
@@ -1753,7 +1750,7 @@ Suff_FindPath(GNode* gn)
 	LstNode ln;
 	sd.len = strlen(gn->name);
 	sd.ename = gn->name + sd.len;
-	ln = Lst_Find(sufflist, SuffSuffIsSuffixP, &sd);
+	ln = Lst_FindS(sufflist, SuffSuffIsSuffixP, &sd);
 
 	if (DEBUG(SUFF)) {
 	    fprintf(debug_file, "Wildcard expanding \"%s\"...", gn->name);
@@ -1964,8 +1961,8 @@ SuffFindArchiveDeps(GNode *gn, Lst slst)
      * Now we've got the important local variables set, expand any sources
      * that still contain variables or wildcards in their names.
      */
-    for (ln = Lst_First(gn->children); ln != NULL; ln = nln) {
-	nln = Lst_Succ(ln);
+    for (ln = Lst_FirstS(gn->children); ln != NULL; ln = nln) {
+	nln = Lst_SuccS(ln);
 	SuffExpandChildren(ln, gn);
     }
 
@@ -2470,7 +2467,7 @@ SuffFindDeps(GNode *gn, Lst slst)
 	LstNode	ln;
 	Suff	*s;
 
-	ln = Lst_Find(sufflist, SuffSuffHasNameP, LIBSUFF);
+	ln = Lst_FindS(sufflist, SuffSuffHasNameP, LIBSUFF);
 	if (gn->suffix)
 	    gn->suffix->refCount--;
 	if (ln != NULL) {
@@ -2518,7 +2515,7 @@ Suff_SetNull(char *name)
     Suff    *s;
     LstNode ln;
 
-    ln = Lst_Find(sufflist, SuffSuffHasNameP, name);
+    ln = Lst_FindS(sufflist, SuffSuffHasNameP, name);
     if (ln != NULL) {
 	s = Lst_DatumS(ln);
 	if (suffNull != NULL) {
@@ -2583,12 +2580,12 @@ void
 Suff_End(void)
 {
 #ifdef CLEANUP
-    Lst_Destroy(sufflist, SuffFree);
-    Lst_Destroy(suffClean, SuffFree);
+    Lst_DestroyS(sufflist, SuffFree);
+    Lst_DestroyS(suffClean, SuffFree);
     if (suffNull)
 	SuffFree(suffNull);
-    Lst_Destroy(srclist, NULL);
-    Lst_Destroy(transforms, NULL);
+    Lst_FreeS(srclist);
+    Lst_FreeS(transforms);
 #endif
 }
 
@@ -2633,10 +2630,10 @@ SuffPrintSuff(void *sp, void *dummy MAKE
     }
     fputc('\n', debug_file);
     fprintf(debug_file, "#\tTo: ");
-    Lst_ForEach(s->parents, SuffPrintName, NULL);
+    Lst_ForEachS(s->parents, SuffPrintName, NULL);
     fputc('\n', debug_file);
     fprintf(debug_file, "#\tFrom: ");
-    Lst_ForEach(s->children, SuffPrintName, NULL);
+    Lst_ForEachS(s->children, SuffPrintName, NULL);
     fputc('\n', debug_file);
     fprintf(debug_file, "#\tSearch Path: ");
     Dir_PrintPath(s->searchPath);

Index: src/usr.bin/make/targ.c
diff -u src/usr.bin/make/targ.c:1.72 src/usr.bin/make/targ.c:1.73
--- src/usr.bin/make/targ.c:1.72	Mon Aug 24 20:15:51 2020
+++ src/usr.bin/make/targ.c	Wed Aug 26 22:55:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: targ.c,v 1.72 2020/08/24 20:15:51 rillig Exp $	*/
+/*	$NetBSD: targ.c,v 1.73 2020/08/26 22:55:46 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: targ.c,v 1.72 2020/08/24 20:15:51 rillig Exp $";
+static char rcsid[] = "$NetBSD: targ.c,v 1.73 2020/08/26 22:55:46 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)targ.c	8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: targ.c,v 1.72 2020/08/24 20:15:51 rillig Exp $");
+__RCSID("$NetBSD: targ.c,v 1.73 2020/08/26 22:55:46 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -188,9 +188,9 @@ Targ_End(void)
 {
     Targ_Stats();
 #ifdef CLEANUP
-    Lst_Destroy(allTargets, NULL);
-    if (allGNs)
-	Lst_Destroy(allGNs, TargFreeGN);
+    Lst_FreeS(allTargets);
+    if (allGNs != NULL)
+	Lst_DestroyS(allGNs, TargFreeGN);
     Hash_DeleteTable(&targets);
 #endif
 }
@@ -303,14 +303,14 @@ TargFreeGN(void *gnp)
     free(gn->path);
     /* gn->fname points to name allocated when file was opened, don't free */
 
-    Lst_Destroy(gn->iParents, NULL);
-    Lst_Destroy(gn->cohorts, NULL);
-    Lst_Destroy(gn->parents, NULL);
-    Lst_Destroy(gn->children, NULL);
-    Lst_Destroy(gn->order_succ, NULL);
-    Lst_Destroy(gn->order_pred, NULL);
+    Lst_FreeS(gn->iParents);
+    Lst_FreeS(gn->cohorts);
+    Lst_FreeS(gn->parents);
+    Lst_FreeS(gn->children);
+    Lst_FreeS(gn->order_succ);
+    Lst_FreeS(gn->order_pred);
     Hash_DeleteTable(&gn->context);
-    Lst_Destroy(gn->commands, NULL);
+    Lst_FreeS(gn->commands);
     free(gn);
 }
 #endif

Reply via email to