]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Make AS_IF, AS_CASE, and AS_FOR more robust to blank arguments.
authorEric Blake <ebb9@byu.net>
Fri, 10 Apr 2009 03:45:18 +0000 (21:45 -0600)
committerEric Blake <ebb9@byu.net>
Mon, 13 Apr 2009 19:15:34 +0000 (13:15 -0600)
* lib/m4sugar/m4sh.m4 (_AS_CASE, _AS_CASE_DEFAULT, AS_FOR, _AS_IF)
(_AS_IF_ELSE, AS_IF): Avoid syntax error on blank argument,
including a macro with an empty expansion.
* NEWS: Mention this.
* tests/m4sh.at (AS@&t@_IF and AS@&t@_CASE, AS@&t@_FOR): Update
tests.
Reported by Mike Frysinger.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
NEWS
lib/m4sugar/m4sh.m4
tests/m4sh.at

index 3c2b4a115dff6b4e7dfed435f5b043e9fbc5a43c..be0c8689e21abe7852d192570c74d86aa6cb2289 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2009-04-13  Eric Blake  <ebb9@byu.net>
 
+       Make AS_IF, AS_CASE, and AS_FOR more robust to blank arguments.
+       * lib/m4sugar/m4sh.m4 (_AS_CASE, _AS_CASE_DEFAULT, AS_FOR, _AS_IF)
+       (_AS_IF_ELSE, AS_IF): Avoid syntax error on blank argument,
+       including a macro with an empty expansion.
+       * NEWS: Mention this.
+       * tests/m4sh.at (AS@&t@_IF and AS@&t@_CASE, AS@&t@_FOR): Update
+       tests.
+       Reported by Mike Frysinger.
+
        Add m4_blank and friends.
        * lib/m4sugar/m4sugar.m4 (m4_blank, m4_nblank, m4_default_nblank)
        (m4_default_nblank_quoted): New macros.
diff --git a/NEWS b/NEWS
index 0357cbdbb5abfe35d8bbacb79d038d36bd1ccd25..8eb3a068ad4ae824717906510ffb0ec355d0ee44 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,9 @@ GNU Autoconf NEWS - User visible changes.
 * Major changes in Autoconf 2.64 (2009-??-??) [stable]
   Released by Eric Blake, based on git versions 2.63b.*.
 
+** AS_IF, AS_CASE, and AS_FOR have been taught to avoid syntax errors
+   even when given arguments that expand to just whitespace.
+
 ** Ensure AT_CHECK can support commands that include a # given with
    proper m4 quoting.  For shell comments, this is a new feature; for
    non-shell comments, this fixes a regression introduced in 2.63b.
index 2b32802e96033cb4346601f266253ea1ad3626d2..052c7eb1021217fe3ab5363129feaf5f20ab0c4c 100644 (file)
@@ -514,14 +514,16 @@ _AS_UNSET_PREPARE
 # | esac
 # The shell comments are intentional, to work around people who don't
 # realize the impacts of using insufficient m4 quoting.  This macro
-# always provides a default case, to work around a Solaris /bin/sh
-# bug regarding the exit status when no case matches.
+# always uses : and provides a default case, to work around Solaris
+# /bin/sh bugs regarding the exit status.
 m4_define([_AS_CASE],
 [ [@%:@(]
-  $1[)] m4_default([$2], [:]) ;;])
+  $1[)] :
+    $2 ;;])
 m4_define([_AS_CASE_DEFAULT],
 [ [@%:@(]
-  *[)] m4_default([$1], [:]) ;;])
+  *[)] :
+    $1 ;;])
 
 m4_defun([AS_CASE],
 [case $1 in[]m4_map_args_pair([_$0], [_$0_DEFAULT],
@@ -583,8 +585,8 @@ m4_defun([AS_FOR],
 [m4_pushdef([$1], m4_if([$3], [], [[$$2]], m4_translit([$3], ]dnl
 m4_dquote(_m4_defn([m4_cr_symbols2]))[[%+=:,./-]), [], [[$3]], [[$$2]]))]dnl
 [for $2[]m4_ifval([$3], [ in $3])
-do
-  m4_default([$4], [:])
+do :
+  $4
 done[]_m4_popdef([$1])])
 
 
@@ -602,17 +604,18 @@ done[]_m4_popdef([$1])])
 # with simplifications if IF-TRUE1 and/or IF-FALSE is empty.
 #
 m4_define([_AS_IF],
-[elif $1; then
-  m4_default([$2], [:])
+[elif $1; then :
+  $2
 ])
 m4_define([_AS_IF_ELSE],
-[m4_ifvaln([$1],
-[else
-  $1])])
+[m4_ifnblank([$1],
+[else :
+  $1
+])])
 
 m4_defun([AS_IF],
-[if $1; then
-  m4_default([$2], [:])
+[if $1; then :
+  $2
 m4_map_args_pair([_$0], [_$0_ELSE], m4_shift2($@))]dnl
 [fi[]])# AS_IF
 
index d747bfe95a6532059b02ca4d0654ec71aa4adcaf..5f7dc847b340333992c01893f3fef736c5bd4193 100644 (file)
@@ -859,6 +859,11 @@ rm -f file
 AS_CASE([`touch file; false`]) && test -f file && echo fifteen
 dnl The next line is badly underquoted; don't intentionally copy this style.
 AS_CASE([foo], [foo], m4_do(AS_CASE([bar], [bar], [echo sixteen])))
+dnl Handle blank arguments.
+AS_IF([false], [:], [ ]) && AS_CASE([foo], [foo], []
+) && echo seventeen
+m4_define([empty])AS_IF([false], [:], [empty]
+) && AS_CASE([foo], [foo], [empty]) && echo eighteen
 
 # check that require works correctly
 m4_for([n], 1, 9, [],
@@ -911,6 +916,8 @@ thirteen
 fourteen
 fifteen
 sixteen
+seventeen
+eighteen
 foo1=1 bar1=1
 foo2=2 bar2=
 foo3=3 bar3=
@@ -979,13 +986,15 @@ AS_FOR([m4var], [shvar], ['$list'],
 AS_FOR([m4var], [shvar], [\'],
 [echo "m4var $shvar"])
 
-# Syntax checks: cope with empty arguments.
+# Syntax checks: cope with empty/blank arguments.
 set f g
 AS_FOR([], [shvar], [],
 [echo "m4_defn([]) $shvar"])
 rm -f file
 AS_FOR([], [shvar], [`touch file`])
 test -f file || exit 1
+AS_FOR([], [shvar], [], [ ])
+m4_define([empty])AS_FOR([], [shvar], [], [empty])
 
 # Check that break works.
 while :