develooper Front page | perl.perl5.porters | Postings from June 2012

[perl #89544] closure keeps containing scope alive

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
June 18, 2012 09:41
Subject:
[perl #89544] closure keeps containing scope alive
Message ID:
rt-3.6.HEAD-5009-1340037654-763.89544-15-0@perl.org
On Fri Jun 15 05:41:40 2012, LeonT wrote:
> On Tue May 17 06:23:23 2011, davem wrote:
> > The other bit of information missing is that inner anon subs hold a
> > reference to their enclosing sub, so any outer sub (anon or otherwise)
> > doesn't normally get freed until the inner sub has been freed.
> 
> But is there any conceptual reason why it has to do this? Why can't it
> just keep the variables in encloses alive instead?
> 
> > So I don't think its a bug, nor do do I think the behaviour should be
> > changed.
> 
> I do think this is a misfeature, and I would like to see it changed: it
> makes working with nested closures unnecessarily complicated.

I have just been bitten by the same thing.  So I wrote a patch.  It is
only eight lines (excluding tests).  Ignoring the new flag I added to
cv.h, it is only three lines of changes.

Can Dave Mitchell please comment?

As far as I can tell, CvOUTSIDE is only used during compilation when
looking up variables.  So at run time we only need it if there is a
string eval.

However, we might have to close over $_ even when it appears unused for
UNDERBAR to work.  But that is already partially broken.

-- 

Father Chrysostomos


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


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