From: Eric Blake Date: Fri, 10 Apr 2009 03:45:18 +0000 (-0600) Subject: Make AS_IF, AS_CASE, and AS_FOR more robust to blank arguments. X-Git-Tag: v2.64~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=52b83b8c374080dceeaeec57b80a6ed0d2b3d38f;p=thirdparty%2Fautoconf.git 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. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index 3c2b4a115..be0c8689e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2009-04-13 Eric Blake + 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 0357cbdbb..8eb3a068a 100644 --- 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. diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4 index 2b32802e9..052c7eb10 100644 --- a/lib/m4sugar/m4sh.m4 +++ b/lib/m4sugar/m4sh.m4 @@ -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 diff --git a/tests/m4sh.at b/tests/m4sh.at index d747bfe95..5f7dc847b 100644 --- a/tests/m4sh.at +++ b/tests/m4sh.at @@ -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 :