Module Name: src
Committed By: rillig
Date: Fri Aug 21 04:42:03 UTC 2020
Modified Files:
src/usr.bin/make: arch.c dir.c lst.c lst.h make.c suff.c targ.c
Log Message:
make(1): use stricter list API for sequential access
In several places, it just doesn't make sense to have a null pointer
when a list is expected.
In the existing unit tests, the list passed to Lst_Open is always valid,
but that's not a guarantee for real-world usage. Therefore, Lst_Open
has been left for now, and Lst_OpenS is only the preferred alternative
to it.
To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/usr.bin/make/arch.c
cvs rdiff -u -r1.95 -r1.96 src/usr.bin/make/dir.c
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/lst.c
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/make/lst.h
cvs rdiff -u -r1.106 -r1.107 src/usr.bin/make/make.c
cvs rdiff -u -r1.99 -r1.100 src/usr.bin/make/suff.c
cvs rdiff -u -r1.66 -r1.67 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.85 src/usr.bin/make/arch.c:1.86
--- src/usr.bin/make/arch.c:1.85 Fri Aug 21 04:09:12 2020
+++ src/usr.bin/make/arch.c Fri Aug 21 04:42:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: arch.c,v 1.85 2020/08/21 04:09:12 rillig Exp $ */
+/* $NetBSD: arch.c,v 1.86 2020/08/21 04:42:02 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: arch.c,v 1.85 2020/08/21 04:09:12 rillig Exp $";
+static char rcsid[] = "$NetBSD: arch.c,v 1.86 2020/08/21 04:42:02 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.85 2020/08/21 04:09:12 rillig Exp $");
+__RCSID("$NetBSD: arch.c,v 1.86 2020/08/21 04:42:02 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -1158,7 +1158,7 @@ Arch_MemMTime(GNode *gn)
}
}
- Lst_Close(gn->parents);
+ Lst_CloseS(gn->parents);
return gn->mtime;
}
Index: src/usr.bin/make/dir.c
diff -u src/usr.bin/make/dir.c:1.95 src/usr.bin/make/dir.c:1.96
--- src/usr.bin/make/dir.c:1.95 Fri Aug 21 04:09:12 2020
+++ src/usr.bin/make/dir.c Fri Aug 21 04:42:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: dir.c,v 1.95 2020/08/21 04:09:12 rillig Exp $ */
+/* $NetBSD: dir.c,v 1.96 2020/08/21 04:42:02 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.95 2020/08/21 04:09:12 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.96 2020/08/21 04:42:02 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.95 2020/08/21 04:09:12 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.96 2020/08/21 04:42:02 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -524,7 +524,7 @@ Dir_SetPATH(void)
if (cur)
Var_Append(".PATH", cur->name, VAR_GLOBAL);
}
- Lst_Close(dirSearchPath);
+ Lst_CloseS(dirSearchPath);
}
}
@@ -817,7 +817,7 @@ DirExpandInt(const char *word, Lst path,
p = (Path *)Lst_Datum(ln);
DirMatchFiles(word, p, expansions);
}
- Lst_Close(path);
+ Lst_CloseS(path);
}
}
@@ -1181,7 +1181,7 @@ Dir_FindFile(const char *name, Lst path)
* specifies (fish.c) and what pmake finds (./fish.c).
*/
if (!hasLastDot && (file = DirFindDot(hasSlash, name, cp)) != NULL) {
- Lst_Close(path);
+ Lst_CloseS(path);
return file;
}
@@ -1190,17 +1190,17 @@ Dir_FindFile(const char *name, Lst path)
if (p == dotLast)
continue;
if ((file = DirLookup(p, name, cp, hasSlash)) != NULL) {
- Lst_Close(path);
+ Lst_CloseS(path);
return file;
}
}
if (hasLastDot && (file = DirFindDot(hasSlash, name, cp)) != NULL) {
- Lst_Close(path);
+ Lst_CloseS(path);
return file;
}
}
- Lst_Close(path);
+ Lst_CloseS(path);
/*
* We didn't find the file on any directory in the search path.
@@ -1242,7 +1242,7 @@ Dir_FindFile(const char *name, Lst path)
return file;
}
- (void)Lst_Open(path);
+ Lst_OpenS(path);
while ((ln = Lst_NextS(path)) != NULL) {
p = (Path *)Lst_Datum(ln);
if (p == dotLast)
@@ -1253,11 +1253,11 @@ Dir_FindFile(const char *name, Lst path)
checkedDot = TRUE;
}
if ((file = DirLookupSubdir(p, name)) != NULL) {
- Lst_Close(path);
+ Lst_CloseS(path);
return file;
}
}
- Lst_Close(path);
+ Lst_CloseS(path);
if (hasLastDot) {
if (dot && !checkedDot) {
@@ -1300,13 +1300,13 @@ Dir_FindFile(const char *name, Lst path)
return file;
}
- (void)Lst_Open(path);
+ Lst_OpenS(path);
while ((ln = Lst_NextS(path)) != NULL) {
p = (Path *)Lst_Datum(ln);
if (p == dotLast)
continue;
if ((file = DirLookupAbs(p, name, cp)) != NULL) {
- Lst_Close(path);
+ Lst_CloseS(path);
if (file[0] == '\0') {
free(file);
return NULL;
@@ -1314,7 +1314,7 @@ Dir_FindFile(const char *name, Lst path)
return file;
}
}
- Lst_Close(path);
+ Lst_CloseS(path);
if (hasLastDot && cur &&
((file = DirLookupAbs(cur, name, cp)) != NULL)) {
@@ -1685,7 +1685,7 @@ Dir_MakeFlags(const char *flag, Lst path
Buf_AddStr(&buf, flag);
Buf_AddStr(&buf, p->name);
}
- Lst_Close(path);
+ Lst_CloseS(path);
}
return Buf_Destroy(&buf, FALSE);
@@ -1808,7 +1808,7 @@ Dir_PrintDirectories(void)
fprintf(debug_file, "# %-20s %10d\t%4d\n", p->name, p->refCount,
p->hits);
}
- Lst_Close(openDirectories);
+ Lst_CloseS(openDirectories);
}
}
Index: src/usr.bin/make/lst.c
diff -u src/usr.bin/make/lst.c:1.9 src/usr.bin/make/lst.c:1.10
--- src/usr.bin/make/lst.c:1.9 Fri Aug 21 04:09:12 2020
+++ src/usr.bin/make/lst.c Fri Aug 21 04:42:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.9 2020/08/21 04:09:12 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.10 2020/08/21 04:42:02 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -38,11 +38,11 @@
#include "make_malloc.h"
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: lst.c,v 1.9 2020/08/21 04:09:12 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.10 2020/08/21 04:42:02 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.9 2020/08/21 04:09:12 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.10 2020/08/21 04:42:02 rillig Exp $");
#endif /* not lint */
#endif
@@ -907,20 +907,21 @@ Lst_Open(Lst l)
return SUCCESS;
}
-/*-
- *-----------------------------------------------------------------------
- * Lst_Next --
- * Return the next node for the given list.
- *
- * Results:
- * The next node or NULL if the list has yet to be opened. Also
- * if the end has been reached, NULL is returned.
- *
- * Side Effects:
- * the curPtr field is updated.
- *
- *-----------------------------------------------------------------------
- */
+/* Open a list for sequential access. A list can still be searched, etc.,
+ * without confusing these functions. */
+void
+Lst_OpenS(Lst l)
+{
+ assert(LstValid(l));
+ assert(!l->isOpen);
+
+ l->isOpen = TRUE;
+ l->atEnd = LstIsEmpty(l) ? Head : Unknown;
+ l->curPtr = NULL;
+}
+
+/* Return the next node for the given list, or NULL if the end has been
+ * reached. */
LstNode
Lst_NextS(Lst l)
{
@@ -965,31 +966,16 @@ Lst_NextS(Lst l)
return tln;
}
-/*-
- *-----------------------------------------------------------------------
- * Lst_Close --
- * Close a list which was opened for sequential access.
- *
- * Input:
- * l The list to close
- *
- * Results:
- * None.
- *
- * Side Effects:
- * The list is closed.
- *
- *-----------------------------------------------------------------------
- */
+/* Close a list which was opened for sequential access. */
void
-Lst_Close(Lst l)
+Lst_CloseS(Lst l)
{
List list = l;
- if (LstValid(l) == TRUE) {
- list->isOpen = FALSE;
- list->atEnd = Unknown;
- }
+ assert(LstValid(l));
+ assert(list->isOpen);
+ list->isOpen = FALSE;
+ list->atEnd = Unknown;
}
Index: src/usr.bin/make/lst.h
diff -u src/usr.bin/make/lst.h:1.25 src/usr.bin/make/lst.h:1.26
--- src/usr.bin/make/lst.h:1.25 Fri Aug 21 04:09:12 2020
+++ src/usr.bin/make/lst.h Fri Aug 21 04:42:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.h,v 1.25 2020/08/21 04:09:12 rillig Exp $ */
+/* $NetBSD: lst.h,v 1.26 2020/08/21 04:42:02 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -167,10 +167,11 @@ int Lst_ForEachFrom(Lst, LstNode, int (
*/
/* Open the list */
ReturnStatus Lst_Open(Lst);
+void Lst_OpenS(Lst);
/* Next element please, or NULL */
LstNode Lst_NextS(Lst);
/* Finish table access */
-void Lst_Close(Lst);
+void Lst_CloseS(Lst);
/*
* for using the list as a queue
Index: src/usr.bin/make/make.c
diff -u src/usr.bin/make/make.c:1.106 src/usr.bin/make/make.c:1.107
--- src/usr.bin/make/make.c:1.106 Fri Aug 21 04:09:12 2020
+++ src/usr.bin/make/make.c Fri Aug 21 04:42:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: make.c,v 1.106 2020/08/21 04:09:12 rillig Exp $ */
+/* $NetBSD: make.c,v 1.107 2020/08/21 04:42:02 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: make.c,v 1.106 2020/08/21 04:09:12 rillig Exp $";
+static char rcsid[] = "$NetBSD: make.c,v 1.107 2020/08/21 04:42:02 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.106 2020/08/21 04:09:12 rillig Exp $");
+__RCSID("$NetBSD: make.c,v 1.107 2020/08/21 04:42:02 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -496,7 +496,7 @@ Make_HandleUse(GNode *cgn, GNode *pgn)
(void)Lst_AtEnd(gn->parents, pgn);
pgn->unmade += 1;
}
- Lst_Close(cgn->children);
+ Lst_CloseS(cgn->children);
}
pgn->type |= cgn->type & ~(OP_OPMASK|OP_USE|OP_USEBEFORE|OP_TRANSFORM);
@@ -818,7 +818,7 @@ Make_Update(GNode *cgn)
pgn->made = REQUESTED;
(void)Lst_EnQueue(toBeMade, pgn);
}
- Lst_Close(parents);
+ Lst_CloseS(parents);
}
/*
@@ -837,7 +837,7 @@ Make_Update(GNode *cgn)
}
}
bmake_free(p1);
- Lst_Close(cgn->iParents);
+ Lst_CloseS(cgn->iParents);
}
}
@@ -1446,7 +1446,7 @@ Make_ProcessWait(Lst targs)
}
owln = Lst_First(pgn->children);
- Lst_Open(pgn->children);
+ Lst_OpenS(pgn->children);
for (; (ln = Lst_NextS(pgn->children)) != NULL; ) {
cgn = Lst_Datum(ln);
if (cgn->type & OP_WAIT) {
@@ -1457,7 +1457,7 @@ Make_ProcessWait(Lst targs)
Lst_AtEnd(examine, cgn);
}
}
- Lst_Close(pgn->children);
+ Lst_CloseS(pgn->children);
}
Lst_Destroy(examine, NULL);
Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.99 src/usr.bin/make/suff.c:1.100
--- src/usr.bin/make/suff.c:1.99 Fri Aug 21 04:09:12 2020
+++ src/usr.bin/make/suff.c Fri Aug 21 04:42:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: suff.c,v 1.99 2020/08/21 04:09:12 rillig Exp $ */
+/* $NetBSD: suff.c,v 1.100 2020/08/21 04:42:02 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.99 2020/08/21 04:09:12 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.100 2020/08/21 04:42:02 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.99 2020/08/21 04:09:12 rillig Exp $");
+__RCSID("$NetBSD: suff.c,v 1.100 2020/08/21 04:42:02 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -499,17 +499,15 @@ SuffInsert(Lst l, Suff *s)
LstNode ln; /* current element in l we're examining */
Suff *s2 = NULL; /* the suffix descriptor in this element */
- if (Lst_Open(l) == FAILURE) {
- return;
- }
+ Lst_OpenS(l);
while ((ln = Lst_NextS(l)) != NULL) {
s2 = (Suff *)Lst_Datum(ln);
if (s2->sNum >= s->sNum) {
break;
}
}
+ Lst_CloseS(l);
- Lst_Close(l);
if (DEBUG(SUFF)) {
fprintf(debug_file, "inserting %s(%d)...", s->name, s->sNum);
}
@@ -1069,13 +1067,11 @@ Suff_DoPaths(void)
Lst inIncludes; /* Cumulative .INCLUDES path */
Lst inLibs; /* Cumulative .LIBS path */
- if (Lst_Open(sufflist) == FAILURE) {
- return;
- }
inIncludes = Lst_Init();
inLibs = Lst_Init();
+ Lst_OpenS(sufflist);
while ((ln = Lst_NextS(sufflist)) != NULL) {
s = (Suff *)Lst_Datum(ln);
if (!Lst_IsEmpty (s->searchPath)) {
@@ -1095,6 +1091,7 @@ Suff_DoPaths(void)
s->searchPath = Lst_Duplicate(dirSearchPath, Dir_CopyDir);
}
}
+ Lst_CloseS(sufflist);
Var_Set(".INCLUDES", ptr = Dir_MakeFlags("-I", inIncludes), VAR_GLOBAL);
free(ptr);
@@ -1103,8 +1100,6 @@ Suff_DoPaths(void)
Lst_Destroy(inIncludes, Dir_Destroy);
Lst_Destroy(inLibs, Dir_Destroy);
-
- Lst_Close(sufflist);
}
/*-
@@ -1291,9 +1286,8 @@ SuffRemoveSrc(Lst l)
Src *s;
int t = 0;
- if (Lst_Open(l) == FAILURE) {
- return 0;
- }
+ Lst_OpenS(l);
+
#ifdef DEBUG_SRC
fprintf(debug_file, "cleaning %lx: ", (unsigned long) l);
Lst_ForEach(l, PrintAddr, NULL);
@@ -1322,7 +1316,7 @@ SuffRemoveSrc(Lst l)
Lst_RemoveS(l, ln);
free(s);
t |= 1;
- Lst_Close(l);
+ Lst_CloseS(l);
return TRUE;
}
#ifdef DEBUG_SRC
@@ -1334,7 +1328,7 @@ SuffRemoveSrc(Lst l)
#endif
}
- Lst_Close(l);
+ Lst_CloseS(l);
return t;
}
@@ -1435,13 +1429,13 @@ SuffFindCmds(Src *targ, Lst slst)
char *cp;
t = targ->node;
- (void)Lst_Open(t->children);
+ Lst_OpenS(t->children);
prefLen = strlen(targ->pref);
for (;;) {
ln = Lst_NextS(t->children);
if (ln == NULL) {
- Lst_Close(t->children);
+ Lst_CloseS(t->children);
return NULL;
}
s = (GNode *)Lst_Datum(ln);
Index: src/usr.bin/make/targ.c
diff -u src/usr.bin/make/targ.c:1.66 src/usr.bin/make/targ.c:1.67
--- src/usr.bin/make/targ.c:1.66 Fri Aug 21 04:09:12 2020
+++ src/usr.bin/make/targ.c Fri Aug 21 04:42:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: targ.c,v 1.66 2020/08/21 04:09:12 rillig Exp $ */
+/* $NetBSD: targ.c,v 1.67 2020/08/21 04:42:02 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: targ.c,v 1.66 2020/08/21 04:09:12 rillig Exp $";
+static char rcsid[] = "$NetBSD: targ.c,v 1.67 2020/08/21 04:42:02 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.66 2020/08/21 04:09:12 rillig Exp $");
+__RCSID("$NetBSD: targ.c,v 1.67 2020/08/21 04:42:02 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -395,9 +395,7 @@ Targ_FindList(Lst names, int flags)
nodes = Lst_Init();
- if (Lst_Open(names) == FAILURE) {
- return nodes;
- }
+ Lst_OpenS(names);
while ((ln = Lst_NextS(names)) != NULL) {
name = (char *)Lst_Datum(ln);
gn = Targ_FindNode(name, flags);
@@ -412,7 +410,7 @@ Targ_FindList(Lst names, int flags)
Error("\"%s\" -- target unknown.", name);
}
}
- Lst_Close(names);
+ Lst_CloseS(names);
return nodes;
}