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): do not look up local variables like .T...
details: https://anonhg.NetBSD.org/src/rev/9c3b360b76ee
branches: trunk
changeset: 1015734:9c3b360b76ee
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Oct 31 11:54:33 2020 +0000
description:
make(1): do not look up local variables like .TARGET anywhere else
Nobody defines a global variable named .TARGET since that would have
many unpredictable effects, applying to all targets at once.
Nobody defines an environment variable named .TARGET since that's
against the naming conventions for environment variables and would have
the same effect.
Because of this, there is no point looking up the variables that are
local to a GNode anywhere else. This means they cannot come from the
environment and thus their value doesn't need to be freed after use,
which makes the code simpler.
The newly added accessor functions in make.h refer to external
functions, but since that header is not used anywhere outside of
usr.bin/make, it doesn't matter. Between 2020-08-25 and 2020-10-30,
that header had been referenced by usr.bin/xinstall.
diffstat:
usr.bin/make/arch.c | 20 ++++----------------
usr.bin/make/compat.c | 20 ++++++--------------
usr.bin/make/job.c | 8 +++-----
usr.bin/make/make.c | 28 ++++++++--------------------
usr.bin/make/make.h | 17 ++++++++++++++++-
usr.bin/make/meta.c | 12 +++++-------
usr.bin/make/nonints.h | 3 ++-
usr.bin/make/suff.c | 13 ++++---------
usr.bin/make/var.c | 13 +++++++++++--
9 files changed, 59 insertions(+), 75 deletions(-)
diffs (truncated from 411 to 300 lines):
diff -r 148b5d8ba6fe -r 9c3b360b76ee usr.bin/make/arch.c
--- a/usr.bin/make/arch.c Sat Oct 31 11:34:30 2020 +0000
+++ b/usr.bin/make/arch.c Sat Oct 31 11:54:33 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: arch.c,v 1.149 2020/10/30 20:30:44 rillig Exp $ */
+/* $NetBSD: arch.c,v 1.150 2020/10/31 11:54:33 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -130,7 +130,7 @@
#include "config.h"
/* "@(#)arch.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: arch.c,v 1.149 2020/10/30 20:30:44 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.150 2020/10/31 11:54:33 rillig Exp $");
#ifdef TARGET_MACHINE
#undef MAKE_MACHINE
@@ -861,15 +861,10 @@
{
FILE *arch; /* Stream open to archive, positioned properly */
struct ar_hdr arh; /* Current header describing member */
- void *p1, *p2;
- arch = ArchFindMember(Var_Value(ARCHIVE, gn, &p1),
- Var_Value(MEMBER, gn, &p2),
+ arch = ArchFindMember(GNode_VarArchive(gn), GNode_VarMember(gn),
&arh, "r+");
- bmake_free(p1);
- bmake_free(p2);
-
snprintf(arh.ar_date, sizeof(arh.ar_date), "%-12ld", (long)now);
if (arch != NULL) {
@@ -921,15 +916,8 @@
{
struct ar_hdr *arhPtr; /* Header of desired member */
time_t modTime; /* Modification time as an integer */
- void *p1, *p2;
- arhPtr = ArchStatMember(Var_Value(ARCHIVE, gn, &p1),
- Var_Value(MEMBER, gn, &p2),
- TRUE);
-
- bmake_free(p1);
- bmake_free(p2);
-
+ arhPtr = ArchStatMember(GNode_VarArchive(gn), GNode_VarMember(gn), TRUE);
if (arhPtr != NULL) {
modTime = (time_t)strtol(arhPtr->ar_date, NULL, 10);
} else {
diff -r 148b5d8ba6fe -r 9c3b360b76ee usr.bin/make/compat.c
--- a/usr.bin/make/compat.c Sat Oct 31 11:34:30 2020 +0000
+++ b/usr.bin/make/compat.c Sat Oct 31 11:54:33 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: compat.c,v 1.170 2020/10/30 20:30:44 rillig Exp $ */
+/* $NetBSD: compat.c,v 1.171 2020/10/31 11:54:33 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -96,7 +96,7 @@
#include "pathnames.h"
/* "@(#)compat.c 8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: compat.c,v 1.170 2020/10/30 20:30:44 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.171 2020/10/31 11:54:33 rillig Exp $");
static GNode *curTarg = NULL;
static pid_t compatChild;
@@ -110,14 +110,11 @@
CompatDeleteTarget(GNode *gn)
{
if (gn != NULL && !Targ_Precious(gn)) {
- void *file_freeIt;
- const char *file = Var_Value(TARGET, gn, &file_freeIt);
+ const char *file = GNode_VarTarget(gn);
if (!opts.noExecute && eunlink(file) != -1) {
Error("*** %s removed", file);
}
-
- bmake_free(file_freeIt);
}
}
@@ -502,11 +499,8 @@
goto cohorts;
}
- if (Lst_FindDatum(gn->implicitParents, pgn) != NULL) {
- void *target_freeIt;
- Var_Set(IMPSRC, Var_Value(TARGET, gn, &target_freeIt), pgn);
- bmake_free(target_freeIt);
- }
+ if (Lst_FindDatum(gn->implicitParents, pgn) != NULL)
+ Var_Set(IMPSRC, GNode_VarTarget(gn), pgn);
/*
* All the children were made ok. Now youngestChild->mtime contains the
@@ -597,10 +591,8 @@
pgn->flags &= ~(unsigned)REMAKE;
} else {
if (Lst_FindDatum(gn->implicitParents, pgn) != NULL) {
- void *target_freeIt;
- const char *target = Var_Value(TARGET, gn, &target_freeIt);
+ const char *target = GNode_VarTarget(gn);
Var_Set(IMPSRC, target != NULL ? target : "", pgn);
- bmake_free(target_freeIt);
}
switch(gn->made) {
case BEINGMADE:
diff -r 148b5d8ba6fe -r 9c3b360b76ee usr.bin/make/job.c
--- a/usr.bin/make/job.c Sat Oct 31 11:34:30 2020 +0000
+++ b/usr.bin/make/job.c Sat Oct 31 11:54:33 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: job.c,v 1.296 2020/10/30 20:30:44 rillig Exp $ */
+/* $NetBSD: job.c,v 1.297 2020/10/31 11:54:33 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -143,7 +143,7 @@
#include "trace.h"
/* "@(#)job.c 8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: job.c,v 1.296 2020/10/30 20:30:44 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.297 2020/10/31 11:54:33 rillig Exp $");
/* A shell defines how the commands are run. All commands for a target are
* written into a single file, which is then given to the shell to execute
@@ -1193,7 +1193,6 @@
*/
if ((DEFAULT != NULL) && !Lst_IsEmpty(DEFAULT->commands) &&
(gn->type & OP_SPECIAL) == 0) {
- void *p1;
/*
* Make only looks for a .DEFAULT if the node was never the
* target of an operator, so that's what we do too. If
@@ -1204,8 +1203,7 @@
* .DEFAULT itself.
*/
Make_HandleUse(DEFAULT, gn);
- Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), gn);
- bmake_free(p1);
+ Var_Set(IMPSRC, GNode_VarTarget(gn), gn);
return TRUE;
}
diff -r 148b5d8ba6fe -r 9c3b360b76ee usr.bin/make/make.c
--- a/usr.bin/make/make.c Sat Oct 31 11:34:30 2020 +0000
+++ b/usr.bin/make/make.c Sat Oct 31 11:54:33 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: make.c,v 1.183 2020/10/30 20:30:44 rillig Exp $ */
+/* $NetBSD: make.c,v 1.184 2020/10/31 11:54:33 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -107,7 +107,7 @@
#include "job.h"
/* "@(#)make.c 8.1 (Berkeley) 6/6/93" */
-MAKE_RCSID("$NetBSD: make.c,v 1.183 2020/10/30 20:30:44 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.184 2020/10/31 11:54:33 rillig Exp $");
/* Sequence # to detect recursion. */
static unsigned int checked = 1;
@@ -569,8 +569,7 @@
UpdateImplicitParentsVars(GNode *cgn, const char *cname)
{
GNodeListNode *ln;
- void *cpref_freeIt;
- const char *cpref = Var_Value(PREFIX, cgn, &cpref_freeIt);
+ const char *cpref = GNode_VarPrefix(cgn);
for (ln = cgn->implicitParents->first; ln != NULL; ln = ln->next) {
GNode *pgn = ln->datum;
@@ -580,7 +579,6 @@
Var_Set(PREFIX, cpref, pgn);
}
}
- bmake_free(cpref_freeIt);
}
/* Perform update on the parents of a node. Used by JobFinish once
@@ -614,11 +612,7 @@
/* It is save to re-examine any nodes again */
checked++;
- {
- void *cname_freeIt;
- cname = Var_Value(TARGET, cgn, &cname_freeIt);
- assert(cname_freeIt == NULL);
- }
+ cname = GNode_VarTarget(cgn);
DEBUG2(MAKE, "Make_Update: %s%s\n", cgn->name, cgn->cohort_num);
@@ -779,20 +773,18 @@
if ((cgn->type & (OP_EXEC|OP_USE|OP_USEBEFORE|OP_INVISIBLE)) == 0) {
const char *child, *allsrc;
- void *p1 = NULL, *p2 = NULL;
if (cgn->type & OP_ARCHV)
- child = Var_Value(MEMBER, cgn, &p1);
+ child = GNode_VarMember(cgn);
else
child = GNode_Path(cgn);
if (cgn->type & OP_JOIN) {
- allsrc = Var_Value(ALLSRC, cgn, &p2);
+ allsrc = GNode_VarAllsrc(cgn);
} else {
allsrc = child;
}
if (allsrc != NULL)
Var_Append(ALLSRC, allsrc, pgn);
- bmake_free(p2);
if (pgn->type & OP_JOIN) {
if (cgn->made == MADE) {
Var_Append(OODATE, child, pgn);
@@ -818,7 +810,6 @@
*/
Var_Append(OODATE, child, pgn);
}
- bmake_free(p1);
}
}
@@ -854,11 +845,8 @@
Var_Set(ALLSRC, "", gn);
}
- if (gn->type & OP_JOIN) {
- void *p1;
- Var_Set(TARGET, Var_Value(ALLSRC, gn, &p1), gn);
- bmake_free(p1);
- }
+ if (gn->type & OP_JOIN)
+ Var_Set(TARGET, GNode_VarAllsrc(gn), gn);
gn->flags |= DONE_ALLSRC;
}
diff -r 148b5d8ba6fe -r 9c3b360b76ee usr.bin/make/make.h
--- a/usr.bin/make/make.h Sat Oct 31 11:34:30 2020 +0000
+++ b/usr.bin/make/make.h Sat Oct 31 11:54:33 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: make.h,v 1.177 2020/10/30 17:10:48 rillig Exp $ */
+/* $NetBSD: make.h,v 1.178 2020/10/31 11:54:33 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -644,6 +644,21 @@
return gn->path != NULL ? gn->path : gn->name;
}
+static MAKE_ATTR_UNUSED const char *
+GNode_VarTarget(GNode *gn) { return Var_ValueDirect(TARGET, gn); }
+static MAKE_ATTR_UNUSED const char *
+GNode_VarOodate(GNode *gn) { return Var_ValueDirect(OODATE, gn); }
+static MAKE_ATTR_UNUSED const char *
+GNode_VarAllsrc(GNode *gn) { return Var_ValueDirect(ALLSRC, gn); }
+static MAKE_ATTR_UNUSED const char *
+GNode_VarImpsrc(GNode *gn) { return Var_ValueDirect(IMPSRC, gn); }
+static MAKE_ATTR_UNUSED const char *
+GNode_VarPrefix(GNode *gn) { return Var_ValueDirect(PREFIX, gn); }
+static MAKE_ATTR_UNUSED const char *
+GNode_VarArchive(GNode *gn) { return Var_ValueDirect(ARCHIVE, gn); }
+static MAKE_ATTR_UNUSED const char *
+GNode_VarMember(GNode *gn) { return Var_ValueDirect(MEMBER, gn); }
+
#ifdef __GNUC__
#define UNCONST(ptr) ({ \
union __unconst { \
diff -r 148b5d8ba6fe -r 9c3b360b76ee usr.bin/make/meta.c
--- a/usr.bin/make/meta.c Sat Oct 31 11:34:30 2020 +0000
+++ b/usr.bin/make/meta.c Sat Oct 31 11:54:33 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: meta.c,v 1.134 2020/10/31 09:57:47 rillig Exp $ */
+/* $NetBSD: meta.c,v 1.135 2020/10/31 11:54:33 rillig Exp $ */
/*
* Implement 'meta' mode.
@@ -481,7 +481,7 @@
i = 0;
dname = Var_Value(".OBJDIR", gn, &p[i++]);
- tname = Var_Value(TARGET, gn, &p[i++]);
+ tname = GNode_VarTarget(gn);
/* if this succeeds objdir is realpath of dname */
if (!meta_needed(gn, dname, tname, objdir, TRUE))
@@ -529,7 +529,7 @@
fprintf(mf.fp, "CWD %s\n", getcwd(buf, sizeof(buf)));
fprintf(mf.fp, "TARGET %s\n", tname);
- cp = Var_Value(".OODATE", gn, &p[i++]);
+ cp = GNode_VarOodate(gn);
if (cp && *cp) {
fprintf(mf.fp, "OODATE %s\n", cp);
}
Home |
Main Index |
Thread Index |
Old Index