autoconf-patches
[Top][All Lists]
Advanced

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

Re: [PATCH 4/5] remove shell function "spy"


From: Eric Blake
Subject: Re: [PATCH 4/5] remove shell function "spy"
Date: Tue, 7 Oct 2008 18:19:41 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

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

> 
> This patch removes the shell function "spy" that was added a
> few years ago.  It did help finding a couple of bugs, it has
> made its time though.

I tried this patch out-of-order, and things blew up because _AS_CLEANUP wasn't 
defined properly.  While I won't apply the 4/5 patch until 2/5 and 3/5 have 
been tackled first, I'm at least committing this to expose and correct the 
failure that occurs when no spy is in place.

From: Eric Blake <address@hidden>
Date: Tue, 7 Oct 2008 10:55:05 -0600
Subject: [PATCH] Improve m4sh maintainability.

* lib/m4sugar/m4sh.m4: Sort macros for sanitizing the shell; no
code change.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog           |    4 +
 lib/m4sugar/m4sh.m4 |  234 +++++++++++++++++++++++++-------------------------
 2 files changed, 121 insertions(+), 117 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5127319..f610c79 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2008-10-07  Eric Blake  <address@hidden>
 
+       Improve m4sh maintainability.
+       * lib/m4sugar/m4sh.m4: Sort macros for sanitizing the shell; no
+       code change.
+
        Fix m4 quoting in previous patch.
        * lib/m4sugar/m4sh.m4 (AS_REQUIRE_SHELL_FN): Determine diversion
        name prior to invoking AS_REQUIRE.
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 914987e..edad040 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -101,66 +101,7 @@ m4_copy([_m4_divert(M4SH-INIT)], [_m4_divert(NOTICE)])
 ## ------------------------- ##
 ## 1. Sanitizing the shell.  ##
 ## ------------------------- ##
-
-
-# AS_REQUIRE(NAME-TO-CHECK, [BODY-TO-EXPAND = NAME-TO-CHECK],
-#            [DIVERSION = M4SH-INIT])
-# -----------------------------------------------------------
-# BODY-TO-EXPAND is some initialization which must be expanded in the
-# given diversion when expanded (required or not).  This is very
-# different from m4_require.  For instance:
-#
-#      m4_defun([_FOO_PREPARE], [foo=foo])
-#      m4_defun([FOO],
-#      [m4_require([_FOO_PREPARE])dnl
-#      echo $foo])
-#
-#      m4_defun([_BAR_PREPARE], [bar=bar])
-#      m4_defun([BAR],
-#      [AS_REQUIRE([_BAR_PREPARE])dnl
-#      echo $bar])
-#
-#      AS_INIT
-#      foo1=`FOO`
-#      foo2=`FOO`
-#      bar1=`BAR`
-#      bar2=`BAR`
-#
-# gives
-#
-#      #! /bin/sh
-#      bar=bar
-#
-#      foo1=`foo=foo
-#      echo $foo`
-#      foo2=`echo $foo`
-#      bar1=`echo $bar`
-#      bar2=`echo $bar`
-#
-# Due to the simple implementation, all the AS_REQUIRE calls have to be at
-# the very beginning of the macro body, or the AS_REQUIREs may not be nested.
-# More exactly, if a macro doesn't have all AS_REQUIREs at its beginning,
-# it may not be AS_REQUIREd.
-#
-m4_define([AS_REQUIRE],
-[m4_provide_if([$1], [],
-              [m4_divert_text(m4_default_quoted([$3], [M4SH-INIT]),
-                              [m4_default([$2], [$1])])])])
-
-
-# AS_REQUIRE_SHELL_FN(NAME-TO-CHECK, BODY-TO-EXPAND,
-#                     [DIVERSION = M4SH-INIT-FN])
-# --------------------------------------------------
-# BODY-TO-EXPAND is the body of a shell function to be emitted in the
-# given diversion when expanded (required or not).  Unlike other
-# xx_REQUIRE macros, BODY-TO-EXPAND is mandatory.
-#
-m4_define([AS_REQUIRE_SHELL_FN],
-[_AS_DETECT_REQUIRED([_AS_SHELL_FN_WORK])dnl
-AS_REQUIRE([AS_SHELL_FN_$1], [m4_provide([AS_SHELL_FN_$1])$1() {
-$2
-}], m4_default_quoted([$3], [M4SH-INIT-FN]))])
-
+# Please maintain lexicographic sorting of this section, ignoring leading _.
 
 # AS_BOURNE_COMPATIBLE
 # --------------------
@@ -193,18 +134,15 @@ m4_define([_AS_BOURNE_COMPATIBLE],
 ])
 
 
-# _AS_RUN(TEST, [SHELL])
-# ----------------------
-# Run TEST under the current shell (if one parameter is used)
-# or under the given SHELL, protecting it from syntax errors.
-m4_define([_AS_RUN],
-[m4_ifval([$2],
-[{ $2 <<\_ASEOF
-_AS_BOURNE_COMPATIBLE
-$1
-_ASEOF
-}],
-[(eval "AS_ESCAPE(m4_expand([$1]))")])])
+# AS_COPYRIGHT(TEXT)
+# ------------------
+# Emit TEXT, a copyright notice, as a shell comment near the top of the
+# script.  TEXT is evaluated once; to accomplish that, we do not prepend
+# `# ' but address@hidden:@ '.
+m4_define([AS_COPYRIGHT],
+[m4_divert_text([HEADER-COPYRIGHT],
+[m4_bpatsubst([
+$1], [^], address@hidden:@ ])])])
 
 
 # _AS_DETECT_REQUIRED(TEST)
@@ -291,6 +229,113 @@ fi
 ])])])# _AS_DETECT_BETTER_SHELL
 
 
+# _AS_PREPARE
+# -----------
+# This macro has a very special status.  Normal use of M4sh relies
+# heavily on AS_REQUIRE, so that needed initializations (such as
+# _AS_TEST_PREPARE) are performed on need, not on demand.  But
+# Autoconf is the first client of M4sh, and for two reasons: configure
+# 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
+# important not to forget some: config.status needs them.
+m4_defun([_AS_PREPARE],
+[_AS_LINENO_PREPARE
+
+_AS_DIRNAME_PREPARE
+_AS_ECHO_N_PREPARE[]dnl We do not need this ourselves but user code might.
+_AS_EXPR_PREPARE
+_AS_LN_S_PREPARE
+_AS_MKDIR_P_PREPARE
+_AS_TEST_PREPARE
+_AS_TR_CPP_PREPARE
+_AS_TR_SH_PREPARE
+])
+
+
+# AS_PREPARE
+# ----------
+# Output all the M4sh possible initialization into the initialization
+# diversion.
+m4_defun([AS_PREPARE],
+[m4_divert_text([M4SH-INIT], [_AS_PREPARE])])
+
+
+# AS_REQUIRE(NAME-TO-CHECK, [BODY-TO-EXPAND = NAME-TO-CHECK],
+#            [DIVERSION = M4SH-INIT])
+# -----------------------------------------------------------
+# BODY-TO-EXPAND is some initialization which must be expanded in the
+# given diversion when expanded (required or not).  This is very
+# different from m4_require.  For instance:
+#
+#      m4_defun([_FOO_PREPARE], [foo=foo])
+#      m4_defun([FOO],
+#      [m4_require([_FOO_PREPARE])dnl
+#      echo $foo])
+#
+#      m4_defun([_BAR_PREPARE], [bar=bar])
+#      m4_defun([BAR],
+#      [AS_REQUIRE([_BAR_PREPARE])dnl
+#      echo $bar])
+#
+#      AS_INIT
+#      foo1=`FOO`
+#      foo2=`FOO`
+#      bar1=`BAR`
+#      bar2=`BAR`
+#
+# gives
+#
+#      #! /bin/sh
+#      bar=bar
+#
+#      foo1=`foo=foo
+#      echo $foo`
+#      foo2=`echo $foo`
+#      bar1=`echo $bar`
+#      bar2=`echo $bar`
+#
+# Due to the simple implementation, all the AS_REQUIRE calls have to be at
+# the very beginning of the macro body, or the AS_REQUIREs may not be nested.
+# More exactly, if a macro doesn't have all AS_REQUIREs at its beginning,
+# it may not be AS_REQUIREd.
+#
+m4_define([AS_REQUIRE],
+[m4_provide_if([$1], [],
+              [m4_divert_text(m4_default_quoted([$3], [M4SH-INIT]),
+                              [m4_default([$2], [$1])])])])
+
+
+# AS_REQUIRE_SHELL_FN(NAME-TO-CHECK, BODY-TO-EXPAND,
+#                     [DIVERSION = M4SH-INIT-FN])
+# --------------------------------------------------
+# BODY-TO-EXPAND is the body of a shell function to be emitted in the
+# given diversion when expanded (required or not).  Unlike other
+# xx_REQUIRE macros, BODY-TO-EXPAND is mandatory.
+#
+m4_define([AS_REQUIRE_SHELL_FN],
+[_AS_DETECT_REQUIRED([_AS_SHELL_FN_WORK])dnl
+AS_REQUIRE([AS_SHELL_FN_$1], [m4_provide([AS_SHELL_FN_$1])$1() {
+$2
+}], m4_default_quoted([$3], [M4SH-INIT-FN]))])
+
+
+# _AS_RUN(TEST, [SHELL])
+# ----------------------
+# Run TEST under the current shell (if one parameter is used)
+# or under the given SHELL, protecting it from syntax errors.
+m4_define([_AS_RUN],
+[m4_ifval([$2],
+[{ $2 <<\_ASEOF
+_AS_BOURNE_COMPATIBLE
+$1
+_ASEOF
+}],
+[(eval "AS_ESCAPE(m4_expand([$1]))")])])
+
+
 # _AS_SHELL_FN_WORK
 # -----------------
 # This is a spy to detect "in the wild" shells that do not support shell
@@ -332,17 +377,6 @@ test $exitcode = 0[]dnl
 ])# _AS_SHELL_FN_WORK
 
 
-# AS_COPYRIGHT(TEXT)
-# ------------------
-# Emit TEXT, a copyright notice, as a shell comment near the top of the
-# script.  TEXT is evaluated once; to accomplish that, we do not prepend
-# `# ' but address@hidden:@ '.
-m4_define([AS_COPYRIGHT],
-[m4_divert_text([HEADER-COPYRIGHT],
-[m4_bpatsubst([
-$1], [^], address@hidden:@ ])])])
-
-
 # AS_SHELL_SANITIZE
 # -----------------
 m4_defun([AS_SHELL_SANITIZE],
@@ -408,40 +442,6 @@ $as_unset CDPATH
 ])# AS_SHELL_SANITIZE
 
 
-# _AS_PREPARE
-# -----------
-# This macro has a very special status.  Normal use of M4sh relies
-# heavily on AS_REQUIRE, so that needed initializations (such as
-# _AS_TEST_PREPARE) are performed on need, not on demand.  But
-# Autoconf is the first client of M4sh, and for two reasons: configure
-# 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
-# important not to forget some: config.status needs them.
-m4_defun([_AS_PREPARE],
-[_AS_LINENO_PREPARE
-
-_AS_DIRNAME_PREPARE
-_AS_ECHO_N_PREPARE[]dnl We do not need this ourselves but user code might.
-_AS_EXPR_PREPARE
-_AS_LN_S_PREPARE
-_AS_MKDIR_P_PREPARE
-_AS_TEST_PREPARE
-_AS_TR_CPP_PREPARE
-_AS_TR_SH_PREPARE
-])
-
-
-# AS_PREPARE
-# ----------
-# Output all the M4sh possible initialization into the initialization
-# diversion.
-m4_defun([AS_PREPARE],
-[m4_divert_text([M4SH-INIT], [_AS_PREPARE])])
-
-
 ## ----------------------------- ##
 ## 2. Wrappers around builtins.  ##
 ## ----------------------------- ##
-- 
1.6.0.2


>From 6f106cdeadea6ea32c7047247cdb800f8d105d02 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Tue, 7 Oct 2008 12:00:02 -0600
Subject: [PATCH] Ensure _AS_CLEANUP is defined.

* lib/m4sugar/m4sh.m4 (_AS_CLEANUP): Give initial definition.
* tests/m4sh.at (AS@&address@hidden cleanup): Expose the need for this.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog           |    4 ++++
 lib/m4sugar/m4sh.m4 |    7 +++++++
 tests/m4sh.at       |    1 +
 3 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f610c79..f072ae4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2008-10-07  Eric Blake  <address@hidden>
 
+       Ensure _AS_CLEANUP is defined.
+       * lib/m4sugar/m4sh.m4 (_AS_CLEANUP): Give initial definition.
+       * tests/m4sh.at (AS@&address@hidden cleanup): Expose the need for this.
+
        Improve m4sh maintainability.
        * lib/m4sugar/m4sh.m4: Sort macros for sanitizing the shell; no
        code change.
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index edad040..b49f302 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -134,6 +134,13 @@ m4_define([_AS_BOURNE_COMPATIBLE],
 ])
 
 
+# _AS_CLEANUP
+# -----------
+# Expanded as the last thing before m4sugar cleanup begins.  Macros
+# may append m4sh cleanup hooks to this as appropriate.
+m4_define([_AS_CLEANUP])
+
+
 # AS_COPYRIGHT(TEXT)
 # ------------------
 # Emit TEXT, a copyright notice, as a shell comment near the top of the
diff --git a/tests/m4sh.at b/tests/m4sh.at
index 33bcca5..1fc9852 100644
--- a/tests/m4sh.at
+++ b/tests/m4sh.at
@@ -805,6 +805,7 @@ AT_DATA_M4SH([script.as], [[dnl
 dnl Registered before AS_INIT's cleanups
 m4_wrap([echo cleanup 1
 ])
+m4_pushdef([_AS_SHELL_FN_SPY])dnl neutralize the spy, we don't care about it
 AS_INIT
 dnl Registered after AS_INIT's cleanups, thus goes to KILL diversion
 m4_wrap([echo cleanup 2
-- 
1.6.0.2








reply via email to

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