Module Name: src
Committed By: rillig
Date: Sun Dec 20 21:07:32 UTC 2020
Modified Files:
src/usr.bin/make: compat.c job.c nonints.h
Log Message:
make(1): omit linear search for command in Compat_RunCommand
To generate a diff of this commit:
cvs rdiff -u -r1.215 -r1.216 src/usr.bin/make/compat.c
cvs rdiff -u -r1.388 -r1.389 src/usr.bin/make/job.c
cvs rdiff -u -r1.179 -r1.180 src/usr.bin/make/nonints.h
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/compat.c
diff -u src/usr.bin/make/compat.c:1.215 src/usr.bin/make/compat.c:1.216
--- src/usr.bin/make/compat.c:1.215 Sun Dec 13 19:33:53 2020
+++ src/usr.bin/make/compat.c Sun Dec 20 21:07:32 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: compat.c,v 1.215 2020/12/13 19:33:53 rillig Exp $ */
+/* $NetBSD: compat.c,v 1.216 2020/12/20 21:07:32 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.215 2020/12/13 19:33:53 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.216 2020/12/20 21:07:32 rillig Exp $");
static GNode *curTarg = NULL;
static pid_t compatChild;
@@ -211,13 +211,14 @@ UseShell(const char *cmd MAKE_ATTR_UNUSE
*
* Input:
* cmdp Command to execute
- * gnp Node from which the command came
+ * gn Node from which the command came
+ * ln List node that contains the command
*
* Results:
* 0 if the command succeeded, 1 if an error occurred.
*/
int
-Compat_RunCommand(const char *cmdp, GNode *gn)
+Compat_RunCommand(const char *cmdp, GNode *gn, StringListNode *ln)
{
char *cmdStart; /* Start of expanded command */
char *bp;
@@ -228,7 +229,6 @@ Compat_RunCommand(const char *cmdp, GNod
int status; /* Description of child's death */
pid_t cpid; /* Child actually found */
pid_t retstat; /* Result of wait */
- StringListNode *cmdNode; /* Node where current command is located */
const char **volatile av; /* Argument vector for thing to exec */
char **volatile mav; /* Copy of the argument vector for freeing */
Boolean useShell; /* TRUE if command should be executed
@@ -239,12 +239,6 @@ Compat_RunCommand(const char *cmdp, GNod
errCheck = !(gn->type & OP_IGNORE);
doIt = FALSE;
- /* Luckily the commands don't end up in a string pool, otherwise
- * this comparison could match too early, in a dependency using "..."
- * for delayed commands, run in parallel mode, using the same shell
- * command line more than once; see JobPrintCommand.
- * TODO: write a unit-test to protect against this potential bug. */
- cmdNode = Lst_FindDatum(&gn->commands, cmd);
(void)Var_Subst(cmd, gn, VARE_WANTRES, &cmdStart);
/* TODO: handle errors */
@@ -253,7 +247,7 @@ Compat_RunCommand(const char *cmdp, GNod
return 0;
}
cmd = cmdStart;
- LstNode_Set(cmdNode, cmdStart);
+ LstNode_Set(ln, cmdStart);
if (gn->type & OP_SAVE_CMDS) {
GNode *endNode = Targ_GetEndNode();
@@ -379,7 +373,7 @@ Compat_RunCommand(const char *cmdp, GNod
/* XXX: Memory management looks suspicious here. */
/* XXX: Setting a list item to NULL is unexpected. */
- LstNode_SetNull(cmdNode);
+ LstNode_SetNull(ln);
#ifdef USE_META
if (useMeta) {
@@ -467,7 +461,7 @@ RunCommands(GNode *gn)
for (ln = gn->commands.first; ln != NULL; ln = ln->next) {
const char *cmd = ln->datum;
- if (Compat_RunCommand(cmd, gn) != 0)
+ if (Compat_RunCommand(cmd, gn, ln) != 0)
break;
}
}
Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.388 src/usr.bin/make/job.c:1.389
--- src/usr.bin/make/job.c:1.388 Tue Dec 15 21:19:47 2020
+++ src/usr.bin/make/job.c Sun Dec 20 21:07:32 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: job.c,v 1.388 2020/12/15 21:19:47 rillig Exp $ */
+/* $NetBSD: job.c,v 1.389 2020/12/20 21:07:32 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.388 2020/12/15 21:19:47 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.389 2020/12/20 21:07:32 rillig Exp $");
/*
* A shell defines how the commands are run. All commands for a target are
@@ -890,7 +890,7 @@ JobPrintSpecials(Job *job, ShellWriter *
* after all other targets have been made.
*/
static void
-JobPrintCommand(Job *job, ShellWriter *wr, const char *ucmd)
+JobPrintCommand(Job *job, ShellWriter *wr, StringListNode *ln, const char *ucmd)
{
Boolean run;
@@ -917,7 +917,7 @@ JobPrintCommand(Job *job, ShellWriter *w
* We're not actually executing anything...
* but this one needs to be - use compat mode just for it.
*/
- Compat_RunCommand(ucmd, job->node);
+ Compat_RunCommand(ucmd, job->node, ln);
free(xcmdStart);
return;
}
@@ -1005,7 +1005,7 @@ JobPrintCommands(Job *job)
break;
}
- JobPrintCommand(job, &wr, ln->datum);
+ JobPrintCommand(job, &wr, ln, ln->datum);
seen = TRUE;
}
Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.179 src/usr.bin/make/nonints.h:1.180
--- src/usr.bin/make/nonints.h:1.179 Sun Dec 20 14:39:46 2020
+++ src/usr.bin/make/nonints.h Sun Dec 20 21:07:32 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: nonints.h,v 1.179 2020/12/20 14:39:46 rillig Exp $ */
+/* $NetBSD: nonints.h,v 1.180 2020/12/20 21:07:32 rillig Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
@@ -86,7 +86,7 @@ Boolean Arch_LibOODate(GNode *);
Boolean Arch_IsLib(GNode *);
/* compat.c */
-int Compat_RunCommand(const char *, GNode *);
+int Compat_RunCommand(const char *, GNode *, StringListNode *);
void Compat_Run(GNodeList *);
void Compat_Make(GNode *, GNode *);