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): convert Lst_Enqueue and Lst_Dequeue to...



details:   https://anonhg.NetBSD.org/src/rev/38e062cf3452
branches:  trunk
changeset: 975146:38e062cf3452
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Aug 22 14:39:12 2020 +0000

description:
make(1): convert Lst_Enqueue and Lst_Dequeue to nonnull variants

Except for once instance in parse.c, the usage pattern for Lst_Dequeue
was to first test whether the list is empty.  This pattern allowed the
implementation of Lst_Dequeue to become simpler since the null check is
not needed anymore.

The calls to Lst_Enqueue never pass an invalid list or a null pointer,
therefore making them strict was trivial.

diffstat:

 usr.bin/make/arch.c   |   9 ++++-----
 usr.bin/make/compat.c |  10 +++++-----
 usr.bin/make/dir.c    |   9 ++++-----
 usr.bin/make/lst.c    |  33 +++++++++++++--------------------
 usr.bin/make/lst.h    |   6 +++---
 usr.bin/make/make.c   |  22 +++++++++++-----------
 usr.bin/make/parse.c  |  18 +++++++++---------
 usr.bin/make/suff.c   |  12 ++++++------
 8 files changed, 55 insertions(+), 64 deletions(-)

diffs (truncated from 400 to 300 lines):

diff -r 8a29d4df312b -r 38e062cf3452 usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Sat Aug 22 14:04:22 2020 +0000
+++ b/usr.bin/make/arch.c       Sat Aug 22 14:39:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.87 2020/08/22 11:35:00 rillig Exp $ */
+/*     $NetBSD: arch.c,v 1.88 2020/08/22 14:39:12 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: arch.c,v 1.87 2020/08/22 11:35:00 rillig Exp $";
+static char rcsid[] = "$NetBSD: arch.c,v 1.88 2020/08/22 14:39:12 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.87 2020/08/22 11:35:00 rillig Exp $");
+__RCSID("$NetBSD: arch.c,v 1.88 2020/08/22 14:39:12 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -393,13 +393,12 @@
            free(buf);
        } else if (Dir_HasWildcards(memName)) {
            Lst   members = Lst_Init();
-           char  *member;
            size_t sz = MAXPATHLEN, nsz;
            nameBuf = bmake_malloc(sz);
 
            Dir_Expand(memName, dirSearchPath, members);
            while (!Lst_IsEmpty(members)) {
-               member = (char *)Lst_DeQueue(members);
+               char *member = Lst_DequeueS(members);
                nsz = strlen(libName) + strlen(member) + 3;
                if (sz > nsz)
                    nameBuf = bmake_realloc(nameBuf, sz = nsz * 2);
diff -r 8a29d4df312b -r 38e062cf3452 usr.bin/make/compat.c
--- a/usr.bin/make/compat.c     Sat Aug 22 14:04:22 2020 +0000
+++ b/usr.bin/make/compat.c     Sat Aug 22 14:39:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat.c,v 1.122 2020/08/22 11:35:00 rillig Exp $      */
+/*     $NetBSD: compat.c,v 1.123 2020/08/22 14:39:12 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.122 2020/08/22 11:35:00 rillig Exp $";
+static char rcsid[] = "$NetBSD: compat.c,v 1.123 2020/08/22 14:39:12 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.122 2020/08/22 11:35:00 rillig Exp $");
+__RCSID("$NetBSD: compat.c,v 1.123 2020/08/22 14:39:12 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -746,8 +746,8 @@
      *                     could not be made due to errors.
      */
     errors = 0;
-    while (!Lst_IsEmpty (targs)) {
-       gn = (GNode *)Lst_DeQueue(targs);
+    while (!Lst_IsEmpty(targs)) {
+       gn = Lst_DequeueS(targs);
        Compat_Make(gn, gn);
 
        if (gn->made == UPTODATE) {
diff -r 8a29d4df312b -r 38e062cf3452 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Sat Aug 22 14:04:22 2020 +0000
+++ b/usr.bin/make/dir.c        Sat Aug 22 14:39:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.101 2020/08/22 14:04:22 rillig Exp $ */
+/*     $NetBSD: dir.c,v 1.102 2020/08/22 14:39:12 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.101 2020/08/22 14:04:22 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.102 2020/08/22 14:39:12 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.101 2020/08/22 14:04:22 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.102 2020/08/22 14:39:12 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1732,9 +1732,8 @@
 void
 Dir_ClearPath(Lst path)
 {
-    Path *p;
     while (!Lst_IsEmpty(path)) {
-       p = (Path *)Lst_DeQueue(path);
+       Path *p = Lst_DequeueS(path);
        Dir_Destroy(p);
     }
 }
diff -r 8a29d4df312b -r 38e062cf3452 usr.bin/make/lst.c
--- a/usr.bin/make/lst.c        Sat Aug 22 14:04:22 2020 +0000
+++ b/usr.bin/make/lst.c        Sat Aug 22 14:39:12 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.24 2020/08/22 13:49:40 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.25 2020/08/22 14:39:12 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.24 2020/08/22 13:49:40 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.25 2020/08/22 14:39:12 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.24 2020/08/22 13:49:40 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.25 2020/08/22 14:39:12 rillig Exp $");
 #endif /* not lint */
 #endif
 
@@ -786,30 +786,23 @@
  */
 
 /* Add the datum to the tail of the given list. */
-ReturnStatus
-Lst_EnQueue(Lst list, void *datum)
+void
+Lst_EnqueueS(Lst list, void *datum)
 {
-    if (!LstIsValid(list)) {
-       return FAILURE;
-    }
-
-    return Lst_InsertAfter(list, Lst_Last(list), datum);
+    Lst_AppendS(list, datum);
 }
 
-/* Remove and return the datum at the head of the given list, or NULL if the
- * list is empty. */
+/* Remove and return the datum at the head of the given list. */
 void *
-Lst_DeQueue(Lst list)
+Lst_DequeueS(Lst list)
 {
-    LstNode head;
     void *datum;
 
-    head = Lst_First(list);
-    if (head == NULL) {
-       return NULL;
-    }
+    assert(LstIsValid(list));
+    assert(!LstIsEmpty(list));
 
-    datum = head->datum;
-    Lst_RemoveS(list, head);
+    datum = list->first->datum;
+    Lst_RemoveS(list, list->first);
+    assert(datum != NULL);
     return datum;
 }
diff -r 8a29d4df312b -r 38e062cf3452 usr.bin/make/lst.h
--- a/usr.bin/make/lst.h        Sat Aug 22 14:04:22 2020 +0000
+++ b/usr.bin/make/lst.h        Sat Aug 22 14:39:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lst.h,v 1.30 2020/08/22 13:28:20 rillig Exp $  */
+/*     $NetBSD: lst.h,v 1.31 2020/08/22 14:39:12 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -180,8 +180,8 @@
  * for using the list as a queue
  */
 /* Place an element at tail of queue */
-ReturnStatus   Lst_EnQueue(Lst, void *);
+void           Lst_EnqueueS(Lst, void *);
 /* Remove an element from head of queue */
-void           *Lst_DeQueue(Lst);
+void           *Lst_DequeueS(Lst);
 
 #endif /* MAKE_LST_H */
diff -r 8a29d4df312b -r 38e062cf3452 usr.bin/make/make.c
--- a/usr.bin/make/make.c       Sat Aug 22 14:04:22 2020 +0000
+++ b/usr.bin/make/make.c       Sat Aug 22 14:39:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.c,v 1.114 2020/08/22 13:44:17 rillig Exp $        */
+/*     $NetBSD: make.c,v 1.115 2020/08/22 14:39:12 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: make.c,v 1.114 2020/08/22 13:44:17 rillig Exp $";
+static char rcsid[] = "$NetBSD: make.c,v 1.115 2020/08/22 14:39:12 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.114 2020/08/22 13:44:17 rillig Exp $");
+__RCSID("$NetBSD: make.c,v 1.115 2020/08/22 14:39:12 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -378,7 +378,7 @@
        if (DEBUG(MAKE))
            fprintf(debug_file, "MakeAddChild: need to examine %s%s\n",
                gn->name, gn->cohort_num);
-       (void)Lst_EnQueue(l, gn);
+       Lst_EnqueueS(l, gn);
     }
     return 0;
 }
@@ -794,7 +794,7 @@
            }
            /* Ok, we can schedule the parent again */
            pgn->made = REQUESTED;
-           (void)Lst_EnQueue(toBeMade, pgn);
+           Lst_EnqueueS(toBeMade, pgn);
        }
        Lst_CloseS(parents);
     }
@@ -1050,13 +1050,13 @@
     GNode      *gn;
     int                have_token = 0;
 
-    while (!Lst_IsEmpty (toBeMade)) {
+    while (!Lst_IsEmpty(toBeMade)) {
        /* Get token now to avoid cycling job-list when we only have 1 token */
        if (!have_token && !Job_TokenWithdraw())
            break;
        have_token = 1;
 
-       gn = (GNode *)Lst_DeQueue(toBeMade);
+       gn = Lst_DequeueS(toBeMade);
        if (DEBUG(MAKE))
            fprintf(debug_file, "Examining %s%s...\n",
                    gn->name, gn->cohort_num);
@@ -1269,8 +1269,8 @@
      * be looked at in a minute, otherwise we add its children to our queue
      * and go on about our business.
      */
-    while (!Lst_IsEmpty (examine)) {
-       gn = (GNode *)Lst_DeQueue(examine);
+    while (!Lst_IsEmpty(examine)) {
+       gn = Lst_DequeueS(examine);
 
        if (gn->flags & REMAKE)
            /* We've looked at this one already */
@@ -1405,8 +1405,8 @@
     examine = Lst_Init();
     Lst_AppendS(examine, pgn);
 
-    while (!Lst_IsEmpty (examine)) {
-       pgn = Lst_DeQueue(examine);
+    while (!Lst_IsEmpty(examine)) {
+       pgn = Lst_DequeueS(examine);
 
        /* We only want to process each child-list once */
        if (pgn->flags & DONE_WAIT)
diff -r 8a29d4df312b -r 38e062cf3452 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sat Aug 22 14:04:22 2020 +0000
+++ b/usr.bin/make/parse.c      Sat Aug 22 14:39:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.255 2020/08/22 13:44:17 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.256 2020/08/22 14:39:12 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.255 2020/08/22 13:44:17 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.256 2020/08/22 14:39:12 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0



Home | Main Index | Thread Index | Old Index