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): use stricter list API for sequential a...



details:   https://anonhg.NetBSD.org/src/rev/a484761ed202
branches:  trunk
changeset: 937548:a484761ed202
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Aug 21 04:42:02 2020 +0000

description:
make(1): use stricter list API for sequential access

In several places, it just doesn't make sense to have a null pointer
when a list is expected.

In the existing unit tests, the list passed to Lst_Open is always valid,
but that's not a guarantee for real-world usage.  Therefore, Lst_Open
has been left for now, and Lst_OpenS is only the preferred alternative
to it.

diffstat:

 usr.bin/make/arch.c |   8 +++---
 usr.bin/make/dir.c  |  34 ++++++++++++++--------------
 usr.bin/make/lst.c  |  62 ++++++++++++++++++++--------------------------------
 usr.bin/make/lst.h  |   5 ++-
 usr.bin/make/make.c |  16 ++++++------
 usr.bin/make/suff.c |  32 +++++++++++----------------
 usr.bin/make/targ.c |  12 ++++-----
 7 files changed, 74 insertions(+), 95 deletions(-)

diffs (truncated from 535 to 300 lines):

diff -r 1261a6ef518e -r a484761ed202 usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Fri Aug 21 04:09:12 2020 +0000
+++ b/usr.bin/make/arch.c       Fri Aug 21 04:42:02 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.85 2020/08/21 04:09:12 rillig Exp $ */
+/*     $NetBSD: arch.c,v 1.86 2020/08/21 04:42:02 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: arch.c,v 1.85 2020/08/21 04:09:12 rillig Exp $";
+static char rcsid[] = "$NetBSD: arch.c,v 1.86 2020/08/21 04:42:02 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)arch.c     8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: arch.c,v 1.85 2020/08/21 04:09:12 rillig Exp $");
+__RCSID("$NetBSD: arch.c,v 1.86 2020/08/21 04:42:02 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1158,7 +1158,7 @@
        }
     }
 
-    Lst_Close(gn->parents);
+    Lst_CloseS(gn->parents);
 
     return gn->mtime;
 }
diff -r 1261a6ef518e -r a484761ed202 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Fri Aug 21 04:09:12 2020 +0000
+++ b/usr.bin/make/dir.c        Fri Aug 21 04:42:02 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.95 2020/08/21 04:09:12 rillig Exp $  */
+/*     $NetBSD: dir.c,v 1.96 2020/08/21 04:42:02 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.95 2020/08/21 04:09:12 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.96 2020/08/21 04:42:02 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.95 2020/08/21 04:09:12 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.96 2020/08/21 04:42:02 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -524,7 +524,7 @@
            if (cur)
                Var_Append(".PATH", cur->name, VAR_GLOBAL);
        }
-       Lst_Close(dirSearchPath);
+       Lst_CloseS(dirSearchPath);
     }
 }
 
@@ -817,7 +817,7 @@
            p = (Path *)Lst_Datum(ln);
            DirMatchFiles(word, p, expansions);
        }
-       Lst_Close(path);
+       Lst_CloseS(path);
     }
 }
 
@@ -1181,7 +1181,7 @@
         * specifies (fish.c) and what pmake finds (./fish.c).
         */
        if (!hasLastDot && (file = DirFindDot(hasSlash, name, cp)) != NULL) {
-           Lst_Close(path);
+           Lst_CloseS(path);
            return file;
        }
 
@@ -1190,17 +1190,17 @@
            if (p == dotLast)
                continue;
            if ((file = DirLookup(p, name, cp, hasSlash)) != NULL) {
-               Lst_Close(path);
+               Lst_CloseS(path);
                return file;
            }
        }
 
        if (hasLastDot && (file = DirFindDot(hasSlash, name, cp)) != NULL) {
-           Lst_Close(path);
+           Lst_CloseS(path);
            return file;
        }
     }
-    Lst_Close(path);
+    Lst_CloseS(path);
 
     /*
      * We didn't find the file on any directory in the search path.
@@ -1242,7 +1242,7 @@
                return file;
        }
 
-       (void)Lst_Open(path);
+       Lst_OpenS(path);
        while ((ln = Lst_NextS(path)) != NULL) {
            p = (Path *)Lst_Datum(ln);
            if (p == dotLast)
@@ -1253,11 +1253,11 @@
                checkedDot = TRUE;
            }
            if ((file = DirLookupSubdir(p, name)) != NULL) {
-               Lst_Close(path);
+               Lst_CloseS(path);
                return file;
            }
        }
-       Lst_Close(path);
+       Lst_CloseS(path);
 
        if (hasLastDot) {
            if (dot && !checkedDot) {
@@ -1300,13 +1300,13 @@
            return file;
        }
 
-       (void)Lst_Open(path);
+       Lst_OpenS(path);
        while ((ln = Lst_NextS(path)) != NULL) {
            p = (Path *)Lst_Datum(ln);
            if (p == dotLast)
                continue;
            if ((file = DirLookupAbs(p, name, cp)) != NULL) {
-               Lst_Close(path);
+               Lst_CloseS(path);
                if (file[0] == '\0') {
                    free(file);
                    return NULL;
@@ -1314,7 +1314,7 @@
                return file;
            }
        }
-       Lst_Close(path);
+       Lst_CloseS(path);
 
        if (hasLastDot && cur &&
            ((file = DirLookupAbs(cur, name, cp)) != NULL)) {
@@ -1685,7 +1685,7 @@
            Buf_AddStr(&buf, flag);
            Buf_AddStr(&buf, p->name);
        }
-       Lst_Close(path);
+       Lst_CloseS(path);
     }
 
     return Buf_Destroy(&buf, FALSE);
@@ -1808,7 +1808,7 @@
            fprintf(debug_file, "# %-20s %10d\t%4d\n", p->name, p->refCount,
                    p->hits);
        }
-       Lst_Close(openDirectories);
+       Lst_CloseS(openDirectories);
     }
 }
 
diff -r 1261a6ef518e -r a484761ed202 usr.bin/make/lst.c
--- a/usr.bin/make/lst.c        Fri Aug 21 04:09:12 2020 +0000
+++ b/usr.bin/make/lst.c        Fri Aug 21 04:42:02 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.9 2020/08/21 04:09:12 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.10 2020/08/21 04:42:02 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -38,11 +38,11 @@
 #include "make_malloc.h"
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: lst.c,v 1.9 2020/08/21 04:09:12 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.10 2020/08/21 04:42:02 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.9 2020/08/21 04:09:12 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.10 2020/08/21 04:42:02 rillig Exp $");
 #endif /* not lint */
 #endif
 
@@ -907,20 +907,21 @@
     return SUCCESS;
 }
 
-/*-
- *-----------------------------------------------------------------------
- * Lst_Next --
- *     Return the next node for the given list.
- *
- * Results:
- *     The next node or NULL if the list has yet to be opened. Also
- *     if the end has been reached, NULL is returned.
- *
- * Side Effects:
- *     the curPtr field is updated.
- *
- *-----------------------------------------------------------------------
- */
+/* Open a list for sequential access. A list can still be searched, etc.,
+ * without confusing these functions. */
+void
+Lst_OpenS(Lst l)
+{
+    assert(LstValid(l));
+    assert(!l->isOpen);
+
+    l->isOpen = TRUE;
+    l->atEnd = LstIsEmpty(l) ? Head : Unknown;
+    l->curPtr = NULL;
+}
+
+/* Return the next node for the given list, or NULL if the end has been
+ * reached. */
 LstNode
 Lst_NextS(Lst l)
 {
@@ -965,31 +966,16 @@
     return tln;
 }
 
-/*-
- *-----------------------------------------------------------------------
- * Lst_Close --
- *     Close a list which was opened for sequential access.
- *
- * Input:
- *     l               The list to close
- *
- * Results:
- *     None.
- *
- * Side Effects:
- *     The list is closed.
- *
- *-----------------------------------------------------------------------
- */
+/* Close a list which was opened for sequential access. */
 void
-Lst_Close(Lst l)
+Lst_CloseS(Lst l)
 {
     List list = l;
 
-    if (LstValid(l) == TRUE) {
-       list->isOpen = FALSE;
-       list->atEnd = Unknown;
-    }
+    assert(LstValid(l));
+    assert(list->isOpen);
+    list->isOpen = FALSE;
+    list->atEnd = Unknown;
 }
 
 
diff -r 1261a6ef518e -r a484761ed202 usr.bin/make/lst.h
--- a/usr.bin/make/lst.h        Fri Aug 21 04:09:12 2020 +0000
+++ b/usr.bin/make/lst.h        Fri Aug 21 04:42:02 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lst.h,v 1.25 2020/08/21 04:09:12 rillig Exp $  */
+/*     $NetBSD: lst.h,v 1.26 2020/08/21 04:42:02 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -167,10 +167,11 @@
  */
 /* Open the list */
 ReturnStatus   Lst_Open(Lst);
+void           Lst_OpenS(Lst);
 /* Next element please, or NULL */
 LstNode                Lst_NextS(Lst);
 /* Finish table access */
-void           Lst_Close(Lst);
+void           Lst_CloseS(Lst);
 
 /*
  * for using the list as a queue
diff -r 1261a6ef518e -r a484761ed202 usr.bin/make/make.c
--- a/usr.bin/make/make.c       Fri Aug 21 04:09:12 2020 +0000
+++ b/usr.bin/make/make.c       Fri Aug 21 04:42:02 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.c,v 1.106 2020/08/21 04:09:12 rillig Exp $        */
+/*     $NetBSD: make.c,v 1.107 2020/08/21 04:42:02 rillig Exp $        */



Home | Main Index | Thread Index | Old Index