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: don't interpret the return value of Var_P...



details:   https://anonhg.NetBSD.org/src/rev/5b3fae86284b
branches:  trunk
changeset: 373528:5b3fae86284b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Feb 14 20:49:09 2023 +0000

description:
make: don't interpret the return value of Var_Parse

The return value of Var_Parse is largely redundant to the returned
string.  The idea behind the type VarParseResult was to migrate all call
sites to checking this return value instead of the returned string, but
that hasn't happened.  Instead, the additional type only added more
complexity.

There was a single place where that return value was actually used, when
parsing conditions.  And even in that case, ignoring the VarParseResult
added back an error message that previously hid bugs, in the test
cond-token-plain.mk.

Even though these error messages are redundant in the other tests, they
don't hurt as they don't happen often.

diffstat:

 usr.bin/make/cond.c                          |  32 +++++++---------------------
 usr.bin/make/unit-tests/cond-token-plain.exp |   1 +
 usr.bin/make/unit-tests/cond-token-plain.mk  |   8 +++---
 usr.bin/make/unit-tests/cond-undef-lint.exp  |   3 ++
 usr.bin/make/unit-tests/opt-debug-lint.exp   |   2 +
 5 files changed, 18 insertions(+), 28 deletions(-)

diffs (142 lines):

diff -r 6b3040e9d4ca -r 5b3fae86284b usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Tue Feb 14 20:27:17 2023 +0000
+++ b/usr.bin/make/cond.c       Tue Feb 14 20:49:09 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.342 2022/09/24 16:13:48 rillig Exp $        */
+/*     $NetBSD: cond.c,v 1.343 2023/02/14 20:49:09 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -92,7 +92,7 @@
 #include "dir.h"
 
 /*     "@(#)cond.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: cond.c,v 1.342 2022/09/24 16:13:48 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.343 2023/02/14 20:49:09 rillig Exp $");
 
 /*
  * Conditional expressions conform to this grammar:
@@ -380,7 +380,9 @@
 
 /*
  * In a quoted or unquoted string literal or a number, parse a variable
- * expression.
+ * expression and add its value to the buffer.
+ *
+ * Return whether to continue parsing the leaf.
  *
  * Example: .if x${CENTER}y == "${PREFIX}${SUFFIX}" || 0x${HEX}
  */
@@ -392,7 +394,6 @@
        VarEvalMode emode;
        const char *p;
        bool atStart;
-       VarParseResult parseResult;
 
        emode = doEval && quoted ? VARE_WANTRES
            : doEval ? VARE_UNDEFERR
@@ -400,27 +401,10 @@
 
        p = par->p;
        atStart = p == start;
-       parseResult = Var_Parse(&p, SCOPE_CMDLINE, emode, inout_str);
+       (void)Var_Parse(&p, SCOPE_CMDLINE, emode, inout_str);
        /* TODO: handle errors */
        if (inout_str->str == var_Error) {
-               if (parseResult == VPR_ERR) {
-                       /*
-                        * FIXME: Even if an error occurs, there is no
-                        *  guarantee that it is reported.
-                        *
-                        * See cond-token-plain.mk $$$$$$$$.
-                        */
-                       par->printedError = true;
-               }
-               /*
-                * XXX: Can there be any situation in which a returned
-                * var_Error needs to be freed?
-                */
                FStr_Done(inout_str);
-               /*
-                * Even if !doEval, we still report syntax errors, which is
-                * what getting var_Error back with !doEval means.
-                */
                *inout_str = FStr_InitRefer(NULL);
                return false;
        }
@@ -428,8 +412,8 @@
 
        /*
         * If the '$' started the string literal (which means no quotes), and
-        * the variable expression is followed by a space, looks like a
-        * comparison operator or is the end of the expression, we are done.
+        * the expression is followed by a space, a comparison operator or
+        * the end of the expression, we are done.
         */
        if (atStart && is_separator(par->p[0]))
                return false;
diff -r 6b3040e9d4ca -r 5b3fae86284b usr.bin/make/unit-tests/cond-token-plain.exp
--- a/usr.bin/make/unit-tests/cond-token-plain.exp      Tue Feb 14 20:27:17 2023 +0000
+++ b/usr.bin/make/unit-tests/cond-token-plain.exp      Tue Feb 14 20:49:09 2023 +0000
@@ -49,6 +49,7 @@
 CondParser_Eval: "unquoted\"quoted" != unquoted"quoted
 Comparing "unquoted"quoted" != "unquoted"quoted"
 CondParser_Eval: $$$$$$$$ != ""
+make: "cond-token-plain.mk" line 186: Malformed conditional ($$$$$$$$ != "")
 CondParser_Eval: left == right
 make: "cond-token-plain.mk" line 195: Malformed conditional (left == right)
 CondParser_Eval: ${0:?:} || left == right
diff -r 6b3040e9d4ca -r 5b3fae86284b usr.bin/make/unit-tests/cond-token-plain.mk
--- a/usr.bin/make/unit-tests/cond-token-plain.mk       Tue Feb 14 20:27:17 2023 +0000
+++ b/usr.bin/make/unit-tests/cond-token-plain.mk       Tue Feb 14 20:49:09 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: cond-token-plain.mk,v 1.16 2022/09/25 12:51:37 rillig Exp $
+# $NetBSD: cond-token-plain.mk,v 1.17 2023/02/14 20:49:09 rillig Exp $
 #
 # Tests for plain tokens (that is, string literals without quotes)
 # in .if conditions.  These are also called bare words.
@@ -89,7 +89,7 @@
 # a coincidence that the '!' is both used in the '!=' comparison operator
 # as well as for negating a comparison result.
 #
-# The boolean operators '&' and '|' don't terminate a comparison operand.
+# The characters '&' and '|' are part of the comparison operand.
 .if ${:Uvar}&&name != "var&&name"
 .  error
 .endif
@@ -97,8 +97,8 @@
 .  error
 .endif
 
-# A bare word may appear alone in a condition, without any comparison
-# operator.  It is implicitly converted into defined(bare).
+# A bare word may occur alone in a condition, without any comparison
+# operator.  It is interpreted as the function call 'defined(bare)'.
 .if bare
 .  error
 .else
diff -r 6b3040e9d4ca -r 5b3fae86284b usr.bin/make/unit-tests/cond-undef-lint.exp
--- a/usr.bin/make/unit-tests/cond-undef-lint.exp       Tue Feb 14 20:27:17 2023 +0000
+++ b/usr.bin/make/unit-tests/cond-undef-lint.exp       Tue Feb 14 20:49:09 2023 +0000
@@ -1,7 +1,10 @@
 make: "cond-undef-lint.mk" line 23: Variable "UNDEF" is undefined
+make: "cond-undef-lint.mk" line 23: Malformed conditional (${UNDEF})
 make: "cond-undef-lint.mk" line 38: Variable "UNDEF" is undefined
 make: "cond-undef-lint.mk" line 38: Variable "VAR." is undefined
+make: "cond-undef-lint.mk" line 38: Malformed conditional (${VAR.${UNDEF}})
 make: "cond-undef-lint.mk" line 49: Variable "VAR.defined" is undefined
+make: "cond-undef-lint.mk" line 49: Malformed conditional (${VAR.${DEF}})
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
diff -r 6b3040e9d4ca -r 5b3fae86284b usr.bin/make/unit-tests/opt-debug-lint.exp
--- a/usr.bin/make/unit-tests/opt-debug-lint.exp        Tue Feb 14 20:27:17 2023 +0000
+++ b/usr.bin/make/unit-tests/opt-debug-lint.exp        Tue Feb 14 20:49:09 2023 +0000
@@ -1,5 +1,7 @@
 make: "opt-debug-lint.mk" line 19: Variable "X" is undefined
+make: "opt-debug-lint.mk" line 19: Malformed conditional ($X)
 make: "opt-debug-lint.mk" line 41: Variable "UNDEF" is undefined
+make: "opt-debug-lint.mk" line 41: Malformed conditional (${UNDEF})
 make: "opt-debug-lint.mk" line 61: Missing delimiter ':' after modifier "L"
 make: "opt-debug-lint.mk" line 61: Missing delimiter ':' after modifier "P"
 make: "opt-debug-lint.mk" line 69: Unknown modifier "${"



Home | Main Index | Thread Index | Old Index