do FILE should not see outside lexicals (from Rick Delaney
Gurusamy Sarathy [Wed, 8 Mar 2000 18:35:48 +0000 (18:35 +0000)]
<rick@consumercontact.com>)

p4raw-id: //depot/perl@5620

op.c
pp_ctl.c
t/comp/require.t

diff --git a/op.c b/op.c
index bc07904..689fc18 100644 (file)
--- a/op.c
+++ b/op.c
@@ -356,8 +356,9 @@ S_pad_findlex(pTHX_ char *name, PADOFFSET newoff, U32 seq, CV* startcv,
                if (CxREALEVAL(cx))
                    saweval = i;
                break;
+           case OP_DOFILE:
            case OP_REQUIRE:
-               /* require must have its own scope */
+               /* require/do must have their own scope */
                return 0;
            }
            break;
index edbe7b1..42811f5 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -2727,8 +2727,11 @@ S_doeval(pTHX_ int gimme, OP** startop)
     av_store(comppadlist, 1, (SV*)PL_comppad);
     CvPADLIST(PL_compcv) = comppadlist;
 
-    if (!saveop || saveop->op_type != OP_REQUIRE)
+    if (!saveop ||
+       (saveop->op_type != OP_REQUIRE && saveop->op_type != OP_DOFILE))
+    {
        CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(caller);
+    }
 
     SAVEFREESV(PL_compcv);
 
index efce899..1d92687 100755 (executable)
@@ -7,7 +7,7 @@ BEGIN {
 
 # don't make this lexical
 $i = 1;
-print "1..19\n";
+print "1..20\n";
 
 sub do_require {
     %INC = ();
@@ -113,7 +113,18 @@ do_require "1";
 print "# $@\nnot " if $@;
 print "ok ",$i++,"\n";
 
-END { 1 while unlink 'bleah.pm'; }
+# do FILE shouldn't see any outside lexicals
+my $x = "ok $i\n";
+write_file("bleah.do", <<EOT);
+\$x = "not ok $i\\n";
+EOT
+do "bleah.do";
+dofile();
+sub dofile { do "bleah.do"; };
+print $x;
+$i++;
+
+END { 1 while unlink 'bleah.pm'; 1 while unlink 'bleah.do'; }
 
 # ***interaction with pod (don't put any thing after here)***