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): inline Lst_ForEachUntil in meta mode



details:   https://anonhg.NetBSD.org/src/rev/645835ecde73
branches:  trunk
changeset: 946423:645835ecde73
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Nov 27 08:07:26 2020 +0000

description:
make(1): inline Lst_ForEachUntil in meta mode

This means no more unnecessary void pointers in function signatures and
no more abstraction level at checking a single element of a list.  In
most cases it is more appropriate to define a function that operates on
the list as a whole, thereby hiding implementation details like the
ListNode from the caller.

diffstat:

 usr.bin/make/lst.c  |  18 ++----------------
 usr.bin/make/lst.h  |  12 +-----------
 usr.bin/make/make.c |   8 ++++----
 usr.bin/make/meta.c |  51 ++++++++++++++++++++++++++++++++++-----------------
 4 files changed, 41 insertions(+), 48 deletions(-)

diffs (229 lines):

diff -r 724d6c69a1af -r 645835ecde73 usr.bin/make/lst.c
--- a/usr.bin/make/lst.c        Fri Nov 27 07:11:49 2020 +0000
+++ b/usr.bin/make/lst.c        Fri Nov 27 08:07:26 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.93 2020/11/24 19:46:29 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.94 2020/11/27 08:07:26 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -34,7 +34,7 @@
 
 #include "make.h"
 
-MAKE_RCSID("$NetBSD: lst.c,v 1.93 2020/11/24 19:46:29 rillig Exp $");
+MAKE_RCSID("$NetBSD: lst.c,v 1.94 2020/11/27 08:07:26 rillig Exp $");
 
 static ListNode *
 LstNodeNew(ListNode *prev, ListNode *next, void *datum)
@@ -198,20 +198,6 @@
        return NULL;
 }
 
-int
-Lst_ForEachUntil(List *list, LstActionUntilProc proc, void *procData)
-{
-       ListNode *ln;
-       int result = 0;
-
-       for (ln = list->first; ln != NULL; ln = ln->next) {
-               result = proc(ln->datum, procData);
-               if (result != 0)
-                       break;
-       }
-       return result;
-}
-
 /* Move all nodes from src to the end of dst.
  * The source list is destroyed and freed. */
 void
diff -r 724d6c69a1af -r 645835ecde73 usr.bin/make/lst.h
--- a/usr.bin/make/lst.h        Fri Nov 27 07:11:49 2020 +0000
+++ b/usr.bin/make/lst.h        Fri Nov 27 08:07:26 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lst.h,v 1.86 2020/11/24 19:46:29 rillig Exp $  */
+/*     $NetBSD: lst.h,v 1.87 2020/11/27 08:07:26 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -104,8 +104,6 @@
 
 /* Free the datum of a node, called before freeing the node itself. */
 typedef void LstFreeProc(void *);
-/* An action for Lst_ForEachUntil and Lst_ForEachUntilConcurrent. */
-typedef int LstActionUntilProc(void *datum, void *args);
 
 /* Create or destroy a list */
 
@@ -146,14 +144,6 @@
 /* Set the value of the node to NULL. Having NULL in a list is unusual. */
 void LstNode_SetNull(ListNode *);
 
-/* Iterating over a list, using a callback function */
-
-/* Run the action for each datum of the list, until the action returns
- * non-zero.
- *
- * During this iteration, the list must not be modified structurally. */
-int Lst_ForEachUntil(List *, LstActionUntilProc, void *);
-
 /* Using the list as a queue */
 
 /* Add a datum at the tail of the queue. */
diff -r 724d6c69a1af -r 645835ecde73 usr.bin/make/make.c
--- a/usr.bin/make/make.c       Fri Nov 27 07:11:49 2020 +0000
+++ b/usr.bin/make/make.c       Fri Nov 27 08:07:26 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.c,v 1.217 2020/11/24 23:13:09 rillig Exp $        */
+/*     $NetBSD: make.c,v 1.218 2020/11/27 08:07:26 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -102,7 +102,7 @@
 #include "job.h"
 
 /*     "@(#)make.c     8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: make.c,v 1.217 2020/11/24 23:13:09 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.218 2020/11/27 08:07:26 rillig Exp $");
 
 /* Sequence # to detect recursion. */
 static unsigned int checked_seqno = 1;
@@ -1032,9 +1032,9 @@
 
 static void MakePrintStatusList(GNodeList *, int *);
 
-/* Print the status of a top-level node, viz. it being up-to-date already
+/*
+ * Print the status of a top-level node, viz. it being up-to-date already
  * or not created due to an error in a lower level.
- * Callback function for Make_Run via Lst_ForEachUntil.
  */
 static Boolean
 MakePrintStatus(GNode *gn, int *errors)
diff -r 724d6c69a1af -r 645835ecde73 usr.bin/make/meta.c
--- a/usr.bin/make/meta.c       Fri Nov 27 07:11:49 2020 +0000
+++ b/usr.bin/make/meta.c       Fri Nov 27 08:07:26 2020 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: meta.c,v 1.148 2020/11/23 23:44:03 rillig Exp $ */
+/*      $NetBSD: meta.c,v 1.149 2020/11/27 08:07:26 rillig Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -312,17 +312,15 @@
  * Return true if running ${.MAKE}
  * Bypassed if target is flagged .MAKE
  */
-static int
-is_submake(void *cmdp, void *gnp)
+static Boolean
+is_submake(const char *cmd, GNode *gn)
 {
     static const char *p_make = NULL;
     static size_t p_len;
-    char  *cmd = cmdp;
-    GNode *gn = gnp;
     char *mp = NULL;
     char *cp;
     char *cp2;
-    int rc = 0;                                /* keep looking */
+    Boolean rc = FALSE;
 
     if (p_make == NULL) {
        void *dontFreeIt;
@@ -342,17 +340,17 @@
        case ' ':
        case '\t':
        case '\n':
-           rc = 1;
+           rc = TRUE;
            break;
        }
-       if (cp2 > cmd && rc > 0) {
+       if (cp2 > cmd && rc) {
            switch (cp2[-1]) {
            case ' ':
            case '\t':
            case '\n':
                break;
            default:
-               rc = 0;                 /* no match */
+               rc = FALSE;             /* no match */
                break;
            }
        }
@@ -361,6 +359,17 @@
     return rc;
 }
 
+static Boolean
+any_is_submake(GNode *gn)
+{
+    StringListNode *ln;
+
+    for (ln = gn->commands->first; ln != NULL; ln = ln->next)
+       if (is_submake(ln->datum, gn))
+           return TRUE;
+    return FALSE;
+}
+
 typedef struct meta_file_s {
     FILE *fp;
     GNode *gn;
@@ -434,7 +443,7 @@
     }
     if ((gn->type & (OP_META|OP_SUBMAKE)) == OP_SUBMAKE) {
        /* OP_SUBMAKE is a bit too aggressive */
-       if (Lst_ForEachUntil(gn->commands, is_submake, gn)) {
+       if (any_is_submake(gn)) {
            DEBUG1(META, "Skipping meta for %s: .SUBMAKE\n", gn->name);
            return FALSE;
        }
@@ -945,17 +954,25 @@
     return 0;
 }
 
-/* Lst_ForEachUntil wants 1 to stop search */
-static int
-prefix_match(void *p, void *q)
+static Boolean
+prefix_match(const char *prefix, const char *path)
 {
-    const char *prefix = p;
-    const char *path = q;
     size_t n = strlen(prefix);
 
     return strncmp(path, prefix, n) == 0;
 }
 
+static Boolean
+has_any_prefix(const char *path, StringList *prefixes)
+{
+    StringListNode *ln;
+
+    for (ln = prefixes->first; ln != NULL; ln = ln->next)
+       if (prefix_match(ln->datum, path))
+           return TRUE;
+    return FALSE;
+}
+
 /* See if the path equals prefix or starts with "prefix/". */
 static Boolean
 path_starts_with(const char *path, const char *prefix)
@@ -977,7 +994,7 @@
 
     if (*p == '/') {
        cached_realpath(p, fname); /* clean it up */
-       if (Lst_ForEachUntil(metaIgnorePaths, prefix_match, fname)) {
+       if (has_any_prefix(fname, metaIgnorePaths)) {
 #ifdef DEBUG_META_MODE
            DEBUG1(META, "meta_oodate: ignoring path: %s\n", p);
 #endif
@@ -1369,7 +1386,7 @@
                    if (strncmp(p, cwd, cwdlen) == 0)
                        break;
 
-                   if (!Lst_ForEachUntil(metaBailiwick, prefix_match, p))
+                   if (!has_any_prefix(p, metaBailiwick))
                        break;
 
                    /* tmpdir might be within */



Home | Main Index | Thread Index | Old Index