Module Name:    src
Committed By:   rillig
Date:           Sun Jan 24 20:11:55 UTC 2021

Modified Files:
        src/usr.bin/make: dir.c main.c make.h nonints.h parse.c suff.c

Log Message:
make(1): convert SearchPath to struct

This prepares for making dotLast a simple struct member instead of a
fake CachedDir, which is easier to understand.


To generate a diff of this commit:
cvs rdiff -u -r1.263 -r1.264 src/usr.bin/make/dir.c
cvs rdiff -u -r1.516 -r1.517 src/usr.bin/make/main.c
cvs rdiff -u -r1.245 -r1.246 src/usr.bin/make/make.h
cvs rdiff -u -r1.187 -r1.188 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.530 -r1.531 src/usr.bin/make/parse.c
cvs rdiff -u -r1.339 -r1.340 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.263 src/usr.bin/make/dir.c:1.264
--- src/usr.bin/make/dir.c:1.263	Sat Jan 23 12:36:02 2021
+++ src/usr.bin/make/dir.c	Sun Jan 24 20:11:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.263 2021/01/23 12:36:02 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.264 2021/01/24 20:11:55 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -138,7 +138,7 @@
 #include "job.h"
 
 /*	"@(#)dir.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: dir.c,v 1.263 2021/01/23 12:36:02 rillig Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.264 2021/01/24 20:11:55 rillig Exp $");
 
 /*
  * A search path is a list of CachedDir structures. A CachedDir has in it the
@@ -253,7 +253,7 @@ typedef enum CachedStatsFlags {
 } CachedStatsFlags;
 
 
-SearchPath dirSearchPath = LST_INIT;	/* main search path */
+SearchPath dirSearchPath = { LST_INIT }; /* main search path */
 
 static OpenDirs openDirs;	/* all cached directories */
 
@@ -551,7 +551,7 @@ Dir_SetPATH(void)
 
 	Var_Delete(".PATH", VAR_GLOBAL);
 
-	if ((ln = dirSearchPath.first) != NULL) {
+	if ((ln = dirSearchPath.dirs.first) != NULL) {
 		CachedDir *dir = ln->datum;
 		if (dir == dotLast) {
 			seenDotLast = TRUE;
@@ -566,7 +566,7 @@ Dir_SetPATH(void)
 			Var_Append(".PATH", cur->name, VAR_GLOBAL);
 	}
 
-	for (ln = dirSearchPath.first; ln != NULL; ln = ln->next) {
+	for (ln = dirSearchPath.dirs.first; ln != NULL; ln = ln->next) {
 		CachedDir *dir = ln->datum;
 		if (dir == dotLast)
 			continue;
@@ -818,7 +818,7 @@ static void
 DirExpandPath(const char *word, SearchPath *path, StringList *expansions)
 {
 	SearchPathNode *ln;
-	for (ln = path->first; ln != NULL; ln = ln->next) {
+	for (ln = path->dirs.first; ln != NULL; ln = ln->next) {
 		CachedDir *dir = ln->datum;
 		DirMatchFiles(word, dir, expansions);
 	}
@@ -1085,7 +1085,7 @@ FindFileRelative(SearchPath *path, Boole
 			goto found;
 	}
 
-	for (ln = path->first; ln != NULL; ln = ln->next) {
+	for (ln = path->dirs.first; ln != NULL; ln = ln->next) {
 		CachedDir *dir = ln->datum;
 		if (dir == dotLast)
 			continue;
@@ -1150,7 +1150,7 @@ FindFileAbsolute(SearchPath *path, Boole
 	    ((file = DirLookupAbs(cur, name, base)) != NULL))
 		goto found;
 
-	for (ln = path->first; ln != NULL; ln = ln->next) {
+	for (ln = path->dirs.first; ln != NULL; ln = ln->next) {
 		CachedDir *dir = ln->datum;
 		if (dir == dotLast)
 			continue;
@@ -1207,8 +1207,8 @@ Dir_FindFile(const char *name, SearchPat
 		return NULL;
 	}
 
-	if (path->first != NULL) {
-		CachedDir *dir = path->first->datum;
+	if (path->dirs.first != NULL) {
+		CachedDir *dir = path->dirs.first->datum;
 		if (dir == dotLast) {
 			seenDotLast = TRUE;
 			DEBUG0(DIR, "[dot last]...");
@@ -1241,7 +1241,7 @@ Dir_FindFile(const char *name, SearchPat
 		if (!seenDotLast && (file = DirFindDot(name, base)) != NULL)
 			return file;
 
-		for (ln = path->first; ln != NULL; ln = ln->next) {
+		for (ln = path->dirs.first; ln != NULL; ln = ln->next) {
 			CachedDir *dir = ln->datum;
 			if (dir == dotLast)
 				continue;
@@ -1544,7 +1544,7 @@ CacheNewDir(const char *name, SearchPath
 
 	OpenDirs_Add(&openDirs, dir);
 	if (path != NULL)
-		Lst_Append(path, CachedDir_Ref(dir));
+		Lst_Append(&path->dirs, CachedDir_Ref(dir));
 
 	DEBUG1(DIR, "Caching %s done\n", name);
 	return dir;
@@ -1576,21 +1576,21 @@ SearchPath_Add(SearchPath *path, const c
 		SearchPathNode *ln;
 
 		/* XXX: Linear search gets slow with thousands of entries. */
-		for (ln = path->first; ln != NULL; ln = ln->next) {
+		for (ln = path->dirs.first; ln != NULL; ln = ln->next) {
 			CachedDir *pathDir = ln->datum;
 			if (strcmp(pathDir->name, name) == 0)
 				return pathDir;
 		}
 
-		Lst_Prepend(path, CachedDir_Ref(dotLast));
+		Lst_Prepend(&path->dirs, CachedDir_Ref(dotLast));
 	}
 
 	if (path != NULL) {
 		/* XXX: Why is OpenDirs only checked if path != NULL? */
 		CachedDir *dir = OpenDirs_Find(&openDirs, name);
 		if (dir != NULL) {
-			if (Lst_FindDatum(path, dir) == NULL)
-				Lst_Append(path, CachedDir_Ref(dir));
+			if (Lst_FindDatum(&path->dirs, dir) == NULL)
+				Lst_Append(&path->dirs, CachedDir_Ref(dir));
 			return dir;
 		}
 	}
@@ -1607,9 +1607,9 @@ Dir_CopyDirSearchPath(void)
 {
 	SearchPath *path = SearchPath_New();
 	SearchPathNode *ln;
-	for (ln = dirSearchPath.first; ln != NULL; ln = ln->next) {
+	for (ln = dirSearchPath.dirs.first; ln != NULL; ln = ln->next) {
 		CachedDir *dir = ln->datum;
-		Lst_Append(path, CachedDir_Ref(dir));
+		Lst_Append(&path->dirs, CachedDir_Ref(dir));
 	}
 	return path;
 }
@@ -1637,7 +1637,7 @@ SearchPath_ToFlags(SearchPath *path, con
 	Buf_Init(&buf);
 
 	if (path != NULL) {
-		for (ln = path->first; ln != NULL; ln = ln->next) {
+		for (ln = path->dirs.first; ln != NULL; ln = ln->next) {
 			CachedDir *dir = ln->datum;
 			Buf_AddStr(&buf, " ");
 			Buf_AddStr(&buf, flag);
@@ -1654,11 +1654,12 @@ SearchPath_Free(SearchPath *path)
 {
 	SearchPathNode *ln;
 
-	for (ln = path->first; ln != NULL; ln = ln->next) {
+	for (ln = path->dirs.first; ln != NULL; ln = ln->next) {
 		CachedDir *dir = ln->datum;
 		CachedDir_Unref(dir);
 	}
-	Lst_Free(path);
+	Lst_Done(&path->dirs);
+	free(path);
 }
 
 /*
@@ -1668,8 +1669,8 @@ SearchPath_Free(SearchPath *path)
 void
 SearchPath_Clear(SearchPath *path)
 {
-	while (!Lst_IsEmpty(path)) {
-		CachedDir *dir = Lst_Dequeue(path);
+	while (!Lst_IsEmpty(&path->dirs)) {
+		CachedDir *dir = Lst_Dequeue(&path->dirs);
 		CachedDir_Unref(dir);
 	}
 }
@@ -1684,10 +1685,10 @@ SearchPath_AddAll(SearchPath *dst, Searc
 {
 	SearchPathNode *ln;
 
-	for (ln = src->first; ln != NULL; ln = ln->next) {
+	for (ln = src->dirs.first; ln != NULL; ln = ln->next) {
 		CachedDir *dir = ln->datum;
-		if (Lst_FindDatum(dst, dir) == NULL)
-			Lst_Append(dst, CachedDir_Ref(dir));
+		if (Lst_FindDatum(&dst->dirs, dir) == NULL)
+			Lst_Append(&dst->dirs, CachedDir_Ref(dir));
 	}
 }
 
@@ -1722,7 +1723,7 @@ SearchPath_Print(SearchPath *path)
 {
 	SearchPathNode *ln;
 
-	for (ln = path->first; ln != NULL; ln = ln->next) {
+	for (ln = path->dirs.first; ln != NULL; ln = ln->next) {
 		const CachedDir *dir = ln->datum;
 		debug_printf("%s ", dir->name);
 	}

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.516 src/usr.bin/make/main.c:1.517
--- src/usr.bin/make/main.c:1.516	Sat Jan 23 11:34:41 2021
+++ src/usr.bin/make/main.c	Sun Jan 24 20:11:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.516 2021/01/23 11:34:41 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.517 2021/01/24 20:11:55 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -110,7 +110,7 @@
 #include "trace.h"
 
 /*	"@(#)main.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: main.c,v 1.516 2021/01/23 11:34:41 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.517 2021/01/24 20:11:55 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	    "The Regents of the University of California.  "
@@ -1215,7 +1215,7 @@ ReadBuiltinRules(void)
 	StringList sysMkPath = LST_INIT;
 
 	SearchPath_Expand(
-	    Lst_IsEmpty(sysIncPath) ? defSysIncPath : sysIncPath,
+	    Lst_IsEmpty(&sysIncPath->dirs) ? defSysIncPath : sysIncPath,
 	    _PATH_DEFSYSMK,
 	    &sysMkPath);
 	if (Lst_IsEmpty(&sysMkPath))
@@ -1721,7 +1721,7 @@ ReadMakefile(const char *fname)
 		/* look in -I and system include directories. */
 		name = Dir_FindFile(fname, parseIncPath);
 		if (name == NULL) {
-			SearchPath *sysInc = Lst_IsEmpty(sysIncPath)
+			SearchPath *sysInc = Lst_IsEmpty(&sysIncPath->dirs)
 					     ? defSysIncPath : sysIncPath;
 			name = Dir_FindFile(fname, sysInc);
 		}

Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.245 src/usr.bin/make/make.h:1.246
--- src/usr.bin/make/make.h:1.245	Thu Jan 21 14:30:01 2021
+++ src/usr.bin/make/make.h	Sun Jan 24 20:11:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.245 2021/01/21 14:30:01 rillig Exp $	*/
+/*	$NetBSD: make.h,v 1.246 2021/01/24 20:11:55 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -361,7 +361,9 @@ typedef struct ListNode StringListNode;
 typedef struct List GNodeList;
 typedef struct ListNode GNodeListNode;
 
-typedef struct List /* of CachedDir */ SearchPath;
+typedef struct SearchPath {
+	List /* of CachedDir */ dirs;
+} SearchPath;
 
 /*
  * A graph node represents a target that can possibly be made, including its

Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.187 src/usr.bin/make/nonints.h:1.188
--- src/usr.bin/make/nonints.h:1.187	Tue Jan 19 20:51:46 2021
+++ src/usr.bin/make/nonints.h	Sun Jan 24 20:11:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nonints.h,v 1.187 2021/01/19 20:51:46 rillig Exp $	*/
+/*	$NetBSD: nonints.h,v 1.188 2021/01/24 20:11:55 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -107,7 +107,11 @@ str_basename(const char *pathname)
 
 MAKE_INLINE SearchPath *
 SearchPath_New(void)
-{ return Lst_New(); }
+{
+	SearchPath *path = bmake_malloc(sizeof *path);
+	Lst_Init(&path->dirs);
+	return path;
+}
 
 void SearchPath_Free(SearchPath *);
 

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.530 src/usr.bin/make/parse.c:1.531
--- src/usr.bin/make/parse.c:1.530	Sat Jan 23 12:03:25 2021
+++ src/usr.bin/make/parse.c	Sun Jan 24 20:11:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.530 2021/01/23 12:03:25 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.531 2021/01/24 20:11:55 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.530 2021/01/23 12:03:25 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.531 2021/01/24 20:11:55 rillig Exp $");
 
 /* types and constants */
 
@@ -2159,8 +2159,8 @@ Parse_include_file(char *file, Boolean i
 		/*
 		 * Look for it on the system path
 		 */
-		SearchPath *path = Lst_IsEmpty(sysIncPath) ? defSysIncPath
-		    : sysIncPath;
+		SearchPath *path = Lst_IsEmpty(&sysIncPath->dirs)
+		    ? defSysIncPath : sysIncPath;
 		fullname = Dir_FindFile(file, path);
 	}
 

Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.339 src/usr.bin/make/suff.c:1.340
--- src/usr.bin/make/suff.c:1.339	Sat Jan 23 12:35:22 2021
+++ src/usr.bin/make/suff.c	Sun Jan 24 20:11:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.339 2021/01/23 12:35:22 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.340 2021/01/24 20:11:55 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.339 2021/01/23 12:35:22 rillig Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.340 2021/01/24 20:11:55 rillig Exp $");
 
 typedef List SuffixList;
 typedef ListNode SuffixListNode;
@@ -885,7 +885,7 @@ Suff_DoPaths(void)
 
 	for (ln = sufflist.first; ln != NULL; ln = ln->next) {
 		Suffix *suff = ln->datum;
-		if (!Lst_IsEmpty(suff->searchPath)) {
+		if (!Lst_IsEmpty(&suff->searchPath->dirs)) {
 #ifdef INCLUDES
 			if (suff->flags & SUFF_INCLUDE)
 				SearchPath_AddAll(includesPath,

Reply via email to