CC: | bug-Storable [...] rt.cpan.org, perl5-porters [...] perl.org |
Subject: | Re: Storable - Feature-request - alternate freeze/thaw hooks |
Date: | Sun, 30 May 2010 10:05:53 -0700 |
To: | Yuval Kogman <nothingmuch [...] woobling.org> |
From: | tabris <tabris [...] tabris.net> |
Yuval Kogman wrote:
Show quoted text
> That would break circular references, which might not be a concern for
> GMP ints but is required for other things.
>
> However, ince the typemap specifies:
>
> OUTPUT
> MPZ
> sv_setref_pv($arg, \"Math::BigInt::GMP\", INT2PTR(void*, $var));
>
>
> You can probably just get away with
>
> sub STORABLE_thaw {
> my ( $self ) = @_;
>
> my $new = ... thaw a new instance ...;
> bless $new, "Something::Else"; # avoid any destructors
> $$self = $$new; # simply steal the pointer
> }
>
I'll try this approach again (I did something similar but was trying to
replace the obj-ref, not the pointer itself).
And incidentally, is there a way that in the freeze hook I could freeze
a Math::BigInt, rather than Math::BigInt::GMP ? That would get around
this problem _and_ 'do the right thing' insofar as the _user_ probably
just wanted a Math::BigInt, not a Math::BigInt::GMP.
Show quoted text> but it would probably be better to refactor the M::B::GMP code to
> allow doing this sort of thing without violating encapsulation.
>
>
Message body not shown because it is not plain text.