diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-07-09 06:29:09 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-09-15 22:45:01 -0700 |
commit | e07561e6ac7f381061f112bee32ebc779683a84c (patch) | |
tree | 86ad55151c90232dceb0b431f846beafe5434a56 /perly.y | |
parent | 20d337866901b1d0118edc4ff2cb2407b27e0275 (diff) | |
download | perl-e07561e6ac7f381061f112bee32ebc779683a84c.tar.gz |
Clone state subs in anon subs
Since state variables are not shared between closures, but only
between invocations of the same closure, state subs should behave
the same way.
This was a little tricky. When we clone a sub, we now clone inner
state subs at the same time. When walking through the pad, cloning
items, we cannot simply clone the inner sub when we see it, because it
may close over things we haven’t cloned yet:
sub {
state sub foo;
my $x
sub foo { $x }
}
We can’t just delay cloning it and do it afterwards, because they may
be multiple subs closing over each other:
sub {
state sub foo;
state sub bar;
sub foo { \&bar }
sub bar { \&foo }
}
So *all* the entries in the new pad must be filled before any inner
subs can be cloned.
So what we do is put a stub in place of the cloned sub. And then
in a second pass clone the inner subs, reusing the stubs from the
first pass.
Diffstat (limited to 'perly.y')
-rw-r--r-- | perly.y | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -324,6 +324,13 @@ barestmt: PLUGSTMT || strEQ(name, "UNITCHECK")) CvSPECIAL_on(PL_compcv); } + else + /* State subs inside anonymous subs need to be + clonable themselves. */ + /* XXX This will need adjustment for state subs + inside my subs. */ + if (CvANON(CvOUTSIDE(PL_compcv))) + CvCLONE_on(PL_compcv); PL_parser->in_my = 0; PL_parser->in_my_stash = NULL; } |