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): prepare Var_Subst for proper error han...



details:   https://anonhg.NetBSD.org/src/rev/810f93bcb940
branches:  trunk
changeset: 938988:810f93bcb940
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Sep 22 20:19:46 2020 +0000

description:
make(1): prepare Var_Subst for proper error handling

Returning a VarParseResult instead of a string makes it possible to let
the error bubble up, until it reaches the main expression.

diffstat:

 usr.bin/make/arch.c    |  11 +++++--
 usr.bin/make/compat.c  |   7 ++--
 usr.bin/make/for.c     |   8 +++--
 usr.bin/make/job.c     |  19 ++++++++-----
 usr.bin/make/main.c    |  64 +++++++++++++++++++++++++++++++----------------
 usr.bin/make/make.c    |   7 ++--
 usr.bin/make/meta.c    |  36 +++++++++++++++++---------
 usr.bin/make/nonints.h |   4 +-
 usr.bin/make/parse.c   |  29 ++++++++++++++-------
 usr.bin/make/suff.c    |   7 ++--
 usr.bin/make/var.c     |  67 +++++++++++++++++++++++++++++++++----------------
 11 files changed, 167 insertions(+), 92 deletions(-)

diffs (truncated from 772 to 300 lines):

diff -r 2783a11204b0 -r 810f93bcb940 usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Tue Sep 22 19:51:19 2020 +0000
+++ b/usr.bin/make/arch.c       Tue Sep 22 20:19:46 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.117 2020/09/22 04:05:41 rillig Exp $        */
+/*     $NetBSD: arch.c,v 1.118 2020/09/22 20:19:46 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -133,7 +133,7 @@
 #include    "config.h"
 
 /*     "@(#)arch.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: arch.c,v 1.117 2020/09/22 04:05:41 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.118 2020/09/22 20:19:46 rillig Exp $");
 
 #ifdef TARGET_MACHINE
 #undef MAKE_MACHINE
@@ -247,7 +247,8 @@
 
     *cp++ = '\0';
     if (subLibName) {
-       libName = Var_Subst(libName, ctxt, VARE_UNDEFERR|VARE_WANTRES);
+       (void)Var_Subst(libName, ctxt, VARE_UNDEFERR|VARE_WANTRES, &libName);
+       /* TODO: handle errors */
     }
 
 
@@ -327,7 +328,9 @@
            char    *sacrifice;
            char    *oldMemName = memName;
 
-           memName = Var_Subst(memName, ctxt, VARE_UNDEFERR | VARE_WANTRES);
+           (void)Var_Subst(memName, ctxt, VARE_UNDEFERR | VARE_WANTRES,
+                           &memName);
+           /* TODO: handle errors */
 
            /*
             * Now form an archive spec and recurse to deal with nested
diff -r 2783a11204b0 -r 810f93bcb940 usr.bin/make/compat.c
--- a/usr.bin/make/compat.c     Tue Sep 22 19:51:19 2020 +0000
+++ b/usr.bin/make/compat.c     Tue Sep 22 20:19:46 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat.c,v 1.147 2020/09/22 04:05:41 rillig Exp $      */
+/*     $NetBSD: compat.c,v 1.148 2020/09/22 20:19:46 rillig Exp $      */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -99,7 +99,7 @@
 #include    "pathnames.h"
 
 /*     "@(#)compat.c   8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: compat.c,v 1.147 2020/09/22 04:05:41 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.148 2020/09/22 20:19:46 rillig Exp $");
 
 static GNode       *curTarg = NULL;
 static GNode       *ENDNode;
@@ -209,7 +209,8 @@
     doIt = FALSE;
 
     cmdNode = Lst_FindDatum(gn->commands, cmd);
-    cmdStart = Var_Subst(cmd, gn, VARE_WANTRES);
+    (void)Var_Subst(cmd, gn, VARE_WANTRES, &cmdStart);
+    /* TODO: handle errors */
 
     /*
      * brk_string will return an argv with a NULL in av[0], thus causing
diff -r 2783a11204b0 -r 810f93bcb940 usr.bin/make/for.c
--- a/usr.bin/make/for.c        Tue Sep 22 19:51:19 2020 +0000
+++ b/usr.bin/make/for.c        Tue Sep 22 20:19:46 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: for.c,v 1.84 2020/09/14 20:43:44 rillig Exp $  */
+/*     $NetBSD: for.c,v 1.85 2020/09/22 20:19:46 rillig Exp $  */
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -60,7 +60,7 @@
 #include    "strlist.h"
 
 /*     "@(#)for.c      8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: for.c,v 1.84 2020/09/14 20:43:44 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.85 2020/09/22 20:19:46 rillig Exp $");
 
 typedef enum {
     FOR_SUB_ESCAPE_CHAR = 0x0001,
@@ -190,7 +190,9 @@
      * we will be substituting into ${...} or $(...).
      */
     {
-       char *items = Var_Subst(ptr, VAR_GLOBAL, VARE_WANTRES);
+       char *items;
+       (void)Var_Subst(ptr, VAR_GLOBAL, VARE_WANTRES, &items);
+       /* TODO: handle errors */
        words = Str_Words(items, FALSE);
        free(items);
     }
diff -r 2783a11204b0 -r 810f93bcb940 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Tue Sep 22 19:51:19 2020 +0000
+++ b/usr.bin/make/job.c        Tue Sep 22 20:19:46 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.233 2020/09/21 17:44:25 rillig Exp $ */
+/*     $NetBSD: job.c,v 1.234 2020/09/22 20:19:46 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -140,7 +140,7 @@
 #include "trace.h"
 
 /*     "@(#)job.c      8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: job.c,v 1.233 2020/09/21 17:44:25 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.234 2020/09/22 20:19:46 rillig Exp $");
 
 # define STATIC static
 
@@ -712,7 +712,9 @@
 
     numCommands += 1;
 
-    cmdStart = cmd = Var_Subst(cmd, job->node, VARE_WANTRES);
+    Var_Subst(cmd, job->node, VARE_WANTRES, &cmd);
+    /* TODO: handle errors */
+    cmdStart = cmd;
 
     cmdTemplate = "%s\n";
 
@@ -902,8 +904,10 @@
 static int
 JobSaveCommand(void *cmd, void *gn)
 {
-    cmd = Var_Subst((char *)cmd, (GNode *)gn, VARE_WANTRES);
-    Lst_Append(postCommands->commands, cmd);
+    char *expanded_cmd;
+    (void)Var_Subst(cmd, (GNode *)gn, VARE_WANTRES, &expanded_cmd);
+    /* TODO: handle errors */
+    Lst_Append(postCommands->commands, expanded_cmd);
     return 0;
 }
 
@@ -2209,8 +2213,9 @@
        Var_Set(MAKE_JOB_PREFIX, "---", VAR_GLOBAL);
     }
 
-    targPrefix = Var_Subst("${" MAKE_JOB_PREFIX "}",
-                          VAR_GLOBAL, VARE_WANTRES);
+    (void)Var_Subst("${" MAKE_JOB_PREFIX "}",
+                   VAR_GLOBAL, VARE_WANTRES, &targPrefix);
+    /* TODO: handle errors */
 }
 
 /* Initialize the process module. */
diff -r 2783a11204b0 -r 810f93bcb940 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Tue Sep 22 19:51:19 2020 +0000
+++ b/usr.bin/make/main.c       Tue Sep 22 20:19:46 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.340 2020/09/22 19:51:19 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.341 2020/09/22 20:19:46 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -126,7 +126,7 @@
 #endif
 
 /*     "@(#)main.c     8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.340 2020/09/22 19:51:19 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.341 2020/09/22 20:19:46 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\
  The Regents of the University of California.  All rights reserved.");
@@ -761,9 +761,11 @@
        /* expand variable substitutions */
        xpath = path;
        xpath_freeIt = NULL;
-       if (strchr(path, '$') != 0)
-               xpath = xpath_freeIt = Var_Subst(path, VAR_GLOBAL,
-                                                VARE_WANTRES);
+       if (strchr(path, '$') != 0) {
+               (void)Var_Subst(path, VAR_GLOBAL, VARE_WANTRES, &xpath_freeIt);
+               /* TODO: handle errors */
+               xpath = xpath_freeIt;
+       }
 
        (void)Main_SetObjdir("%s%s", xpath, suffix);
 
@@ -828,9 +830,12 @@
 {
     char *mode_freeIt = NULL;
 
-    if (mode == NULL)
-       mode = mode_freeIt = Var_Subst("${" MAKE_MODE ":tl}",
-                                      VAR_GLOBAL, VARE_WANTRES);
+    if (mode == NULL) {
+       (void)Var_Subst("${" MAKE_MODE ":tl}",
+                 VAR_GLOBAL, VARE_WANTRES, &mode_freeIt);
+       /* TODO: handle errors */
+       mode = mode_freeIt;
+    }
 
     if (mode[0] != '\0') {
        if (strstr(mode, "compat")) {
@@ -865,10 +870,14 @@
                char *p1;
 
                if (strchr(var, '$')) {
-                       value = p1 = Var_Subst(var, VAR_GLOBAL, VARE_WANTRES);
+                       (void)Var_Subst(var, VAR_GLOBAL, VARE_WANTRES, &p1);
+                       /* TODO: handle errors */
+                       value = p1;
                } else if (expandVars) {
                        char *expr = str_concat3("${", var, "}");
-                       value = p1 = Var_Subst(expr, VAR_GLOBAL, VARE_WANTRES);
+                       (void)Var_Subst(expr, VAR_GLOBAL, VARE_WANTRES, &p1);
+                       /* TODO: handle errors */
+                       value = p1;
                        free(expr);
                } else {
                        value = Var_Value(var, VAR_GLOBAL, &p1);
@@ -1331,8 +1340,9 @@
                        Fatal("%s: cannot open %s.", progname,
                            (char *)LstNode_Datum(ln));
        } else {
-               p1 = Var_Subst("${" MAKEFILE_PREFERENCE "}",
-                              VAR_CMD, VARE_WANTRES);
+               (void)Var_Subst("${" MAKEFILE_PREFERENCE "}",
+                   VAR_CMD, VARE_WANTRES, &p1);
+               /* TODO: handle errors */
                (void)str2Lst_Append(makefiles, p1, NULL);
                (void)Lst_Find(makefiles, ReadMakefileSucceeded, NULL);
                free(p1);
@@ -1340,8 +1350,9 @@
 
        /* In particular suppress .depend for '-r -V .OBJDIR -f /dev/null' */
        if (!noBuiltins || !printVars) {
-           makeDependfile = Var_Subst("${.MAKE.DEPENDFILE:T}",
-               VAR_CMD, VARE_WANTRES);
+           (void)Var_Subst("${.MAKE.DEPENDFILE:T}",
+               VAR_CMD, VARE_WANTRES, &makeDependfile);
+           /* TODO: handle errors */
            doing_depend = TRUE;
            (void)ReadMakefile(makeDependfile);
            doing_depend = FALSE;
@@ -1360,7 +1371,8 @@
            char *value;
            int n;
 
-           value = Var_Subst("${.MAKE.JOBS}", VAR_GLOBAL, VARE_WANTRES);
+           (void)Var_Subst("${.MAKE.JOBS}", VAR_GLOBAL, VARE_WANTRES, &value);
+           /* TODO: handle errors */
            n = strtol(value, NULL, 0);
            if (n < 1) {
                (void)fprintf(stderr, "%s: illegal value for .MAKE.JOBS -- must be positive integer!\n",
@@ -1411,7 +1423,8 @@
                 */
                static char VPATH[] = "${VPATH}";
 
-               vpath = Var_Subst(VPATH, VAR_CMD, VARE_WANTRES);
+               (void)Var_Subst(VPATH, VAR_CMD, VARE_WANTRES, &vpath);
+               /* TODO: handle errors */
                path = vpath;
                do {
                        /* skip to end of directory */
@@ -2005,7 +2018,8 @@
        Lst_ForEach(gn->commands, addErrorCMD, gn);
     }
     expr = "${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'\n@}";
-    cp = Var_Subst(expr, VAR_GLOBAL, VARE_WANTRES);
+    (void)Var_Subst(expr, VAR_GLOBAL, VARE_WANTRES, &cp);
+    /* TODO: handle errors */
     printf("%s", cp);
     free(cp);
     fflush(stdout);
@@ -2032,7 +2046,8 @@
     once = FALSE;
 
     expr = "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}";
-    s = Var_Subst(expr, VAR_CMD, VARE_WANTRES);
+    (void)Var_Subst(expr, VAR_CMD, VARE_WANTRES, &s);
+    /* TODO: handle errors */
     if (s[0] != '\0') {
 #ifdef POSIX
        setenv("MAKEFLAGS", s, 1);
@@ -2054,8 +2069,9 @@
         * Honor $TMPDIR but only if it is valid.
         * Ensure it ends with /.
         */
-       tmpdir = Var_Subst("${TMPDIR:tA:U" _PATH_TMP "}/", VAR_GLOBAL,
-                          VARE_WANTRES);
+       (void)Var_Subst("${TMPDIR:tA:U" _PATH_TMP "}/", VAR_GLOBAL,
+                       VARE_WANTRES, &tmpdir);
+       /* TODO: handle errors */
        if (stat(tmpdir, &st) < 0 || !S_ISDIR(st.st_mode)) {
            free(tmpdir);
            tmpdir = bmake_strdup(_PATH_TMP);
@@ -2145,8 +2161,12 @@
 getBoolean(const char *name, Boolean fallback)
 {
     char *expr = str_concat3("${", name, ":U:tl}");
-    char *value = Var_Subst(expr, VAR_GLOBAL, VARE_WANTRES);
-    Boolean res = s2Boolean(value, fallback);
+    char *value;
+    Boolean res;



Home | Main Index | Thread Index | Old Index