develooper Front page | perl.perl5.porters | Postings from March 2013

Re: [perl #117299] keys are readonly in perl 5.14.2!

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
March 25, 2013 09:44
Subject:
Re: [perl #117299] keys are readonly in perl 5.14.2!
Message ID:
20130325094432.GF3729@plum.flirble.org
On Fri, Mar 22, 2013 at 06:01:02PM +0100, Leon Timmermans wrote:
> On Fri, Mar 22, 2013 at 5:58 PM, demerphq <demerphq@gmail.com> wrote:
> > Ah. I see. So the bug is in HTML::Entities.
> >
> > The actual code that kicked this off was this:
> >
> > $ booking-perl5.14.2 -MDevel::Peek -MHTML::Entities -le'print $]; my
> > %hash=("A".."D"); @x= sort keys %hash; decode_entities($x[0]);'
> > 5.014002
> > Can't inline decode readonly string at -e line 1.
> 
> This is a perfect example of one of those reasons why
> SV_CHECK_THINKFIRST was already necessary before the recent COW work.

It actually dates all the way back to 5.8.0, which made hash keys themselves
Copy On Write. So this has been around for over a decade. But before 5.10.0
you only really get to spot it if you use something that doesn't copy the
hash keys, such as foreach() or a function parameter. So:


$ ~/Sandpit/580g/bin/perl5.8.0 -MHTML::Entities -le 'my %hash=("A".."D"); foreach (keys %hash) {decode_entities($_); print $_}'
Can't inline decode readonly string at -e line 1.


whereas concatenating an empty string on the key:

$ ~/Sandpit/580g/bin/perl5.8.0 -MHTML::Entities -le 'my %hash=("A".."D"); foreach (keys %hash) {$_ .= ""; decode_entities($_); print $_}'
A
C


triggers the copy.

Nicholas Clark

Thread Previous | Thread Next


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