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

Re: Hash::Util and read-only values

Thread Previous | Thread Next
September 19, 2014 23:35
Re: Hash::Util and read-only values
Message ID:
On 20 September 2014 00:48, Father Chrysostomos <> wrote:

> With Hash::Util::hv_store and Hash::Util::unlock_value, it is possible
> to turn off the read-only flag of any scalar.
> There are cases where the core uses this flag to protect things that
> must not be modified.  So we need to stop Hash::Util from being able
> to do this.

This suggests a deeper design problem that I think needs to be thought
through independently of Hash::Util.

> (I bring this up, because with lvalue references it will become easier
> to do this by mistake.)
Yes, exactly, that is the problem.

> So we need to distinguish truly read-only values from values locked by
> Hash::Util.
Or alternatively we need to change things that are using the read-only bit
for different purposes.

> Hash::Util::unlock_value should croak for any read-only (as opposed to
> locked) value.

There is no difference between a locked value and a read only value.

> But should Hash::Util::lock_value croak for those, or
> just return?  I am inclined to think it should croak, as a successful
> lock_value implies that later unlock_value will work.
> Actually, since locking or unlocking an entire hash's values at
> once is possible, should (un)locking silently do nothing with read-
> only values?

For me this has subject has XY problem written all over it.

I think we should solve the X problem, that we use the read only flag for
multiple purposes.

Once we solve that there will be no Y problem, that Hash::Util does the
wrong thing.

Independently, I think it is arguable that the locked hash implementation
is broken to the point of being nearly unusable.

Specifically there is no way to lock a hash so you can not modify, delete
or add keys or values, but can still do things like fetch a missing key,
call exists on a missing key etc.

Also related to this is the question of how to serialize a locked or read
only value?


perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About