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): return FStr from Var_Parse



details:   https://anonhg.NetBSD.org/src/rev/80dcfa4bacc4
branches:  trunk
changeset: 958015:80dcfa4bacc4
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Dec 20 13:38:43 2020 +0000

description:
make(1): return FStr from Var_Parse

This reduces the number of variable declarations at the call sites.

diffstat:

 usr.bin/make/arch.c    |   23 +++----
 usr.bin/make/cond.c    |   31 +++++------
 usr.bin/make/nonints.h |    5 +-
 usr.bin/make/parse.c   |   11 +--
 usr.bin/make/suff.c    |   14 ++--
 usr.bin/make/var.c     |  133 +++++++++++++++++++++----------------------------
 6 files changed, 94 insertions(+), 123 deletions(-)

diffs (truncated from 575 to 300 lines):

diff -r e8dc8ef4e97e -r 80dcfa4bacc4 usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Sun Dec 20 13:03:48 2020 +0000
+++ b/usr.bin/make/arch.c       Sun Dec 20 13:38:43 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.189 2020/12/18 15:47:34 rillig Exp $        */
+/*     $NetBSD: arch.c,v 1.190 2020/12/20 13:38:43 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -125,7 +125,7 @@
 #include "config.h"
 
 /*     "@(#)arch.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: arch.c,v 1.189 2020/12/18 15:47:34 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.190 2020/12/20 13:38:43 rillig Exp $");
 
 typedef struct List ArchList;
 typedef struct ListNode ArchListNode;
@@ -202,17 +202,15 @@
                        /* Expand nested variable expressions. */
                        /* XXX: This code can probably be shortened. */
                        const char *nested_p = cp;
-                       void *result_freeIt;
-                       const char *result;
+                       FStr result;
                        Boolean isError;
 
                        /* XXX: is expanded twice: once here and once below */
                        (void)Var_Parse(&nested_p, ctxt,
-                                       VARE_WANTRES | VARE_UNDEFERR,
-                                       &result, &result_freeIt);
+                                       VARE_WANTRES | VARE_UNDEFERR, &result);
                        /* TODO: handle errors */
-                       isError = result == var_Error;
-                       free(result_freeIt);
+                       isError = result.str == var_Error;
+                       FStr_Done(&result);
                        if (isError)
                                return FALSE;
 
@@ -246,17 +244,16 @@
                        if (*cp == '$') {
                                /* Expand nested variable expressions. */
                                /* XXX: This code can probably be shortened. */
-                               void *freeIt;
-                               const char *result;
+                               FStr result;
                                Boolean isError;
                                const char *nested_p = cp;
 
                                (void)Var_Parse(&nested_p, ctxt,
                                                VARE_WANTRES | VARE_UNDEFERR,
-                                               &result, &freeIt);
+                                               &result);
                                /* TODO: handle errors */
-                               isError = result == var_Error;
-                               free(freeIt);
+                               isError = result.str == var_Error;
+                               FStr_Done(&result);
 
                                if (isError)
                                        return FALSE;
diff -r e8dc8ef4e97e -r 80dcfa4bacc4 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Sun Dec 20 13:03:48 2020 +0000
+++ b/usr.bin/make/cond.c       Sun Dec 20 13:38:43 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.228 2020/12/20 13:03:48 rillig Exp $        */
+/*     $NetBSD: cond.c,v 1.229 2020/12/20 13:38:43 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.228 2020/12/20 13:03:48 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.229 2020/12/20 13:38:43 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -247,16 +247,14 @@
                         * so we don't need to do it. Nor do we return an
                         * error, though perhaps we should.
                         */
-                       void *nestedVal_freeIt;
                        VarEvalFlags eflags = doEval
                            ? VARE_WANTRES | VARE_UNDEFERR
                            : VARE_NONE;
-                       const char *nestedVal;
-                       (void)Var_Parse(&p, VAR_CMDLINE, eflags,
-                                       &nestedVal, &nestedVal_freeIt);
+                       FStr nestedVal;
+                       (void)Var_Parse(&p, VAR_CMDLINE, eflags, &nestedVal);
                        /* TODO: handle errors */
-                       Buf_AddStr(&argBuf, nestedVal);
-                       free(nestedVal_freeIt);
+                       Buf_AddStr(&argBuf, nestedVal.str);
+                       FStr_Done(&nestedVal);
                        continue;
                }
                if (ch == '(')
@@ -451,7 +449,7 @@
                        nested_p = par->p;
                        atStart = nested_p == start;
                        parseResult = Var_Parse(&nested_p, VAR_CMDLINE, eflags,
-                                               &str.str, &str.freeIt);
+                           &str);
                        /* TODO: handle errors */
                        if (str.str == var_Error) {
                                if (parseResult & VPR_ANY_MSG)
@@ -693,8 +691,7 @@
 ParseEmptyArg(const char **pp, Boolean doEval,
              const char *func MAKE_ATTR_UNUSED, char **out_arg)
 {
-       void *val_freeIt;
-       const char *val;
+       FStr val;
        size_t magic_res;
 
        /* We do all the work here and return the result as the length */
@@ -702,12 +699,12 @@
 
        (*pp)--;                /* Make (*pp)[1] point to the '('. */
        (void)Var_Parse(pp, VAR_CMDLINE, doEval ? VARE_WANTRES : VARE_NONE,
-                       &val, &val_freeIt);
+           &val);
        /* TODO: handle errors */
        /* If successful, *pp points beyond the closing ')' now. */
 
-       if (val == var_Error) {
-               free(val_freeIt);
+       if (val.str == var_Error) {
+               FStr_Done(&val);
                return (size_t)-1;
        }
 
@@ -715,14 +712,14 @@
         * A variable is empty when it just contains spaces...
         * 4/15/92, christos
         */
-       cpp_skip_whitespace(&val);
+       cpp_skip_whitespace(&val.str);
 
        /*
         * For consistency with the other functions we can't generate the
         * true/false here.
         */
-       magic_res = *val != '\0' ? 2 : 1;
-       free(val_freeIt);
+       magic_res = val.str[0] != '\0' ? 2 : 1;
+       FStr_Done(&val);
        return magic_res;
 }
 
diff -r e8dc8ef4e97e -r 80dcfa4bacc4 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Sun Dec 20 13:03:48 2020 +0000
+++ b/usr.bin/make/nonints.h    Sun Dec 20 13:38:43 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nonints.h,v 1.176 2020/12/20 12:53:34 rillig Exp $     */
+/*     $NetBSD: nonints.h,v 1.177 2020/12/20 13:38:43 rillig Exp $     */
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -404,8 +404,7 @@
 Boolean Var_Exists(const char *, GNode *);
 const char *Var_Value(const char *, GNode *, void **);
 const char *Var_ValueDirect(const char *, GNode *);
-VarParseResult Var_Parse(const char **, GNode *, VarEvalFlags,
-                        const char **, void **);
+VarParseResult Var_Parse(const char **, GNode *, VarEvalFlags, FStr *);
 VarParseResult Var_Subst(const char *, GNode *, VarEvalFlags, char **);
 void Var_Stats(void);
 void Var_Dump(GNode *);
diff -r e8dc8ef4e97e -r 80dcfa4bacc4 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sun Dec 20 13:03:48 2020 +0000
+++ b/usr.bin/make/parse.c      Sun Dec 20 13:38:43 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.503 2020/12/19 22:33:11 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.504 2020/12/20 13:38:43 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
 #include "pathnames.h"
 
 /*     "@(#)parse.c    8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.503 2020/12/19 22:33:11 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.504 2020/12/20 13:38:43 rillig Exp $");
 
 /* types and constants */
 
@@ -1080,14 +1080,13 @@
                         * we wouldn't be here.
                         */
                        const char *nested_p = cp;
-                       const char *nested_val;
-                       void *freeIt;
+                       FStr nested_val;
 
                        /* XXX: Why VARE_WANTRES? */
                        (void)Var_Parse(&nested_p, VAR_CMDLINE,
-                           VARE_WANTRES | VARE_UNDEFERR, &nested_val, &freeIt);
+                           VARE_WANTRES | VARE_UNDEFERR, &nested_val);
                        /* TODO: handle errors */
-                       free(freeIt);
+                       FStr_Done(&nested_val);
                        cp += nested_p - cp;
                } else
                        cp++;
diff -r e8dc8ef4e97e -r 80dcfa4bacc4 usr.bin/make/suff.c
--- a/usr.bin/make/suff.c       Sun Dec 20 13:03:48 2020 +0000
+++ b/usr.bin/make/suff.c       Sun Dec 20 13:38:43 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: suff.c,v 1.331 2020/12/18 15:47:34 rillig Exp $        */
+/*     $NetBSD: suff.c,v 1.332 2020/12/20 13:38:43 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -114,7 +114,7 @@
 #include "dir.h"
 
 /*     "@(#)suff.c     8.4 (Berkeley) 3/21/94" */
-MAKE_RCSID("$NetBSD: suff.c,v 1.331 2020/12/18 15:47:34 rillig Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.332 2020/12/20 13:38:43 rillig Exp $");
 
 typedef List SuffixList;
 typedef ListNode SuffixListNode;
@@ -1300,13 +1300,11 @@
                } else if (*cp == '$') {
                        /* Skip over the variable expression. */
                        const char *nested_p = cp;
-                       const char *junk;
-                       void *freeIt;
+                       FStr junk;
 
-                       (void)Var_Parse(&nested_p, pgn,
-                           VARE_NONE, &junk, &freeIt);
+                       (void)Var_Parse(&nested_p, pgn, VARE_NONE, &junk);
                        /* TODO: handle errors */
-                       if (junk == var_Error) {
+                       if (junk.str == var_Error) {
                                Parse_Error(PARSE_FATAL,
                                    "Malformed variable expression at \"%s\"",
                                    cp);
@@ -1315,7 +1313,7 @@
                                cp += nested_p - cp;
                        }
 
-                       free(freeIt);
+                       FStr_Done(&junk);
                } else if (cp[0] == '\\' && cp[1] != '\0') {
                        /* Escaped something -- skip over it. */
                        /*
diff -r e8dc8ef4e97e -r 80dcfa4bacc4 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Dec 20 13:03:48 2020 +0000
+++ b/usr.bin/make/var.c        Sun Dec 20 13:38:43 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.742 2020/12/20 12:53:34 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.743 2020/12/20 13:38:43 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.742 2020/12/20 12:53:34 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.743 2020/12/20 13:38:43 rillig Exp $");
 
 typedef enum VarFlags {
        VAR_NONE        = 0,
@@ -2044,16 +2044,15 @@
 
                if (eflags & VARE_WANTRES) { /* Nested variable, evaluated */
                        const char *nested_p = p;
-                       const char *nested_val;
-                       void *nested_val_freeIt;
+                       FStr nested_val;
                        VarEvalFlags nested_eflags =
                            eflags & ~(unsigned)VARE_KEEP_DOLLAR;
 
                        (void)Var_Parse(&nested_p, st->ctxt, nested_eflags,
-                           &nested_val, &nested_val_freeIt);
+                           &nested_val);
                        /* TODO: handle errors */
-                       Buf_AddStr(&buf, nested_val);
-                       free(nested_val_freeIt);
+                       Buf_AddStr(&buf, nested_val.str);
+                       FStr_Done(&nested_val);
                        p += nested_p - p;
                        continue;
                }
@@ -2266,14 +2265,12 @@
 
                /* Nested variable expression */
                if (*p == '$') {
-                       const char *nested_val;
-                       void *nested_val_freeIt;
-
-                       (void)Var_Parse(&p, st->ctxt, eflags,



Home | Main Index | Thread Index | Old Index