summaryrefslogtreecommitdiff
path: root/usr.bin/make
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2020-09-24 06:45:59 +0000
committerrillig <rillig@NetBSD.org>2020-09-24 06:45:59 +0000
commitd26428226aaa14d02c0608ed588cfa080f536497 (patch)
treef5bade3d829335e61de35ccda6e45857e6bacb7d /usr.bin/make
parent1a84c72b43e32a844033098f55e19551b47343e9 (diff)
make(1): refactor add_wait_dep to not use Lst_ForEachFrom anymore
It was the last remaining use of that function outside of lst.c. While here, clean up the code of add_wait_dep by removing unreachable code (the GNode lists never contain NULL, only the GNode.commands lists do that).
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/lst.c6
-rw-r--r--usr.bin/make/lst.h5
-rw-r--r--usr.bin/make/make.c37
-rw-r--r--usr.bin/make/targ.c6
4 files changed, 24 insertions, 30 deletions
diff --git a/usr.bin/make/lst.c b/usr.bin/make/lst.c
index 0c45178f02e..f32495728b0 100644
--- a/usr.bin/make/lst.c
+++ b/usr.bin/make/lst.c
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.65 2020/09/22 04:05:41 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.66 2020/09/24 06:45:59 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -36,7 +36,7 @@
#include "make.h"
-MAKE_RCSID("$NetBSD: lst.c,v 1.65 2020/09/22 04:05:41 rillig Exp $");
+MAKE_RCSID("$NetBSD: lst.c,v 1.66 2020/09/24 06:45:59 rillig Exp $");
struct ListNode {
struct ListNode *prev; /* previous element in list */
@@ -415,6 +415,8 @@ Lst_FindDatum(List *list, const void *datum)
return NULL;
}
+static int Lst_ForEachFrom(List *, ListNode *, LstActionProc, void *);
+
/* 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. */
diff --git a/usr.bin/make/lst.h b/usr.bin/make/lst.h
index 9542c4ae7dc..0270a157a3d 100644
--- a/usr.bin/make/lst.h
+++ b/usr.bin/make/lst.h
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.h,v 1.62 2020/09/22 04:05:41 rillig Exp $ */
+/* $NetBSD: lst.h,v 1.63 2020/09/24 06:45:59 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -155,9 +155,6 @@ void LstNode_SetNull(ListNode *);
/* Apply a function to each datum of the list, until the callback function
* returns non-zero. */
int Lst_ForEach(List *, LstActionProc, void *);
-/* Apply a function to each datum of the list, starting at the node,
- * until the callback function returns non-zero. */
-int Lst_ForEachFrom(List *, ListNode *, LstActionProc, void *);
/* Iterating over a list while keeping track of the current node and possible
* concurrent modifications */
diff --git a/usr.bin/make/make.c b/usr.bin/make/make.c
index f1e69107ec9..af079c7bca6 100644
--- a/usr.bin/make/make.c
+++ b/usr.bin/make/make.c
@@ -1,4 +1,4 @@
-/* $NetBSD: make.c,v 1.138 2020/09/22 20:19:46 rillig Exp $ */
+/* $NetBSD: make.c,v 1.139 2020/09/24 06:45:59 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -107,7 +107,7 @@
#include "job.h"
/* "@(#)make.c 8.1 (Berkeley) 6/6/93" */
-MAKE_RCSID("$NetBSD: make.c,v 1.138 2020/09/22 20:19:46 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.139 2020/09/24 06:45:59 rillig Exp $");
static unsigned int checked = 1;/* Sequence # to detect recursion */
static GNodeList *toBeMade; /* The current fringe of the graph. These
@@ -1372,27 +1372,23 @@ link_parent(void *cnp, void *pnp)
return 0;
}
-static int
-add_wait_dep(void *v_cn, void *v_wn)
+/* Make the .WAIT node depend on the previous children */
+static void
+add_wait_dependency(GNodeListNode *owln, GNode *wn)
{
- GNode *cn = v_cn;
- GNode *wn = v_wn;
+ GNodeListNode *cln;
+ GNode *cn;
- if (cn == wn)
- return 1;
+ for (cln = owln; (cn = LstNode_Datum(cln)) != wn; cln = LstNode_Next(cln)) {
+ if (DEBUG(MAKE))
+ fprintf(debug_file, ".WAIT: add dependency %s%s -> %s\n",
+ cn->name, cn->cohort_num, wn->name);
- if (cn == NULL || wn == NULL) {
- printf("bad wait dep %p %p\n", cn, wn);
- exit(4);
+ /* XXX: This pattern should be factored out, it repeats often */
+ Lst_Append(wn->children, cn);
+ wn->unmade++;
+ Lst_Append(cn->parents, wn);
}
- if (DEBUG(MAKE))
- fprintf(debug_file, ".WAIT: add dependency %s%s -> %s\n",
- cn->name, cn->cohort_num, wn->name);
-
- Lst_Append(wn->children, cn);
- wn->unmade++;
- Lst_Append(cn->parents, wn);
- return 0;
}
static void
@@ -1442,8 +1438,7 @@ Make_ProcessWait(GNodeList *targs)
for (; (ln = Lst_Next(pgn->children)) != NULL; ) {
cgn = LstNode_Datum(ln);
if (cgn->type & OP_WAIT) {
- /* Make the .WAIT node depend on the previous children */
- Lst_ForEachFrom(pgn->children, owln, add_wait_dep, cgn);
+ add_wait_dependency(owln, cgn);
owln = ln;
} else {
Lst_Append(examine, cgn);
diff --git a/usr.bin/make/targ.c b/usr.bin/make/targ.c
index b1cac92351a..36441bb2d4d 100644
--- a/usr.bin/make/targ.c
+++ b/usr.bin/make/targ.c
@@ -1,4 +1,4 @@
-/* $NetBSD: targ.c,v 1.90 2020/09/23 03:06:38 rillig Exp $ */
+/* $NetBSD: targ.c,v 1.91 2020/09/24 06:45:59 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -122,7 +122,7 @@
#include "dir.h"
/* "@(#)targ.c 8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: targ.c,v 1.90 2020/09/23 03:06:38 rillig Exp $");
+MAKE_RCSID("$NetBSD: targ.c,v 1.91 2020/09/24 06:45:59 rillig Exp $");
static GNodeList *allTargets; /* the list of all targets found so far */
#ifdef CLEANUP
@@ -171,7 +171,7 @@ Targ_List(void)
* all gnodes.
*
* Input:
- * name the name of the node, such as "clean", "src.c"
+ * name the name of the node, such as "clean", "src.c", ".END"
*/
GNode *
Targ_NewGN(const char *name)