autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: more efficient AS_EXIT


From: Eric Blake
Subject: Re: more efficient AS_EXIT
Date: Thu, 20 Nov 2008 17:37:48 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Paolo Bonzini <bonzini <at> gnu.org> writes:

> > The _only_ place where AS_EXIT changed semantics from what
> > it had in 2.63 to what it has now in autoconf.git is if you:
> > 1) use it without arguments, and
> > 2) $? is greater than 1
> 
> Yes, and I understand that the result *is* better in general if the
> default argument is not 1.  And I appreciate your effort, but the
> semantics when $? = 0 are just too unobvious.  I think we *can*
> sacrifice backwards-compatibility and default to $?, because there is a
> reason why the macro was almost unused in the wild; the reason being
> that there are pretty good documented AC_* macros to exit with an error
> message, so no one should need to use AS_EXIT except in pure M4sh
> scripts.  In fact, the only user within configure scripts was in
> kpathsea, while Libtool is using it in the generated config.lt file.

Those are some good arguments.  But changing the default for AS_EXIT to allow a 
0 status means that AS_ERROR also needs to be changed.  So what do you think of 
this, which moves the max($?,1) logic into AS_ERROR?

>From 30b12e953354a82a5ac3f45c6f498cd85d5a629d Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 20 Nov 2008 09:44:32 -0700
Subject: [PATCH] Change the semantics of AS_EXIT without argument.

* lib/m4sugar/m4sh.m4 (_AS_EXIT_PREPARE): When defaulting, use $?
even if it is 0.
(AS_ERROR): Guarantee non-zero status.
* bin/autoconf.as (exit_missing_arg, getopt): Revert prior change;
we want non-zero status.
* tests/m4sh.at (AS@&address@hidden): Update test accordingly.
* doc/autoconf.texi (Common Shell Constructs) <AS_EXIT>: Update
the documentation.
<AS_SET_STATUS>: Don't overly restrict implementation.
(Printing Messages) <AC_MSG_ERROR>: Describe better default.
Suggestions by Paolo Bonzini and Ralf Wildenhues.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog           |   15 +++++++++++++++
 bin/autoconf.as     |    8 ++++----
 doc/autoconf.texi   |   18 +++++++++---------
 lib/m4sugar/m4sh.m4 |   24 +++++++++++++-----------
 tests/m4sh.at       |   10 ++++++----
 5 files changed, 47 insertions(+), 28 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 10bd336..e41c0be 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2008-11-20  Eric Blake  <address@hidden>
+
+       Change the semantics of AS_EXIT without argument.
+       * lib/m4sugar/m4sh.m4 (_AS_EXIT_PREPARE): When defaulting, use $?
+       even if it is 0.
+       (AS_ERROR): Guarantee non-zero status.
+       * bin/autoconf.as (exit_missing_arg, getopt): Revert prior change;
+       we want non-zero status.
+       * tests/m4sh.at (AS@&address@hidden): Update test accordingly.
+       * doc/autoconf.texi (Common Shell Constructs) <AS_EXIT>: Update
+       the documentation.
+       <AS_SET_STATUS>: Don't overly restrict implementation.
+       (Printing Messages) <AC_MSG_ERROR>: Describe better default.
+       Suggestions by Paolo Bonzini and Ralf Wildenhues.
+
 2008-11-20  Alfred G. de Wijn  <address@hidden>  (tiny change)
 
        For consistency, make temporary variable match language name.
diff --git a/bin/autoconf.as b/bin/autoconf.as
index c6bb0f6..c678e55 100644
--- a/bin/autoconf.as
+++ b/bin/autoconf.as
@@ -81,7 +81,7 @@ Try \`$as_me --help' for more information."
 exit_missing_arg='
   AS_ECHO(["$as_me: option \`$[1]'\'' requires an argument"]) >&2
   AS_ECHO(["$help"]) >&2
-  AS_EXIT
+  AS_EXIT([1])
 ' # restore font-lock: "
 
 # Variables.
@@ -156,7 +156,7 @@ while test $# -gt 0 ; do
        exec >&2
        AS_ECHO(["$as_me: invalid option $[1]"])
        AS_ECHO(["$help"])
-       AS_EXIT ;;
+       AS_EXIT([1]) ;;
     * )
        break ;;
   esac
@@ -175,7 +175,7 @@ case $# in
       infile=configure.in
     else
       AS_ECHO(["$as_me: no input file"]) >&2
-      AS_EXIT
+      AS_EXIT([1])
     fi
     test -z "$traces" && test -z "$outfile" && outfile=configure;;
   1)
@@ -183,7 +183,7 @@ case $# in
   *) exec >&2
      AS_ECHO(["$as_me: invalid number of arguments."])
      AS_ECHO(["$help"])
-     AS_EXIT ;;
+     AS_EXIT([1]) ;;
 esac
 
 # Unless specified, the output is stdout.
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index f06a545..b9f8954 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -9221,11 +9221,12 @@ Printing Messages
 @end defmac
 
 @anchor{AC_MSG_ERROR}
address@hidden AC_MSG_ERROR (@var{error-description}, @ovar{exit-status})
address@hidden AC_MSG_ERROR (@var{error-description}, @dvar{exit-status, 
max($?,1)})
 @acindex{MSG_ERROR}
 Notify the user of an error that prevents @command{configure} from
 completing.  This macro prints an error message to the standard error
-output and exits @command{configure} with @var{exit-status} (1 by default).
+output and exits @command{configure} with @var{exit-status} (@samp{$?}
+by default, except that @samp{0} is converted to @samp{1}).
 @var{error-description} should be something like @samp{invalid value
 $HOME for \$HOME}.
 
@@ -12010,12 +12011,10 @@ Common Shell Constructs
 Redirections can be placed outside the macro invocation.
 @end defmac
 
address@hidden AS_EXIT (@dvar{status, max($?/1)})
address@hidden AS_EXIT (@dvar{status, $?})
 @asindex{EXIT}
-Emit code to exit the shell with @var{status}.  If @var{status} is
-omitted, then @samp{$?} is used, except that a status of zero is
-converted to @samp{1}.  To exit with successful status, it is necessary
-to supply an explicit @var{status} that expands to @samp{0}.  This macro
+Emit code to exit the shell with @var{status}, defaulting to @samp{$?}.
+This macro
 works around shells that see the exit status of the command prior to
 @code{exit} inside a @samp{trap 0} handler (@pxref{Limitations of
 Builtins, , Limitations of Shell Builtins}).
@@ -12057,8 +12056,9 @@ Common Shell Constructs
 
 @defmac AS_SET_STATUS (@var{status})
 @asindex{SET_STATUS}
-Emit shell code to set the value of @samp{$?} to @var{status} without
-forking.  However, this is not guaranteed to abort a shell running with
+Emit shell code to set the value of @samp{$?} to @var{status}, as
+efficiently as possible.  However, this is not guaranteed to abort a
+shell running with
 @code{set -e} (@pxref{Limitations of Builtins, , Limitations of Shell
 Builtins}).
 @end defmac
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 8863c82..6a87408 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -539,21 +539,19 @@ m4_defun([_AS_EXIT_PREPARE],
   [AS_FUNCTION_DESCRIBE([as_fn_set_status], [STATUS],
     [Set $? to STATUS, without forking.])], [  return $[]1])]dnl
 [AS_REQUIRE_SHELL_FN([as_fn_exit],
-  [AS_FUNCTION_DESCRIBE([as_fn_exit], [[[STATUS]]],
-    [Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
-     If STATUS is omitted, use the maximum of $? and 1.])],
+  [AS_FUNCTION_DESCRIBE([as_fn_exit], [[[STATUS=$?]]],
+    [Exit the shell with STATUS, even in a "trap 0" or "set -e" context.])],
 [  as_status=$?
   set +e
-  test $as_status = 0 && as_status=1
   as_fn_set_status ${1-$as_status}
   exit ${1-$as_status}])])#_AS_EXIT_PREPARE
 
 
-# AS_EXIT([EXIT-CODE = $?/1])
-# ---------------------------
+# AS_EXIT([EXIT-CODE = $?])
+# -------------------------
 # Exit, with status set to EXIT-CODE in the way that it's seen
 # within "trap 0", and without interference from "set -e".  If
-# EXIT-CODE is omitted, then use $?, except use 1 if $? is 0.
+# EXIT-CODE is omitted, then use $?.
 m4_defun([AS_EXIT],
 [AS_REQUIRE([_AS_EXIT_PREPARE])[]as_fn_exit[]m4_ifval([$1], [ $1])])
 
@@ -771,15 +769,19 @@ _AS_ECHO([$as_me: $1], [$2]);}],
 
 # AS_WARN(PROBLEM)
 # ----------------
+# Output "`basename $0`: WARNING: "STRING to stderr.
 m4_define([AS_WARN],
 [AS_MESSAGE([WARNING: $1], [2])])# AS_WARN
 
 
-# AS_ERROR(ERROR, [EXIT-STATUS = 1])
-# ----------------------------------
+# AS_ERROR(ERROR, [EXIT-STATUS = max($?/1)])
+# ------------------------------------------
+# Output "`basename $0`: error: "STRING to stderr, then exit the
+# script with EXIT-STATUS.
 m4_define([AS_ERROR],
-[{ AS_MESSAGE([error: $1], [2])
-   AS_EXIT([$2]); }])# AS_ERROR
+[{ m4_ifval([$2], [], [as_status=$?; test $as_status -eq 0 && as_status=1
+   ]) AS_MESSAGE([error: $1], [2])
+    AS_EXIT(m4_default([$2], [$as_status])); }])# AS_ERROR
 
 
 
diff --git a/tests/m4sh.at b/tests/m4sh.at
index 1f39bb1..e85aabe 100644
--- a/tests/m4sh.at
+++ b/tests/m4sh.at
@@ -308,6 +308,7 @@ test x${1} = xb && AS_EXIT([${2}])
 test x${1} = xc && { AS_SET_STATUS([${2}]); AS_EXIT; }
 test x${1} = xd && trap 's=$?; echo $s; AS_EXIT([$s])' 0
 test x${2} = xe && set -e
+test $[#] -gt 0 || AS_EXIT
 AS_SET_STATUS([3])
 dnl Solaris /bin/sh 'set -e' doesn't react to failed function calls
 test x${2} = xe \
@@ -316,12 +317,13 @@ AS_SET_STATUS([4])
 ]])
 
 AT_CHECK_M4SH
-AT_CHECK([./script], [4])
-AT_CHECK([./script a], [1])
-AT_CHECK([./script b], [1])
+AT_CHECK([./script], [1])
+AT_CHECK([./script ''], [4])
+AT_CHECK([./script a], [0])
+AT_CHECK([./script b], [0])
 AT_CHECK([./script b 0], [0])
 AT_CHECK([./script b 2], [2])
-AT_CHECK([./script c 0], [1])
+AT_CHECK([./script c 0], [0])
 AT_CHECK([./script c 2], [2])
 AT_CHECK([./script d], [4], [[4
 ]])
-- 
1.6.0.4








reply via email to

[Prev in Thread] Current Thread [Next in Thread]