| Store | Cart

Re: Cannot write serialization code without access to Perl_hv_backreferences_p

From: Aristotle Pagaltzis <paga...@gmx.de>
Mon, 22 Dec 2014 13:51:35 +0100
* bulk88 <bul...@hotmail.com> [2014-12-21 23:30]:
> demerphq wrote:> > Imagine I have a structure like this:> >> > my $x="foo";> > my $r= \$x;> > weaken($r);> >> > If we then serialize $r, when we deserialize it if we preserve the> > weakref then instantly the deserialized $x will go out of scope.>> Then don't do a FREETMPS or LEAVE until the entire data on disk> structure is in Perl space. Something like>> SAVETMPS;> ......later on......> sv_2mortal(SvREFCNT_inc_simple_NN(SvRV(sv)))> sv_rvweaken(sv);> ......later on......> FREETMPS;

You completely missed the point. The issue is not that $r will go out of
scope *during* deserialisation, but that it will go out of scope *after*
deserialisation – i.e. it will not be in the deserialised data structure
returned to the caller of the deserialiser. [^1]

But should be.

Which means that the deserialiser needs to know that all references to
it are weak, so it can strengthen one of them so that it will survive.

However, Yves:

Can this really not be done without Perl_hv_backreferences_p? Namely,
since you are deserialising the structure, you know every part of the
structure. You also know when you are recreating a reference to some
other part of that structure, and whether that was a weak reference or
not. So you can just keep track of whether a referent has any strong
references or not – no? Am I missing something?


[^1]: So the exact timing of FREETMPS/LEAVE is completely irrelevant.

-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

Recent Messages in this Thread
Father Chrysostomos Dec 21, 2014 08:49 pm
demerphq Dec 21, 2014 09:23 pm
demerphq Dec 21, 2014 09:24 pm
demerphq Dec 21, 2014 09:53 pm
bulk88 Dec 21, 2014 10:25 pm
demerphq Dec 21, 2014 10:31 pm
bulk88 Dec 21, 2014 11:31 pm
demerphq Dec 22, 2014 02:22 am
Aristotle Pagaltzis Dec 22, 2014 12:51 pm
demerphq Dec 22, 2014 02:51 pm
Steffen Mueller Dec 22, 2014 04:56 pm
demerphq Dec 22, 2014 05:06 pm
Aristotle Pagaltzis Dec 23, 2014 06:44 am
demerphq Dec 23, 2014 01:41 pm
bulk88 Dec 21, 2014 10:11 pm
demerphq Dec 21, 2014 10:15 pm
Steffen Mueller Dec 21, 2014 07:23 pm
Messages in this thread