No, weakrefs cast backref magic onto their target to avoid this problem. When the reference count drops to zero the magic ensures that the weakref is set to undef.

See Perl_sv_rvweaken() in sv.c for more.

Sam.

Orton, Yves wrote:

> From: "Orton, Yves" <[EMAIL PROTECTED]>
> > > I thought you are just automagicaly weaken()ing the referenced
> > > stored in the tied hash??? Something like package
> Hash::NoRef; use
> > > Scalar::Util qw(weaken); require Tie::Hash; @ISA = (Tie::StdHash);
> > > sub STORE { $_[0]{$_[1]} = $_[2]; > weaken($_[0]{$_[1]}) if (ref
> > > $_[2]);
> > > }
> > > 'And that\'s it!';
> > > Am I missing something?
> >
> > Itll segfault under many circumstances.
> >
> > yves
>
> Then you should report an error in Scalar::Util.
>
> Do you have an example script that segfaults?



Maybe you were thinking I meant a problem with your code. I meant a problem with the entire approach. IMO weak refs are not the greatest solution to the problems that they are usually used for. Often there are much better approaches that don't involve risking segfaults.


Anyway, :-)
Yves




--
Sam Vilain, sam /\T vilain |><>T net, PGP key ID: 0x05B52F13
(include my PGP key ID in personal replies to avoid spam filtering)



Reply via email to