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): clean up API for finding and creating ...



details:   https://anonhg.NetBSD.org/src/rev/fcf2a949c147
branches:  trunk
changeset: 939382:fcf2a949c147
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Sep 26 16:00:12 2020 +0000

description:
make(1): clean up API for finding and creating GNodes

The previous API had complicated rules for the cases in which the single
function returned NULL or what it did.  The flags for that function were
confusing since passing TARG_NOHASH would create a new node even though
TARG_CREATE was not included in that bit mask.

Splitting the function into 3 separate functions avoids this confusion.
It also reveals several places where the complicated API led to
unreachable code.  Such code has been removed.

diffstat:

 usr.bin/make/arch.c    |  25 ++++++-----------------
 usr.bin/make/compat.c  |   8 +++---
 usr.bin/make/cond.c    |  12 +++-------
 usr.bin/make/job.c     |   9 +++----
 usr.bin/make/main.c    |   8 +++---
 usr.bin/make/make.c    |   6 ++--
 usr.bin/make/make.h    |  14 +------------
 usr.bin/make/nonints.h |   8 ++++--
 usr.bin/make/parse.c   |  16 +++++++-------
 usr.bin/make/suff.c    |  18 ++++++++--------
 usr.bin/make/targ.c    |  52 ++++++++++++++++++++++++++++++++++---------------
 usr.bin/make/var.c     |   6 ++--
 12 files changed, 88 insertions(+), 94 deletions(-)

diffs (truncated from 587 to 300 lines):

diff -r 1ff2cbf3ba57 -r fcf2a949c147 usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Sat Sep 26 15:41:53 2020 +0000
+++ b/usr.bin/make/arch.c       Sat Sep 26 16:00:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.122 2020/09/26 14:48:31 rillig Exp $        */
+/*     $NetBSD: arch.c,v 1.123 2020/09/26 16:00:12 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -133,7 +133,7 @@
 #include    "config.h"
 
 /*     "@(#)arch.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: arch.c,v 1.122 2020/09/26 14:48:31 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.123 2020/09/26 16:00:12 rillig Exp $");
 
 #ifdef TARGET_MACHINE
 #undef MAKE_MACHINE
@@ -345,15 +345,10 @@
                 * Just create an ARCHV node for the thing and let
                 * SuffExpandChildren handle it...
                 */
-               gn = Targ_FindNode(buf, TARG_CREATE);
+               gn = Targ_GetNode(buf);
+               gn->type |= OP_ARCHV;
+               Lst_Append(nodeLst, gn);
 
-               if (gn == NULL) {
-                   free(buf);
-                   return FALSE;
-               } else {
-                   gn->type |= OP_ARCHV;
-                   Lst_Append(nodeLst, gn);
-               }
            } else if (!Arch_ParseArchive(&sacrifice, nodeLst, ctxt)) {
                /*
                 * Error in nested call -- free buffer and return FALSE
@@ -375,12 +370,9 @@
                char *fullname = str_concat4(libName, "(", member, ")");
                free(member);
 
-               gn = Targ_FindNode(fullname, TARG_CREATE);
+               gn = Targ_GetNode(fullname);
                free(fullname);
 
-               if (gn == NULL)
-                   return FALSE;
-
                /*
                 * We've found the node, but have to make sure the rest of
                 * the world knows it's an archive member, without having
@@ -394,12 +386,9 @@
            Lst_Free(members);
        } else {
            char *fullname = str_concat4(libName, "(", memName, ")");
-           gn = Targ_FindNode(fullname, TARG_CREATE);
+           gn = Targ_GetNode(fullname);
            free(fullname);
 
-           if (gn == NULL)
-               return FALSE;
-
            /*
             * We've found the node, but have to make sure the rest of the
             * world knows it's an archive member, without having to
diff -r 1ff2cbf3ba57 -r fcf2a949c147 usr.bin/make/compat.c
--- a/usr.bin/make/compat.c     Sat Sep 26 15:41:53 2020 +0000
+++ b/usr.bin/make/compat.c     Sat Sep 26 16:00:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat.c,v 1.150 2020/09/24 07:11:29 rillig Exp $      */
+/*     $NetBSD: compat.c,v 1.151 2020/09/26 16:00:12 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.150 2020/09/24 07:11:29 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.151 2020/09/26 16:00:12 rillig Exp $");
 
 static GNode       *curTarg = NULL;
 static void CompatInterrupt(int);
@@ -145,7 +145,7 @@
         * Run .INTERRUPT only if hit with interrupt signal
         */
        if (signo == SIGINT) {
-           gn = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
+           gn = Targ_FindNode(".INTERRUPT");
            if (gn != NULL) {
                Compat_Make(gn, gn);
            }
@@ -692,7 +692,7 @@
      * to it.
      */
     if (!queryFlag) {
-       gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
+       gn = Targ_FindNode(".BEGIN");
        if (gn != NULL) {
            Compat_Make(gn, gn);
            if (gn->made == ERROR) {
diff -r 1ff2cbf3ba57 -r fcf2a949c147 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Sat Sep 26 15:41:53 2020 +0000
+++ b/usr.bin/make/cond.c       Sat Sep 26 16:00:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.151 2020/09/25 20:48:23 rillig Exp $        */
+/*     $NetBSD: cond.c,v 1.152 2020/09/26 16:00:12 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -93,7 +93,7 @@
 #include "dir.h"
 
 /*     "@(#)cond.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: cond.c,v 1.151 2020/09/25 20:48:23 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.152 2020/09/26 16:00:12 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -329,9 +329,7 @@
 static Boolean
 FuncTarget(int argLen MAKE_ATTR_UNUSED, const char *arg)
 {
-    GNode *gn;
-
-    gn = Targ_FindNode(arg, TARG_NOCREATE);
+    GNode *gn = Targ_FindNode(arg);
     return gn != NULL && !OP_NOP(gn->type);
 }
 
@@ -340,9 +338,7 @@
 static Boolean
 FuncCommands(int argLen MAKE_ATTR_UNUSED, const char *arg)
 {
-    GNode *gn;
-
-    gn = Targ_FindNode(arg, TARG_NOCREATE);
+    GNode *gn = Targ_FindNode(arg);
     return gn != NULL && !OP_NOP(gn->type) && !Lst_IsEmpty(gn->commands);
 }
 
diff -r 1ff2cbf3ba57 -r fcf2a949c147 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Sat Sep 26 15:41:53 2020 +0000
+++ b/usr.bin/make/job.c        Sat Sep 26 16:00:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.238 2020/09/25 06:20:44 rillig Exp $ */
+/*     $NetBSD: job.c,v 1.239 2020/09/26 16:00:12 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.238 2020/09/25 06:20:44 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.239 2020/09/26 16:00:12 rillig Exp $");
 
 # define STATIC static
 
@@ -2572,7 +2572,7 @@
     JobSigUnlock(&mask);
 
     if (runINTERRUPT && !touchFlag) {
-       interrupt = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
+       interrupt = Targ_FindNode(".INTERRUPT");
        if (interrupt != NULL) {
            ignoreErrors = FALSE;
            JobRun(interrupt);
@@ -2968,8 +2968,7 @@
  */
 Boolean
 Job_RunTarget(const char *target, const char *fname) {
-    GNode *gn = Targ_FindNode(target, TARG_NOCREATE);
-
+    GNode *gn = Targ_FindNode(target);
     if (gn == NULL)
        return FALSE;
 
diff -r 1ff2cbf3ba57 -r fcf2a949c147 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Sat Sep 26 15:41:53 2020 +0000
+++ b/usr.bin/make/main.c       Sat Sep 26 16:00:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.345 2020/09/25 23:18:59 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.346 2020/09/26 16:00:12 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -126,7 +126,7 @@
 #endif
 
 /*     "@(#)main.c     8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.345 2020/09/25 23:18:59 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.346 2020/09/26 16:00:12 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\
  The Regents of the University of California.  All rights reserved.");
@@ -907,7 +907,7 @@
        if (Lst_IsEmpty(create))
                targs = Parse_MainName();
        else
-               targs = Targ_FindList(create, TARG_CREATE);
+               targs = Targ_FindList(create);
 
        if (!compatMake) {
                /*
@@ -2039,7 +2039,7 @@
     /*
      * Finally, see if there is a .ERROR target, and run it if so.
      */
-    en = Targ_FindNode(".ERROR", TARG_NOCREATE);
+    en = Targ_FindNode(".ERROR");
     if (en) {
        en->type |= OP_SPECIAL;
        Compat_Make(en, en);
diff -r 1ff2cbf3ba57 -r fcf2a949c147 usr.bin/make/make.c
--- a/usr.bin/make/make.c       Sat Sep 26 15:41:53 2020 +0000
+++ b/usr.bin/make/make.c       Sat Sep 26 16:00:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.c,v 1.144 2020/09/25 14:00:17 rillig Exp $        */
+/*     $NetBSD: make.c,v 1.145 2020/09/26 16:00:12 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -107,7 +107,7 @@
 #include    "job.h"
 
 /*     "@(#)make.c     8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: make.c,v 1.144 2020/09/25 14:00:17 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.145 2020/09/26 16:00:12 rillig Exp $");
 
 static unsigned int checked = 1;/* Sequence # to detect recursion */
 static GNodeList *toBeMade;    /* The current fringe of the graph. These
@@ -483,7 +483,7 @@
        /* TODO: handle errors */
        if (gn->uname && strcmp(gn->name, gn->uname) != 0) {
            /* See if we have a target for this node. */
-           GNode *tgn = Targ_FindNode(gn->name, TARG_NOCREATE);
+           GNode *tgn = Targ_FindNode(gn->name);
            if (tgn != NULL)
                gn = tgn;
        }
diff -r 1ff2cbf3ba57 -r fcf2a949c147 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Sat Sep 26 15:41:53 2020 +0000
+++ b/usr.bin/make/make.h       Sat Sep 26 16:00:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.h,v 1.146 2020/09/24 07:37:42 rillig Exp $        */
+/*     $NetBSD: make.h,v 1.147 2020/09/26 16:00:12 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -367,18 +367,6 @@
 #define OP_NOTARGET (OP_NOTMAIN|OP_USE|OP_EXEC|OP_TRANSFORM)
 
 /*
- * The TARG_ constants are used when calling the Targ_FindNode and
- * Targ_FindList functions in targ.c. They simply tell the functions what to
- * do if the desired node(s) is (are) not found. If the TARG_CREATE constant
- * is given, a new, empty node will be created for the target, placed in the
- * table of all targets and its address returned. If TARG_NOCREATE is given,
- * a NULL pointer will be returned.
- */
-#define TARG_NOCREATE  0x00      /* don't create it */
-#define TARG_CREATE    0x01      /* create node if not found */
-#define TARG_NOHASH    0x02      /* don't look in/add to hash table */
-
-/*
  * Error levels for parsing. PARSE_FATAL means the process cannot continue
  * once the makefile has been parsed. PARSE_WARNING means it can. Passed
  * as the first argument to Parse_Error.
diff -r 1ff2cbf3ba57 -r fcf2a949c147 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Sat Sep 26 15:41:53 2020 +0000
+++ b/usr.bin/make/nonints.h    Sat Sep 26 16:00:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nonints.h,v 1.129 2020/09/25 19:50:04 rillig Exp $     */
+/*     $NetBSD: nonints.h,v 1.130 2020/09/26 16:00:12 rillig Exp $     */
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -173,9 +173,11 @@
 void Targ_Stats(void);
 GNodeList *Targ_List(void);
 GNode *Targ_NewGN(const char *);
-GNode *Targ_FindNode(const char *, int);
+GNode *Targ_FindNode(const char *);
+GNode *Targ_GetNode(const char *);
+GNode *Targ_NewInternalNode(const char *);
 GNode *Targ_GetEndNode(void);
-GNodeList *Targ_FindList(StringList *, int);
+GNodeList *Targ_FindList(StringList *);
 Boolean Targ_Ignore(GNode *);
 Boolean Targ_Silent(GNode *);
 Boolean Targ_Precious(GNode *);
diff -r 1ff2cbf3ba57 -r fcf2a949c147 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sat Sep 26 15:41:53 2020 +0000
+++ b/usr.bin/make/parse.c      Sat Sep 26 16:00:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.331 2020/09/26 00:03:29 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.332 2020/09/26 16:00:12 rillig Exp $       */
 
 /*



Home | Main Index | Thread Index | Old Index