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): add stricter variants for remaining Ls...



details:   https://anonhg.NetBSD.org/src/rev/c3188e10d3d5
branches:  trunk
changeset: 975316:c3188e10d3d5
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Aug 26 22:55:46 2020 +0000

description:
make(1): add stricter variants for remaining Lst functions

In most cases the Lst functions are only called when the arguments are
indeed valid.  It's not guaranteed though, therefore each function call
needs to be analyzed and converted individually.

While here, remove a few statements that were only useful when the Lst
functions handled circular lists.

diffstat:

 usr.bin/make/arch.c  |   42 ++----------
 usr.bin/make/dir.c   |   12 +-
 usr.bin/make/lst.c   |  159 ++++++++++++++++++++++++++++++++++++++------------
 usr.bin/make/lst.h   |   14 +++-
 usr.bin/make/main.c  |   16 ++--
 usr.bin/make/make.c  |   12 +-
 usr.bin/make/meta.c  |   10 +-
 usr.bin/make/parse.c |   46 +++++++-------
 usr.bin/make/suff.c  |   75 +++++++++++------------
 usr.bin/make/targ.c  |   26 ++++----
 10 files changed, 239 insertions(+), 173 deletions(-)

diffs (truncated from 1060 to 300 lines):

diff -r f254ebf4aa60 -r c3188e10d3d5 usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Wed Aug 26 22:54:30 2020 +0000
+++ b/usr.bin/make/arch.c       Wed Aug 26 22:55:46 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.96 2020/08/23 18:59:01 rillig Exp $ */
+/*     $NetBSD: arch.c,v 1.97 2020/08/26 22:55:46 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: arch.c,v 1.96 2020/08/23 18:59:01 rillig Exp $";
+static char rcsid[] = "$NetBSD: arch.c,v 1.97 2020/08/26 22:55:46 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.96 2020/08/23 18:59:01 rillig Exp $");
+__RCSID("$NetBSD: arch.c,v 1.97 2020/08/26 22:55:46 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -391,7 +391,7 @@
             */
            free(buf);
        } else if (Dir_HasWildcards(memName)) {
-           Lst   members = Lst_Init();
+           Lst members = Lst_Init();
            Buffer nameBuf;
 
            Buf_Init(&nameBuf, 0);
@@ -422,7 +422,7 @@
                    Lst_AppendS(nodeLst, gn);
                }
            }
-           Lst_Destroy(members, NULL);
+           Lst_FreeS(members);
            Buf_Destroy(&nameBuf, TRUE);
        } else {
            Buffer nameBuf;
@@ -1288,45 +1288,19 @@
     return oodate;
 }
 
-/*-
- *-----------------------------------------------------------------------
- * Arch_Init --
- *     Initialize things for this module.
- *
- * Results:
- *     None.
- *
- * Side Effects:
- *     The 'archives' list is initialized.
- *
- *-----------------------------------------------------------------------
- */
+/* Initialize things for this module. */
 void
 Arch_Init(void)
 {
     archives = Lst_Init();
 }
 
-
-
-/*-
- *-----------------------------------------------------------------------
- * Arch_End --
- *     Cleanup things for this module.
- *
- * Results:
- *     None.
- *
- * Side Effects:
- *     The 'archives' list is freed
- *
- *-----------------------------------------------------------------------
- */
+/* Clean up things for this module. */
 void
 Arch_End(void)
 {
 #ifdef CLEANUP
-    Lst_Destroy(archives, ArchFree);
+    Lst_DestroyS(archives, ArchFree);
 #endif
 }
 
diff -r f254ebf4aa60 -r c3188e10d3d5 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Wed Aug 26 22:54:30 2020 +0000
+++ b/usr.bin/make/dir.c        Wed Aug 26 22:55:46 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.110 2020/08/23 16:58:02 rillig Exp $ */
+/*     $NetBSD: dir.c,v 1.111 2020/08/26 22:55:46 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.110 2020/08/23 16:58:02 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.111 2020/08/26 22:55:46 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.110 2020/08/23 16:58:02 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.111 2020/08/26 22:55:46 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -461,9 +461,9 @@
     Dir_Destroy(dotLast);
     Dir_Destroy(dot);
     Dir_ClearPath(dirSearchPath);
-    Lst_Destroy(dirSearchPath, NULL);
+    Lst_FreeS(dirSearchPath);
     Dir_ClearPath(openDirectories);
-    Lst_Destroy(openDirectories, NULL);
+    Lst_FreeS(openDirectories);
     Hash_DeleteTable(&mtimes);
 #endif
 }
@@ -895,7 +895,7 @@
                        path = Lst_Init();
                        (void)Dir_AddDir(path, dirpath);
                        DirExpandInt(cp + 1, path, expansions);
-                       Lst_Destroy(path, NULL);
+                       Lst_FreeS(path);
                    }
                } else {
                    /*
diff -r f254ebf4aa60 -r c3188e10d3d5 usr.bin/make/lst.c
--- a/usr.bin/make/lst.c        Wed Aug 26 22:54:30 2020 +0000
+++ b/usr.bin/make/lst.c        Wed Aug 26 22:55:46 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.41 2020/08/23 16:58:02 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.42 2020/08/26 22:55:46 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.41 2020/08/23 16:58:02 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.42 2020/08/26 22:55:46 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.41 2020/08/23 16:58:02 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.42 2020/08/26 22:55:46 rillig Exp $");
 #endif /* not lint */
 #endif
 
@@ -142,36 +142,38 @@
     return newList;
 }
 
+/* Free a list and all its nodes. The list data itself are not freed though. */
+void
+Lst_FreeS(Lst list)
+{
+    LstNode node;
+    LstNode next;
+
+    assert(LstIsValid(list));
+
+    for (node = list->first; node != NULL; node = next) {
+       next = node->next;
+       free(node);
+    }
+
+    free(list);
+}
+
 /* Destroy a list and free all its resources. If the freeProc is given, it is
  * called with the datum from each node in turn before the node is freed. */
 void
-Lst_Destroy(Lst list, LstFreeProc freeProc)
+Lst_DestroyS(Lst list, LstFreeProc freeProc)
 {
     LstNode node;
-    LstNode next = NULL;
+    LstNode next;
 
-    if (list == NULL)
-       return;
+    assert(LstIsValid(list));
+    assert(freeProc != NULL);
 
-    /* To ease scanning */
-    if (list->last != NULL)
-       list->last->next = NULL;
-    else {
-       free(list);
-       return;
-    }
-
-    if (freeProc) {
-       for (node = list->first; node != NULL; node = next) {
-           next = node->next;
-           freeProc(node->datum);
-           free(node);
-       }
-    } else {
-       for (node = list->first; node != NULL; node = next) {
-           next = node->next;
-           free(node);
-       }
+    for (node = list->first; node != NULL; node = next) {
+       next = node->next;
+       freeProc(node->datum);
+       free(node);
     }
 
     free(list);
@@ -340,6 +342,15 @@
     }
 }
 
+/* Return the first node from the given list, or NULL if the list is empty. */
+LstNode
+Lst_FirstS(Lst list)
+{
+    assert(LstIsValid(list));
+
+    return list->first;
+}
+
 /* Return the last node from the given list, or NULL if the list is empty or
  * invalid. */
 LstNode
@@ -352,6 +363,15 @@
     }
 }
 
+/* Return the last node from the given list, or NULL if the list is empty. */
+LstNode
+Lst_LastS(Lst list)
+{
+    assert(LstIsValid(list));
+
+    return list->last;
+}
+
 /* Return the successor to the given node on its list, or NULL. */
 LstNode
 Lst_Succ(LstNode node)
@@ -363,6 +383,15 @@
     }
 }
 
+/* Return the successor to the given node on its list, or NULL. */
+LstNode
+Lst_SuccS(LstNode node)
+{
+    assert(LstNodeIsValid(node));
+
+    return node->next;
+}
+
 /* Return the predecessor to the given node on its list, or NULL. */
 LstNode
 Lst_PrevS(LstNode node)
@@ -391,6 +420,15 @@
     return !LstIsValid(list) || LstIsEmpty(list);
 }
 
+/* Return TRUE if the given list is empty. */
+Boolean
+Lst_IsEmptyS(Lst list)
+{
+    assert(LstIsValid(list));
+
+    return LstIsEmpty(list);
+}
+
 /* Return the first node from the given list for which the given comparison
  * function returns 0, or NULL if none of the nodes matches. */
 LstNode
@@ -399,27 +437,45 @@
     return Lst_FindFrom(list, Lst_First(list), cmp, cmpData);
 }
 
+/* Return the first node from the given list for which the given comparison
+ * function returns 0, or NULL if none of the nodes matches. */
+LstNode
+Lst_FindS(Lst list, LstFindProc cmp, const void *cmpData)
+{
+    if (LstIsEmpty(list))
+       return NULL;



Home | Main Index | Thread Index | Old Index