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): require argument of Lst_Member to be n...



details:   https://anonhg.NetBSD.org/src/rev/2ec6122ad2a8
branches:  trunk
changeset: 937622:2ec6122ad2a8
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Aug 22 15:43:32 2020 +0000

description:
make(1): require argument of Lst_Member to be non-null

Since the lists don't contain null pointers, it doesn't make sense to
search for a null pointer.  All calls but one already had obviously
non-null arguments.  The one remaining call using targ->suff has been
guarded for now.

The code for Lst_Member became much simpler than before.  Partly because
the old code had an extra condition for circular lists, which are not
used by make.

diffstat:

 usr.bin/make/compat.c |  12 ++++++------
 usr.bin/make/dir.c    |  14 +++++++-------
 usr.bin/make/job.c    |  10 +++++-----
 usr.bin/make/lst.c    |  22 ++++++++--------------
 usr.bin/make/lst.h    |   4 ++--
 usr.bin/make/make.c   |   8 ++++----
 usr.bin/make/suff.c   |  22 ++++++++++++----------
 7 files changed, 44 insertions(+), 48 deletions(-)

diffs (truncated from 349 to 300 lines):

diff -r 72469fe8f0ce -r 2ec6122ad2a8 usr.bin/make/compat.c
--- a/usr.bin/make/compat.c     Sat Aug 22 15:34:51 2020 +0000
+++ b/usr.bin/make/compat.c     Sat Aug 22 15:43:32 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat.c,v 1.123 2020/08/22 14:39:12 rillig Exp $      */
+/*     $NetBSD: compat.c,v 1.124 2020/08/22 15:43:32 rillig Exp $      */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: compat.c,v 1.123 2020/08/22 14:39:12 rillig Exp $";
+static char rcsid[] = "$NetBSD: compat.c,v 1.124 2020/08/22 15:43:32 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)compat.c   8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: compat.c,v 1.123 2020/08/22 14:39:12 rillig Exp $");
+__RCSID("$NetBSD: compat.c,v 1.124 2020/08/22 15:43:32 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -232,7 +232,7 @@
     errCheck = !(gn->type & OP_IGNORE);
     doIt = FALSE;
 
-    cmdNode = Lst_Member(gn->commands, cmd);
+    cmdNode = Lst_MemberS(gn->commands, cmd);
     cmdStart = Var_Subst(cmd, gn, VARE_WANTRES);
 
     /*
@@ -538,7 +538,7 @@
            goto cohorts;
        }
 
-       if (Lst_Member(gn->iParents, pgn) != NULL) {
+       if (Lst_MemberS(gn->iParents, pgn) != NULL) {
            char *p1;
            Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn);
            bmake_free(p1);
@@ -642,7 +642,7 @@
         */
        pgn->flags &= ~REMAKE;
     } else {
-       if (Lst_Member(gn->iParents, pgn) != NULL) {
+       if (Lst_MemberS(gn->iParents, pgn) != NULL) {
            char *p1;
            Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn);
            bmake_free(p1);
diff -r 72469fe8f0ce -r 2ec6122ad2a8 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Sat Aug 22 15:34:51 2020 +0000
+++ b/usr.bin/make/dir.c        Sat Aug 22 15:43:32 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.103 2020/08/22 15:17:09 rillig Exp $ */
+/*     $NetBSD: dir.c,v 1.104 2020/08/22 15:43:32 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: dir.c,v 1.103 2020/08/22 15:17:09 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.104 2020/08/22 15:43:32 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c      8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.103 2020/08/22 15:17:09 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.104 2020/08/22 15:43:32 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -417,7 +417,7 @@
        LstNode ln;
 
        /* Remove old entry from openDirectories, but do not destroy. */
-       ln = Lst_Member(openDirectories, dot);
+       ln = Lst_MemberS(openDirectories, dot);
        Lst_RemoveS(openDirectories, ln);
     }
 
@@ -1574,7 +1574,7 @@
        ln = Lst_Find(openDirectories, name, DirFindName);
     if (ln != NULL) {
        p = Lst_DatumS(ln);
-       if (path && Lst_Member(path, p) == NULL) {
+       if (path && Lst_MemberS(path, p) == NULL) {
            p->refCount += 1;
            Lst_AppendS(path, p);
        }
@@ -1702,7 +1702,7 @@
     if (p->refCount == 0) {
        LstNode ln;
 
-       ln = Lst_Member(openDirectories, p);
+       ln = Lst_MemberS(openDirectories, p);
        Lst_RemoveS(openDirectories, ln);
 
        Hash_DeleteTable(&p->files);
@@ -1764,7 +1764,7 @@
 
     for (ln = Lst_First(path2); ln != NULL; ln = Lst_Succ(ln)) {
        p = Lst_DatumS(ln);
-       if (Lst_Member(path1, p) == NULL) {
+       if (Lst_MemberS(path1, p) == NULL) {
            p->refCount += 1;
            Lst_AppendS(path1, p);
        }
diff -r 72469fe8f0ce -r 2ec6122ad2a8 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Sat Aug 22 15:34:51 2020 +0000
+++ b/usr.bin/make/job.c        Sat Aug 22 15:43:32 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.211 2020/08/22 13:28:20 rillig Exp $ */
+/*     $NetBSD: job.c,v 1.212 2020/08/22 15:43:32 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: job.c,v 1.211 2020/08/22 13:28:20 rillig Exp $";
+static char rcsid[] = "$NetBSD: job.c,v 1.212 2020/08/22 15:43:32 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)job.c      8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: job.c,v 1.211 2020/08/22 13:28:20 rillig Exp $");
+__RCSID("$NetBSD: job.c,v 1.212 2020/08/22 15:43:32 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -714,8 +714,8 @@
     if (strcmp(cmd, "...") == 0) {
        job->node->type |= OP_SAVE_CMDS;
        if ((job->flags & JOB_IGNDOTS) == 0) {
-           job->tailCmds = Lst_Succ(Lst_Member(job->node->commands,
-                                               cmd));
+           LstNode dotsNode = Lst_MemberS(job->node->commands, cmd);
+           job->tailCmds = Lst_Succ(dotsNode);
            return 1;
        }
        return 0;
diff -r 72469fe8f0ce -r 2ec6122ad2a8 usr.bin/make/lst.c
--- a/usr.bin/make/lst.c        Sat Aug 22 15:34:51 2020 +0000
+++ b/usr.bin/make/lst.c        Sat Aug 22 15:43:32 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.28 2020/08/22 15:17:09 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.29 2020/08/22 15:43:32 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -37,11 +37,11 @@
 #include "make.h"
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: lst.c,v 1.28 2020/08/22 15:17:09 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.29 2020/08/22 15:43:32 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.28 2020/08/22 15:17:09 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.29 2020/08/22 15:43:32 rillig Exp $");
 #endif /* not lint */
 #endif
 
@@ -519,24 +519,18 @@
 
 /* Return the first node that contains the given datum, or NULL. */
 LstNode
-Lst_Member(Lst list, void *datum)
+Lst_MemberS(Lst list, void *datum)
 {
     LstNode node;
 
-    if (list == NULL) {
-       return NULL;
-    }
-    node = list->first;
-    if (node == NULL) {
-       return NULL;
-    }
+    assert(LstIsValid(list));
+    assert(datum != NULL);
 
-    do {
+    for (node = list->first; node != NULL; node = node->next) {
        if (node->datum == datum) {
            return node;
        }
-       node = node->next;
-    } while (node != NULL && node != list->first);
+    }
 
     return NULL;
 }
diff -r 72469fe8f0ce -r 2ec6122ad2a8 usr.bin/make/lst.h
--- a/usr.bin/make/lst.h        Sat Aug 22 15:34:51 2020 +0000
+++ b/usr.bin/make/lst.h        Sat Aug 22 15:43:32 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lst.h,v 1.34 2020/08/22 15:17:09 rillig Exp $  */
+/*     $NetBSD: lst.h,v 1.35 2020/08/22 15:43:32 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -155,7 +155,7 @@
  * See if the given datum is on the list. Returns the LstNode containing
  * the datum
  */
-LstNode                Lst_Member(Lst, void *);
+LstNode                Lst_MemberS(Lst, void *);
 /* Apply a function to all elements of a lst */
 int            Lst_ForEach(Lst, int (*)(void *, void *), void *);
 /* Apply a function to all elements of a lst starting from a certain point. */
diff -r 72469fe8f0ce -r 2ec6122ad2a8 usr.bin/make/make.c
--- a/usr.bin/make/make.c       Sat Aug 22 15:34:51 2020 +0000
+++ b/usr.bin/make/make.c       Sat Aug 22 15:43:32 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.c,v 1.117 2020/08/22 15:17:09 rillig Exp $        */
+/*     $NetBSD: make.c,v 1.118 2020/08/22 15:43:32 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: make.c,v 1.117 2020/08/22 15:17:09 rillig Exp $";
+static char rcsid[] = "$NetBSD: make.c,v 1.118 2020/08/22 15:43:32 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.117 2020/08/22 15:17:09 rillig Exp $");
+__RCSID("$NetBSD: make.c,v 1.118 2020/08/22 15:43:32 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -525,7 +525,7 @@
      * children the parent has. This is used by Make_Run to decide
      * whether to queue the parent or examine its children...
      */
-    if ((ln = Lst_Member(pgn->children, cgn)) != NULL) {
+    if ((ln = Lst_MemberS(pgn->children, cgn)) != NULL) {
        Lst_RemoveS(pgn->children, ln);
        pgn->unmade--;
     }
diff -r 72469fe8f0ce -r 2ec6122ad2a8 usr.bin/make/suff.c
--- a/usr.bin/make/suff.c       Sat Aug 22 15:34:51 2020 +0000
+++ b/usr.bin/make/suff.c       Sat Aug 22 15:43:32 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: suff.c,v 1.106 2020/08/22 15:17:09 rillig Exp $        */
+/*     $NetBSD: suff.c,v 1.107 2020/08/22 15:43:32 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.106 2020/08/22 15:17:09 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.107 2020/08/22 15:43:32 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)suff.c     8.4 (Berkeley) 3/21/94";
 #else
-__RCSID("$NetBSD: suff.c,v 1.106 2020/08/22 15:17:09 rillig Exp $");
+__RCSID("$NetBSD: suff.c,v 1.107 2020/08/22 15:43:32 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -407,7 +407,7 @@
 {
     Lst l = (Lst) lp;
 
-    LstNode ln = Lst_Member(l, sp);
+    LstNode ln = Lst_MemberS(l, sp);
     if (ln != NULL) {
        Lst_RemoveS(l, ln);
        ((Suff *)sp)->refCount--;
@@ -1303,7 +1303,7 @@
                free(s->pref);
            else {
 #ifdef DEBUG_SRC
-               LstNode ln2 = Lst_Member(s->parent->cp, s);
+               LstNode ln2 = Lst_MemberS(s->parent->cp, s);
                if (ln2 != NULL)



Home | Main Index | Thread Index | Old Index