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): add specific typedefs for lists



details:   https://anonhg.NetBSD.org/src/rev/0a281af99796
branches:  trunk
changeset: 938953:0a281af99796
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Sep 21 17:44:25 2020 +0000

description:
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.

diffstat:

 usr.bin/make/compat.c |   6 +++---
 usr.bin/make/job.c    |   6 +++---
 usr.bin/make/job.h    |   4 ++--
 usr.bin/make/make.h   |  21 +++++++++++++--------
 usr.bin/make/meta.c   |  31 ++++++++++++++++---------------
 5 files changed, 37 insertions(+), 31 deletions(-)

diffs (222 lines):

diff -r f24d422c53ff -r 0a281af99796 usr.bin/make/compat.c
--- a/usr.bin/make/compat.c     Mon Sep 21 16:12:16 2020 +0000
+++ b/usr.bin/make/compat.c     Mon Sep 21 17:44:25 2020 +0000
@@ -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 @@
     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
diff -r f24d422c53ff -r 0a281af99796 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Mon Sep 21 16:12:16 2020 +0000
+++ b/usr.bin/make/job.c        Mon Sep 21 17:44:25 2020 +0000
@@ -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 @@
     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;
        }
diff -r f24d422c53ff -r 0a281af99796 usr.bin/make/job.h
--- a/usr.bin/make/job.h        Mon Sep 21 16:12:16 2020 +0000
+++ b/usr.bin/make/job.h        Mon Sep 21 17:44:25 2020 +0000
@@ -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 @@
 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 */
diff -r f24d422c53ff -r 0a281af99796 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Mon Sep 21 16:12:16 2020 +0000
+++ b/usr.bin/make/make.h       Mon Sep 21 17:44:25 2020 +0000
@@ -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 @@
     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 @@
     /* 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 @@
     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) */
diff -r f24d422c53ff -r 0a281af99796 usr.bin/make/meta.c
--- a/usr.bin/make/meta.c       Mon Sep 21 16:12:16 2020 +0000
+++ b/usr.bin/make/meta.c       Mon Sep 21 17:44:25 2020 +0000
@@ -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 @@
        int lastpid = 0;
        int pid;
        int x;
-       LstNode ln;
+       StringListNode *cmdNode;
        struct make_stat mst;
 
        if (!buf) {
@@ -1148,7 +1148,7 @@
        /* 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 @@
                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 @@
                 * 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 @@
                            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;



Home | Main Index | Thread Index | Old Index