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): convert SearchPath to struct
details: https://anonhg.NetBSD.org/src/rev/a5c8094a2e96
branches: trunk
changeset: 958924:a5c8094a2e96
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Jan 24 20:11:55 2021 +0000
description:
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.
diffstat:
usr.bin/make/dir.c | 55 +++++++++++++++++++++++++------------------------
usr.bin/make/main.c | 8 +++---
usr.bin/make/make.h | 6 +++-
usr.bin/make/nonints.h | 8 +++++-
usr.bin/make/parse.c | 8 +++---
usr.bin/make/suff.c | 6 ++--
6 files changed, 49 insertions(+), 42 deletions(-)
diffs (truncated from 331 to 300 lines):
diff -r 0083dc0b77df -r a5c8094a2e96 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c Sun Jan 24 20:09:03 2021 +0000
+++ b/usr.bin/make/dir.c Sun Jan 24 20:11:55 2021 +0000
@@ -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 @@
} 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 @@
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 @@
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 @@
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 @@
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 @@
((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 @@
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 @@
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 @@
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 @@
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 @@
{
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 @@
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 @@
{
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 @@
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 @@
{
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 @@
{
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);
}
diff -r 0083dc0b77df -r a5c8094a2e96 usr.bin/make/main.c
--- a/usr.bin/make/main.c Sun Jan 24 20:09:03 2021 +0000
+++ b/usr.bin/make/main.c Sun Jan 24 20:11:55 2021 +0000
@@ -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 @@
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 @@
/* 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);
}
diff -r 0083dc0b77df -r a5c8094a2e96 usr.bin/make/make.h
--- a/usr.bin/make/make.h Sun Jan 24 20:09:03 2021 +0000
+++ b/usr.bin/make/make.h Sun Jan 24 20:11:55 2021 +0000
@@ -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 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
diff -r 0083dc0b77df -r a5c8094a2e96 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h Sun Jan 24 20:09:03 2021 +0000
+++ b/usr.bin/make/nonints.h Sun Jan 24 20:11:55 2021 +0000
@@ -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 @@
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 *);
diff -r 0083dc0b77df -r a5c8094a2e96 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c Sun Jan 24 20:09:03 2021 +0000
+++ b/usr.bin/make/parse.c Sun Jan 24 20:11:55 2021 +0000
@@ -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 @@
/*
* Look for it on the system path
*/
- SearchPath *path = Lst_IsEmpty(sysIncPath) ? defSysIncPath
- : sysIncPath;
+ SearchPath *path = Lst_IsEmpty(&sysIncPath->dirs)
Home |
Main Index |
Thread Index |
Old Index