Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

segfault in p5_unwrap_p6_hash #179

Open
jonathanstowe opened this issue Nov 20, 2022 · 0 comments
Open

segfault in p5_unwrap_p6_hash #179

jonathanstowe opened this issue Nov 20, 2022 · 0 comments

Comments

@jonathanstowe
Copy link

By way of experiment I tried:

use Storable:from<Perl5> <store retrieve>; 
my $a =  { a => 1, b => 2, c => 3 } ;
store($a, 'foo.store'); 
say retrieve('foo.store').raku

The retrieve causes a segfault.

It seems this is in the p5_unwrap_p6_hash :

Thread 1 "rakudo-m" received signal SIGSEGV, Segmentation fault.
p5_unwrap_p6_hash (my_perl=<optimized out>, obj=<optimized out>) at /home/jonathan/.zef/tmp/Inline%3A%3APerl5%3Aver%3C0.60%3E%3Aauth%3Ccpan%3ANINE%3E.tar.gz/Inline-Perl5-0.60/p5helper.c:298
298	        return ((_perl6_hash_magic*)(mg->mg_ptr))->index;
(gdb) bt
#0  p5_unwrap_p6_hash (my_perl=<optimized out>, obj=<optimized out>)
    at /home/jonathan/.zef/tmp/Inline%3A%3APerl5%3Aver%3C0.60%3E%3Aauth%3Ccpan%3ANINE%3E.tar.gz/Inline-Perl5-0.60/p5helper.c:298
#1  0x00007ffff7965de2 in dcCall_x64_sysv () from //usr/local/lib/libmoar.so
#2  0x0000026144030080 in ?? ()
#3  0x00007fffffffce00 in ?? ()
#4  0x00007ffff7965c1c in dc_callvm_call_x64 () from //usr/local/lib/libmoar.so
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb) print mg
$1 = (MAGIC * const) 0x0

Which seems to be that the

MAGIC * const mg = mg_find(SvRV(p6hashobj), '~');

Can set mg to 0 without a check.

This may or may not be related to the Perl program:

use Storable qw(retrieve);

use Data::Dump qw(pp);

my $f = retrieve('foo.store');

print pp($f);

(using the Storable file generated above,) blowing up with:

Cannot restore overloading on SCALAR(0x561bc28b4518) (package Perl6::Object) (even after a "require Perl6::Object;") at /usr/lib64/perl5/vendor_perl/Storable.pm line 421, at p5-retrieve-hash line 7.

(which seems to indicate that the storable is storing something whacky in the file, but I 'm not sure whether Storable should even be expected to deal with this properly, so that's a different story.)

FWIW doing the reverse with a hash created in Perl:

use Storable qw(store);

my $a = { a => 1, b => 2, c => 3 };

store($a, 'foo.store');

and loading in Raku:

use Storable:from<Perl5> <retrieve>; 
say retrieve('foo.store').raku

Works fine.

It's only the segfault that is the problem, the rest might be expected given that Storable is being asked to do something it wasn't made for.

BTW, if anyone is interested, this roundtrip can be made to work if one de-references the Hash from raku in Perl space (thus losing the thing that Storable doesn't like about the reference,) before storing it:

use Inline::Perl5;
use Storable:from<Perl5> <store retrieve>; 

my $p5 = Inline::Perl5.new;
my $a =  { a => 1, b => 2, c => 3 } ;

$p5.run(q:to/P5/);
	use Storable qw(store);
    sub my_store {
        my ( $ref, $f ) = @_;
        my %a = %$ref;
        store(\%a, $f);
    }
P5
$p5.call('my_store', $a, 'foo.store'); 
say retrieve('foo.store').raku
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant