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): omit linear search for command in Comp...



details:   https://anonhg.NetBSD.org/src/rev/c241b66f7342
branches:  trunk
changeset: 948214:c241b66f7342
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Dec 20 21:07:32 2020 +0000

description:
make(1): omit linear search for command in Compat_RunCommand

diffstat:

 usr.bin/make/compat.c  |  22 ++++++++--------------
 usr.bin/make/job.c     |  10 +++++-----
 usr.bin/make/nonints.h |   4 ++--
 3 files changed, 15 insertions(+), 21 deletions(-)

diffs (146 lines):

diff -r 0c3f5808a032 -r c241b66f7342 usr.bin/make/compat.c
--- a/usr.bin/make/compat.c     Sun Dec 20 19:51:37 2020 +0000
+++ b/usr.bin/make/compat.c     Sun Dec 20 21:07:32 2020 +0000
@@ -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 @@
  *
  * 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 @@
        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 @@
        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 @@
                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 @@
 
        /* 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 @@
 
        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;
        }
 }
diff -r 0c3f5808a032 -r c241b66f7342 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Sun Dec 20 19:51:37 2020 +0000
+++ b/usr.bin/make/job.c        Sun Dec 20 21:07:32 2020 +0000
@@ -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 @@
  * 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 @@
                 * 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 @@
                        break;
                }
 
-               JobPrintCommand(job, &wr, ln->datum);
+               JobPrintCommand(job, &wr, ln, ln->datum);
                seen = TRUE;
        }
 
diff -r 0c3f5808a032 -r c241b66f7342 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Sun Dec 20 19:51:37 2020 +0000
+++ b/usr.bin/make/nonints.h    Sun Dec 20 21:07:32 2020 +0000
@@ -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_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 *);
 



Home | Main Index | Thread Index | Old Index