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: do not return unevaluated 'else' part fro...



details:   https://anonhg.NetBSD.org/src/rev/b67e2b1ad341
branches:  trunk
changeset: 953638:b67e2b1ad341
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Mar 14 19:21:28 2021 +0000

description:
make: do not return unevaluated 'else' part from the ':?' modifier

No functional change outside debug mode.

diffstat:

 usr.bin/make/unit-tests/var-eval-short.exp |  8 ++++----
 usr.bin/make/unit-tests/var-eval-short.mk  |  7 ++++---
 usr.bin/make/var.c                         |  9 ++++++---
 3 files changed, 14 insertions(+), 10 deletions(-)

diffs (83 lines):

diff -r 42e3b9d3731d -r b67e2b1ad341 usr.bin/make/unit-tests/var-eval-short.exp
--- a/usr.bin/make/unit-tests/var-eval-short.exp        Sun Mar 14 19:16:41 2021 +0000
+++ b/usr.bin/make/unit-tests/var-eval-short.exp        Sun Mar 14 19:21:28 2021 +0000
@@ -9,8 +9,8 @@
 Applying ${0:?...} to "" (none, none, undefined)
 Modifier part: "${FAIL}then"
 Modifier part: "${FAIL}else"
-Result of ${0:?${FAIL}then:${FAIL}else} is "${FAIL}else" (none, none, defined)
-ParseReadLine (141): 'DEFINED= defined'
+Result of ${0:?${FAIL}then:${FAIL}else} is "" (none, none, defined)
+ParseReadLine (142): 'DEFINED= defined'
 Global:DEFINED = defined
 CondParser_Eval: 0 && ${DEFINED:L:?${FAIL}then:${FAIL}else}
 Var_Parse: ${DEFINED:L:?${FAIL}then:${FAIL}else} with none
@@ -19,8 +19,8 @@
 Applying ${DEFINED:?...} to "defined" (none, none, regular)
 Modifier part: "${FAIL}then"
 Modifier part: "${FAIL}else"
-Result of ${DEFINED:?${FAIL}then:${FAIL}else} is "${FAIL}else" (none, none, regular)
-ParseReadLine (144): '.MAKEFLAGS: -d0'
+Result of ${DEFINED:?${FAIL}then:${FAIL}else} is "defined" (none, none, regular)
+ParseReadLine (145): '.MAKEFLAGS: -d0'
 ParseDoDependency(.MAKEFLAGS: -d0)
 Global:.MAKEFLAGS =  -r -k -d cpv -d
 Global:.MAKEFLAGS =  -r -k -d cpv -d 0
diff -r 42e3b9d3731d -r b67e2b1ad341 usr.bin/make/unit-tests/var-eval-short.mk
--- a/usr.bin/make/unit-tests/var-eval-short.mk Sun Mar 14 19:16:41 2021 +0000
+++ b/usr.bin/make/unit-tests/var-eval-short.mk Sun Mar 14 19:21:28 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: var-eval-short.mk,v 1.2 2021/03/14 19:16:41 rillig Exp $
+# $NetBSD: var-eval-short.mk,v 1.3 2021/03/14 19:21:28 rillig Exp $
 #
 # Tests for each variable modifier to ensure that they only do the minimum
 # necessary computations.  If the result of the expression is not needed, they
@@ -125,7 +125,7 @@
 .if 0 && ${:Uword:word=replacement}
 .endif
 
-# Before var.c 1.XXX from 2021-03-14, Var_Parse returned "${FAIL}else" for the
+# Before var.c 1.875 from 2021-03-14, Var_Parse returned "${FAIL}else" for the
 # irrelevant right-hand side of the condition, even though this was not
 # necessary.  Since the return value from Var_Parse is supposed to be ignored
 # anyway, and since it is actually ignored in an overly complicated way,
@@ -137,7 +137,8 @@
 # The ':L' is applied before the ':?' modifier, giving the expression a name
 # and a value, just to see whether this value gets passed through or whether
 # the parse-only mode results in an empty string (only visible in the debug
-# log).
+# log).  As of var.c 1.875 from 2021-03-14, the value of the variable gets
+# through, even though an empty string would suffice.
 DEFINED=       defined
 .if 0 && ${DEFINED:L:?${FAIL}then:${FAIL}else}
 .endif
diff -r 42e3b9d3731d -r b67e2b1ad341 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Mar 14 19:16:41 2021 +0000
+++ b/usr.bin/make/var.c        Sun Mar 14 19:21:28 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.874 2021/03/14 18:30:24 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.875 2021/03/14 19:21:28 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.874 2021/03/14 18:30:24 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.875 2021/03/14 19:21:28 rillig Exp $");
 
 typedef enum VarFlags {
        VFL_NONE        = 0,
@@ -3322,7 +3322,10 @@
                return AMR_CLEANUP;
        }
 
-       if (value) {
+       if (!(expr->eflags & VARE_WANTRES)) {
+               free(then_expr);
+               free(else_expr);
+       } else if (value) {
                Expr_SetValueOwn(expr, then_expr);
                free(else_expr);
        } else {



Home | Main Index | Thread Index | Old Index