Change 31451 by [EMAIL PROTECTED] on 2007/06/23 19:04:04

        Resolve 
        
http://www.nntp.perl.org/group/perl.perl5.porters/2007/06/msg125667.html by 
reverting part of change #29354. 
        
        Unfortunately match vars after a /g match in scalar context will be 
unsafe (again) after this, but such matches on long strings won't be as 
diabolically slow.
        
        Question: why does the new test in t/op/pat.t pass, but the same test 
in t/op/reg_unsafe.t fail? (Latter is TODO for now)

Affected files ...

... //depot/perl/MANIFEST#1590 edit
... //depot/perl/pp_hot.c#522 edit
... //depot/perl/t/op/pat.t#291 edit
... //depot/perl/t/op/reg_unsafe.t#1 add

Differences ...

==== //depot/perl/MANIFEST#1590 (text) ====
Index: perl/MANIFEST
--- perl/MANIFEST#1589~31446~   2007-06-22 08:17:23.000000000 -0700
+++ perl/MANIFEST       2007-06-23 12:04:04.000000000 -0700
@@ -3761,6 +3761,7 @@
 t/op/regexp.t                  See if regular expressions work
 t/op/regexp_trielist.t         See if regular expressions work with trie 
optimisation
 t/op/regmesg.t                 See if one can get regular expression errors
+t/op/reg_unsafe.t              Check for unsafe match vars
 t/op/repeat.t                  See if x operator works
 t/op/reset.t                   See if reset operator works
 t/op/re_tests                  Regular expressions for regexp.t

==== //depot/perl/pp_hot.c#522 (text) ====
Index: perl/pp_hot.c
--- perl/pp_hot.c#521~31333~    2007-06-05 03:10:33.000000000 -0700
+++ perl/pp_hot.c       2007-06-23 12:04:04.000000000 -0700
@@ -1266,9 +1266,12 @@
            }
        }
     }
-    /* remove comment to get faster /g but possibly unsafe $1 vars after a
-       match. Test for the unsafe vars will fail as well*/
-    if (( /* !global &&  */ rx->nparens) 
+    /* XXX: comment out !global get safe $1 vars after a
+       match, BUT be aware that this leads to drammatic slowdowns on
+       /g matches against large strings.  So far a solution to this problem
+       appears to be quite tricky.
+       Test for the unsafe vars are TODO for now. */
+    if ((  !global &&  rx->nparens) 
            || SvTEMP(TARG) || PL_sawampersand ||
            (rx->extflags & (RXf_EVAL_SEEN|RXf_PMf_KEEPCOPY)))
        r_flags |= REXEC_COPY_STR;

==== //depot/perl/t/op/pat.t#291 (xtext) ====
Index: perl/t/op/pat.t
--- perl/t/op/pat.t#290~31341~  2007-06-06 07:42:01.000000000 -0700
+++ perl/t/op/pat.t     2007-06-23 12:04:04.000000000 -0700
@@ -4453,7 +4453,12 @@
         if 'foo'=~/(?<x>foo)|bar/;
     iseq($ok,1,'$+{x} exists after "foo"=~/(?<x>foo)|bar/');
 }
-
+{
+    local $_;
+    ($_ = 'abc')=~/(abc)/g;
+    $_ = '123'; 
+    iseq("$1",'abc',"/g leads to unsafe match vars: $1");
+}
 
 # Test counter is at bottom of file. Put new tests above here.
 #-------------------------------------------------------------------
@@ -4504,6 +4509,6 @@
 iseq(0+$::test,$::TestCount,"Got the right number of tests!");
 # Don't forget to update this!
 BEGIN {
-    $::TestCount = 1960;
+    $::TestCount = 1961;
     print "1..$::TestCount\n";
 }

==== //depot/perl/t/op/reg_unsafe.t#1 (text) ====
Index: perl/t/op/reg_unsafe.t
--- /dev/null   2007-03-19 09:41:43.516454971 -0700
+++ perl/t/op/reg_unsafe.t      2007-06-23 12:04:04.000000000 -0700
@@ -0,0 +1,19 @@
+#!./perl
+
+BEGIN {
+    chdir 't' if -d 't';
+    @INC = '../lib';
+    
+}
+print "1..1\n";
+
+# there is an equivelent test in t/op/pat.t which does NOT fail
+# its not clear why it doesnt fail, so this todo gets its own test
+# file until we can work it out.
+
+my $x; 
+($x='abc')=~/(abc)/g; 
+$x='123'; 
+
+print "not " if $1 ne 'abc';
+print "ok 1 # TODO safe match vars make /g slow\n";
End of Patch.

Reply via email to