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
Father Chrysostomos via RT
August 1, 2013 01:15
[perl #119049] referencing some variables hides others from PadWalker starting 5.17.2
Message ID:
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.

use PadWalker peek_my;

sub outer {
    my $x = 2;
    my $sub = sub { ${ peek_my(0)->{'$x'} } };
    print "Before scope exit: ", $sub->();
print "After scope exit: ", outer->();
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

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About