Wed Aug 26 22:55:46 2020 UTC ()
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.
(rillig)
diff -r1.96 -r1.97 src/usr.bin/make/arch.c
diff -r1.110 -r1.111 src/usr.bin/make/dir.c
diff -r1.41 -r1.42 src/usr.bin/make/lst.c
diff -r1.43 -r1.44 src/usr.bin/make/lst.h
diff -r1.313 -r1.314 src/usr.bin/make/main.c
diff -r1.123 -r1.124 src/usr.bin/make/make.c
diff -r1.99 -r1.100 src/usr.bin/make/meta.c
diff -r1.262 -r1.263 src/usr.bin/make/parse.c
diff -r1.115 -r1.116 src/usr.bin/make/suff.c
diff -r1.72 -r1.73 src/usr.bin/make/targ.c
--- src/usr.bin/make/arch.c 2020/08/23 18:59:01 1.96
+++ src/usr.bin/make/arch.c 2020/08/26 22:55:46 1.97
@@ -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 @@
*/
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 @@
Lst_AppendS(nodeLst, gn);
}
}
- Lst_Destroy(members, NULL);
+ Lst_FreeS(members);
Buf_Destroy(&nameBuf, TRUE);
} else {
Buffer nameBuf;
@@ -1288,45 +1288,19 @@
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
}
--- src/usr.bin/make/dir.c 2020/08/23 16:58:02 1.110
+++ src/usr.bin/make/dir.c 2020/08/26 22:55:46 1.111
@@ -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_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 @@
path = Lst_Init();
(void)Dir_AddDir(path, dirpath);
DirExpandInt(cp + 1, path, expansions);
- Lst_Destroy(path, NULL);
+ Lst_FreeS(path);
}
} else {
/*
--- src/usr.bin/make/lst.c 2020/08/23 16:58:02 1.41
+++ src/usr.bin/make/lst.c 2020/08/26 22:55:46 1.42
@@ -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,38 +142,40 @@
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;
+ for (node = list->first; node != NULL; node = next) {
+ next = node->next;
+ freeProc(node->datum);
+ free(node);
}
- 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);
- }
- }
-
free(list);
}
@@ -340,6 +342,15 @@
}
}
+/* 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 @@
}
}
+/* 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 @@
}
}
+/* 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 @@
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 @@
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 @@
* 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 {
/*
--- src/usr.bin/make/lst.h 2020/08/23 17:04:21 1.43
+++ src/usr.bin/make/lst.h 2020/08/26 22:55:46 1.44
@@ -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 @@
/* 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 @@
/* 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 @@
*/
/* 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 @@
*/
/* 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_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
--- src/usr.bin/make/main.c 2020/08/25 16:50:02 1.313
+++ src/usr.bin/make/main.c 2020/08/26 22:55:46 1.314
@@ -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 @@
#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 @@
* 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 @@
Compat_Run(targs);
outOfDate = FALSE;
}
- Lst_Destroy(targs, NULL);
+ Lst_FreeS(targs);
return outOfDate;
}
@@ -1467,9 +1467,9 @@
}
#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 */
--- src/usr.bin/make/make.c 2020/08/25 16:27:24 1.123
+++ src/usr.bin/make/make.c 2020/08/26 22:55:46 1.124
@@ -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 @@
* 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 @@
Lst_ForEach(gn->children, MakeAddChild, examine);
}
- Lst_Destroy(examine, NULL);
+ Lst_FreeS(examine);
}
/*-
@@ -1465,7 +1465,7 @@
Lst_CloseS(pgn->children);
}
- Lst_Destroy(examine, NULL);
+ Lst_FreeS(examine);
}
/*-
--- src/usr.bin/make/meta.c 2020/08/23 16:58:02 1.99
+++ src/usr.bin/make/meta.c 2020/08/26 22:55:46 1.100
--- src/usr.bin/make/parse.c 2020/08/25 16:50:02 1.262
+++ src/usr.bin/make/parse.c 2020/08/26 22:55:46 1.263
@@ -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 @@
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 @@
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 @@
/*
* 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 @@
line = cp;
}
if (paths) {
- Lst_Destroy(paths, NULL);
+ Lst_FreeS(paths);
paths = NULL;
}
if (specType == ExPath)
@@ -1723,7 +1723,7 @@
gn = Lst_DequeueS(sources);
ParseDoSrc(tOp, gn->name);
}
- Lst_Destroy(sources, NULL);
+ Lst_FreeS(sources);
cp = line;
} else {
if (*cp) {
@@ -1751,10 +1751,10 @@
}
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 @@
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 @@
/*
* 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 @@
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
}
--- src/usr.bin/make/suff.c 2020/08/25 16:50:02 1.115
+++ src/usr.bin/make/suff.c 2020/08/26 22:55:46 1.116
@@ -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 @@
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 @@
*/
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 @@
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 @@
* 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 @@
*/
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 @@
* 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 @@
*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 @@
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 @@
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 @@
#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 @@
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 @@
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 @@
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 @@
}
#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 @@
* 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 @@
/* Expand wildcards on new node */
SuffExpandWildcards(Lst_PrevS(cln), pgn);
}
- Lst_Destroy(members, NULL);
+ Lst_FreeS(members);
/*
* Free the result
@@ -1705,10 +1705,7 @@
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 @@
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 @@
* 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 @@
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 *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 @@
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 @@
}
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);
--- src/usr.bin/make/targ.c 2020/08/24 20:15:51 1.72
+++ src/usr.bin/make/targ.c 2020/08/26 22:55:46 1.73
@@ -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_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 @@
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