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): rename Lst_ForEach to Lst_ForEachUntil



details:   https://anonhg.NetBSD.org/src/rev/32e20965d272
branches:  trunk
changeset: 955220:32e20965d272
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Sep 24 07:11:29 2020 +0000

description:
make(1): rename Lst_ForEach to Lst_ForEachUntil

Since the callback function returns a terminating condition, this is not
really a foreach loop.

Many of the calls to Lst_ForEachUntil don't make use of the terminating
condition, and several don't modify the list structurally, which means
they don't need this complicated implementation.

In a follow-up commit, Lst_ForEach will be added back with a much
simpler implementation that iterates over the list naively, without a
terminating condition and without taking the iteration state from
Lst_Open/Lst_Next/Lst_Close into account.  The migration to this simpler
implementation will be done step by step since each callback function
needs to be examined closely.

diffstat:

 usr.bin/make/compat.c |  10 +++++-----
 usr.bin/make/dir.c    |  12 ++++++------
 usr.bin/make/job.c    |  10 +++++-----
 usr.bin/make/lst.c    |  10 +++++-----
 usr.bin/make/lst.h    |   8 ++++----
 usr.bin/make/main.c   |   6 +++---
 usr.bin/make/make.c   |  46 +++++++++++++++++++++++-----------------------
 usr.bin/make/meta.c   |  12 ++++++------
 usr.bin/make/parse.c  |  30 +++++++++++++++---------------
 usr.bin/make/suff.c   |  36 ++++++++++++++++++------------------
 usr.bin/make/targ.c   |  14 +++++++-------
 11 files changed, 97 insertions(+), 97 deletions(-)

diffs (truncated from 825 to 300 lines):

diff -r 38589550c0ed -r 32e20965d272 usr.bin/make/compat.c
--- a/usr.bin/make/compat.c     Thu Sep 24 06:52:48 2020 +0000
+++ b/usr.bin/make/compat.c     Thu Sep 24 07:11:29 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat.c,v 1.149 2020/09/23 03:06:38 rillig Exp $      */
+/*     $NetBSD: compat.c,v 1.150 2020/09/24 07:11:29 rillig Exp $      */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -99,7 +99,7 @@
 #include    "pathnames.h"
 
 /*     "@(#)compat.c   8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: compat.c,v 1.149 2020/09/23 03:06:38 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.150 2020/09/24 07:11:29 rillig Exp $");
 
 static GNode       *curTarg = NULL;
 static void CompatInterrupt(int);
@@ -512,7 +512,7 @@
        gn->made = BEINGMADE;
        if ((gn->type & OP_MADE) == 0)
            Suff_FindDeps(gn);
-       Lst_ForEach(gn->children, CompatMake, gn);
+       Lst_ForEachUntil(gn->children, CompatMake, gn);
        if ((gn->flags & REMAKE) == 0) {
            gn->made = ABORTED;
            pgn->flags &= ~(unsigned)REMAKE;
@@ -582,7 +582,7 @@
                    meta_job_start(NULL, gn);
                }
 #endif
-               Lst_ForEach(gn->commands, CompatRunCommand, gn);
+               Lst_ForEachUntil(gn->commands, CompatRunCommand, gn);
                curTarg = NULL;
            } else {
                Job_Touch(gn, (gn->type & OP_SILENT) != 0);
@@ -652,7 +652,7 @@
     }
 
 cohorts:
-    Lst_ForEach(gn->cohorts, CompatMake, pgn);
+    Lst_ForEachUntil(gn->cohorts, CompatMake, pgn);
     return 0;
 }
 
diff -r 38589550c0ed -r 32e20965d272 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Thu Sep 24 06:52:48 2020 +0000
+++ b/usr.bin/make/dir.c        Thu Sep 24 07:11:29 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.144 2020/09/22 04:05:41 rillig Exp $ */
+/*     $NetBSD: dir.c,v 1.145 2020/09/24 07:11:29 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -134,7 +134,7 @@
 #include "job.h"
 
 /*     "@(#)dir.c      8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: dir.c,v 1.144 2020/09/22 04:05:41 rillig Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.145 2020/09/24 07:11:29 rillig Exp $");
 
 #define DIR_DEBUG0(fmt) \
     if (!DEBUG(DIR)) (void) 0; else fprintf(debug_file, fmt)
@@ -759,7 +759,7 @@
 }
 
 /* Print a word in the list of expansions.
- * Callback for Dir_Expand when DEBUG(DIR), via Lst_ForEach. */
+ * Callback for Dir_Expand when DEBUG(DIR), via Lst_ForEachUntil. */
 static int
 DirPrintWord(void *word, void *dummy MAKE_ATTR_UNUSED)
 {
@@ -879,7 +879,7 @@
        }
     }
     if (DEBUG(DIR)) {
-       Lst_ForEach(expansions, DirPrintWord, NULL);
+       Lst_ForEachUntil(expansions, DirPrintWord, NULL);
        fprintf(debug_file, "\n");
     }
 }
@@ -1489,7 +1489,7 @@
  * Dir_AddDir --
  *     Add the given name to the end of the given path. The order of
  *     the arguments is backwards so ParseDoDependency can do a
- *     Lst_ForEach of its list of paths...
+ *     Lst_ForEachUntil of its list of paths...
  *
  * Input:
  *     path            the path to which the directory should be
@@ -1763,5 +1763,5 @@
 void
 Dir_PrintPath(SearchPath *path)
 {
-    Lst_ForEach(path, DirPrintDir, NULL);
+    Lst_ForEachUntil(path, DirPrintDir, NULL);
 }
diff -r 38589550c0ed -r 32e20965d272 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Thu Sep 24 06:52:48 2020 +0000
+++ b/usr.bin/make/job.c        Thu Sep 24 07:11:29 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.236 2020/09/23 07:30:12 rillig Exp $ */
+/*     $NetBSD: job.c,v 1.237 2020/09/24 07:11:29 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -140,7 +140,7 @@
 #include "trace.h"
 
 /*     "@(#)job.c      8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: job.c,v 1.236 2020/09/23 07:30:12 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.237 2020/09/24 07:11:29 rillig Exp $");
 
 # define STATIC static
 
@@ -648,7 +648,7 @@
  *     made and return non-zero to signal that the end of the commands
  *     was reached. These commands are later attached to the postCommands
  *     node and executed by Job_End when all things are done.
- *     This function is called from JobStart via Lst_ForEach.
+ *     This function is called from JobStart via Lst_ForEachUntil.
  *
  * Input:
  *     cmdp            command string to print
@@ -1605,7 +1605,7 @@
         * We can do all the commands at once. hooray for sanity
         */
        numCommands = 0;
-       Lst_ForEach(gn->commands, JobPrintCommand, job);
+       Lst_ForEachUntil(gn->commands, JobPrintCommand, job);
 
        /*
         * If we didn't print out any commands to the shell script,
@@ -1632,7 +1632,7 @@
         * doesn't do any harm in this case and may do some good.
         */
        if (cmdsOK) {
-           Lst_ForEach(gn->commands, JobPrintCommand, job);
+           Lst_ForEachUntil(gn->commands, JobPrintCommand, job);
        }
        /*
         * Don't execute the shell, thank you.
diff -r 38589550c0ed -r 32e20965d272 usr.bin/make/lst.c
--- a/usr.bin/make/lst.c        Thu Sep 24 06:52:48 2020 +0000
+++ b/usr.bin/make/lst.c        Thu Sep 24 07:11:29 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.66 2020/09/24 06:45:59 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.67 2020/09/24 07:11:29 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -36,7 +36,7 @@
 
 #include "make.h"
 
-MAKE_RCSID("$NetBSD: lst.c,v 1.66 2020/09/24 06:45:59 rillig Exp $");
+MAKE_RCSID("$NetBSD: lst.c,v 1.67 2020/09/24 07:11:29 rillig Exp $");
 
 struct ListNode {
     struct ListNode *prev;     /* previous element in list */
@@ -415,13 +415,13 @@
     return NULL;
 }
 
-static int Lst_ForEachFrom(List *, ListNode *, LstActionProc, void *);
+static int Lst_ForEachFrom(List *, ListNode *, LstActionUntilProc, 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. */
 int
-Lst_ForEach(List *list, LstActionProc proc, void *procData)
+Lst_ForEachUntil(List *list, LstActionUntilProc proc, void *procData)
 {
     if (LstIsEmpty(list))
        return 0;               /* XXX: Document what this value means. */
@@ -433,7 +433,7 @@
  * and non-zero if it should abort. */
 int
 Lst_ForEachFrom(List *list, ListNode *node,
-                LstActionProc proc, void *procData)
+                LstActionUntilProc proc, void *procData)
 {
     ListNode *tln = node;
     ListNode *next;
diff -r 38589550c0ed -r 32e20965d272 usr.bin/make/lst.h
--- a/usr.bin/make/lst.h        Thu Sep 24 06:52:48 2020 +0000
+++ b/usr.bin/make/lst.h        Thu Sep 24 07:11:29 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lst.h,v 1.63 2020/09/24 06:45:59 rillig Exp $  */
+/*     $NetBSD: lst.h,v 1.64 2020/09/24 07:11:29 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -94,8 +94,8 @@
 typedef void LstFreeProc(void *);
 /* Return TRUE if the datum matches the args, for Lst_Find. */
 typedef Boolean LstFindProc(const void *datum, const void *args);
-/* An action for Lst_ForEach. */
-typedef int LstActionProc(void *datum, void *args);
+/* An action for Lst_ForEachUntil. */
+typedef int LstActionUntilProc(void *datum, void *args);
 
 /* Create or destroy a list */
 
@@ -154,7 +154,7 @@
 
 /* Apply a function to each datum of the list, until the callback function
  * returns non-zero. */
-int Lst_ForEach(List *, LstActionProc, void *);
+int Lst_ForEachUntil(List *, LstActionUntilProc, void *);
 
 /* Iterating over a list while keeping track of the current node and possible
  * concurrent modifications */
diff -r 38589550c0ed -r 32e20965d272 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Thu Sep 24 06:52:48 2020 +0000
+++ b/usr.bin/make/main.c       Thu Sep 24 07:11:29 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.341 2020/09/22 20:19:46 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.342 2020/09/24 07:11:29 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -126,7 +126,7 @@
 #endif
 
 /*     "@(#)main.c     8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.341 2020/09/22 20:19:46 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.342 2020/09/24 07:11:29 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\
  The Regents of the University of California.  All rights reserved.");
@@ -2015,7 +2015,7 @@
         */
        Var_Set(".ERROR_TARGET", gn->name, VAR_GLOBAL);
        Var_Delete(".ERROR_CMD", VAR_GLOBAL);
-       Lst_ForEach(gn->commands, addErrorCMD, gn);
+       Lst_ForEachUntil(gn->commands, addErrorCMD, gn);
     }
     expr = "${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'\n@}";
     (void)Var_Subst(expr, VAR_GLOBAL, VARE_WANTRES, &cp);
diff -r 38589550c0ed -r 32e20965d272 usr.bin/make/make.c
--- a/usr.bin/make/make.c       Thu Sep 24 06:52:48 2020 +0000
+++ b/usr.bin/make/make.c       Thu Sep 24 07:11:29 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.c,v 1.139 2020/09/24 06:45:59 rillig Exp $        */
+/*     $NetBSD: make.c,v 1.140 2020/09/24 07:11:29 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.139 2020/09/24 06:45:59 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.140 2020/09/24 07:11:29 rillig Exp $");
 
 static unsigned int checked = 1;/* Sequence # to detect recursion */
 static GNodeList *toBeMade;    /* The current fringe of the graph. These
@@ -179,7 +179,7 @@
  *-----------------------------------------------------------------------
  * Make_TimeStamp --
  *     Set the cmgn field of a parent node based on the mtime stamp in its
- *     child. Called from MakeOODate via Lst_ForEach.
+ *     child. Called from MakeOODate via Lst_ForEachUntil.
  *
  * Input:
  *     pgn             the current parent
@@ -369,7 +369,7 @@
      * thinking they're out-of-date.
      */
     if (!oodate) {
-       Lst_ForEach(gn->parents, MakeTimeStamp, gn);
+       Lst_ForEachUntil(gn->parents, MakeTimeStamp, gn);
     }
 
     return oodate;
@@ -507,7 +507,7 @@
 /*-
  *-----------------------------------------------------------------------
  * MakeHandleUse --
- *     Callback function for Lst_ForEach, used by Make_Run on the downward
+ *     Callback function for Lst_ForEachUntil, used by Make_Run on the downward
  *     pass to handle .USE nodes. Should be called before the children
  *     are enqueued to be looked at by MakeAddChild.
  *     This function calls Make_HandleUse to copy the .USE node's commands,
@@ -723,7 +723,7 @@
     parents = centurion->parents;
 
     /* If this was a .ORDER node, schedule the RHS */
-    Lst_ForEach(centurion->order_succ, MakeBuildParent, Lst_First(toBeMade));
+    Lst_ForEachUntil(centurion->order_succ, MakeBuildParent, Lst_First(toBeMade));
 
     /* Now mark all the parents as having one less unmade child */
     Lst_Open(parents);
@@ -805,7 +805,7 @@
            continue;
        }
        assert(pgn->order_pred != NULL);
-       if (Lst_ForEach(pgn->order_pred, MakeCheckOrder, 0)) {



Home | Main Index | Thread Index | Old Index