diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 1998-10-15 02:19:03 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1998-10-15 02:19:03 +0000 |
commit | 33b8ce059bff80913058d8738ead1314953634ba (patch) | |
tree | 370514e12c68e3cc55abf97ffab278d70529a8d1 | |
parent | d289e7db020f51c3b365d7505ca1a0e8ad4ae805 (diff) | |
download | perl-33b8ce059bff80913058d8738ead1314953634ba.tar.gz |
tweak to make fix in change#1944 behave correctly for closures
created within eval''
p4raw-link: @1944 on //depot/perl: 6b35e00972a13cc3d5e641e82fd498a9d9f6a324
p4raw-id: //depot/perl@1966
-rw-r--r-- | op.c | 15 | ||||
-rwxr-xr-x | t/op/eval.t | 14 |
2 files changed, 23 insertions, 6 deletions
@@ -310,6 +310,7 @@ pad_findmy(char *name) SV **svp = AvARRAY(PL_comppad_name); U32 seq = PL_cop_seqmax; PERL_CONTEXT *cx; + CV *outside; #ifdef USE_THREADS /* @@ -339,16 +340,20 @@ pad_findmy(char *name) } } - /* Check if if we're in an eval'', and adjust seq to be the eval's - * seq number */ - if (cxstack_ix >= 0) { + outside = CvOUTSIDE(PL_compcv); + + /* Check if if we're compiling an eval'', and adjust seq to be the + * eval's seq number. This depends on eval'' having a non-null + * CvOUTSIDE() while it is being compiled. The eval'' itself is + * identified by CvUNIQUE being set and CvGV being null. */ + if (outside && CvUNIQUE(PL_compcv) && !CvGV(PL_compcv) && cxstack_ix >= 0) { cx = &cxstack[cxstack_ix]; if (CxREALEVAL(cx)) seq = cx->blk_oldcop->cop_seq; } /* See if it's in a nested scope */ - off = pad_findlex(name, 0, seq, CvOUTSIDE(PL_compcv), cxstack_ix, 0); + off = pad_findlex(name, 0, seq, outside, cxstack_ix, 0); if (off) { /* If there is a pending local definition, this new alias must die */ if (pendoff) @@ -3500,7 +3505,7 @@ CV* cv; cv, (CvANON(cv) ? "ANON" : (cv == PL_main_cv) ? "MAIN" - : CvUNIQUE(outside) ? "UNIQUE" + : CvUNIQUE(cv) ? "UNIQUE" : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"), outside, (!outside ? "null" diff --git a/t/op/eval.t b/t/op/eval.t index 0d2a90b21c..498c63aaf3 100755 --- a/t/op/eval.t +++ b/t/op/eval.t @@ -1,6 +1,6 @@ #!./perl -print "1..28\n"; +print "1..29\n"; eval 'print "ok 1\n";'; @@ -117,3 +117,15 @@ sub recurse { local $SIG{__WARN__} = sub { die "not ok $x\n" if $_[0] =~ /^Deep recurs/ }; recurse($x-5); } +$x++; + +# do closures created within eval bind correctly? +eval <<'EOT'; + sub create_closure { + my $self = shift; + return sub { + print $self; + }; + } +EOT +create_closure("ok $x\n")->(); |