This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix CvOUTSIDE for state subs in predeclared subs
authorFather Chrysostomos <sprout@cpan.org>
Sat, 3 Jan 2015 04:15:10 +0000 (20:15 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 4 Jan 2015 00:05:56 +0000 (16:05 -0800)
commit307cbb9fc37bc4e2ceb1d77690249dea0ccbc0ca
treeb985119437150cc1fc746d7cd643b4c87cd88813
parentfa87ec39c0ab9e6a9009caf5bc528efa6dc8aabc
Fix CvOUTSIDE for state subs in predeclared subs

use 5.018;
use experimental 'lexical_subs';
$::x = "global";
sub x;
sub x {
    state $x = 42;
    state sub x { print eval '$x', "\n" }
    \&x;
}
x()->();
__END__

Output:

Segmentation fault: 11

Because this line in pad.c:S_findpadlex:

1141     const PADLIST * const padlist = CvPADLIST(cv);

is trying to read this SV:

SV = UNKNOWN(0x76) (0xaa170e4fd) at 0x10060c928
  REFCNT = 1697135711
  FLAGS = (PADSTALE,TEMP,GMG,SMG,IOK,pNOK,pPOK,UTF8)

(i.e., gibberish).

During compilation, â€˜sub x{’ creates a new CV.  When the sub is about
to be installed (when the final â€˜}’ is reached), the existing stub
must be reused.  So everything is copied from the new CV (PL_compcv)
to the stub.  Also, any CvOUTSIDE pointers of nested subs get updated
to point to the erstwhile stub.

State subs were not getting their CvOUTSIDE pointers updated.  This
patch implements that.
pad.c
t/op/lexsub.t