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): change return type of Var_Value to FStr



details:   https://anonhg.NetBSD.org/src/rev/0bd71cd9b4bd
branches:  trunk
changeset: 979242:0bd71cd9b4bd
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Dec 20 14:32:13 2020 +0000

description:
make(1): change return type of Var_Value to FStr

diffstat:

 usr.bin/make/cond.c    |  10 +++---
 usr.bin/make/main.c    |  66 ++++++++++++++++++++++---------------------------
 usr.bin/make/meta.c    |  64 ++++++++++++++++++++++-------------------------
 usr.bin/make/nonints.h |   4 +-
 usr.bin/make/parse.c   |  42 +++++++++++++++---------------
 usr.bin/make/trace.c   |   9 +++---
 usr.bin/make/var.c     |  17 ++++++------
 7 files changed, 101 insertions(+), 111 deletions(-)

diffs (truncated from 520 to 300 lines):

diff -r e97f76a61748 -r 0bd71cd9b4bd usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Sun Dec 20 13:50:10 2020 +0000
+++ b/usr.bin/make/cond.c       Sun Dec 20 14:32:13 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.229 2020/12/20 13:38:43 rillig Exp $        */
+/*     $NetBSD: cond.c,v 1.230 2020/12/20 14:32:13 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -94,7 +94,7 @@
 #include "dir.h"
 
 /*     "@(#)cond.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: cond.c,v 1.229 2020/12/20 13:38:43 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.230 2020/12/20 14:32:13 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -286,9 +286,9 @@
 static Boolean
 FuncDefined(size_t argLen MAKE_ATTR_UNUSED, const char *arg)
 {
-       void *freeIt;
-       Boolean result = Var_Value(arg, VAR_CMDLINE, &freeIt) != NULL;
-       bmake_free(freeIt);
+       FStr value = Var_Value(arg, VAR_CMDLINE);
+       Boolean result = value.str != NULL;
+       FStr_Done(&value);
        return result;
 }
 
diff -r e97f76a61748 -r 0bd71cd9b4bd usr.bin/make/main.c
--- a/usr.bin/make/main.c       Sun Dec 20 13:50:10 2020 +0000
+++ b/usr.bin/make/main.c       Sun Dec 20 14:32:13 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.498 2020/12/13 20:14:48 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.499 2020/12/20 14:32:13 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
 #include "trace.h"
 
 /*     "@(#)main.c     8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.498 2020/12/13 20:14:48 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.499 2020/12/20 14:32:13 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
            "The Regents of the University of California.  "
@@ -690,10 +690,9 @@
                return;
 
        {
-               void *freeIt;
-               const char *argv0 = Var_Value(".MAKE", VAR_GLOBAL, &freeIt);
-               buf = str_concat3(argv0, " ", line);
-               free(freeIt);
+               FStr argv0 = Var_Value(".MAKE", VAR_GLOBAL);
+               buf = str_concat3(argv0.str, " ", line);
+               FStr_Done(&argv0);
        }
 
        words = Str_Words(buf, TRUE);
@@ -751,29 +750,27 @@
 static Boolean
 SetVarObjdir(Boolean writable, const char *var, const char *suffix)
 {
-       void *path_freeIt;
-       const char *path = Var_Value(var, VAR_CMDLINE, &path_freeIt);
-       const char *xpath;
-       char *xpath_freeIt;
+       FStr path = Var_Value(var, VAR_CMDLINE);
+       FStr xpath;
 
-       if (path == NULL || path[0] == '\0') {
-               bmake_free(path_freeIt);
+       if (path.str == NULL || path.str[0] == '\0') {
+               FStr_Done(&path);
                return FALSE;
        }
 
        /* expand variable substitutions */
-       xpath = path;
-       xpath_freeIt = NULL;
-       if (strchr(path, '$') != 0) {
-               (void)Var_Subst(path, VAR_GLOBAL, VARE_WANTRES, &xpath_freeIt);
+       xpath = FStr_InitRefer(path.str);
+       if (strchr(path.str, '$') != 0) {
+               char *expanded;
+               (void)Var_Subst(path.str, VAR_GLOBAL, VARE_WANTRES, &expanded);
                /* TODO: handle errors */
-               xpath = xpath_freeIt;
+               xpath = FStr_InitOwn(expanded);
        }
 
-       (void)Main_SetObjdir(writable, "%s%s", xpath, suffix);
+       (void)Main_SetObjdir(writable, "%s%s", xpath.str, suffix);
 
-       bmake_free(xpath_freeIt);
-       bmake_free(path_freeIt);
+       FStr_Done(&xpath);
+       FStr_Done(&path);
        return TRUE;
 }
 
@@ -859,10 +856,9 @@
                bmake_free(evalue);
 
        } else {
-               void *freeIt;
-               const char *value = Var_Value(varname, VAR_GLOBAL, &freeIt);
-               printf("%s\n", value ? value : "");
-               bmake_free(freeIt);
+               FStr value = Var_Value(varname, VAR_GLOBAL);
+               printf("%s\n", value.str != NULL ? value.str : "");
+               FStr_Done(&value);
        }
 }
 
@@ -1047,21 +1043,20 @@
 HandlePWD(const struct stat *curdir_st)
 {
        char *pwd;
-       void *prefix_freeIt, *makeobjdir_freeIt;
-       const char *makeobjdir;
+       FStr prefix, makeobjdir;
        struct stat pwd_st;
 
        if (ignorePWD || (pwd = getenv("PWD")) == NULL)
                return;
 
-       if (Var_Value("MAKEOBJDIRPREFIX", VAR_CMDLINE, &prefix_freeIt) !=
-           NULL) {
-               bmake_free(prefix_freeIt);
+       prefix = Var_Value("MAKEOBJDIRPREFIX", VAR_CMDLINE);
+       if (prefix.str != NULL) {
+               FStr_Done(&prefix);
                return;
        }
 
-       makeobjdir = Var_Value("MAKEOBJDIR", VAR_CMDLINE, &makeobjdir_freeIt);
-       if (makeobjdir != NULL && strchr(makeobjdir, '$') != NULL)
+       makeobjdir = Var_Value("MAKEOBJDIR", VAR_CMDLINE);
+       if (makeobjdir.str != NULL && strchr(makeobjdir.str, '$') != NULL)
                goto ignore_pwd;
 
        if (stat(pwd, &pwd_st) == 0 &&
@@ -1070,7 +1065,7 @@
                (void)strncpy(curdir, pwd, MAXPATHLEN);
 
 ignore_pwd:
-       bmake_free(makeobjdir_freeIt);
+       FStr_Done(&makeobjdir);
 }
 #endif
 
@@ -1554,10 +1549,9 @@
        MakeMode(NULL);
 
        {
-               void *freeIt;
-               Var_Append("MFLAGS", Var_Value(MAKEFLAGS, VAR_GLOBAL, &freeIt),
-                   VAR_GLOBAL);
-               bmake_free(freeIt);
+               FStr makeflags = Var_Value(MAKEFLAGS, VAR_GLOBAL);
+               Var_Append("MFLAGS", makeflags.str, VAR_GLOBAL);
+               FStr_Done(&makeflags);
        }
 
        InitMaxJobs();
diff -r e97f76a61748 -r 0bd71cd9b4bd usr.bin/make/meta.c
--- a/usr.bin/make/meta.c       Sun Dec 20 13:50:10 2020 +0000
+++ b/usr.bin/make/meta.c       Sun Dec 20 14:32:13 2020 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: meta.c,v 1.160 2020/12/13 21:27:45 rillig Exp $ */
+/*      $NetBSD: meta.c,v 1.161 2020/12/20 14:32:13 rillig Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -323,8 +323,7 @@
     Boolean rc = FALSE;
 
     if (p_make == NULL) {
-       void *dontFreeIt;
-       p_make = Var_Value(".MAKE", gn, &dontFreeIt);
+       p_make = Var_Value(".MAKE", gn).str;
        p_len = strlen(p_make);
     }
     cp = strchr(cmd, '$');
@@ -473,21 +472,20 @@
     char buf[MAXPATHLEN];
     char objdir_realpath[MAXPATHLEN];
     char **ptr;
-    const char *dname;
+    FStr dname;
     const char *tname;
     char *fname;
     const char *cp;
-    void *dname_freeIt;
 
     fp = NULL;
 
-    dname = Var_Value(".OBJDIR", gn, &dname_freeIt);
+    dname = Var_Value(".OBJDIR", gn);
     tname = GNode_VarTarget(gn);
 
     /* if this succeeds objdir_realpath is realpath of dname */
-    if (!meta_needed(gn, dname, objdir_realpath, TRUE))
+    if (!meta_needed(gn, dname.str, objdir_realpath, TRUE))
        goto out;
-    dname = objdir_realpath;
+    dname.str = objdir_realpath;
 
     if (metaVerbose) {
        char *mp;
@@ -509,7 +507,7 @@
        goto out;
 
     fname = meta_name(pbm->meta_fname, sizeof pbm->meta_fname,
-                     dname, tname, objdir_realpath);
+                     dname.str, tname, objdir_realpath);
 
 #ifdef DEBUG_META_MODE
     DEBUG1(META, "meta_create: %s\n", fname);
@@ -544,7 +542,7 @@
            gn->type |= OP_SILENT;
     }
  out:
-    bmake_free(dname_freeIt);
+    FStr_Done(&dname);
 
     return fp;
 }
@@ -588,7 +586,7 @@
 {
     static Boolean once = FALSE;
     char *cp;
-    void *freeIt;
+    FStr value;
 
     useMeta = TRUE;
     useFilemon = TRUE;
@@ -644,15 +642,15 @@
     /*
      * We ignore any paths that match ${.MAKE.META.IGNORE_PATTERNS}
      */
-    freeIt = NULL;
-    if (Var_Value(MAKE_META_IGNORE_PATTERNS, VAR_GLOBAL, &freeIt)) {
+    value = Var_Value(MAKE_META_IGNORE_PATTERNS, VAR_GLOBAL);
+    if (value.str != NULL) {
        metaIgnorePatterns = TRUE;
-       bmake_free(freeIt);
+       FStr_Done(&value);
     }
-    freeIt = NULL;
-    if (Var_Value(MAKE_META_IGNORE_FILTER, VAR_GLOBAL, &freeIt)) {
+    value = Var_Value(MAKE_META_IGNORE_FILTER, VAR_GLOBAL);
+    if (value.str != NULL) {
        metaIgnoreFilter = TRUE;
-       bmake_free(freeIt);
+       FStr_Done(&value);
     }
 }
 
@@ -1075,7 +1073,7 @@
     char fname1[MAXPATHLEN];
     char fname2[MAXPATHLEN];
     char fname3[MAXPATHLEN];
-    const char *dname;
+    FStr dname;
     const char *tname;
     char *p;
     char *cp;
@@ -1087,18 +1085,17 @@
     Boolean needOODATE = FALSE;
     StringList missingFiles;
     Boolean have_filemon = FALSE;
-    void *objdir_freeIt;
 
     if (oodate)
        return oodate;          /* we're done */
 
-    dname = Var_Value(".OBJDIR", gn, &objdir_freeIt);
+    dname = Var_Value(".OBJDIR", gn);
     tname = GNode_VarTarget(gn);
 
     /* if this succeeds fname3 is realpath of dname */
-    if (!meta_needed(gn, dname, fname3, FALSE))
+    if (!meta_needed(gn, dname.str, fname3, FALSE))
        goto oodate_out;
-    dname = fname3;
+    dname.str = fname3;
 
     Lst_Init(&missingFiles);
 
@@ -1110,7 +1107,7 @@
      */
     Make_DoAllVar(gn);
 
-    meta_name(fname, sizeof fname, dname, tname, dname);



Home | Main Index | Thread Index | Old Index