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

[PATCH] weaken read only refs

From:
Fergal Daly
Date:
November 19, 2003 05:59
Subject:
[PATCH] weaken read only refs
Message ID:
20031119124746.GB13881@dyn.fergaldaly.com
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__};               
        weaken($a);
};    

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?                                                            

F     

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).




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About