From: Eric Blake Date: Mon, 27 Oct 2008 21:07:57 +0000 (-0600) Subject: Use AS_VAR_ARITH. X-Git-Tag: v2.63b~185 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cfa144a9556cec71d3cc4e29bc6dfcdf042135a3;p=thirdparty%2Fautoconf.git Use AS_VAR_ARITH. * lib/autotest/general.m4 (at_func_arith): Delete; replace all clients with AS_VAR_ARITH instead. * lib/autoconf/general.m4 (_AC_COMPUTE_INT_COMPILE): Use new macro. * lib/autoconf/programs.m4 (_AC_FEATURE_CHECK_LENGTH): Likewise. * tests/torture.at (Torturing config.status): Likewise. * tests/tools.at (autom4te --force): Likewise. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index d5b68adbb..06d08ded2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2008-10-27 Eric Blake + Use AS_VAR_ARITH. + * lib/autotest/general.m4 (at_func_arith): Delete; replace all + clients with AS_VAR_ARITH instead. + * lib/autoconf/general.m4 (_AC_COMPUTE_INT_COMPILE): Use new + macro. + * lib/autoconf/programs.m4 (_AC_FEATURE_CHECK_LENGTH): Likewise. + * tests/torture.at (Torturing config.status): Likewise. + * tests/tools.at (autom4te --force): Likewise. + Add AS_VAR_ARITH. * lib/m4sugar/m4sh.m4 (_AS_VAR_ARITH_PREPARE, _AS_VAR_ARITH_WORKS) (AS_VAR_ARITH): New macros. diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4 index 000f705b7..c8ab4afbc 100644 --- a/lib/autoconf/general.m4 +++ b/lib/autoconf/general.m4 @@ -2871,31 +2871,32 @@ _AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) >= 0])], while :; do _AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) <= $ac_mid])], [ac_hi=$ac_mid; break], - [ac_lo=`expr $ac_mid + 1` + [AS_VAR_ARITH([ac_lo], [$ac_mid + 1]) if test $ac_lo -le $ac_mid; then ac_lo= ac_hi= break fi - ac_mid=`expr 2 '*' $ac_mid + 1`]) + AS_VAR_ARITH([ac_mid], [2 '*' $ac_mid + 1])]) done], [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) < 0])], [ac_hi=-1 ac_mid=-1 while :; do _AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) >= $ac_mid])], [ac_lo=$ac_mid; break], - [ac_hi=`expr '(' $ac_mid ')' - 1` + [AS_VAR_ARITH([ac_hi], ['(' $ac_mid ')' - 1]) if test $ac_mid -le $ac_hi; then ac_lo= ac_hi= break fi - ac_mid=`expr 2 '*' $ac_mid`]) + AS_VAR_ARITH([ac_mid], [2 '*' $ac_mid])]) done], [ac_lo= ac_hi=])]) # Binary search between lo and hi bounds. while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` + AS_VAR_ARITH([ac_mid], ['(' $ac_hi - $ac_lo ')' / 2 + $ac_lo]) _AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) <= $ac_mid])], - [ac_hi=$ac_mid], [ac_lo=`expr '(' $ac_mid ')' + 1`]) + [ac_hi=$ac_mid], + [AS_VAR_ARITH([ac_lo], ['(' $ac_mid ')' + 1])]) done case $ac_lo in @%:@(( ?*) AS_VAR_SET([$2], [$ac_lo]); $4 ;; diff --git a/lib/autoconf/programs.m4 b/lib/autoconf/programs.m4 index 6e79cdc9b..3f66ae32d 100644 --- a/lib/autoconf/programs.m4 +++ b/lib/autoconf/programs.m4 @@ -510,7 +510,7 @@ m4_define([_AC_FEATURE_CHECK_LENGTH], AS_ECHO(['$4']) >> "conftest.nl" $3 < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break - ac_count=`expr $ac_count + 1` + AS_VAR_ARITH([ac_count], [$ac_count + 1]) if test $ac_count -gt ${$1_max-0}; then # Best one so far, save it but keep looking for a better one $2="$$1" diff --git a/lib/autotest/general.m4 b/lib/autotest/general.m4 index 00817b1a7..4d7c0f5aa 100644 --- a/lib/autotest/general.m4 +++ b/lib/autotest/general.m4 @@ -355,24 +355,6 @@ at_func_create_debugging_script () chmod +x "$at_group_dir/run" } -AS_FUNCTION_DESCRIBE([at_func_arith], [ARG...], -[Arithmetic evaluation, avoids expr if the shell is sane. The -interpretation of leading zeroes is unspecified.]) -# -# subshell and eval are needed to keep Solaris sh from bailing out: -if ( eval 'test $(( 1 + 1 )) = 2' ) 2>/dev/null; then - [#] With "$[@]", bash does not split positional parameters: - eval 'at_func_arith () - { - at_func_arith_result=$(( $[*] )) - }' -else - at_func_arith () - { - at_func_arith_result=`expr "$[@]"` - } -fi - m4_text_box([End of autotest shell functions.]) m4_divert_pop([PREPARE_TESTS])dnl back to DEFAULTS @@ -448,7 +430,7 @@ at_func_validate_ranges () fi case $at_value in 0*) # We want to treat leading 0 as decimal, like expr and test, but - # at_func_arith treats it as octal if it uses $(( )). + # AS_VAR_ARITH treats it as octal if it uses $(( )). # With XSI shells, ${at_value#${at_value%%[1-9]*}} avoids the # expr fork, but it is not worth the effort to determine if the # shell supports XSI when the user can just avoid leading 0. @@ -1265,12 +1247,9 @@ set X $at_xfail_list; shift; at_xfail_count=$[@%:@] set X $at_fail_list; shift; at_fail_count=$[@%:@]; at_fail_list=$[*] set X $at_skip_list; shift; at_skip_count=$[@%:@] -at_func_arith $at_group_count - $at_skip_count -at_run_count=$at_func_arith_result -at_func_arith $at_xpass_count + $at_fail_count -at_unexpected_count=$at_func_arith_result -at_func_arith $at_xfail_count + $at_fail_count -at_total_fail_count=$at_func_arith_result +AS_VAR_ARITH([at_run_count], [$at_group_count - $at_skip_count]) +AS_VAR_ARITH([at_unexpected_count], [$at_xpass_count + $at_fail_count]) +AS_VAR_ARITH([at_total_fail_count], [$at_xfail_count + $at_fail_count]) # Back to the top directory. cd "$at_dir" @@ -1282,16 +1261,11 @@ at_stop_time=`date +%s 2>/dev/null` AS_ECHO(["$as_me: ending at: $at_stop_date"]) >&AS_MESSAGE_LOG_FD case $at_start_time,$at_stop_time in [[0-9]*,[0-9]*]) - at_func_arith $at_stop_time - $at_start_time - at_duration_s=$at_func_arith_result - at_func_arith $at_duration_s / 60 - at_duration_m=$at_func_arith_result - at_func_arith $at_duration_m / 60 - at_duration_h=$at_func_arith_result - at_func_arith $at_duration_s % 60 - at_duration_s=$at_func_arith_result - at_func_arith $at_duration_m % 60 - at_duration_m=$at_func_arith_result + AS_VAR_ARITH([at_duration_s], [$at_stop_time - $at_start_time]) + AS_VAR_ARITH([at_duration_m], [$at_duration_s / 60]) + AS_VAR_ARITH([at_duration_h], [$at_duration_m / 60]) + AS_VAR_ARITH([at_duration_s], [$at_duration_s % 60]) + AS_VAR_ARITH([at_duration_m], [$at_duration_m % 60]) at_duration="${at_duration_h}h ${at_duration_m}m ${at_duration_s}s" AS_ECHO(["$as_me: test suite duration: $at_duration"]) >&AS_MESSAGE_LOG_FD ;; diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4 index 300923a23..7ba1adf02 100644 --- a/lib/m4sugar/m4sh.m4 +++ b/lib/m4sugar/m4sh.m4 @@ -944,7 +944,8 @@ m4_defun([_AS_ME_PREPARE], # This macro does not expand to a single shell command, so be careful # when using it. Surrounding the body of this macro with {} would # cause "bash -c '_ASLINENO_WORKS'" to fail (with Bash 2.05, anyway), -# but that bug is irrelevant to our use of LINENO. +# but that bug is irrelevant to our use of LINENO. We can't use +# AS_VAR_ARITH, as this is expanded prior to shell functions. m4_define([_AS_LINENO_WORKS], [ as_lineno_1=$LINENO diff --git a/tests/tools.at b/tests/tools.at index 0123f825e..06fcf6a9e 100644 --- a/tests/tools.at +++ b/tests/tools.at @@ -130,7 +130,8 @@ AT_CHECK_AUTOM4TE([-o file file.m4]) # even on slow machines. echo BAD >file this_year=`TZ=UTC0 date +%Y` -TZ=UTC0 touch -t `expr $this_year + 1`01010001 file +AS_VAR_ARITH([next_year], [$this_year + 1]) +TZ=UTC0 touch -t ${next_year}01010001 file AT_CHECK_AUTOM4TE([--force -o file file.m4]) AT_CHECK([cat file], 0, diff --git a/tests/torture.at b/tests/torture.at index b79ff895f..74aab9e9d 100644 --- a/tests/torture.at +++ b/tests/torture.at @@ -614,7 +614,7 @@ AT_DATA([dummy.in], i=1 while test $i != 101; do echo "content of file $i" > file_$i - i=`expr $i + 1` + AS_VAR_ARITH([i], [$i + 1]) done