Module Name:    src
Committed By:   rillig
Date:           Mon Sep 21 17:44:25 UTC 2020

Modified Files:
        src/usr.bin/make: compat.c job.c job.h make.h meta.c

Log Message:
make(1): add specific typedefs for lists

These typedefs are only intended to help human readers, they do not
provide any type-safety.  They also make the pointers explicit, which
had been hidden before by the typedef for Lst and LstNode.  Typing a few
'*' is less work than finding out which of the many types are pointers
and which aren't.

In meta.c, the variable "ln" served two completely different purposes,
which have been split again.  Register allocation is the job of the
compiler, not of the human source code reader.


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 src/usr.bin/make/compat.c
cvs rdiff -u -r1.232 -r1.233 src/usr.bin/make/job.c
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/make/job.h
cvs rdiff -u -r1.142 -r1.143 src/usr.bin/make/make.h
cvs rdiff -u -r1.114 -r1.115 src/usr.bin/make/meta.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/compat.c
diff -u src/usr.bin/make/compat.c:1.145 src/usr.bin/make/compat.c:1.146
--- src/usr.bin/make/compat.c:1.145	Sun Sep 13 15:15:51 2020
+++ src/usr.bin/make/compat.c	Mon Sep 21 17:44:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat.c,v 1.145 2020/09/13 15:15:51 rillig Exp $	*/
+/*	$NetBSD: compat.c,v 1.146 2020/09/21 17:44:25 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.145 2020/09/13 15:15:51 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.146 2020/09/21 17:44:25 rillig Exp $");
 
 static GNode	    *curTarg = NULL;
 static GNode	    *ENDNode;
@@ -197,7 +197,7 @@ Compat_RunCommand(char *cmdp, struct GNo
     int	    	  status;   	/* Description of child's death */
     pid_t	  cpid;	    	/* Child actually found */
     pid_t	  retstat;    	/* Result of wait */
-    LstNode 	  cmdNode;  	/* Node where current command is located */
+    StringListNode *cmdNode;  	/* Node where current command is located */
     const char  ** volatile av;	/* Argument vector for thing to exec */
     char	** volatile mav;/* Copy of the argument vector for freeing */
     Boolean 	  useShell;    	/* TRUE if command should be executed

Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.232 src/usr.bin/make/job.c:1.233
--- src/usr.bin/make/job.c:1.232	Sun Sep 13 15:15:51 2020
+++ src/usr.bin/make/job.c	Mon Sep 21 17:44:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.232 2020/09/13 15:15:51 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.233 2020/09/21 17:44:25 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.232 2020/09/13 15:15:51 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.233 2020/09/21 17:44:25 rillig Exp $");
 
 # define STATIC static
 
@@ -697,7 +697,7 @@ JobPrintCommand(void *cmdp, void *jobp)
     if (strcmp(cmd, "...") == 0) {
 	job->node->type |= OP_SAVE_CMDS;
 	if ((job->flags & JOB_IGNDOTS) == 0) {
-	    LstNode dotsNode = Lst_FindDatum(job->node->commands, cmd);
+	    StringListNode *dotsNode = Lst_FindDatum(job->node->commands, cmd);
 	    job->tailCmds = dotsNode != NULL ? LstNode_Next(dotsNode) : NULL;
 	    return 1;
 	}

Index: src/usr.bin/make/job.h
diff -u src/usr.bin/make/job.h:1.47 src/usr.bin/make/job.h:1.48
--- src/usr.bin/make/job.h:1.47	Sat Aug 29 12:20:17 2020
+++ src/usr.bin/make/job.h	Mon Sep 21 17:44:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.h,v 1.47 2020/08/29 12:20:17 rillig Exp $	*/
+/*	$NetBSD: job.h,v 1.48 2020/09/21 17:44:25 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -143,7 +143,7 @@ struct pollfd;
 typedef struct Job {
     int       	pid;	    /* The child's process ID */
     GNode    	*node;      /* The target the child is making */
-    LstNode 	tailCmds;   /* The node of the first command to be
+    StringListNode *tailCmds; /* The node of the first command to be
 			     * saved when the job has been run */
     FILE 	*cmdFILE;   /* When creating the shell script, this is
 			     * where the commands go */

Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.142 src/usr.bin/make/make.h:1.143
--- src/usr.bin/make/make.h:1.142	Sun Sep 13 15:15:51 2020
+++ src/usr.bin/make/make.h	Mon Sep 21 17:44:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.142 2020/09/13 15:15:51 rillig Exp $	*/
+/*	$NetBSD: make.h,v 1.143 2020/09/21 17:44:25 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -272,6 +272,11 @@ typedef enum {
     INTERNAL	= 0x4000	/* Internal use only */
 } GNodeFlags;
 
+typedef struct List StringList;
+typedef struct ListNode StringListNode;
+typedef struct List GNodeList;
+typedef struct ListNode GNodeListNode;
+
 /* A graph node represents a target that can possibly be made, including its
  * relation to other targets and a lot of other details. */
 typedef struct GNode {
@@ -299,25 +304,25 @@ typedef struct GNode {
     /* The GNodes for which this node is an implied source. May be empty.
      * For example, when there is an inference rule for .c.o, the node for
      * file.c has the node for file.o in this list. */
-    Lst implicitParents;
+    GNodeList *implicitParents;
 
     /* Other nodes of the same name for the :: operator. */
-    Lst cohorts;
+    GNodeList *cohorts;
 
     /* The nodes that depend on this one, or in other words, the nodes for
      * which this is a source. */
-    Lst parents;
+    GNodeList *parents;
     /* The nodes on which this one depends. */
-    Lst children;
+    GNodeList *children;
 
     /* .ORDER nodes we need made. The nodes that must be made (if they're
      * made) before this node can be made, but that do not enter into the
      * datedness of this node. */
-    Lst order_pred;
+    GNodeList *order_pred;
     /* .ORDER nodes who need us. The nodes that must be made (if they're made
      * at all) after this node is made, but that do not depend on this node,
      * in the normal sense. */
-    Lst order_succ;
+    GNodeList *order_succ;
 
     /* #n for this cohort */
     char cohort_num[8];
@@ -335,7 +340,7 @@ typedef struct GNode {
     Hash_Table context;
 
     /* The commands to be given to a shell to create this target. */
-    Lst commands;
+    StringList *commands;
 
     /* Suffix for the node (determined by Suff_FindDeps and opaque to everyone
      * but the Suff module) */

Index: src/usr.bin/make/meta.c
diff -u src/usr.bin/make/meta.c:1.114 src/usr.bin/make/meta.c:1.115
--- src/usr.bin/make/meta.c:1.114	Sat Sep 12 14:41:00 2020
+++ src/usr.bin/make/meta.c	Mon Sep 21 17:44:25 2020
@@ -1,4 +1,4 @@
-/*      $NetBSD: meta.c,v 1.114 2020/09/12 14:41:00 rillig Exp $ */
+/*      $NetBSD: meta.c,v 1.115 2020/09/21 17:44:25 rillig Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -1124,7 +1124,7 @@ meta_oodate(GNode *gn, Boolean oodate)
 	int lastpid = 0;
 	int pid;
 	int x;
-	LstNode ln;
+	StringListNode *cmdNode;
 	struct make_stat mst;
 
 	if (!buf) {
@@ -1148,7 +1148,7 @@ meta_oodate(GNode *gn, Boolean oodate)
 	/* we want to track all the .meta we read */
 	Var_Append(".MAKE.META.FILES", fname, VAR_GLOBAL);
 
-	ln = Lst_First(gn->commands);
+	cmdNode = Lst_First(gn->commands);
 	while (!oodate && (x = fgetLine(&buf, &bufsz, 0, fp)) > 0) {
 	    lineno++;
 	    if (buf[x - 1] == '\n')
@@ -1315,19 +1315,20 @@ meta_oodate(GNode *gn, Boolean oodate)
 		case 'D':		/* unlink */
 		    if (*p == '/' && !Lst_IsEmpty(missingFiles)) {
 			/* remove any missingFiles entries that match p */
-			ln = Lst_Find(missingFiles, path_match, p);
-			if (ln != NULL) {
-			    LstNode nln;
-			    char *tp;
+			StringListNode *missingNode =
+				Lst_Find(missingFiles, path_match, p);
+			if (missingNode != NULL) {
+			    StringListNode *nln;
 
 			    do {
+				char *tp;
 				nln = Lst_FindFrom(missingFiles,
-						   LstNode_Next(ln),
+						   LstNode_Next(missingNode),
 						   path_match, p);
-				tp = LstNode_Datum(ln);
-				Lst_Remove(missingFiles, ln);
+				tp = LstNode_Datum(missingNode);
+				Lst_Remove(missingFiles, missingNode);
 				free(tp);
-			    } while ((ln = nln) != NULL);
+			    } while ((missingNode = nln) != NULL);
 			}
 		    }
 		    if (buf[0] == 'M') {
@@ -1498,12 +1499,12 @@ meta_oodate(GNode *gn, Boolean oodate)
 		 * Compare the current command with the one in the
 		 * meta data file.
 		 */
-		if (ln == NULL) {
+		if (cmdNode == NULL) {
 		    if (DEBUG(META))
 			fprintf(debug_file, "%s: %d: there were more build commands in the meta data file than there are now...\n", fname, lineno);
 		    oodate = TRUE;
 		} else {
-		    char *cmd = LstNode_Datum(ln);
+		    char *cmd = LstNode_Datum(cmdNode);
 		    Boolean hasOODATE = FALSE;
 
 		    if (strstr(cmd, "$?"))
@@ -1555,14 +1556,14 @@ meta_oodate(GNode *gn, Boolean oodate)
 			    oodate = TRUE;
 		    }
 		    free(cmd);
-		    ln = LstNode_Next(ln);
+		    cmdNode = LstNode_Next(cmdNode);
 		}
 	    } else if (strcmp(buf, "CWD") == 0) {
 		/*
 		 * Check if there are extra commands now
 		 * that weren't in the meta data file.
 		 */
-		if (!oodate && ln != NULL) {
+		if (!oodate && cmdNode != NULL) {
 		    if (DEBUG(META))
 			fprintf(debug_file, "%s: %d: there are extra build commands now that weren't in the meta data file\n", fname, lineno);
 		    oodate = TRUE;

Reply via email to