autoconf-patches
[Top][All Lists]
Advanced

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

[PATCH] Modernize AS_UNSET, take 3


From: Paolo Bonzini
Subject: [PATCH] Modernize AS_UNSET, take 3
Date: Wed, 15 Oct 2008 13:32:09 +0200

This addresses all the nits in the previous patch, except one.  I had to
leave the AS_REQUIRE of _AS_UNSET_PREPARE in AS_INIT, because it defines
a shell function and so it must go *after* the better-shell search.

In order to use AS_UNSET([$foo]), which expands to "eval $foo=; unset $foo",
I had to add an AS_LITERAL_IF.  Nothing special.

Ok?

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

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

        * lib/m4sugar/m4sh.m4 (_AS_UNSET_PREPARE): Provide $as_unset as an
        alias for AS_UNSET, for backwards compatibility.
        (_AS_DETECT_BETTER_SHELL): Set BASH_ENV and ENV to /dev/null in case
        the shell does not support unset.
        (_AS_SHELL_SANITIZE): Work around Bash 2.01 bugs.  Unset BASH_ENV.
        (AS_INIT, _AS_PREPARE, AS_PREPARE): Call it.
        (AS_UNSET): Assume it is there but it might fail if the variable is
        not set.  Use it throughout instead of $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..45a74b5 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=
+     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 571a13e..68562ec 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -224,9 +224,12 @@ 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
-       done
+       [# We cannot yet assume a decent shell, so we have to provide a
+       # neutralization value for shells without unset; and this also
+       # works around shells that cannot unset nonexistent variables.
+       BASH_ENV=/dev/null
+       ENV=/dev/null
+       (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
        export CONFIG_SHELL
        exec "$CONFIG_SHELL" "$as_myself" ${1+"address@hidden"}])
 
@@ -270,6 +273,7 @@ _AS_MKDIR_P_PREPARE
 _AS_TEST_PREPARE
 _AS_TR_CPP_PREPARE
 _AS_TR_SH_PREPARE
+_AS_UNSET_PREPARE
 ])
 
 # AS_PREPARE
@@ -290,6 +294,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])
 ])
 
 
@@ -315,8 +320,7 @@ m4_if(m4_eval(_m4_divert(_m4_divert_dump) <= 
_m4_divert(_m4_divert_desired)), 1,
 # 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 ()
+[AS_REQUIRE([AS_SHELL_FN_$1], [m4_provide([AS_SHELL_FN_$1])$1 ()
 {
 $2
 }], m4_default_quoted([$3], [M4SH-INIT-FN]))])
@@ -391,7 +395,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
@@ -417,9 +420,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='> '
@@ -432,7 +437,7 @@ LANGUAGE=C
 export LANGUAGE
 
 # CDPATH.
-$as_unset CDPATH
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
 ])# _AS_SHELL_SANITIZE
 
 
@@ -446,6 +451,7 @@ m4_provide_if([AS_INIT], [],
 [m4_provide([AS_INIT])
 _AS_DETECT_REQUIRED([_AS_SHELL_FN_WORK])
 _AS_DETECT_BETTER_SHELL
+_AS_UNSET_PREPARE
 ])])
 
 
@@ -526,27 +532,24 @@ 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_func_unset ()
+{
+  AS_UNSET([$[1]])
+}
+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; }])
+[{ AS_LITERAL_IF([$1], [], [eval ])$1=; unset $1;}])
 
 
 
@@ -1721,4 +1724,5 @@ m4_divert_text([M4SH-SANITIZE], [_AS_SHELL_SANITIZE])
 m4_divert_pop([KILL])[]dnl
 m4_divert_push([BODY])[]dnl
 _AS_DETECT_REQUIRED([_AS_SHELL_FN_WORK])dnl
+AS_REQUIRE([_AS_UNSET_PREPARE])dnl For backwards compatibility.
 ])
-- 
1.5.5





reply via email to

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