* 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/>