develooper Front page | perl.perl5.porters | Postings from August 2013

[perl #119049] referencing some variables hides others from PadWalker starting 5.17.2

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
August 1, 2013 01:15
Subject:
[perl #119049] referencing some variables hides others from PadWalker starting 5.17.2
Message ID:
rt-3.6.HEAD-2552-1375319732-1198.119049-15-0@perl.org
On Wed Jul 31 16:51:01 2013, rjbs wrote:
> On Wed Jul 31 16:35:13 2013, rjbs wrote:
> > What are the practical wins to making closure per-variable instead of
> > per-environment?
> 
> Presumably the answer is equivalent to "closes #89544"

Yes.  But it can be phrased like this:  It makes it easier to avoid
memory leaks.

Now one thing we could do is leave the closure with its CvOUTSIDE
pointer but make it a weak pointer.  That would involve backreferences
to make sure it gets cleared if the outer sub is freed.

I didn’t think it was worth the complexity involved.  How strongly do
you feel about having this work?

BTW, PadWalker does give surprising results even before a0d2bbd5c47 if
it accesses a variable implicitly closed over that comes from an outer
scope that is not a closure, and that outer scope has already exited.

$\="\n";
use PadWalker peek_my;

sub outer {
    my $x = 2;
    my $sub = sub { ${ peek_my(0)->{'$x'} } };
    print "Before scope exit: ", $sub->();
    $sub;
}
print "After scope exit: ", outer->();
__END__
Before scope exit: 2
After scope exit: 

That we cannot fix without introducing potential memory leaks in places
where 5.16 didn’t have them.

In this case, and in the original report, explicitly naming the variable
in the anonymous subroutine will cause the second line to print 2 as well.

Is it worth trying to fix this if we cannot get it to work completely?

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: rejected
https://rt.perl.org:443/rt3/Ticket/Display.html?id=119049

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About