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:
Zefram
Date:
March 22, 2013 16:53
Subject:
Re: [perl #117299] keys are readonly in perl 5.14.2!
Message ID:
20130322165320.GF18166@lake.fysh.org
yves orton wrote:
>  FLAGS = (POK,FAKE,READONLY,pPOK)

FAKE+READONLY means it's not actually unwritable, it's copy-on-write.
From sv.h:

#define SVf_FAKE        0x01000000  /* 0: glob or lexical is just a copy
                                       1: SV head arena wasn't malloc()ed
                                       2: in conjunction with SVf_READONLY
                                          marks a shared hash key scalar
                                          (SvLEN == 0) or a copy on write
                                          string (SvLEN != 0) [SvIsCOW(sv)]

In your case, SvLEN == 0, marking it as a shared hash key.

$ perl5.14.2 -MDevel::Peek -le'print $]; my %hash=("A".."D"); @x= keys %hash; Dump($x[0]); $x[0] = "foo"; Dump($x[0])'
5.014002
SV = PV(0x83d2100) at 0x83e2cc0
  REFCNT = 1
  FLAGS = (POK,FAKE,READONLY,pPOK)
  PV = 0x83ed36c "A"
  CUR = 1
  LEN = 0
SV = PV(0x83d2100) at 0x83e2cc0
  REFCNT = 1
  FLAGS = (POK,pPOK)
  PV = 0x83d8330 "foo"\0
  CUR = 3
  LEN = 12

-zefram

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