betterworld has asked for the wisdom of the Perl Monks concerning the following question:
I tried using Regexp::Grammars together with MooseX::Declare, and the result was… a segfault. My code is:
#!/usr/bin/perl use MooseX::Declare; my $gr = do { use Regexp::Grammars; qr { <Foo> <objrule: Foo> foo }x; }; class Foo { method BUILD { use Data::Dumper; print 'AH ', Dumper \@_; } } my $m = 'foo' =~ $gr or die 'no match';
The output of this program is:
AH $VAR1 = [ bless( {}, 'Foo' ), { '@' => {}, '!' => '-1' } ]; Segmentation fault
These strange hash keys ("@" and "!") seem to be some internal values of Regexp::Grammars. I see nothing about them in the documentation, so I'd say their exposure is a bug. However this does not seem to have anything to do with the segfault: The grammar calls the Foo constructor like in the following, but it won't segfault if I do so manually:
Foo->new( { '@' => {}, '!' => '-1' } );
Also, the segmentation fault disappears if I do either of:
- remove the BUILD method
- write the class direcly in Moose (without MooseX::Declare)
I should probably report a bug somewhere. However I am unsure where it should be reported. Regexp::Grammar itself does not seem to use any XS or lowlevel stuff, so it is probably not the problem. However, it uses many funny features of the new regexp engine. MooseX::Declare on the other hand uses a whole bunch of modules with a lot of magic in them. Maybe you can help me pinpoint the origin of this bug.
I use perl v5.10.1, MooseX::Declare 0.34, Regexp::Grammars 1.012, all current Debian wheezy versions.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Segfault with MooseX::Declare and Regexp::Grammars
by Anonymous Monk on Feb 27, 2011 at 13:08 UTC | |
by betterworld (Curate) on Feb 27, 2011 at 14:06 UTC | |
by Anonymous Monk on Feb 27, 2011 at 14:30 UTC | |
Re: Segfault with MooseX::Declare and Regexp::Grammars
by ELISHEVA (Prior) on Feb 27, 2011 at 13:12 UTC | |
by betterworld (Curate) on Feb 27, 2011 at 13:24 UTC | |
by ELISHEVA (Prior) on Feb 27, 2011 at 13:41 UTC | |
by betterworld (Curate) on Feb 27, 2011 at 14:13 UTC |