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 <ebb9@byu.net>
This commit is contained in:
Eric Blake 2009-04-09 21:45:18 -06:00
parent 723c9e5c0f
commit 52b83b8c37
4 changed files with 38 additions and 14 deletions

View File

@ -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.

3
NEWS
View File

@ -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.

View 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

View 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 :