develooper Front page | perl.perl5.porters | Postings from September 2014

Re: Hash::Util and read-only values

Thread Previous | Thread Next
From:
Father Chrysostomos
Date:
September 21, 2014 13:56
Subject:
Re: Hash::Util and read-only values
Message ID:
20140921135637.14748.qmail@lists-nntp.develooper.com
Reini Urban wrote:
> On Sat, Sep 20, 2014 at 11:59 AM, Father Chrysostomos <sprout cpan.org> wrote:
> > for my $ro ($locked_hash{locked_elem}) {
> >   # $ro now points to just the SV, so a HE flag would not prevent:
> >   $ro = 42;
> > }
> 
> Why should this be a problem? When you convert this locked HE to a SV,
> you mark the SV as READONLY.

There is no conversion to SV at any point.  Do you mean that
Hash::Util should refrain from turning off the read-only flag if the
HE does not have the bit set?  That would not work if two hash ele-
ments point to the same SV.

> > There is plenty of room in the SV.
> 
> There's none. There was one left free bit,

SVf_OOK and SVf_FAKE are never set together, so they could
be combined.

> No, you are adding a HE-only bit to every single SV,
> instead of adding of to the HE to mark locked hashes entries.
> SvREADONLY_on is now setting the protect bit on every non-HV.
> Locked strings? You got it. Locked integers? You got it now.

I think you misunderstand the purpose of the SVt_PROTECT flag.  It's
the opposite of what you said.  That flag is specifically designed to
protect &PL_sv_no, and other constant values to make sure that
Hash::Util and other modules do not accidentally make them mutable.  I
suppose I should have called it SVp_READONLY.  SVf_READONLY is effect-
ively the public flag, but you would have to turn off the private
flag, too, if you wanted to modify anything.

> It's not as bad as your recent GV change,

Do you still support 5.6 and 5.8 in your modules?  They also had a
gp_flags field.  How do you cope with it in those versions?

> but it affects all my efforts to have
> clean compile-time readonly-ness to be able to do
> compile-time const optimizations and fast coretype checks, esp. typed
> hashes, arrays and scalars.

How so?  The new flag does not make things less read-only than before,
but more so.




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