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

Re: Variable unavailability inconsistency ([perl #113930] Lexicalsubs)

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
September 17, 2012 03:37
Subject:
Re: Variable unavailability inconsistency ([perl #113930] Lexicalsubs)
Message ID:
20120917103713.GO9583@plum.flirble.org
Sorry, this never got answered at the time, partly because I saw that you
seemed to have answered it yourself within 24 hours

On Fri, Aug 03, 2012 at 11:21:05PM -0700, Father Chrysostomos via RT wrote:

> commit adf8f095c5881bcedf07b8e41072f8125e00b5a6
> Author: Nicholas Clark <nick@ccl4.org>
> Date:   Fri Feb 26 09:18:44 2010 +0000
> 
>     Set PADSTALE on all lexicals at the end of sub creation.
>     
>     The PADSTALEness of lexicals between the 0th and 1st call to a
> subroutine is now
>     consistent with the state between the nth and (n + 1)th call.
>     
>     This permits a work around in Perl_padlist_dup() to avoid leaking
> active pad
>     data into a new thread, whilst still correctly bodging the external
> references
>     needed by the current ?{} implementation. Fix that, and this can be
> removed.
> 
> 
> I don't know whether this affects my subs yet, but I would like to gain
> a better understanding of this commit.  How did ?{} blocks work before?
>  What exactly was the fix intended to do?

I can't remember better than the commit message says. 

?{} blocks before and after this commit continued to be a complete
hack. (This was before Dave's fix for them landed). The short description is
"lexicals in ?{} blocks didn't work." Sadly, they *seemed* to work, until
you tried to do anything more exciting than calling a subroutine once.

On Sat, Aug 04, 2012 at 06:03:27PM -0700, Father Chrysostomos via RT wrote:
> On Sat Aug 04 06:43:00 2012, sprout wrote:

> > I can reproduce this bug even further back:
> > 
> > sub foo {
> >     my $x if @_;
> >     return if @_;
> > 
> >     $x = 17;
> >     print $x, "\n";
> >     print sub { $x }->(), "\n";
> >     return;
> > 
> > }
> > foo(1); # make $x stale in all perl versions
> > foo;

This doesn't surprise me. That commit revealed at least one test failure
from the BBC, but I was able to write a different test case for that module
which failed in the same way with perl before the commit you quote.

> > $ pbpaste|perl5.10.1 -w
> > 17
> > Variable "$x" is not available at - line 7.
> > Use of uninitialized value in print at - line 7.
> > 
> > $ pbpaste|perl5.10.0 -w
> > 17
> > 17
> > 
> 
> I've fixed both those issues with commit cae5dbbe3.

Good stuff.

Nicholas Clark

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