Skip Menu |

This queue is for tickets about the Math-BigInt-GMP CPAN distribution.

Report information
The Basics
Id: 57064
Status: resolved
Priority: 0/
Queue: Math-BigInt-GMP

People
Owner: Nobody in particular
Requestors: tabris [...] tabris.net
Cc:
AdminCc:

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



Subject: Cannot serialize Math::BigInt::GMP
Date: Thu, 29 Apr 2010 17:32:52 -0700
To: bug-Math-BigInt-GMP [...] rt.cpan.org
From: tabris <tabris [...] tabris.net>
When one uses 'Storable' on a Math::BigInt::GMP object, it serializes the pointer, not the value. When you load it in, a segfault occurs. Looks related to https://rt.cpan.org/Public/Bug/Display.html?id=49336 I ran into this issue while passing a Math::BigInt::GMP object through Storable and then through a socket to a forked process. Math::BigInt works with Storable, but not JSON (not that Math::BigInt::GMP does either). I think we need better serialize methods for both classes. Basic info: Debian Lenny. perl 5.10.0 tabris@leif:~$ dpkg -l libmath* Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad) ||/ Name Version Description +++-=======================================-=======================================-============================================================================================== ii libmath-bigint-gmp-perl 1.24-1 GMP library for Math::BigInt routines un libmath-bigint-perl <none> (no description available) ii libmath-gmp-perl 2.04-2.1+b1 high speed arbitrary size integer math for perl tabris@leif:~$ dpkg -l perl Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad) ||/ Name Version Description +++-=======================================-=======================================-============================================================================================== ii perl 5.10.0-19lenny2 Larry Wall's Practical Extraction and Report Language tabris@leif:~$
Download signature.asc
application/pgp-signature 258b

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #57064] AutoReply: Cannot serialize Math::BigInt::GMP
Date: Thu, 29 Apr 2010 19:51:42 -0700
To: bug-Math-BigInt-GMP [...] rt.cpan.org
From: tabris <tabris [...] tabris.net>
On 04/29/2010 05:33 PM, Bugs in Math-BigInt-GMP via RT wrote: Show quoted text
> Greetings, > > This message has been automatically generated in response to the > creation of a trouble ticket regarding: > "Cannot serialize Math::BigInt::GMP", > a summary of which appears below. > > There is no need to reply to this message right now. Your ticket has been > assigned an ID of [rt.cpan.org #57064]. Your ticket is accessible > on the web at: > > https://rt.cpan.org/Ticket/Display.html?id=57064 > > Please include the string: > > [rt.cpan.org #57064] > > in the subject line of all future correspondence about this issue. To do so, > you may reply to this message. > > Thank you, > bug-Math-BigInt-GMP@rt.cpan.org > > ------------------------------------------------------------------------- > When one uses 'Storable' on a Math::BigInt::GMP object, it serializes > the pointer, not the value. When you load it in, a segfault occurs. > > Looks related to https://rt.cpan.org/Public/Bug/Display.html?id=49336 > > I ran into this issue while passing a Math::BigInt::GMP object through > Storable and then through a socket to a forked process. > > Math::BigInt works with Storable, but not JSON (not that > Math::BigInt::GMP does either). > > I think we need better serialize methods for both classes. >
After some experimentation, I've managed to get a STORABLE_freeze method that seems to work. But I can't get a STORABLE_thaw method, b/c Storable doesn't let me return an object, but rather try to init an existent fake object. At least so far.
Download signature.asc
application/pgp-signature 261b

Message body not shown because it is not plain text.

CC: bug-Math-BigInt-GMP [...] rt.cpan.org
Subject: [rt.cpan.org #57064] Cannot serialize Math::BigInt::GMP
Date: Fri, 07 May 2010 09:22:50 -0700
To: perl5-porters [...] perl.org
From: tabris <tabris [...] tabris.net>
This is a crosspost for perl5 porters, and updated. When one uses 'Storable' on a Math::BigInt::GMP object, it serializes the pointer, not the value. When you load it in, a segfault occurs. Looks related to https://rt.cpan.org/Public/Bug/Display.html?id=49336 I ran into this issue while passing a Math::BigInt::GMP object through Storable and then through a socket to a forked process. Math::BigInt works with Storable, but not JSON (not that Math::BigInt::GMP does either). I think we need better serialize methods for both classes. I've managed to write a STORABLE_freeze method, but cannot find a way to modify an existing (but broken) Math::BigInt::GMP object so that STORABLE_thaw can work. This is in part b/c Math::BigInt::GMP is a SCALAR (which afaict only is a C pointer) Maybe Storable needs an alt hook so that instead of modifying an existent object, we can return a new object? ------------------------------------------------------------------------ This reasonably works (albeit i'm not sure you need to specifically do the special freeze, you could probably 'return $sv'. sub STORABLE_freeze { my ($this, $cloning) = @_; # the usual behaviour re 'return if $cloning' # doesn't apply here # insofar as we need to actually have a different C pointer my $sv = _str(__PACKAGE__, $this); return Storable::freeze(\$sv); } STORABLE_thaw doesn't work at all, b/c the object created by Storable that is passed in as $this isn't a valid GMP object (dereferencing it causes a segfault). I don't know how it creates it. sub STORABLE_thaw { my ($this, $cloning, $serialized) = @_; my $ref = \$this; print "STORABLE_thaw0: $ref\n"; my $val = ${Storable::thaw($serialized)}; my $obj = Math::BigInt->new($val); $ref = \$obj; print "STORABLE_thaw1: $obj $ref\n"; } ------------------------------------------------------------------------ Basic info: Debian Lenny. perl 5.10.0 tabris@leif:~$ dpkg -l libmath* Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad) ||/ Name Version Description +++-=======================================-=======================================-============================================================================================== ii libmath-bigint-gmp-perl 1.24-1 GMP library for Math::BigInt routines un libmath-bigint-perl <none> (no description available) ii libmath-gmp-perl 2.04-2.1+b1 high speed arbitrary size integer math for perl tabris@leif:~$ dpkg -l perl Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad) ||/ Name Version Description +++-=======================================-=======================================-============================================================================================== ii perl 5.10.0-19lenny2 Larry Wall's Practical Extraction and Report Language tabris@leif:~$
Download signature.asc
application/pgp-signature 261b

Message body not shown because it is not plain text.

CC: bug-Math-BigInt-GMP [...] rt.cpan.org
Subject: [rt.cpan.org #57064] Cannot serialize Math::BigInt::GMP [repost]
Date: Fri, 07 May 2010 11:58:43 -0700
To: perl5-porters [...] perl.org
From: tabris <tabris [...] tabris.net>
This is a crosspost for perl5 porters, and updated. When one uses 'Storable' on a Math::BigInt::GMP object, it serializes the pointer, not the value. When you deserialize and dereference, a segfault occurs. Looks related to https://rt.cpan.org/Public/Bug/Display.html?id=49336 I ran into this issue while passing a Math::BigInt::GMP object through Storable and then through a socket to a forked process. Math::BigInt works with Storable, but not JSON (not that Math::BigInt::GMP does either). If we can make Storable work, we can probably make YAML & JSON work too. I think we need better serialize methods for both classes. I've managed to write a STORABLE_freeze method, but cannot find a way to modify an existing (but broken) Math::BigInt::GMP object so that STORABLE_thaw can work. This is in part b/c Math::BigInt::GMP is a SCALAR (which afaict only is a C pointer) Maybe Storable needs an alt hook so that instead of modifying an existent object, we can return a new object? Should this instead be a Storable feature-request, for a STORABLE_thaw2 that returns a new object, not a pre-existing object? ------------------------------------------------------------------------ This reasonably works (albeit i'm not sure you need to specifically do the special freeze, you could probably 'return $sv'. sub STORABLE_freeze { my ($this, $cloning) = @_; # the usual behaviour re 'return if $cloning' # doesn't apply here # insofar as we need to actually have a different C pointer my $sv = _str(__PACKAGE__, $this); return Storable::freeze(\$sv); } STORABLE_thaw doesn't work at all, b/c the object created by Storable that is passed in as $this isn't a valid GMP object (dereferencing it causes a segfault). I don't know how Storable creates it. sub STORABLE_thaw { my ($this, $cloning, $serialized) = @_; my $ref = \$this; print "STORABLE_thaw0: $ref\n"; my $val = ${Storable::thaw($serialized)}; my $obj = Math::BigInt->new($val); $ref = \$obj; print "STORABLE_thaw1: $obj $ref\n"; } ------------------------------------------------------------------------ Basic info: Debian Lenny. perl 5.10.0 tabris@leif:~$ dpkg -l libmath* Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad) ||/ Name Version Description +++-=======================================-=======================================-============================================================================================== ii libmath-bigint-gmp-perl 1.24-1 GMP library for Math::BigInt routines un libmath-bigint-perl <none> (no description available) ii libmath-gmp-perl 2.04-2.1+b1 high speed arbitrary size integer math for perl tabris@leif:~$ dpkg -l perl Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad) ||/ Name Version Description +++-=======================================-=======================================-============================================================================================== ii perl 5.10.0-19lenny2 Larry Wall's Practical Extraction and Report Language tabris@leif:~$
Download signature.asc
application/pgp-signature 261b

Message body not shown because it is not plain text.

I'll be happy to make Math::BigInt::GMP provide the right hooks for Storable. But to ensure the hooks are actually working, and also keep working in future releases, could you please provide a test case for that feature?
Subject: Re: [rt.cpan.org #57064] Cannot serialize Math::BigInt::GMP
Date: Tue, 14 Sep 2010 13:07:59 -0700
To: bug-Math-BigInt-GMP [...] rt.cpan.org
From: tabris <tabris [...] tabris.net>
Florian Ragwitz via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=57064 > > > I'll be happy to make Math::BigInt::GMP provide the right hooks for > Storable. But to ensure the hooks are actually working, and also keep > working in future releases, could you please provide a test case for > that feature? >
The second script will segfault, if you have GMP available. ------------------------ #!/usr/bin/perl use strict; use warnings; use Storable qw( nstore ); use Math::BigInt try => 'GMP'; my $sv = Math::BigInt->new('68719476736'); print \$sv, "\n"; nstore(\$sv, 'gmptest.dat'); ------------------------------------------------------------------------ #!/usr/bin/perl use strict; use warnings; use Storable qw( nstore retrieve ); use Math::BigInt try => 'GMP'; my $sv = retrieve('gmptest.dat'); print "$sv\n"
Download signature.asc
application/pgp-signature 262b

Message body not shown because it is not plain text.

The development release 1.31 adds Storable hooks similar to the ones you were proposing, and also a unit test based on yours. I'd appreciate if you could give it a try and see if it fixes things for your actual usecase.