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): fix API of Targ_PrintNode



details:   https://anonhg.NetBSD.org/src/rev/a788d0ee2670
branches:  trunk
changeset: 976083:a788d0ee2670
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Sep 12 16:38:19 2020 +0000

description:
make(1): fix API of Targ_PrintNode

There was no need to export Targ_PrintNode at all.  All the callers need
is a high-level API for printing a single node or a list of nodes.  The
implementation detail that Targ_PrintNode was used as a callback to
Lst_ForEach should have never leaked into the API.

diffstat:

 usr.bin/make/make.c    |  15 ++++++---------
 usr.bin/make/nonints.h |   5 +++--
 usr.bin/make/targ.c    |  32 ++++++++++++++++++++++----------
 3 files changed, 31 insertions(+), 21 deletions(-)

diffs (151 lines):

diff -r 934848b09b4d -r a788d0ee2670 usr.bin/make/make.c
--- a/usr.bin/make/make.c       Sat Sep 12 16:24:20 2020 +0000
+++ b/usr.bin/make/make.c       Sat Sep 12 16:38:19 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.c,v 1.134 2020/09/07 06:20:07 rillig Exp $        */
+/*     $NetBSD: make.c,v 1.135 2020/09/12 16:38:19 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: make.c,v 1.134 2020/09/07 06:20:07 rillig Exp $";
+static char rcsid[] = "$NetBSD: make.c,v 1.135 2020/09/12 16:38:19 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.134 2020/09/07 06:20:07 rillig Exp $");
+__RCSID("$NetBSD: make.c,v 1.135 2020/09/12 16:38:19 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -141,11 +141,9 @@
 MAKE_ATTR_DEAD static void
 make_abort(GNode *gn, int line)
 {
-    static int two = 2;
-
     fprintf(debug_file, "make_abort from line %d\n", line);
-    Targ_PrintNode(gn, &two);
-    Lst_ForEach(toBeMade, Targ_PrintNode, &two);
+    Targ_PrintNode(gn, 2);
+    Targ_PrintNodes(toBeMade, 2);
     Targ_PrintGraph(3);
     abort();
 }
@@ -821,11 +819,10 @@
            continue;
        }
        if (DEBUG(MAKE)) {
-           static int two = 2;
            fprintf(debug_file, "- %s%s made, schedule %s%s (made %d)\n",
                    cgn->name, cgn->cohort_num,
                    pgn->name, pgn->cohort_num, pgn->made);
-           Targ_PrintNode(pgn, &two);
+           Targ_PrintNode(pgn, 2);
        }
        /* Ok, we can schedule the parent again */
        pgn->made = REQUESTED;
diff -r 934848b09b4d -r a788d0ee2670 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Sat Sep 12 16:24:20 2020 +0000
+++ b/usr.bin/make/nonints.h    Sat Sep 12 16:38:19 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nonints.h,v 1.112 2020/09/12 16:13:48 rillig Exp $     */
+/*     $NetBSD: nonints.h,v 1.113 2020/09/12 16:38:19 rillig Exp $     */
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -182,7 +182,8 @@
 Boolean Targ_Precious(GNode *);
 void Targ_SetMain(GNode *);
 void Targ_PrintCmds(GNode *);
-int Targ_PrintNode(void *, void *);
+void Targ_PrintNode(GNode *, int);
+void Targ_PrintNodes(Lst, int);
 char *Targ_FmtTime(time_t);
 void Targ_PrintType(int);
 void Targ_PrintGraph(int);
diff -r 934848b09b4d -r a788d0ee2670 usr.bin/make/targ.c
--- a/usr.bin/make/targ.c       Sat Sep 12 16:24:20 2020 +0000
+++ b/usr.bin/make/targ.c       Sat Sep 12 16:38:19 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: targ.c,v 1.86 2020/09/12 16:24:20 rillig Exp $ */
+/*     $NetBSD: targ.c,v 1.87 2020/09/12 16:38:19 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: targ.c,v 1.86 2020/09/12 16:24:20 rillig Exp $";
+static char rcsid[] = "$NetBSD: targ.c,v 1.87 2020/09/12 16:38:19 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.86 2020/09/12 16:24:20 rillig Exp $");
+__RCSID("$NetBSD: targ.c,v 1.87 2020/09/12 16:38:19 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -467,12 +467,11 @@
     }
 }
 
-/* Print the contents of a node. */
-int
-Targ_PrintNode(void *gnp, void *passp)
+static int
+PrintNode(void *gnp, void *passp)
 {
-    GNode         *gn = (GNode *)gnp;
-    int                  pass = passp ? *(int *)passp : 0;
+    GNode *gn = gnp;
+    int pass = *(const int *)passp;
 
     fprintf(debug_file, "# %s%s", gn->name, gn->cohort_num);
     GNode_FprintDetails(debug_file, ", ", gn, "\n");
@@ -526,12 +525,25 @@
        Targ_PrintCmds(gn);
        fprintf(debug_file, "\n\n");
        if (gn->type & OP_DOUBLEDEP) {
-           Lst_ForEach(gn->cohorts, Targ_PrintNode, &pass);
+           Lst_ForEach(gn->cohorts, PrintNode, passp);
        }
     }
     return 0;
 }
 
+/* Print the contents of a node. */
+void
+Targ_PrintNode(GNode *gn, int pass)
+{
+    PrintNode(gn, &pass);
+}
+
+void
+Targ_PrintNodes(Lst gnodes, int pass)
+{
+    Lst_ForEach(gnodes, PrintNode, &pass);
+}
+
 /* Print only those targets that are just a source.
  * The name of each file is printed, preceded by #\t. */
 static int
@@ -558,7 +570,7 @@
 Targ_PrintGraph(int pass)
 {
     fprintf(debug_file, "#*** Input graph:\n");
-    Lst_ForEach(allTargets, Targ_PrintNode, &pass);
+    Lst_ForEach(allTargets, PrintNode, &pass);
     fprintf(debug_file, "\n\n");
     fprintf(debug_file, "#\n#   Files that are only sources:\n");
     Lst_ForEach(allTargets, TargPrintOnlySrc, NULL);



Home | Main Index | Thread Index | Old Index