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): replace Lst_Duplicate with Lst_CopyS



details:   https://anonhg.NetBSD.org/src/rev/980771332754
branches:  trunk
changeset: 942969:980771332754
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Aug 22 22:57:53 2020 +0000

description:
make(1): replace Lst_Duplicate with Lst_CopyS

Lst_Duplicate would have passed through any null pointer, which was not
needed for make.  It was the last function that used Lst_AtEnd, which in
turn was the last function that used LstInsertAfter.  As a result, these
two functions have been removed.

diffstat:

 usr.bin/make/dir.c  |  12 ++-----
 usr.bin/make/lst.c  |  77 ++++++----------------------------------------------
 usr.bin/make/lst.h  |   4 +-
 usr.bin/make/make.c |   8 ++--
 usr.bin/make/suff.c |   8 ++--
 5 files changed, 23 insertions(+), 86 deletions(-)

diffs (261 lines):

diff -r 5c7993735cb9 -r 980771332754 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Sat Aug 22 22:41:42 2020 +0000
+++ b/usr.bin/make/dir.c        Sat Aug 22 22:57:53 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.107 2020/08/22 19:57:43 rillig Exp $ */
+/*     $NetBSD: dir.c,v 1.108 2020/08/22 22:57:53 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.107 2020/08/22 19:57:43 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.108 2020/08/22 22:57:53 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.107 2020/08/22 19:57:43 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.108 2020/08/22 22:57:53 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1613,15 +1613,11 @@
 /*-
  *-----------------------------------------------------------------------
  * Dir_CopyDir --
- *     Callback function for duplicating a search path via Lst_Duplicate.
+ *     Callback function for duplicating a search path via Lst_CopyS.
  *     Ups the reference count for the directory.
  *
  * Results:
  *     Returns the Path it was given.
- *
- * Side Effects:
- *     The refCount of the path is incremented.
- *
  *-----------------------------------------------------------------------
  */
 void *
diff -r 5c7993735cb9 -r 980771332754 usr.bin/make/lst.c
--- a/usr.bin/make/lst.c        Sat Aug 22 22:41:42 2020 +0000
+++ b/usr.bin/make/lst.c        Sat Aug 22 22:57:53 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.34 2020/08/22 22:41:42 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.35 2020/08/22 22:57:53 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.34 2020/08/22 22:41:42 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.35 2020/08/22 22:57:53 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.34 2020/08/22 22:41:42 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.35 2020/08/22 22:57:53 rillig Exp $");
 #endif /* not lint */
 #endif
 
@@ -71,8 +71,6 @@
     LstNode prev;              /* Previous node, if open. Used by Lst_Remove */
 };
 
-static ReturnStatus Lst_AtEnd(Lst, void *);
-
 static Boolean
 LstIsValid(Lst list)
 {
@@ -121,31 +119,20 @@
 
 /* Duplicate an entire list, usually by copying the datum pointers.
  * If copyProc is given, that function is used to create the new datum from the
- * old datum, usually by creating a copy of it.
- * Return the new list, or NULL on failure. */
+ * old datum, usually by creating a copy of it. */
 Lst
-Lst_Duplicate(Lst list, DuplicateProc *copyProc)
+Lst_CopyS(Lst list, DuplicateProc *copyProc)
 {
     Lst newList;
     LstNode node;
 
-    if (!LstIsValid(list)) {
-       return NULL;
-    }
+    assert(LstIsValid(list));
 
     newList = Lst_Init();
 
-    node = list->first;
-    while (node != NULL) {
-       if (copyProc != NULL) {
-           if (Lst_AtEnd(newList, copyProc(node->datum)) == FAILURE) {
-               return NULL;
-           }
-       } else if (Lst_AtEnd(newList, node->datum) == FAILURE) {
-           return NULL;
-       }
-
-       node = node->next;
+    for (node = list->first; node != NULL; node = node->next) {
+       void *datum = copyProc != NULL ? copyProc(node->datum) : node->datum;
+       Lst_AppendS(newList, datum);
     }
 
     return newList;
@@ -256,44 +243,6 @@
     }
 }
 
-/* Insert a new node with the given piece of data after the given node in the
- * given list. */
-static ReturnStatus
-LstInsertAfter(Lst list, LstNode node, void *datum)
-{
-    LstNode newNode;
-
-    if (LstIsValid(list) && (node == NULL && LstIsEmpty(list))) {
-       goto ok;
-    }
-
-    if (!LstIsValid(list) || LstIsEmpty(list) || !LstNodeIsValid(node)) {
-       return FAILURE;
-    }
-    ok:
-
-    newNode = LstNodeNew(datum);
-
-    if (node == NULL) {
-       newNode->next = newNode->prev = NULL;
-       list->first = list->last = newNode;
-    } else {
-       newNode->prev = node;
-       newNode->next = node->next;
-
-       node->next = newNode;
-       if (newNode->next != NULL) {
-           newNode->next->prev = newNode;
-       }
-
-       if (node == list->last) {
-           list->last = newNode;
-       }
-    }
-
-    return SUCCESS;
-}
-
 /* Add a piece of data at the front of the given list. */
 ReturnStatus
 Lst_AtFront(Lst list, void *datum)
@@ -302,14 +251,6 @@
     return LstInsertBefore(list, front, datum);
 }
 
-/* Add a piece of data at the end of the given list. */
-ReturnStatus
-Lst_AtEnd(Lst list, void *datum)
-{
-    LstNode end = Lst_Last(list);
-    return LstInsertAfter(list, end, datum);
-}
-
 /* Add a piece of data at the start of the given list. */
 void
 Lst_PrependS(Lst list, void *datum)
diff -r 5c7993735cb9 -r 980771332754 usr.bin/make/lst.h
--- a/usr.bin/make/lst.h        Sat Aug 22 22:41:42 2020 +0000
+++ b/usr.bin/make/lst.h        Sat Aug 22 22:57:53 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lst.h,v 1.37 2020/08/22 22:41:42 rillig Exp $  */
+/*     $NetBSD: lst.h,v 1.38 2020/08/22 22:57:53 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -101,7 +101,7 @@
 /* Create a new list */
 Lst            Lst_Init(void);
 /* Duplicate an existing list */
-Lst            Lst_Duplicate(Lst, DuplicateProc *);
+Lst            Lst_CopyS(Lst, DuplicateProc *);
 /* Destroy an old one */
 void           Lst_Destroy(Lst, FreeProc *);
 /* True if list is empty */
diff -r 5c7993735cb9 -r 980771332754 usr.bin/make/make.c
--- a/usr.bin/make/make.c       Sat Aug 22 22:41:42 2020 +0000
+++ b/usr.bin/make/make.c       Sat Aug 22 22:57:53 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.c,v 1.120 2020/08/22 22:41:42 rillig Exp $        */
+/*     $NetBSD: make.c,v 1.121 2020/08/22 22:57:53 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: make.c,v 1.120 2020/08/22 22:41:42 rillig Exp $";
+static char rcsid[] = "$NetBSD: make.c,v 1.121 2020/08/22 22:57:53 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.120 2020/08/22 22:41:42 rillig Exp $");
+__RCSID("$NetBSD: make.c,v 1.121 2020/08/22 22:57:53 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1258,7 +1258,7 @@
     GNode  *gn;                /* a temporary pointer */
     Lst    examine;    /* List of targets to examine */
 
-    examine = Lst_Duplicate(targs, NULL);
+    examine = Lst_CopyS(targs, NULL);
 
     /*
      * Make an initial downward pass over the graph, marking nodes to be made
diff -r 5c7993735cb9 -r 980771332754 usr.bin/make/suff.c
--- a/usr.bin/make/suff.c       Sat Aug 22 22:41:42 2020 +0000
+++ b/usr.bin/make/suff.c       Sat Aug 22 22:57:53 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: suff.c,v 1.111 2020/08/22 22:41:42 rillig Exp $        */
+/*     $NetBSD: suff.c,v 1.112 2020/08/22 22:57:53 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.111 2020/08/22 22:41:42 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.112 2020/08/22 22:57:53 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.111 2020/08/22 22:41:42 rillig Exp $");
+__RCSID("$NetBSD: suff.c,v 1.112 2020/08/22 22:57:53 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1085,7 +1085,7 @@
            Dir_Concat(s->searchPath, dirSearchPath);
        } else {
            Lst_Destroy(s->searchPath, Dir_Destroy);
-           s->searchPath = Lst_Duplicate(dirSearchPath, Dir_CopyDir);
+           s->searchPath = Lst_CopyS(dirSearchPath, Dir_CopyDir);
        }
     }
     Lst_CloseS(sufflist);



Home | Main Index | Thread Index | Old Index