Module Name:    src
Committed By:   rillig
Date:           Sat Sep 12 16:38:19 UTC 2020

Modified Files:
        src/usr.bin/make: make.c nonints.h targ.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.134 -r1.135 src/usr.bin/make/make.c
cvs rdiff -u -r1.112 -r1.113 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/make/targ.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/make.c
diff -u src/usr.bin/make/make.c:1.134 src/usr.bin/make/make.c:1.135
--- src/usr.bin/make/make.c:1.134	Mon Sep  7 06:20:07 2020
+++ src/usr.bin/make/make.c	Sat Sep 12 16:38:19 2020
@@ -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 @@ static int MakeBuildParent(void *, void 
 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 @@ Make_Update(GNode *cgn)
 	    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;

Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.112 src/usr.bin/make/nonints.h:1.113
--- src/usr.bin/make/nonints.h:1.112	Sat Sep 12 16:13:48 2020
+++ src/usr.bin/make/nonints.h	Sat Sep 12 16:38:19 2020
@@ -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_Silent(GNode *);
 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);

Index: src/usr.bin/make/targ.c
diff -u src/usr.bin/make/targ.c:1.86 src/usr.bin/make/targ.c:1.87
--- src/usr.bin/make/targ.c:1.86	Sat Sep 12 16:24:20 2020
+++ src/usr.bin/make/targ.c	Sat Sep 12 16:38:19 2020
@@ -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 @@ made_name(GNodeMade made)
     }
 }
 
-/* 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_PrintNode(void *gnp, void *passp)
 	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 @@ void
 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);

Reply via email to