bug-autoconf
[Top][All Lists]
Advanced

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

Re: [PATCH] Dealing with read-only variables


From: Ludovic Courtès
Subject: Re: [PATCH] Dealing with read-only variables
Date: Wed, 9 Jun 2004 12:23:43 +0200
User-agent: Mutt/1.5.4i [Guile enabled]

Hello,

Did anyone had a chance to look at this patch?  I'd like to have some
feedback about it as I think it can be useful (well, yes, it's not
really exciting ;-)).

Thanks,
Ludovic.

4 days, 21 hours, 10 minutes, 2 seconds ago, 
Ludovic Courtès wrote:
> Hi again,
> 
> With the previous patch, read-only variable `as_unused_readonly_var' was
> potentially re-used by `config.status' which does not work.
> 
> Also, `_AS_LINENO_PREPARE' did not check whether `ENV' was read-only
> before unsetting it.
> 
> This patch fixes it.  I tested it by adding a "readonly ENV" (or
> "readonly ENV=x" for bash) line at the beginning of `configure' and then
> letting it run till the end.
> 
> Ludovic.
> 
> Today, one hour, 23 minutes, 19 seconds ago, Ludovic Courtès wrote:
> > Hi,
> > 
> > Some news regarding the `unset' issue with read-only variables when
> > using SGI's /bin/sh on IRIX 6.5 (see below).  According to their manual
> > [1], `sh' supports read-only variables through the `readonly' builtin
> > command and such variables cannot be unset.  From my experience, trying
> > to unset a read-only variable from within a script just makes it stop.
> > Also, by default, it seems that the `ENV' variable is read-only.
> > 
> > So I came up with the following workaround: use the `readonly' or
> > `readonly -p' output and grep it in order to known whether a given
> > variable is read-only.  Unset it iff it is _not_ read-only (or none of
> > `readonly VAR', `readonly' and `readonly -p' works).
> > 
> > The attached patch applies to `lib/m4sugar/m4sh.m4' (Autoconf 2.59).  I
> > did not add an `AS_READONLY_VAR' test to `AS_UNSET' since this is
> > probably not useful for variables which are only used from within the
> > script.  I tested it with Bash 2.05, Tru64 5.1's /bin/sh, and HP-UX
> > 11.11's /bin/sh (couldn't test it with IRIX's /bin/sh though).
> > 
> > Side note: Bash 2.05 seems to be buggy in that `ENV' does not show up in
> > the output of `readonly -p' if one executes `readonly ENV' _after_ it's
> > been defined (although `ENV' actually is read-only, ie. `unset ENV'
> > complains).  However, `ENV' does show up in the `readonly -p' output if
> > it has been defined as `readonly ENV=x'...
> > 
> > Thanks,
> > Ludovic.
> > 
> > [1] 
> > http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?coll=0650&db=man&fname=/usr/share/catman/u_man/cat1/sh.z&srch=sh
> > 
> > 2 days, one hour, one minute, 59 seconds ago, 
> > Ludovic Courtès wrote:
> > > Hi,
> > > 
> > > I'm forwarding this message here since it may be more relevant to post
> > > it here.
> > > 
> > > Thanks,
> > > Ludovic.
> > > 
> > > -------------------[ Forwarded from Ludovic Courtès ]-------------------
> > > 
> > > From: Ludovic Courtès <address@hidden>
> > > To: address@hidden
> > > Date: Fri, 28 May 2004 10:30:45 +0200
> > > Subject: `unset ENV' and `AC_CHECK_LIB' on IRIX
> > > 
> > > Hi,
> > > 
> > > I got into troubles when running an Autoconf 2.59 generated `configure'
> > > script on an IRIX64 6.2 machine.
> > > 
> > > The first problem I had is that I was unable to run `configure' and
> > > `config.status' as is.  Both scripts contain the following line:
> > > 
> > >   # Work around bugs in pre-3.0 UWIN ksh.
> > >   $as_unset ENV MAIL MAILPATH
> > > 
> > > On IRIX (whose `sh' does support `unset'), this causes the script to
> > > abort with the following error message:
> > > 
> > >   configure[35]: ENV: readonly
> > > 
> > > (35 being the number of the line where the `unset' occurs).  Is there a
> > > way to work around this problem?
> > > 
> > > 
> > > The second problem I had was when checking for function `main' in some
> > > libraries, like:
> > > 
> > >   AC_CHECK_LIB([ACE], [main],
> > >          [LIBS="-lACE $LIBS"],
> > >                [AC_MSG_ERROR([Could not find libACE.])])
> > > 
> > > (since there are C++ libraries, I cannot check for actual function name
> > > such as `ACE::init ()' since Autoconf would declare it "as is" which
> > > won't work).  SGI CC C++ compiler produces an error with a message like:
> > > 
> > >   function "main" may not be called or have its address taken
> > > 
> > > Compaq's CXX outputs a similar message except that it only considers it
> > > as a warning.  With SGI CC, this causes `configure' to think that the
> > > library was not found.  Using `CHECK_LIB' with an empty function name
> > > doesn't work.  So, again, what would be the best solution to work around
> > > this problem?
> > > 
> > > Thanks,
> > > Ludovic.
> > > 
> > > 
> > > _______________________________________________
> > > Autoconf mailing list
> > > address@hidden
> > > http://mail.gnu.org/mailman/listinfo/autoconf
> > > 
> > > ----------------------[ End of forwarded message ]----------------------
> > > 
> > > 
> 
> > --- m4sh.m4.orig    Fri Jun  4 10:17:11 2004
> > +++ m4sh.m4 Fri Jun  4 13:22:29 2004
> > @@ -155,9 +155,19 @@
> >  DUALCASE=1; export DUALCASE # for MKS sh
> >  
> >  _AS_UNSET_PREPARE
> > +_AS_READONLY_PREPARE
> >  
> >  # Work around bugs in pre-3.0 UWIN ksh.
> > -$as_unset ENV MAIL MAILPATH
> > +for as_var in ENV MAIL MAILPATH
> > +do
> > +  # Before unsetting a variable, check whether it is read-only.
> > +  # Trying to unset a read-only variable with SGI's /bin/sh on IRIX 6.5
> > +  # causes the script to stop (and the `ENV' variable typically is
> > +  # read-only).
> > +  AS_READONLY_VAR([$as_var], [],
> > +                  [$as_unset $as_var])
> > +done
> > +
> >  PS1='$ '
> >  PS2='> '
> >  PS4='+ '
> > @@ -289,6 +299,30 @@
> >  fi
> >  ])
> >  
> > +# _AS_READONLY_PREPARE
> > +# -----------------
> > +# Compute $as_readonly depending on whether the `readonly' builtin is
> > +# available.
> > +m4_defun([_AS_READONLY_PREPARE],
> > +[# Check whether `readonly' is available.
> > +# Most shells (bash, IRIX's /bin/sh, HP-UX 11.11's /bin/sh) have
> > +# `readonly -p' list all read-only variables; however, Tru64's /bin/sh
> > +# does not support `-p'.  Fortunately, most shells (each one of the
> > +# above shells, although I couldn't check on IRIX) also list all
> > +# readonly variables when no argument is passed to `readonly'.
> > +as_unused_readonly_var=something ; export as_unused_readonly_var
> > +if readonly as_unused_readonly_var >/dev/null 2>&1 ; then
> > +  if readonly | grep "as_unused_readonly_var=" >/dev/null 2>&1; then
> > +    as_readonly=readonly
> > +  elif readonly -p | grep "as_unused_readonly_var=" >/dev/null 2>&1; then
> > +    as_readonly="readonly -p"
> > +  else
> > +    as_readonly=true
> > +  fi
> > +else
> > +  as_readonly=true
> > +fi
> > +])
> >  
> >  # AS_UNSET(VAR, [VALUE-IF-UNSET-NOT-SUPPORTED = `'])
> >  # --------------------------------------------------
> > @@ -298,6 +332,24 @@
> >  [AS_REQUIRE([_AS_UNSET_PREPARE])dnl
> >  $as_unset $1 || test "${$1+set}" != set || { $1=$2; export $1; }])
> >  
> > +# AS_READONLY_VAR(VAR, ACTION-IF-READONLY, ACTION-IF-READWRITE)
> > +# -------------------------------------------------------------
> > +# If read-only variables are supported, check whether VAR is readonly and
> > +# execute ACTION-IF-READONLY if it is, ACTION-IF-READWRITE otherwise.
> > +# Both Tru64's /bin/sh and GNU bash `readonly' builtins list the read-only
> > +# variables when no argument is given.  However, IRIX's /bin/sh manual
> > +# does not mention whether if behaves the same way (`readonly -p' does
> > +# list read-only variables though).
> > +m4_defun([AS_READONLY_VAR],
> > +[AS_REQUIRE([_AS_READONLY_PREPARE])dnl
> > +if $as_readonly | grep "$1=" >/dev/null 2>&1 ; then
> > +   :
> > +   $2
> > +else
> > +   :
> > +   $3
> > +fi
> > +])
> >  
> >  
> >  
> 

> --- m4sh.m4.orig      Fri Jun  4 10:17:11 2004
> +++ m4sh.m4   Fri Jun  4 15:04:14 2004
> @@ -155,9 +155,19 @@
>  DUALCASE=1; export DUALCASE # for MKS sh
>  
>  _AS_UNSET_PREPARE
> +_AS_READONLY_PREPARE
>  
>  # Work around bugs in pre-3.0 UWIN ksh.
> -$as_unset ENV MAIL MAILPATH
> +for as_var in ENV MAIL MAILPATH
> +do
> +  # Before unsetting a variable, check whether it is read-only.
> +  # Trying to unset a read-only variable with SGI's /bin/sh on IRIX 6.5
> +  # causes the script to stop (and the `ENV' variable typically is
> +  # read-only).
> +  AS_READONLY_VAR([$as_var], [],
> +                  [$as_unset $as_var])
> +done
> +
>  PS1='$ '
>  PS2='> '
>  PS4='+ '
> @@ -289,6 +299,40 @@
>  fi
>  ])
>  
> +# _AS_READONLY_PREPARE
> +# -----------------
> +# Compute $as_readonly depending on whether the `readonly' builtin is
> +# available.
> +m4_defun([_AS_READONLY_PREPARE],
> +[# Check whether `readonly' is available.
> +# Most shells (bash, IRIX's /bin/sh, HP-UX 11.11's /bin/sh) have
> +# `readonly -p' list all read-only variables; however, Tru64's /bin/sh
> +# does not support `-p'.  Fortunately, most shells (each one of the
> +# above shells, although I couldn't check on IRIX) also list all
> +# read-only variables when no argument is passed to `readonly'.
> +
> +if test "x$as_readonly_var_name" = "x"; then
> +  as_readonly_var_name="as_unused_readonly_var"
> +else
> +  # don't reuse the same read-only variable name
> +  as_readonly_var_name="${as_readonly_var_name}x"
> +fi
> +export as_readonly_var_name
> +
> +eval "$as_readonly_var_name=something"
> +export $as_readonly_var_name
> +if readonly $as_readonly_var_name >/dev/null 2>&1 ; then
> +  if readonly | grep "$as_readonly_var_name" >/dev/null 2>&1; then
> +    as_readonly=readonly
> +  elif readonly -p | grep "$as_readonly_var_name" >/dev/null 2>&1; then
> +    as_readonly="readonly -p"
> +  else
> +    as_readonly=true
> +  fi
> +else
> +  as_readonly=true
> +fi
> +])
>  
>  # AS_UNSET(VAR, [VALUE-IF-UNSET-NOT-SUPPORTED = `'])
>  # --------------------------------------------------
> @@ -298,6 +342,24 @@
>  [AS_REQUIRE([_AS_UNSET_PREPARE])dnl
>  $as_unset $1 || test "${$1+set}" != set || { $1=$2; export $1; }])
>  
> +# AS_READONLY_VAR(VAR, ACTION-IF-READONLY, ACTION-IF-READWRITE)
> +# -------------------------------------------------------------
> +# If read-only variables are supported, check whether VAR is readonly and
> +# execute ACTION-IF-READONLY if it is, ACTION-IF-READWRITE otherwise.
> +# Both Tru64's /bin/sh and GNU bash `readonly' builtins list the read-only
> +# variables when no argument is given.  However, IRIX's /bin/sh manual
> +# does not mention whether if behaves the same way (`readonly -p' does
> +# list read-only variables though).
> +m4_defun([AS_READONLY_VAR],
> +[AS_REQUIRE([_AS_READONLY_PREPARE])dnl
> +if $as_readonly | grep "$1" >/dev/null 2>&1 ; then
> +   :
> +   $2
> +else
> +   :
> +   $3
> +fi
> +])
>  
>  
>  
> @@ -539,6 +601,7 @@
>  # configure.
>  m4_define([_AS_LINENO_PREPARE],
>  [AS_REQUIRE([_AS_CR_PREPARE])dnl
> +AS_REQUIRE([_AS_READONLY_PREPARE])dnl
>  _AS_LINENO_WORKS || {
>    # Find who we are.  Look in the path if we contain no path at all
>    # relative or not.
> @@ -563,8 +626,10 @@
>        case $as_dir in
>        /*)
>          if ("$as_dir/$as_base" -c '_AS_LINENO_WORKS') 2>/dev/null; then
> -          AS_UNSET(BASH_ENV)
> -          AS_UNSET(ENV)
> +          AS_READONLY_VAR([BASH_ENV], [],
> +                          [AS_UNSET(BASH_ENV)])
> +             AS_READONLY_VAR([ENV], [],
> +                             [AS_UNSET(ENV)])
>            CONFIG_SHELL=$as_dir/$as_base
>            export CONFIG_SHELL
>            exec "$CONFIG_SHELL" "$[0]" ${1+"address@hidden"}





reply via email to

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