develooper Front page | perl.perl5.porters | Postings from November 2003

[PATCH] weaken read only refs

Fergal Daly
November 19, 2003 05:59
[PATCH] weaken read only refs
Message ID:
with 5.8.2, 5.8.1 and 5.6.1 (and presumably 5.6.2 etc)

> perl -MScalar::Util=weaken -e '$a=\"h";weaken($a)'
Modification of a read-only value attempted at -e line 1

this means that if you're writing something general that weakens refs, like
a cache, you have to do

eval {
        local $SIG{__DIE__};               

instead of just 

weaken ($a)

Patch attached to fix this by adding PERL_MAGIC_backref to the list of
things that can be done to a readonly value.

I added some tests, everything still passes, is there some other reason not
to allow this?                                                            


P.S. I sent this to perlbug initially but it never made the list (I think
due to me sending a followup before the ticket was approved). Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About