Module Name: src
Committed By: rillig
Date: Sat Nov 28 22:56:01 UTC 2020
Modified Files:
src/usr.bin/make: dir.c dir.h nonints.h parse.c suff.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.224 -r1.225 src/usr.bin/make/dir.c
cvs rdiff -u -r1.36 -r1.37 src/usr.bin/make/dir.h
cvs rdiff -u -r1.162 -r1.163 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.458 -r1.459 src/usr.bin/make/parse.c
cvs rdiff -u -r1.314 -r1.315 src/usr.bin/make/suff.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/make/dir.c
diff -u src/usr.bin/make/dir.c:1.224 src/usr.bin/make/dir.c:1.225
--- src/usr.bin/make/dir.c:1.224 Sat Nov 28 22:13:56 2020
+++ src/usr.bin/make/dir.c Sat Nov 28 22:56:01 2020
@@ -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 @@ OpenDirs_Init(OpenDirs *odirs)
HashTable_Init(&odirs->table);
}
+static void Dir_Destroy(void *);
+
#ifdef CLEANUP
static void
OpenDirs_Done(OpenDirs *odirs)
@@ -366,7 +368,7 @@ cached_lstat(const char *pathname, struc
void
Dir_Init(void)
{
- dirSearchPath = Lst_New();
+ dirSearchPath = SearchPath_New();
OpenDirs_Init(&openDirs);
HashTable_Init(&mtimes);
HashTable_Init(&lmtimes);
@@ -854,10 +856,12 @@ Dir_Expand(const char *word, SearchPath
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 @@ Dir_AddDir(SearchPath *path, const char
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 @@ SearchPath_ToFlags(const char *flag, Sea
* Input:
* dirp The directory descriptor to nuke
*/
-void
+static void
Dir_Destroy(void *dirp)
{
CachedDir *dir = dirp;
@@ -1547,6 +1551,19 @@ Dir_Destroy(void *dirp)
}
}
+/* 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
Index: src/usr.bin/make/dir.h
diff -u src/usr.bin/make/dir.h:1.36 src/usr.bin/make/dir.h:1.37
--- src/usr.bin/make/dir.h:1.36 Sat Nov 28 22:13:56 2020
+++ src/usr.bin/make/dir.h Sat Nov 28 22:56:01 2020
@@ -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 @@ typedef struct CachedDir {
* 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_Clear(SearchPath *);
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. */
Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.162 src/usr.bin/make/nonints.h:1.163
--- src/usr.bin/make/nonints.h:1.162 Mon Nov 16 21:48:18 2020
+++ src/usr.bin/make/nonints.h Sat Nov 28 22:56:01 2020
@@ -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 @@ CondEvalResult Cond_EvalLine(const char
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 *);
Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.458 src/usr.bin/make/parse.c:1.459
--- src/usr.bin/make/parse.c:1.458 Sat Nov 28 22:13:56 2020
+++ src/usr.bin/make/parse.c Sat Nov 28 22:56:01 2020
@@ -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 @@ ParseDoDependencyTargetMundane(char *lin
* 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 @@ void
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 @@ Parse_End(void)
#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
Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.314 src/usr.bin/make/suff.c:1.315
--- src/usr.bin/make/suff.c:1.314 Sat Nov 28 22:13:56 2020
+++ src/usr.bin/make/suff.c Sat Nov 28 22:56:01 2020
@@ -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 @@ Suffix_Free(Suffix *suff)
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 @@ Suffix_New(const char *name)
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 @@ Suff_DoPaths(void)
{
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 @@ Suff_DoPaths(void)
#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 @@ Suff_DoPaths(void)
Var_Set(".LIBS", flags, VAR_GLOBAL);
free(flags);
- Lst_Destroy(inIncludes, Dir_Destroy);
- Lst_Destroy(inLibs, Dir_Destroy);
+ SearchPath_Free(inIncludes);
+ SearchPath_Free(inLibs);
}
/*