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 Dir_Destroy with SearchPath_Free



details:   https://anonhg.NetBSD.org/src/rev/81119699f6dc
branches:  trunk
changeset: 957446:81119699f6dc
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Nov 28 22:56:01 2020 +0000

description:
make(1): replace Dir_Destroy with SearchPath_Free

The function Dir_Destroy is an implementation detail of the cached
directories, and it should not be exported to the other modules.  The
search paths, on the other hand, are the high-level API that may be used
by the other modules, as the concept of search paths is documented in
the manual page.

diffstat:

 usr.bin/make/dir.c     |  29 +++++++++++++++++++++++------
 usr.bin/make/dir.h     |   4 ++--
 usr.bin/make/nonints.h |  10 +++++++++-
 usr.bin/make/parse.c   |  20 ++++++++++----------
 usr.bin/make/suff.c    |  21 +++++++++------------
 5 files changed, 53 insertions(+), 31 deletions(-)

diffs (265 lines):

diff -r 5e036f2718d4 -r 81119699f6dc usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Sat Nov 28 22:53:06 2020 +0000
+++ b/usr.bin/make/dir.c        Sat Nov 28 22:56:01 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.224 2020/11/28 22:13:56 rillig Exp $ */
+/*     $NetBSD: dir.c,v 1.225 2020/11/28 22:56:01 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -136,7 +136,7 @@
 #include "job.h"
 
 /*     "@(#)dir.c      8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: dir.c,v 1.224 2020/11/28 22:13:56 rillig Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.225 2020/11/28 22:56:01 rillig Exp $");
 
 #define DIR_DEBUG0(text) DEBUG0(DIR, text)
 #define DIR_DEBUG1(fmt, arg1) DEBUG1(DIR, fmt, arg1)
@@ -229,6 +229,8 @@
        HashTable_Init(&odirs->table);
 }
 
+static void Dir_Destroy(void *);
+
 #ifdef CLEANUP
 static void
 OpenDirs_Done(OpenDirs *odirs)
@@ -366,7 +368,7 @@
 void
 Dir_Init(void)
 {
-       dirSearchPath = Lst_New();
+       dirSearchPath = SearchPath_New();
        OpenDirs_Init(&openDirs);
        HashTable_Init(&mtimes);
        HashTable_Init(&lmtimes);
@@ -854,10 +856,12 @@
                        if (*end == '/')
                                *end = '\0';
 
-                       partPath = Lst_New();
+                       partPath = SearchPath_New();
                        (void)Dir_AddDir(partPath, dirpath);
                        DirExpandPath(cp + 1, partPath, expansions);
                        Lst_Free(partPath);
+                       /* XXX: Should the dirs in partPath be freed here?
+                        * It's not obvious whether to free them or not. */
                }
        }
 
@@ -1475,7 +1479,7 @@
 SearchPath *
 Dir_CopyDirSearchPath(void)
 {
-       SearchPath *path = Lst_New();
+       SearchPath *path = SearchPath_New();
        SearchPathNode *ln;
        for (ln = dirSearchPath->first; ln != NULL; ln = ln->next) {
                CachedDir *dir = ln->datum;
@@ -1532,7 +1536,7 @@
  * Input:
  *     dirp            The directory descriptor to nuke
  */
-void
+static void
 Dir_Destroy(void *dirp)
 {
        CachedDir *dir = dirp;
@@ -1547,6 +1551,19 @@
        }
 }
 
+/* Free the search path and all directories mentioned in it. */
+void
+SearchPath_Free(SearchPath *path)
+{
+       SearchPathNode *ln;
+
+       for (ln = path->first; ln != NULL; ln = ln->next) {
+               CachedDir *dir = ln->datum;
+               Dir_Destroy(dir);
+       }
+       Lst_Free(path);
+}
+
 /* Clear out all elements from the given search path.
  * The path is set to the empty list but is not destroyed. */
 void
diff -r 5e036f2718d4 -r 81119699f6dc usr.bin/make/dir.h
--- a/usr.bin/make/dir.h        Sat Nov 28 22:53:06 2020 +0000
+++ b/usr.bin/make/dir.h        Sat Nov 28 22:56:01 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.h,v 1.36 2020/11/28 22:13:56 rillig Exp $  */
+/*     $NetBSD: dir.h,v 1.37 2020/11/28 22:56:01 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -85,6 +85,7 @@
                                 * Not sure what happens when .CURDIR is
                                 * assigned a new value; see Parse_DoVar. */
     int refCount;              /* Number of SearchPaths with this directory */
+    /* TODO: Log the reference counting; see Dir_Expand, partPath. */
     int hits;                  /* The number of times a file in this
                                 * directory has been found */
     HashSet files;             /* The files in the directory. */
@@ -107,7 +108,6 @@
 void SearchPath_AddAll(SearchPath *, SearchPath *);
 void Dir_PrintDirectories(void);
 void SearchPath_Print(SearchPath *);
-void Dir_Destroy(void *);
 SearchPath *Dir_CopyDirSearchPath(void);
 
 /* Stripped-down variant of struct stat. */
diff -r 5e036f2718d4 -r 81119699f6dc usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Sat Nov 28 22:53:06 2020 +0000
+++ b/usr.bin/make/nonints.h    Sat Nov 28 22:56:01 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nonints.h,v 1.162 2020/11/16 21:48:18 rillig Exp $     */
+/*     $NetBSD: nonints.h,v 1.163 2020/11/28 22:56:01 rillig Exp $     */
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -96,6 +96,14 @@
 void Cond_restore_depth(unsigned int);
 unsigned int Cond_save_depth(void);
 
+/* dir.c; see also dir.h */
+
+MAKE_INLINE SearchPath *
+SearchPath_New(void)
+{ return Lst_New(); }
+
+void SearchPath_Free(SearchPath *);
+
 /* for.c */
 int For_Eval(const char *);
 Boolean For_Accum(const char *);
diff -r 5e036f2718d4 -r 81119699f6dc usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sat Nov 28 22:53:06 2020 +0000
+++ b/usr.bin/make/parse.c      Sat Nov 28 22:56:01 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.458 2020/11/28 22:13:56 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.459 2020/11/28 22:56:01 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
 #include "pathnames.h"
 
 /*     "@(#)parse.c    8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.458 2020/11/28 22:13:56 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.459 2020/11/28 22:56:01 rillig Exp $");
 
 /* types and constants */
 
@@ -1205,11 +1205,11 @@
         * use Dir_Destroy in the destruction of the path as the
         * Dir module could have added a directory to the path...
         */
-       SearchPath *emptyPath = Lst_New();
+       SearchPath *emptyPath = SearchPath_New();
 
        Dir_Expand(line, emptyPath, curTargs);
 
-       Lst_Destroy(emptyPath, Dir_Destroy);
+       SearchPath_Free(emptyPath);
     } else {
        /*
         * No wildcards, but we want to avoid code duplication,
@@ -3111,9 +3111,9 @@
 Parse_Init(void)
 {
     mainNode = NULL;
-    parseIncPath = Lst_New();
-    sysIncPath = Lst_New();
-    defSysIncPath = Lst_New();
+    parseIncPath = SearchPath_New();
+    sysIncPath = SearchPath_New();
+    defSysIncPath = SearchPath_New();
     Vector_Init(&includes, sizeof(IFile));
 #ifdef CLEANUP
     targCmds = Lst_New();
@@ -3127,9 +3127,9 @@
 #ifdef CLEANUP
     Lst_Destroy(targCmds, free);
     assert(targets == NULL);
-    Lst_Destroy(defSysIncPath, Dir_Destroy);
-    Lst_Destroy(sysIncPath, Dir_Destroy);
-    Lst_Destroy(parseIncPath, Dir_Destroy);
+    SearchPath_Free(defSysIncPath);
+    SearchPath_Free(sysIncPath);
+    SearchPath_Free(parseIncPath);
     assert(includes.len == 0);
     Vector_Done(&includes);
 #endif
diff -r 5e036f2718d4 -r 81119699f6dc usr.bin/make/suff.c
--- a/usr.bin/make/suff.c       Sat Nov 28 22:53:06 2020 +0000
+++ b/usr.bin/make/suff.c       Sat Nov 28 22:56:01 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: suff.c,v 1.314 2020/11/28 22:13:56 rillig Exp $        */
+/*     $NetBSD: suff.c,v 1.315 2020/11/28 22:56:01 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -114,7 +114,7 @@
 #include "dir.h"
 
 /*     "@(#)suff.c     8.4 (Berkeley) 3/21/94" */
-MAKE_RCSID("$NetBSD: suff.c,v 1.314 2020/11/28 22:13:56 rillig Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.315 2020/11/28 22:56:01 rillig Exp $");
 
 #define SUFF_DEBUG0(text) DEBUG0(SUFF, text)
 #define SUFF_DEBUG1(fmt, arg1) DEBUG1(SUFF, fmt, arg1)
@@ -368,7 +368,7 @@
     Lst_Free(suff->ref);
     Lst_Free(suff->children);
     Lst_Free(suff->parents);
-    Lst_Destroy(suff->searchPath, Dir_Destroy);
+    SearchPath_Free(suff->searchPath);
 
     free(suff->name);
     free(suff);
@@ -436,7 +436,7 @@
 
     suff->name = bmake_strdup(name);
     suff->nameLen = strlen(suff->name);
-    suff->searchPath = Lst_New();
+    suff->searchPath = SearchPath_New();
     suff->children = Lst_New();
     suff->parents = Lst_New();
     suff->ref = Lst_New();
@@ -835,11 +835,8 @@
 {
     SuffixListNode *ln;
     char *flags;
-    SearchPath *inIncludes; /* Cumulative .INCLUDES path */
-    SearchPath *inLibs;            /* Cumulative .LIBS path */
-
-    inIncludes = Lst_New();
-    inLibs = Lst_New();
+    SearchPath *inIncludes = SearchPath_New(); /* Cumulative .INCLUDES path */
+    SearchPath *inLibs = SearchPath_New();     /* Cumulative .LIBS path */
 
     for (ln = sufflist->first; ln != NULL; ln = ln->next) {
        Suffix *suff = ln->datum;
@@ -854,7 +851,7 @@
 #endif
            SearchPath_AddAll(suff->searchPath, dirSearchPath);
        } else {
-           Lst_Destroy(suff->searchPath, Dir_Destroy);
+           SearchPath_Free(suff->searchPath);
            suff->searchPath = Dir_CopyDirSearchPath();
        }
     }
@@ -867,8 +864,8 @@
     Var_Set(".LIBS", flags, VAR_GLOBAL);
     free(flags);
 
-    Lst_Destroy(inIncludes, Dir_Destroy);
-    Lst_Destroy(inLibs, Dir_Destroy);
+    SearchPath_Free(inIncludes);
+    SearchPath_Free(inLibs);
 }
 
 /*



Home | Main Index | Thread Index | Old Index