Module Name:    src
Committed By:   rillig
Date:           Sun Mar 14 19:21:29 UTC 2021

Modified Files:
        src/usr.bin/make: var.c
        src/usr.bin/make/unit-tests: var-eval-short.exp var-eval-short.mk

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

No functional change outside debug mode.


To generate a diff of this commit:
cvs rdiff -u -r1.874 -r1.875 src/usr.bin/make/var.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/var-eval-short.exp
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/var-eval-short.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.874 src/usr.bin/make/var.c:1.875
--- src/usr.bin/make/var.c:1.874	Sun Mar 14 18:30:24 2021
+++ src/usr.bin/make/var.c	Sun Mar 14 19:21:28 2021
@@ -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 @@ ApplyModifier_IfElse(const char **pp, Ap
 		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 {

Index: src/usr.bin/make/unit-tests/var-eval-short.exp
diff -u src/usr.bin/make/unit-tests/var-eval-short.exp:1.4 src/usr.bin/make/unit-tests/var-eval-short.exp:1.5
--- src/usr.bin/make/unit-tests/var-eval-short.exp:1.4	Sun Mar 14 19:16:41 2021
+++ src/usr.bin/make/unit-tests/var-eval-short.exp	Sun Mar 14 19:21:28 2021
@@ -9,8 +9,8 @@ Var_Parse: ${0:?${FAIL}then:${FAIL}else}
 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 @@ Result of ${DEFINED:L} is "defined" (non
 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

Index: src/usr.bin/make/unit-tests/var-eval-short.mk
diff -u src/usr.bin/make/unit-tests/var-eval-short.mk:1.2 src/usr.bin/make/unit-tests/var-eval-short.mk:1.3
--- src/usr.bin/make/unit-tests/var-eval-short.mk:1.2	Sun Mar 14 19:16:41 2021
+++ src/usr.bin/make/unit-tests/var-eval-short.mk	Sun Mar 14 19:21:28 2021
@@ -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 @@ DEFINED=	# defined
 .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 @@ DEFINED=	# defined
 # 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

Reply via email to