From: Gurusamy Sarathy Date: Thu, 15 Oct 1998 02:19:03 +0000 (+0000) Subject: tweak to make fix in change#1944 behave correctly for closures X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=33b8ce059bff80913058d8738ead1314953634ba;p=p5sagit%2Fp5-mst-13.2.git 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 --- diff --git a/op.c b/op.c index d673fad..eb4856e 100644 --- a/op.c +++ b/op.c @@ -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 0d2a90b..498c63a 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")->();