autoconf-patches
[Top][All Lists]
Advanced

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

[PATCH] modernize AS_UNSET a bit (take 2)


From: Paolo Bonzini
Subject: [PATCH] modernize AS_UNSET a bit (take 2)
Date: Tue, 14 Oct 2008 15:16:48 +0200

The last one for today, and hopefully the last before shell functions
are actually used.  This patch takes into account Ralf's worries about
unset portability.

The idea is to only worry about shells that, like Bash 2.05a, give
an error when unsetting a variable that not exists.  For these shells,
we can do much better than as_unset=false.  Other shells have no
shell functions, so we can discard them after the prolog.

The only case that should be considered is that of an old shell executing
a new shell.  In this case, you should really make sure that BASH_ENV and
ENV are unset *or set to a neutral value* before executing the new shell.
If needed, the new shell will unset them for real.

We assume that the user does not try to unset MAIL.  We do that in the
prolog, together with unsetting BASH_ENV and ENV.

Finally, this patch provides $as_unset for backwards compatibility.
Two points on this:

1) clients should nevertheless switch to AS_UNSET.

2) $as_unset points to a shell function; by triggering the
shell-function-required test, this in turn ensures that unset is
available, even if buggy.  If as_unset is removed, _AS_UNSET_PREPARE
should anyway add a required-test for `unset'.

Paolo
---
 lib/m4sugar/m4sh.m4      |   50 ++++++++++++++++++++++----------------------
 lib/autoconf/general.m4  |    2 +-
 lib/autoconf/programs.m4 |    2 +-
 3 files changed, 27 insertions(+), 27 deletions(-)

2008-10-14  Paolo Bonzini  <address@hidden>

        * lib/m4sugar/m4sh.m4 (_AS_UNSET_PREPARE): Provide $as_unset as an
        alias for AS_UNSET, for backwards compatibility.
        (AS_INIT, _AS_PREPARE, AS_PREPARE): Call it.
        (AS_SHELL_SANITIZE): Work around Bash 2.01 bugs.  Unset BASH_ENV.
        (_AS_DETECT_BETTER_SHELL): Set BASH_ENV and ENV to /dev/null in case
        the shell does not support unset.  Do not do _AS_UNSET_PREPARE.
        (AS_UNSET): Assume it is there but it might fail if the variable is
        not there.  Use it throughout instead of $as_unset.
        * lib/autoconf/general.m4 (_AC_CACHE_DUMP): Use AS_UNSET.
        * lib/autoconf/programs.m4 (AC_PROG_SED): Use AS_UNSET.

diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4
index 986b7af..beb3104 100644
--- a/lib/autoconf/general.m4
+++ b/lib/autoconf/general.m4
@@ -1894,7 +1894,7 @@ m4_define([_AC_CACHE_DUMP],
       case $ac_var in #(
       _ | IFS | as_nl) ;; #(
       BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
-      *) $as_unset $ac_var ;;
+      *) AS_UNSET([$ac_var]) ;;
       esac ;;
     esac
   done
diff --git a/lib/autoconf/programs.m4 b/lib/autoconf/programs.m4
index 63f8a13..9e68381 100644
--- a/lib/autoconf/programs.m4
+++ b/lib/autoconf/programs.m4
@@ -894,7 +894,7 @@ AC_DEFUN([AC_PROG_SED],
        ac_script="$ac_script$as_nl$ac_script"
      done
      echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed
-     $as_unset ac_script || ac_script=
+     ac_script=; AS_UNSET([ac_script])
      _AC_PATH_PROGS_FEATURE_CHECK(SED, [sed gsed],
        [_AC_FEATURE_CHECK_LENGTH([ac_path_SED], [ac_cv_path_SED],
                ["$ac_path_SED" -f conftest.sed])])])
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 9c1af0f..dec9f37 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -187,8 +187,7 @@ m4_set_add([_AS_DETECT_SUGGESTED_BODY],
 # <http://lists.gnu.org/archive/html/autoconf-patches/2006-03/msg00081.html>.
 #
 m4_defun_once([_AS_DETECT_BETTER_SHELL],
-[AS_REQUIRE([_AS_UNSET_PREPARE], , [M4SH-SANITIZE])dnl
-m4_append([_AS_CLEANUP], [m4_divert_text([M4SH-SANITIZE], [
+[m4_append([_AS_CLEANUP], [m4_divert_text([M4SH-SANITIZE], [
 if test "x$CONFIG_SHELL" = x; then
 dnl Remove any tests from suggested that are also required
   m4_set_foreach([_AS_DETECT_SUGGESTED_BODY], [AS_snippet],
@@ -226,8 +225,9 @@ dnl Remove any tests from suggested that are also required
       done
 
       AS_IF([test "x$CONFIG_SHELL" != x],
-       [for as_var in BASH_ENV ENV
-       do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
+       [# Provide a neutralization value for shells without unset
+       for as_var in BASH_ENV ENV
+       do eval \$as_var=/dev/null; AS_UNSET([$as_var])
        done
        export CONFIG_SHELL
        exec "$CONFIG_SHELL" "$as_myself" ${1+"address@hidden"}])
@@ -272,6 +272,7 @@ _AS_MKDIR_P_PREPARE
 _AS_TEST_PREPARE
 _AS_TR_CPP_PREPARE
 _AS_TR_SH_PREPARE
+_AS_UNSET_PREPARE
 ])
 
 # AS_PREPARE
@@ -292,6 +293,7 @@ AS_REQUIRE([_AS_MKDIR_P_PREPARE])
 AS_REQUIRE([_AS_TEST_PREPARE])
 AS_REQUIRE([_AS_TR_CPP_PREPARE])
 AS_REQUIRE([_AS_TR_SH_PREPARE])
+AS_REQUIRE([_AS_UNSET_PREPARE])
 ])
 
 
@@ -428,7 +430,6 @@ AS_BOURNE_COMPATIBLE
 _AS_CR_PREPARE
 _AS_ECHO_PREPARE
 _AS_PATH_SEPARATOR_PREPARE
-_AS_UNSET_PREPARE
 
 # IFS
 # We need space, tab and new line, in precisely that order.  Quoting is
@@ -454,9 +455,11 @@ if test ! -f "$as_myself"; then
   AS_EXIT
 fi
 
-# Work around bugs in pre-3.0 UWIN ksh.
-for as_var in ENV MAIL MAILPATH
-do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
+# Unset variables that we do not need and cause bugs (e.g. in pre-3.0 UWIN 
ksh).
+# But do not cause bugs in bash 2.01; the "|| exit 1" suppresses any
+# "Segmentation fault" message there.  '((' could trigger a bug in pdksh 
5.2.14.
+for as_var in BASH_ENV ENV MAIL MAILPATH
+do ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
 done
 PS1='$ '
 PS2='> '
@@ -469,7 +472,7 @@ LANGUAGE=C
 export LANGUAGE
 
 # CDPATH.
-$as_unset CDPATH
+AS_UNSET([CDPATH])
 ])# AS_SHELL_SANITIZE
 
 
@@ -550,27 +553,21 @@ fi
 
 # _AS_UNSET_PREPARE
 # -----------------
-# AS_UNSET depends upon $as_unset: compute it.
-# Use MAIL to trigger a bug in Bash 2.01;
-# the "|| exit" suppresses the resulting "Segmentation fault" message.
-# Avoid 'if ((', as that triggers a bug in pdksh 5.2.14.
+# Define $as_unset to execute AS_UNSET, for backwards compatibility
+# with older versions of M4sh.
 m4_defun([_AS_UNSET_PREPARE],
-[# Support unset when possible.
-if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
-  as_unset=unset
-else
-  as_unset=false
-fi
+[AS_REQUIRE_SHELL_FN([as_func_unset], [AS_UNSET([$1])])dnl
+as_unset=as_func_unset
 ])
 
 
-# AS_UNSET(VAR, [VALUE-IF-UNSET-NOT-SUPPORTED = `'])
-# --------------------------------------------------
-# Try to unset the env VAR, otherwise set it to
-# VALUE-IF-UNSET-NOT-SUPPORTED.  `as_unset' must have been computed.
+# AS_UNSET(VAR)
+# -------------
+# Unset the env VAR, working around shells that do not allow unsetting
+# a variable that is not already set.  You should not unset MAIL and
+# MAILCHECK, as that triggers a bug in Bash 2.01.
 m4_defun([AS_UNSET],
-[AS_REQUIRE([_AS_UNSET_PREPARE])dnl
-$as_unset $1 || test "${$1+set}" != set || { $1=$2; export $1; }])
+[{ unset $1 >/dev/null 2>&1 || :;}])
 
 
 
@@ -1741,6 +1738,9 @@ m4_divert_text([HEADER-COMMENT],
               address@hidden:@ Generated from __file__ by m4_PACKAGE_STRING.])
 m4_divert_text([M4SH-SANITIZE], [AS_SHELL_SANITIZE])
 
+# For backwards compatibility.
+AS_REQUIRE([_AS_UNSET_PREPARE])
+
 # Let's go!
 m4_divert_pop([KILL])[]dnl
 m4_divert_push([BODY])[]dnl
-- 
1.5.5





reply via email to

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