Skip Menu |

This queue is for tickets about the Object-Pad CPAN distribution.

Report information
The Basics
Id: 132321
Status: resolved
Priority: 0/
Queue: Object-Pad

People
Owner: Nobody in particular
Requestors: leonerd-cpan [...] leonerd.org.uk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.19
Fixed in: 0.20



Subject: Anon methods generated other methods segfault at compiletime
A minimal test case: use Object::Pad 0.19; class GeneratedMethod; method BUILD { my $m = method { }; } -- Paul Evans
Initial analysis: $ gdb --args perl -Mblib rt132321.pm (gdb) run Starting program: /usr/bin/perl -Mblib rt132321.pm [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7fc4fa1 in parse_pre_blockend (my_perl=<optimized out>, ctx=ctx@entry=0x7fffffffd630) at lib/Object/Pad.xs:1015 1015 PADNAMELIST *slotnames = PadlistNAMES(CvPADLIST(compclassmeta->methodscope)); (gdb) bt #0 0x00007ffff7fc4fa1 in parse_pre_blockend (my_perl=<optimized out>, ctx=ctx@entry=0x7fffffffd630) at lib/Object/Pad.xs:1015 #1 0x00007ffff7fbcbe6 in parse2 (hooksA=<optimized out>, hooksB=<optimized out>, op_ptr=<optimized out>, my_perl=<optimized out>) at lib/XS/Parse/Sublike.xs:140 #2 0x00005555555ded48 in Perl_yylex (my_perl=my_perl@entry=0x5555558a92a0) at toke.c:7205 #3 0x00005555555f49eb in Perl_yyparse (my_perl=my_perl@entry=0x5555558a92a0, gramtype=gramtype@entry=258) at perly.c:340 #4 0x00005555555c55e1 in S_parse_body (xsinit=0x55555559c570 <xs_init>, env=0x0, my_perl=0x5555558a92a0) at perl.c:2531 #5 perl_parse (my_perl=<optimized out>, xsinit=0x55555559c570 <xs_init>, argc=<optimized out>, argv=<optimized out>, env=0x0) at perl.c:1822 #6 0x000055555559c3b3 in main (argc=<optimized out>, argv=<optimized out>, env=<optimized out>) at perlmain.c:126 Probably the compclassmeta->methodscope of the outer named `method BUILD` got corrupted by the inner `method` one. -- Paul Evans
On Fri Apr 10 08:33:58 2020, PEVANS wrote: Show quoted text
> Probably the compclassmeta->methodscope of the outer named `method > BUILD` got corrupted by the inner `method` one.
Yup. Pretty simple fix. Patch attached. -- Paul Evans
Subject: rt132321.patch
=== modified file 'lib/Object/Pad.xs' --- old/lib/Object/Pad.xs 2020-04-03 23:14:16 +0000 +++ new/lib/Object/Pad.xs 2020-04-10 12:39:53 +0000 @@ -782,6 +782,8 @@ meta->tmpcop = (COP *)newSTATEOP(0, NULL, NULL); CopFILE_set(meta->tmpcop, __FILE__); + meta->methodscope = NULL; + /* CARGOCULT from perl/op.c:Perl_package() */ { SAVEGENERICSV(PL_curstash); @@ -955,6 +957,11 @@ AV *slots = compclassmeta->slots; U32 nslots = av_count(slots); + /* Save the methodscope for this subparse, in case of nested methods + * (RT132321) + */ + SAVESPTR(compclassmeta->methodscope); + /* While creating the new scope CV we need to ENTER a block so as not to * break any interpvars */ === modified file 't/01method.t' --- old/t/01method.t 2020-03-25 19:14:27 +0000 +++ new/t/01method.t 2020-04-10 12:39:53 +0000 @@ -39,4 +39,20 @@ 'anon method' ); } +# nested anon method (RT132321) +{ + class RT132321 { + has $_genvalue; + + method BUILD { + $_genvalue = method { 123 }; + } + + method value { $self->$_genvalue() } + } + + my $obj = RT132321->new; + is( $obj->value, 123, '$obj->value from BUILD-generated anony method' ); +} + done_testing;