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): migrate get_mpt_arg to Var_ParsePP
details: https://anonhg.NetBSD.org/src/rev/9b6579e4699d
branches: trunk
changeset: 938231:9b6579e4699d
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Sep 04 20:51:01 2020 +0000
description:
make(1): migrate get_mpt_arg to Var_ParsePP
This part is covered well by the unit tests. When I forgot to decrement
the linePtr, several of them failed reliably.
diffstat:
usr.bin/make/cond.c | 27 +++++++++------------------
usr.bin/make/unit-tests/cond-func-empty.mk | 14 +++++++++++++-
2 files changed, 22 insertions(+), 19 deletions(-)
diffs (95 lines):
diff -r 03ba00294ab8 -r 9b6579e4699d usr.bin/make/cond.c
--- a/usr.bin/make/cond.c Fri Sep 04 20:32:34 2020 +0000
+++ b/usr.bin/make/cond.c Fri Sep 04 20:51:01 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cond.c,v 1.110 2020/09/04 20:32:34 rillig Exp $ */
+/* $NetBSD: cond.c,v 1.111 2020/09/04 20:51:01 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: cond.c,v 1.110 2020/09/04 20:32:34 rillig Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.111 2020/09/04 20:51:01 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)cond.c 8.2 (Berkeley) 1/2/94";
#else
-__RCSID("$NetBSD: cond.c,v 1.110 2020/09/04 20:32:34 rillig Exp $");
+__RCSID("$NetBSD: cond.c,v 1.111 2020/09/04 20:51:01 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -676,25 +676,16 @@
get_mpt_arg(Boolean doEval, const char **linePtr, char **argPtr,
const char *func MAKE_ATTR_UNUSED)
{
- /*
- * Use Var_Parse to parse the spec in parens and return
- * TOK_TRUE if the resulting string is empty.
- */
- int length;
void *val_freeIt;
const char *val;
- const char *cp = *linePtr;
+ int magic_res;
/* We do all the work here and return the result as the length */
*argPtr = NULL;
- val = Var_Parse(cp - 1, VAR_CMD, doEval ? VARE_WANTRES : 0, &length,
- &val_freeIt);
- /*
- * Advance *linePtr to beyond the closing ). Note that
- * we subtract one because 'length' is calculated from 'cp - 1'.
- */
- *linePtr = cp - 1 + length;
+ (*linePtr)--; /* Make (*linePtr)[1] point to the '('. */
+ val = Var_ParsePP(linePtr, VAR_CMD, doEval ? VARE_WANTRES : 0, &val_freeIt);
+ /* If successful, *linePtr points beyond the closing ')' now. */
if (val == var_Error) {
free(val_freeIt);
@@ -709,9 +700,9 @@
* For consistency with the other functions we can't generate the
* true/false here.
*/
- length = *val ? 2 : 1;
+ magic_res = *val != '\0' ? 2 : 1;
free(val_freeIt);
- return length;
+ return magic_res;
}
static Boolean
diff -r 03ba00294ab8 -r 9b6579e4699d usr.bin/make/unit-tests/cond-func-empty.mk
--- a/usr.bin/make/unit-tests/cond-func-empty.mk Fri Sep 04 20:32:34 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-func-empty.mk Fri Sep 04 20:51:01 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: cond-func-empty.mk,v 1.4 2020/09/04 20:28:16 rillig Exp $
+# $NetBSD: cond-func-empty.mk,v 1.5 2020/09/04 20:51:01 rillig Exp $
#
# Tests for the empty() function in .if conditions, which tests a variable
# expression for emptiness.
@@ -121,5 +121,17 @@
. error
.endif
+# Ensure that variable expressions that appear as part of the argument are
+# properly parsed. Typical use cases for this are .for loops, which are
+# expanded to exactly these ${:U} expressions.
+#
+# If everything goes well, the argument expands to "WORD", and that variable
+# is defined at the beginning of this file. The surrounding 'W' and 'D'
+# ensure that the parser in ParseEmptyArg has the correct position, both
+# before and after the call to Var_ParsePP.
+.if empty(W${:UOR}D)
+. error
+.endif
+
all:
@:;
Home |
Main Index |
Thread Index |
Old Index