[Top][All Lists]
[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: |
Sat, 25 Oct 2008 06:48:55 -0600 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.17) Gecko/20080914 Thunderbird/2.0.0.17 Mnenhy/0.7.5.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Eric Blake on 10/25/2008 6:11 AM:
> I'll try to split it, then, and provide the _AS_REQUIRE_SHELL_FN
> factorization first (it is useful in its own right, whether or not we
> change AS_EXIT).
> I'll keep the patch updated, but we'll re-evaluate it after applying the
> non-controversial improvements.
>
Here's what I'm pushing for now. Adding AS_SET_STATUS or changing AS_EXIT
to use a function are still on hold.
- --
Don't work too hard, make some time for fun as well!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkkDFbYACgkQ84KuGfSFAYA/0QCdF1nPgywcsQ2V6yiboRM1onr1
3zQAnAzExo2owtvto854eRJPbxw8dyfN
=WJq9
-----END PGP SIGNATURE-----
>From 489b6dac8c6c037499908e17171b2fcc75aa7512 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Sat, 25 Oct 2008 06:26:49 -0600
Subject: [PATCH] Use AS_EXIT in autoconf.as.
* bin/autoconf.as: Consistently use AS_EXIT.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 5 +++++
bin/autoconf.as | 8 ++++----
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 6be628c..70cc6fc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-10-25 Eric Blake <address@hidden>
+
+ Use AS_EXIT in autoconf.as.
+ * bin/autoconf.as: Consistently use AS_EXIT.
+
2008-10-24 Eric Blake <address@hidden>
Fix m4 underquoting in AC_PROG_INSTALL.
diff --git a/bin/autoconf.as b/bin/autoconf.as
index 6eab32a..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
- exit 1
+ 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"])
- exit 1 ;;
+ AS_EXIT([1]) ;;
* )
break ;;
esac
@@ -175,7 +175,7 @@ case $# in
infile=configure.in
else
AS_ECHO(["$as_me: no input file"]) >&2
- exit 1
+ 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"])
- (exit 1); exit 1 ;;
+ AS_EXIT([1]) ;;
esac
# Unless specified, the output is stdout.
--
1.6.0.2
>From 5d9dae38a348f4e9cc827bed1e97b6b5a522dcfa Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Sat, 25 Oct 2008 06:29:37 -0600
Subject: [PATCH] Document AS_EXIT.
* doc/autoconf.texi (Common Shell Constructs) <AS_EXIT>: Document
this macro.
(Limitations of Builtins): Mention AS_EXIT.
* NEWS: Mention it.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 6 ++++++
NEWS | 6 +++---
doc/autoconf.texi | 11 ++++++++++-
3 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 70cc6fc..a0f87ec 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2008-10-25 Eric Blake <address@hidden>
+ Document AS_EXIT.
+ * doc/autoconf.texi (Common Shell Constructs) <AS_EXIT>: Document
+ this macro.
+ (Limitations of Builtins): Mention AS_EXIT.
+ * NEWS: Mention it.
+
Use AS_EXIT in autoconf.as.
* bin/autoconf.as: Consistently use AS_EXIT.
diff --git a/NEWS b/NEWS
index 496fac7..5bdff48 100644
--- a/NEWS
+++ b/NEWS
@@ -23,9 +23,9 @@ GNU Autoconf NEWS - User visible changes.
AS_LINENO_PREPARE AS_ME_PREPARE AS_VAR_APPEND AS_VAR_COPY
** The following m4sh macros are documented now:
- AS_ECHO AS_ECHO_N AS_LITERAL_IF AS_UNSET AS_VAR_IF AS_VAR_POPDEF
- AS_VAR_PUSHDEF AS_VAR_SET AS_VAR_SET_IF AS_VAR_TEST_SET
- AS_VERSION_COMPARE
+ AS_ECHO AS_ECHO_N AS_EXIT AS_LITERAL_IF AS_UNSET AS_VAR_IF
+ AS_VAR_POPDEF AS_VAR_PUSHDEF AS_VAR_SET AS_VAR_SET_IF
+ AS_VAR_TEST_SET AS_VERSION_COMPARE
** The m4sh macros AS_IF and AS_CASE can now be used in shell lists.
The responsibility for supplying a trailing newline now belongs to
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 8509322..b89ce5b 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -11966,6 +11966,14 @@ Common Shell Constructs
Redirections can be placed outside the macro invocation.
@end defmac
address@hidden AS_EXIT (@dvar{status, 1})
address@hidden
+Emit code to exit the shell with @var{status}. This works around shells
+that see the exit status of the command prior to @code{exit} inside a
address@hidden 0} handler (@pxref{Limitations of Builtins, , Limitations of
+Shell Builtins}).
address@hidden defmac
+
@defmac AS_IF (@var{test1}, @ovar{run-if-true1}, @dots{}, @ovar{run-if-false})
@asindex{IF}
Run shell code @var{test1}. If @var{test1} exits with a zero status then
@@ -15433,7 +15441,8 @@ Limitations of Builtins
The portable solution is then simple: when you want to @samp{exit 42},
run @samp{(exit 42); exit 42}, the first @command{exit} being used to
set the exit status to 42 for Zsh, and the second to trigger the trap
-and pass 42 as exit status for Bash.
+and pass 42 as exit status for Bash. In m4sh, this is covered by using
address@hidden
The shell in address@hidden 4.0 has the following bug: @samp{$?} is
reset to 0 by empty lines if the code is inside @command{trap}.
--
1.6.0.2
>From ce2d0f043cbe77a78fb1d0e2427543cf8cb9c9ca Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Sat, 25 Oct 2008 06:37:43 -0600
Subject: [PATCH] Simplify _AS_PREPARE handling of functions.
* lib/m4sugar/m4sh.m4 (AS_REQUIRE_SHELL_FN): Factor...
(_AS_REQUIRE_SHELL_FN): ...into new helper macro.
(_AS_PREPARE): Temporarily redefine AS_REQUIRE_SHELL_FN to make
this task easier.
(_AS_LINENO_PREPARE): Make more efficient.
(_AS_MKDIR_P_PREPARE): Simplify use in _AS_PREPARE.
(_AS_UNSET_PREPARE): Avoid blank newline.
(AS_INIT): Emit as_func_unset alongside other functions.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 12 ++++++++++++
lib/m4sugar/m4sh.m4 | 49 +++++++++++++++++++++++++------------------------
2 files changed, 37 insertions(+), 24 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a0f87ec..dab6a6e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2008-10-25 Eric Blake <address@hidden>
+ Simplify _AS_PREPARE handling of functions.
+ * lib/m4sugar/m4sh.m4 (AS_REQUIRE_SHELL_FN): Factor...
+ (_AS_REQUIRE_SHELL_FN): ...into new helper macro.
+ (_AS_PREPARE): Temporarily redefine AS_REQUIRE_SHELL_FN to make
+ this task easier.
+ (_AS_LINENO_PREPARE): Make more efficient.
+ (_AS_MKDIR_P_PREPARE): Simplify use in _AS_PREPARE.
+ (_AS_UNSET_PREPARE): Avoid blank newline.
+ (AS_INIT): Emit as_func_unset alongside other functions.
+
+2008-10-25 Eric Blake <address@hidden>
+
Document AS_EXIT.
* doc/autoconf.texi (Common Shell Constructs) <AS_EXIT>: Document
this macro.
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 6620a56..6124065 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -255,17 +255,17 @@ fi
# and config.status. Relying on AS_REQUIRE is of course fine for
# configure, but fails for config.status (which is created by
# configure). So we need a means to force the inclusion of the
-# various _AS_PREPARE_* on top of config.status. That's basically why
-# there are so many _AS_PREPARE_* below, and that's also why it is
+# various _AS_*_PREPARE on top of config.status. That's basically why
+# there are so many _AS_*_PREPARE below, and that's also why it is
# important not to forget some: config.status needs them.
+# List any preparations that create shell functions first, then
+# topologically sort the others by their dependencies.
m4_defun([_AS_PREPARE],
-[m4_pushdef([AS_REQUIRE], [])]dnl
-[AS_FUNCTION_DESCRIBE([as_func_mkdir_p], [],
-[Create "$as_dir" as a directory, including parents if necessary.])
-as_func_mkdir_p ()
-{
- _AS_MKDIR_P
-}
+[m4_pushdef([AS_REQUIRE])]dnl
+[m4_pushdef([AS_REQUIRE_SHELL_FN], _m4_defn([_AS_REQUIRE_SHELL_FN])
+)]dnl
+[_AS_UNSET_PREPARE
+_AS_VAR_APPEND_PREPARE
_AS_EXPR_PREPARE
_AS_BASENAME_PREPARE
@@ -278,9 +278,7 @@ _AS_MKDIR_P_PREPARE
_AS_TEST_PREPARE
_AS_TR_CPP_PREPARE
_AS_TR_SH_PREPARE
-_AS_UNSET_PREPARE
-_AS_VAR_APPEND_PREPARE
-m4_popdef([AS_REQUIRE])])
+_m4_popdef([AS_REQUIRE], [AS_REQUIRE_SHELL_FN])])
# AS_PREPARE
# ----------
@@ -325,6 +323,14 @@ m4_defun([AS_REQUIRE],
1, [m4_require(],
[m4_divert_require(_m4_divert(_m4_divert_desired),]) [$1], [$2])])
+# _AS_REQUIRE_SHELL_FN(NAME-TO-CHECK, COMMENT, BODY-TO-EXPAND)
+# ------------------------------------------------------------
+# Core of AS_REQUIRE_SHELL_FN, but without diversion support.
+m4_define([_AS_REQUIRE_SHELL_FN], [
+m4_n([$2])$1 ()
+{
+$3
+} @%:@ $1[]])
# AS_REQUIRE_SHELL_FN(NAME-TO-CHECK, COMMENT, BODY-TO-EXPAND,
# [DIVERSION = M4SH-INIT-FN])
@@ -337,12 +343,8 @@ m4_defun([AS_REQUIRE],
m4_define([AS_REQUIRE_SHELL_FN],
[m4_provide_if([AS_SHELL_FN_$1], [],
[AS_REQUIRE([AS_SHELL_FN_$1],
-[m4_provide([AS_SHELL_FN_$1])
-m4_n([$2])$1 ()
-{
-$3
-} [#] $1
-], m4_default_quoted([$4], [M4SH-INIT-FN]))])])
+[m4_provide([AS_SHELL_FN_$1])_$0($@)],
+m4_default_quoted([$4], [M4SH-INIT-FN]))])])
# _AS_RUN(TEST, [SHELL])
@@ -555,8 +557,7 @@ as_func_unset ()
{
AS_UNSET([$[1]])
}
-as_unset=as_func_unset
-])
+as_unset=as_func_unset])
# AS_UNSET(VAR)
@@ -1001,7 +1002,7 @@ dnl Eggert wrote the scripts with optimization help from
Paolo Bonzini).
# Exit status is that of the last command.
exit
}
-m4_popdef([AS_MESSAGE_LOG_FD])])# _AS_LINENO_PREPARE
+_m4_popdef([AS_MESSAGE_LOG_FD])])# _AS_LINENO_PREPARE
# _AS_LN_S_PREPARE
@@ -1090,8 +1091,8 @@ m4_defun([_AS_MKDIR_P_PREPARE],
[Create "$as_dir" as a directory, including parents if necessary.])],
[
_AS_MKDIR_P
-])
-if mkdir -p . 2>/dev/null; then
+])]dnl
+[if mkdir -p . 2>/dev/null; then
as_mkdir_p='mkdir -p "$as_dir"'
else
test -d ./-p && rmdir ./-p
@@ -1818,5 +1819,5 @@ m4_divert_pop([KILL])[]dnl
m4_divert_push([BODY])
m4_text_box([Main body of script.])
_AS_DETECT_REQUIRED([_AS_SHELL_FN_WORK])dnl
-AS_REQUIRE([_AS_UNSET_PREPARE])dnl For backwards compatibility.
+AS_REQUIRE([_AS_UNSET_PREPARE], [], [M4SH-INIT-FN])dnl
])
--
1.6.0.2