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: merge duplicate code for memory handling ...



details:   https://anonhg.NetBSD.org/src/rev/c0ee6c635606
branches:  trunk
changeset: 1027610:c0ee6c635606
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Dec 13 02:34:15 2021 +0000

description:
make: merge duplicate code for memory handling in Var_Parse

No functional change.

diffstat:

 usr.bin/make/var.c |  65 +++++++++++++++++++----------------------------------
 1 files changed, 24 insertions(+), 41 deletions(-)

diffs (104 lines):

diff -r 6f853e8d5015 -r c0ee6c635606 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Mon Dec 13 02:22:14 2021 +0000
+++ b/usr.bin/make/var.c        Mon Dec 13 02:34:15 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.979 2021/12/13 02:22:14 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.980 2021/12/13 02:34:15 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.979 2021/12/13 02:22:14 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.980 2021/12/13 02:34:15 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -4452,12 +4452,8 @@
                 * is still undefined, Var_Parse will return an empty string
                 * instead of the actually computed value.
                 */
-               /*
-                * XXX: shortLived == true sounds more sensible, this will
-                * allow to merge duplicate code at the end of Var_Parse.
-                */
                v = VarNew(LazyBuf_DoneGet(&varname), "",
-                   false, false, false);
+                   true, false, false);
                *out_true_exprDefined = DEF_UNDEF;
        } else
                LazyBuf_Done(&varname);
@@ -4470,18 +4466,6 @@
        return true;
 }
 
-/* Free the short-lived variable, since we own it. */
-static void
-FreeShortLived(Var *v, Expr *expr)
-{
-       if (expr->value.str == v->val.data) {
-               /* move ownership */
-               expr->value.freeIt = v->val.data;
-               v->val.data = NULL;
-       }
-       VarFreeShortLived(v);
-}
-
 #if __STDC_VERSION__ >= 199901L
 #define Expr_Literal(name, value, emode, scope, defined) \
        { name, value, emode, scope, defined }
@@ -4669,31 +4653,30 @@
 
        *pp = p;
 
+       if (expr.defined == DEF_UNDEF) {
+               if (dynamic)
+                       Expr_SetValueOwn(&expr, bmake_strsedup(start, p));
+               else {
+                       /*
+                        * The expression is still undefined, therefore
+                        * discard the actual value and return an error marker
+                        * instead.
+                        */
+                       Expr_SetValueRefer(&expr,
+                           emode == VARE_UNDEFERR
+                               ? var_Error : varUndefined);
+               }
+       }
+
        if (v->shortLived) {
-               FreeShortLived(v, &expr);
-
-       } else if (expr.defined != DEF_REGULAR) {
-               if (expr.defined == DEF_UNDEF) {
-                       if (dynamic) {
-                               Expr_SetValueOwn(&expr,
-                                   bmake_strsedup(start, p));
-                       } else {
-                               /*
-                                * The expression is still undefined,
-                                * therefore discard the actual value and
-                                * return an error marker instead.
-                                */
-                               Expr_SetValueRefer(&expr,
-                                   emode == VARE_UNDEFERR
-                                       ? var_Error : varUndefined);
-                       }
+               if (expr.value.str == v->val.data) {
+                       /* move ownership */
+                       expr.value.freeIt = v->val.data;
+                       v->val.data = NULL;
                }
-               /* XXX: This is not standard memory management. */
-               if (expr.value.str != v->val.data)
-                       Buf_Done(&v->val);
-               FStr_Done(&v->name);
-               free(v);
+               VarFreeShortLived(v);
        }
+
        *out_val = expr.value;
        return VPR_OK;          /* XXX: Is not correct in all cases */
 }



Home | Main Index | Thread Index | Old Index