autoconf-patches
[Top][All Lists]
Advanced

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

Re: _AC_CACHE_DUMP simplified


From: Ralf Wildenhues
Subject: Re: _AC_CACHE_DUMP simplified
Date: Thu, 6 Apr 2006 20:17:14 +0200
User-agent: Mutt/1.5.9i

Hello,

* Paul Eggert wrote on Thu, Apr 06, 2006 at 01:43:25AM CEST:
> I like the new patch, and think it should be installed since it fixes
> some potential real gotchas.  Some minor comments:
> 
> > +    case $ac_val in #(
> > +    *${as_nl}?*)
> 
> That '?' will cause the code to mishandle vars whose values have a newline
> only at the end.  Can't we omit it by....

> Changing this to "_ | as_nl | IFS"?

Yes.

> > +      *_cv_*) AC_MSG_WARN([Cache variable $ac_var contains a newline.]) ;;
> > +      esac
> > +      $as_unset $ac_var ;;
> 
> It sounds a bit risky to unset _ or IFS.  How about something like this 
> instead?

D'oh.  I actually meant to do that, but failed to write it this way.
Thanks for catching it!

I have installed the patch as follows.  It also contains a small
simplification of the last sed script in _AC_CACHE_DUMP by Stepan.

Cheers,
Ralf

2006-04-06  Stepan Kasal  <address@hidden>,
            Eric Blake  <address@hidden>,
            Paul Eggert  <address@hidden>,
            Ralf Wildenhues <address@hidden>

        * lib/autoconf/general.m4 (_AC_CACHE_DUMP): Fix the detection of
        whether `set' quotes correctly: redirect stderr of the tested
        `set', and use a subshell, for Ultrix; use `sed' instead of
        `grep' for zsh `set' which may write binary output; match only
        at the beginning of a line, to avoid false positives.
        In order to avoid false positives by unrelated variables with
        multiline content, put the dump algorithm in a subshell and
        unset all variables containing newlines (except some which are
        special to the shell).  Warn about cache variables that are
        unset.

Index: lib/autoconf/general.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/general.m4,v
retrieving revision 1.899
diff -u -r1.899 general.m4
--- lib/autoconf/general.m4     6 Apr 2006 13:49:08 -0000       1.899
+++ lib/autoconf/general.m4     6 Apr 2006 18:11:14 -0000
@@ -1821,26 +1821,39 @@
 m4_define([_AC_CACHE_DUMP],
 [# The following way of writing the cache mishandles newlines in values,
 # but we know of no workaround that is simple, portable, and efficient.
-# So, don't put newlines in cache variables' values.
+# So, we kill variables containing newlines.
 # Ultrix sh set writes to stderr and can't be redirected directly,
 # and sets the high bit in the cache file unless we assign to the vars.
-{
+(
+  for ac_var in `(set) 2>&1 | sed -n 
['s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p']`; do
+    eval ac_val=\$$ac_var
+    case $ac_val in #(
+    *${as_nl}*)
+      case $ac_var in #(
+      *_cv_*) AC_MSG_WARN([Cache variable $ac_var contains a newline.]) ;;
+      esac
+      case $ac_var in #(
+      _ | IFS | as_nl) ;; #(
+      *) $as_unset $ac_var ;;
+      esac ;;
+    esac
+  done
+
   (set) 2>&1 |
-    case `(ac_space=' '; set | grep ac_space) 2>&1` in
-    *ac_space=\ *)
+    case $as_nl`(ac_space=' '; set) 2>&1` in #(
+    *${as_nl}ac_space=\ *)
       # `set' does not quote correctly, so add quotes (double-quote
       # substitution turns \\\\ into \\, and sed turns \\ into \).
       sed -n \
        ["s/'/'\\\\''/g;
          s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"]
-      ;;
+      ;; #(
     *)
       # `set' quotes correctly as required by POSIX, so do not add quotes.
-      sed -n \
-       ["s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p"]
+      sed -n ["/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"]
       ;;
-    esac;
-}dnl
+    esac
+)dnl
 ])# _AC_CACHE_DUMP
 
 




reply via email to

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