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): error out if .undef has not exactly 1 ...
details: https://anonhg.NetBSD.org/src/rev/90579d9180d2
branches: trunk
changeset: 957993:90579d9180d2
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Dec 19 22:10:17 2020 +0000
description:
make(1): error out if .undef has not exactly 1 argument
diffstat:
usr.bin/make/unit-tests/directive-undef.exp | 6 +++-
usr.bin/make/unit-tests/directive-undef.mk | 38 +++++++++++++++++++++++++---
usr.bin/make/var.c | 29 +++++++++++++++++++---
3 files changed, 64 insertions(+), 9 deletions(-)
diffs (122 lines):
diff -r ef958efd1642 -r 90579d9180d2 usr.bin/make/unit-tests/directive-undef.exp
--- a/usr.bin/make/unit-tests/directive-undef.exp Sat Dec 19 21:54:42 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-undef.exp Sat Dec 19 22:10:17 2020 +0000
@@ -1,1 +1,5 @@
-exit status 0
+make: "directive-undef.mk" line 14: The .undef directive requires exactly 1 argument
+make: "directive-undef.mk" line 24: The .undef directive requires exactly 1 argument
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff -r ef958efd1642 -r 90579d9180d2 usr.bin/make/unit-tests/directive-undef.mk
--- a/usr.bin/make/unit-tests/directive-undef.mk Sat Dec 19 21:54:42 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-undef.mk Sat Dec 19 22:10:17 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: directive-undef.mk,v 1.7 2020/12/19 20:35:39 rillig Exp $
+# $NetBSD: directive-undef.mk,v 1.8 2020/12/19 22:10:18 rillig Exp $
#
# Tests for the .undef directive.
#
@@ -16,9 +16,39 @@
. warning $1$2$3
.endif
-# Without any arguments, .undef tries to delete the variable with the empty
-# name, which never exists; see varname-empty.mk.
-.undef # oops: missing argument
+
+# Without any arguments, until var.c 1.736 from 2020-12-19, .undef tried
+# to delete the variable with the empty name, which never exists; see
+# varname-empty.mk. Since var.c 1.737 from 2020-12-19, .undef complains
+# about a missing argument.
+.undef
+
+
+# Trying to delete the variable with the empty name is ok, it just won't
+# ever do anything since that variable is never defined.
+.undef ${:U}
+
+
+# The argument of .undef is a single word, delimited by whitespace, without
+# any possibility of escaping or having variable expressions containing
+# spaces. This word is then expanded exactly once, and the expanded string
+# is the single variable name. This allows variable names to contain spaces,
+# as well as unbalanced single and double quotes.
+1= 1
+2= 2
+3= 3
+${:U1 2 3}= one two three
+VARNAMES= 1 2 3
+.undef ${VARNAMES} # undefines the variable "1 2 3"
+.if defined(${:U1 2 3})
+. error
+.endif
+.if ${1}${2}${3} != "123" # these are still defined
+. error
+.endif
+.undef 1
+.undef 2
+.undef 3
# It must be possible to undefine variables whose name includes spaces.
diff -r ef958efd1642 -r 90579d9180d2 usr.bin/make/var.c
--- a/usr.bin/make/var.c Sat Dec 19 21:54:42 2020 +0000
+++ b/usr.bin/make/var.c Sat Dec 19 22:10:17 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.736 2020/12/19 20:47:24 rillig Exp $ */
+/* $NetBSD: var.c,v 1.737 2020/12/19 22:10:17 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.736 2020/12/19 20:47:24 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.737 2020/12/19 22:10:17 rillig Exp $");
/* A string that may need to be freed after use. */
typedef struct FStr {
@@ -531,18 +531,39 @@
Var_DeleteVar(name, ctxt);
}
+/*
+ * Undefine a single variable from the global scope. The argument is
+ * expanded once.
+ */
void
Var_Undef(char *arg)
{
+ /*
+ * The argument must consist of exactly 1 word. Accepting more than
+ * 1 word would have required to split the argument into several
+ * words, and such splitting is already done subtly different in many
+ * other places of make.
+ *
+ * Using Str_Words to split the words, followed by Var_Subst to expand
+ * each variable name once would make it impossible to undefine
+ * variables whose names contain space characters or unbalanced
+ * quotes or backslashes in arbitrary positions.
+ *
+ * Using Var_Subst on the whole argument and splitting the words
+ * afterwards using Str_Words would make it impossible to undefine
+ * variables whose names contain space characters.
+ */
char *cp = arg;
for (; !ch_isspace(*cp) && *cp != '\0'; cp++)
continue;
+ if (cp == arg || *cp != '\0') {
+ Parse_Error(PARSE_FATAL,
+ "The .undef directive requires exactly 1 argument");
+ }
*cp = '\0';
Var_Delete(arg, VAR_GLOBAL);
- /* TODO: undefine all variables, not only the first */
- /* TODO: use Str_Words, like everywhere else */
}
static Boolean
Home |
Main Index |
Thread Index |
Old Index