Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): refactor add_wait_dep to not use Lst_F...



details:   https://anonhg.NetBSD.org/src/rev/11ec9278a873
branches:  trunk
changeset: 955218:11ec9278a873
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Sep 24 06:45:59 2020 +0000

description:
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:

 usr.bin/make/lst.c  |   6 ++++--
 usr.bin/make/lst.h  |   5 +----
 usr.bin/make/make.c |  39 +++++++++++++++++----------------------
 usr.bin/make/targ.c |   6 +++---
 4 files changed, 25 insertions(+), 31 deletions(-)

diffs (143 lines):

diff -r 9bdefed6e87e -r 11ec9278a873 usr.bin/make/lst.c
--- a/usr.bin/make/lst.c        Thu Sep 24 06:45:58 2020 +0000
+++ b/usr.bin/make/lst.c        Thu Sep 24 06:45:59 2020 +0000
@@ -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 @@
     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 -r 9bdefed6e87e -r 11ec9278a873 usr.bin/make/lst.h
--- a/usr.bin/make/lst.h        Thu Sep 24 06:45:58 2020 +0000
+++ b/usr.bin/make/lst.h        Thu Sep 24 06:45:59 2020 +0000
@@ -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 @@
 /* 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 -r 9bdefed6e87e -r 11ec9278a873 usr.bin/make/make.c
--- a/usr.bin/make/make.c       Thu Sep 24 06:45:58 2020 +0000
+++ b/usr.bin/make/make.c       Thu Sep 24 06:45:59 2020 +0000
@@ -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 @@
     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;
-
-    if (cn == wn)
-       return 1;
+    GNodeListNode *cln;
+    GNode *cn;
 
-    if (cn == NULL || wn == NULL) {
-       printf("bad wait dep %p %p\n", cn, wn);
-       exit(4);
+    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);
+
+       /* 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 @@
        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 -r 9bdefed6e87e -r 11ec9278a873 usr.bin/make/targ.c
--- a/usr.bin/make/targ.c       Thu Sep 24 06:45:58 2020 +0000
+++ b/usr.bin/make/targ.c       Thu Sep 24 06:45:59 2020 +0000
@@ -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 @@
  * 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)



Home | Main Index | Thread Index | Old Index