autoconf-patches
[Top][All Lists]
Advanced

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

Re: [PATCH] Ditch _AS_LINENO_PREPARE from _AS_PREPARE


From: Paolo Bonzini
Subject: Re: [PATCH] Ditch _AS_LINENO_PREPARE from _AS_PREPARE
Date: Thu, 30 Oct 2008 18:54:31 +0100
User-agent: Thunderbird 2.0.0.17 (Macintosh/20080914)

> Ouch.  Our sed preprocess has the possibility of generating non-portable 
> child 
> scripts.  Anywhere where the parent script uses:
> 
> cat >>child <<EOF
> AS_ESCAPE([text], [$`])
> EOF
> 
> then any instances of $LINENO in text will be turned into \$LINENO.

Then you should not do it. :-(  But we have to warn.  Again, however,
this luckily is not a regression.

We can change

diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 1a61729..4d5e549 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -972,5 +972,5 @@ m4_defun([_AS_ME_PREPARE],
 # handing the test to another shell), so that we know which test to
 # trust.
 m4_define([_AS_LINENO_WORKS],
-[  as_lineno_1=$LINENO as_lineno_1a=$LINENO
-  as_lineno_2=$LINENO as_lineno_2a=$LINENO
+[  as_lineno_1=$LINENO as_lineno_1a=${LINENO}
+  as_lineno_2=$LINENO as_lineno_2a=${LINENO}

and make \$LINENO forbidden, as in the attached patch (proof of concept,
totally untested, includes the above hunk).

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

        * autom4te.in (@preselect): Track _m4_pattern_allow and
        _m4_pattern_forbid (now with underscore prepended).
        (handle_output): Likewise.  Split on whitespace or special m4
        characters.  Do not surround with \b.
        * lib/m4sugar/m4sugar.m4 (_m4_pattern_allow,
        _m4_pattern_forbid): New.
        (m4_pattern_allow, m4_pattern_forbid): Forward to them.
        * lib/m4sugar/m4sh.m4 (AS_INIT): Forbid \\\$LINENO.
        (_AS_LINENO_WORKS): Shut up the new warning here.

diff --git a/bin/autom4te.in b/bin/autom4te.in
index 50c410c..8a145c9 100644
--- a/bin/autom4te.in
+++ b/bin/autom4te.in
@@ -78,7 +78,7 @@ my %trace;
 #
 # FIXME: What about `sinclude'?
 my @preselect = ('include',
-                'm4_pattern_allow', 'm4_pattern_forbid',
+                '_m4_pattern_allow', '_m4_pattern_forbid',
                 '_m4_warn');
 
 # M4 include path.
@@ -524,8 +524,8 @@ sub handle_output ($$)
 
   # Load the forbidden/allowed patterns.
   handle_traces ($req, "$tmp/patterns",
-                ('m4_pattern_forbid' => 'forbid:$1:$2',
-                 'm4_pattern_allow'  => 'allow:$1'));
+                ('_m4_pattern_forbid' => 'forbid:$1:$2',
+                 '_m4_pattern_allow'  => 'allow:$1'));
   my @patterns = new Autom4te::XFile ("< " . open_quote 
("$tmp/patterns"))->getlines;
   chomp @patterns;
   my %forbidden =
@@ -574,7 +574,7 @@ sub handle_output ($$)
       # better, don't consider `#include' etc. are comments.
       s/\#.*//
        unless /^\#\s*(if|include|endif|ifdef|ifndef|define)\b/;
-      foreach (split (/\W+/))
+      foreach (split (/[][\s()+,]/))
        {
          $prohibited{$_} = $.
            if !/^$/ && /$forbidden/o && !/$allowed/o && ! exists 
$prohibited{$_};
@@ -597,7 +597,7 @@ sub handle_output ($$)
   $exit_code = 1;
   if ($ARGV[$#ARGV] ne '-')
     {
-      my $prohibited = '\b(' . join ('|', keys %prohibited) . ')\b';
+      my $prohibited = '(' . join ('|', keys %prohibited) . ')';
       my $file = new Autom4te::XFile ("< " . open_quote ($ARGV[$#ARGV]));
 
       while ($_ = $file->getline)
@@ -616,7 +616,7 @@ sub handle_output ($$)
              # If we're done, exit.
              return
                if ! %prohibited;
-             $prohibited = '\b(' . join ('|', keys %prohibited) . ')\b';
+             $prohibited = '(' . join ('|', keys %prohibited) . ')';
            }
        }
     }
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 1a61729..1fd9df4 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -972,8 +972,8 @@ m4_defun([_AS_ME_PREPARE],
 # handing the test to another shell), so that we know which test to
 # trust.
 m4_define([_AS_LINENO_WORKS],
-[  as_lineno_1=$LINENO as_lineno_1a=$LINENO
-  as_lineno_2=$LINENO as_lineno_2a=$LINENO
+[  as_lineno_1=$LINENO as_lineno_1a=${LINENO}
+  as_lineno_2=$LINENO as_lineno_2a=${LINENO}
   eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" &&
   test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"'])
 
@@ -1896,6 +1896,7 @@ m4_init
 m4_provide([AS_INIT])
 
 # Forbidden tokens and exceptions.
+_m4_pattern_forbid([\\\$LINENO], [something ought to be written here])
 m4_pattern_forbid([^_?AS_])
 
 # Bangshe and minimal initialization.
diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4
index 85d36d0..71900d9 100644
--- a/lib/m4sugar/m4sugar.m4
+++ b/lib/m4sugar/m4sugar.m4
@@ -1768,14 +1768,16 @@ m4_define([$1],
 # -----------------------------
 # Declare that no token matching the forbidden extended regular
 # expression ERE should be seen in the output unless...
-m4_define([m4_pattern_forbid], [])
+m4_define([m4_pattern_forbid], [_$0([\b$1\b], m4_shift($@))])
+m4_define([_m4_pattern_forbid], [])
 
 
 # m4_pattern_allow(ERE)
 # ---------------------
 # ... that token also matches the allowed extended regular expression ERE.
 # Both used via traces.
-m4_define([m4_pattern_allow], [])
+m4_define([m4_pattern_allow], [_$0([\b$1\b], m4_shift($@))])
+m4_define([_m4_pattern_allow], [])
 
 
 ## --------------------------------- ##

reply via email to

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