Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

perl Segmentation fault (with Storable?)

by glide (Pilgrim)
on Nov 20, 2007 at 17:01 UTC ( #651966=perlquestion: print w/replies, xml ) Need Help??

glide has asked for the wisdom of the Perl Monks concerning the following question:

Hi!,
i' getting a Segmentation fault, with a very simple program.
when i run it
perl script_ma.pl ### DESTROY - start ### _write_configuration - store start Segmentation fault
i have tested the script with perl versions: v5.8.5, v5.8.7, v5.8.8 in a ubuntu and fedora linux. (but if i remove the "skip" subroutine, the program run without any problem.)
#!/usr/bin/perl use strict; use warnings; use lib "$ENV{PWD}"; use myConfig; # create the objecto for write the db my $c_config = myConfig->new(); # add default to the configuration db $c_config->add_default(default=>'aa'); sub skip { my (%args)=@_; $c_config->add_default(default=>'bb'); return 0; }
package myConfig; use strict; use warnings; use Storable qw(store); use Class::Std::Utils; use Smart::Comments; { my %db_data; sub new { my ($class, %args) = @_; my $new_object = bless anon_scalar( ), $class; return $new_object; } sub _write_configuration { my ($self,%args) = @_; ### _write_configuration - store start store( $db_data{ident $self}, $ENV{PWD}."test") or die($!); ### _write_configuration - return return; } sub add_default { my ($self,%args) = @_; $db_data{ident $self}{default} = $args{default}; return; } sub DESTROY { my ($self) = @_; ### DESTROY - start $self->_write_configuration(); ### DESTROY - finish return; } } 1;
Any ideas?
many thanks

Replies are listed 'Best First'.
Re: perl Segmentation fault (with Storable?)
by shmem (Chancellor) on Nov 20, 2007 at 21:57 UTC
    It is in fact in Storable. Something is going wrong in XS_Storable_pstore() in the XS shared object. Stay tuned..

    <update>

    Changing your script to

    #!/usr/bin/perl use strict; use warnings; use lib "$ENV{PWD}"; use myConfig; # create the objecto for write the db our $c_config = myConfig->new(); # add default to the configuration db $c_config->add_default ( default => 'aa' ); $c_config->_write_configuration();

    produces the following output:

    ### _write_configuration - store start ### _write_configuration - return ### DESTROY - start ### _write_configuration - store start Segmentation fault

    The segfault is triggered only if store() is called in the DESTROY during global destruction. It occurs in Storable.xs in do_store()

    static int do_store( pTHX_ PerlIO *f, SV *sv, int optype, int network_order, SV **res) { dSTCXT; <--- here int status; ...
    in the macro dSTCXT which resolves to
    SV *perinterp_sv = *hv_fetch(PL_modglobal, MY_VERSION, sizeof(MY_VERSION)-1, TRUE); stcxt_t * cxt = ((perinterp_sv && SvIOK(perinterp_sv) && SvIVX(perinte +rp_sv) ? (stcxt_t *)SvPVX(SvRV(INT2PTR(SV*,SvIVX(perinterp_sv)))) : (stcx +t_t *) 0));

    It doesn't occur with the following script:

    #!/usr/bin/perl use strict; use warnings; use lib "$ENV{PWD}"; use myConfig; # create the objecto for write the db our $c_config = myConfig->new(); # add default to the configuration db $c_config->add_default ( default => 'aa' ); undef $c_config;

    Seems like during global destruction some things needed are already gone.

    </update>

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      It is in fact in Storable

      But don't you find it curious that just nearby there's a magical Damian module being used? Does commenting that out make the problem go away?

      • another intruder with the mooring in the heart of the Perl

        Do you mean Smart::Comments? No, commenting that out doesn't make any difference.

        I ask because there are *two* Damian modules involved ;-)

        --shmem

        _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                      /\_¯/(q    /
        ----------------------------  \__(m.====·.(_("always off the crowd"))."·
        ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: perl Segmentation fault (with Storable?)
by kyle (Abbot) on Nov 20, 2007 at 17:16 UTC

    Any segmentation fault is a bug (it may be a known bug; see rt://Storable). I haven't run your code, but I notice that $ENV{PWD} on my system does not have a trailing slash. As such, $ENV{PWD}."test" may not be what you want. You may want $ENV{PWD}."/test" or you may want to have a look at File::Spec (specifically, catfile).

      Any segmentation fault is a bug
      Not always. It is possible to get segmentation faults by exceeding the maximum memory in perl.

      In theory this could also happen with a bad Storable file, i.e. if some wrong length parameter causes memory overflow.

      Addendum: while this is true for retrieve, a segfault should never happen with store, as in the code of the poster.

      In the real program .. I'm not using the $ENV{PWD} (I'm using the FindBin). But in the example I used the %ENV just to remove dependencies.
        Seeing the real (minimal) program that causes the problem might enable someone to spot the cause of the problem.
Re: perl Segmentation fault (with Storable?)
by Anonymous Monk on Nov 20, 2007 at 20:03 UTC
    i have tested the script with perl versions: v5.8.5, v5.8.7, v5.8.8 in a ubuntu and fedora linux. (but if i remove the "skip" subroutine, the program run without any problem.)
    Latest release is Storable-2.17
      The version 2.17 of the Storable, don't change anything, unfortunately.
Re: perl Segmentation fault (with Storable?)
by Anonymous Monk on Dec 23, 2007 at 19:16 UTC
    I ran into similar segmentation faults in some long running processes which use Storable quite a lot. I am not sure my problems is related to what you mention, but at least on one machine I have your test program works fine and on another it does not. The one where it worked runs Storable 2.16 and the one where it fails runs 2.18. Downgrading to 2.16 on the machine that fails makes your test program run just fine. With some luck, this is indeed the same problem that make my programs segfault from time to time on another machine.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://651966]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2019-12-09 00:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?