| Store | Cart

[perl #125721] Hash::Util::unlock_hashref_recurse doesn't unlock

From: James E Keenan via RT <perl...@perl.org>
Wed, 29 Jul 2015 16:26:32 -0700
On Wed Jul 29 13:24:47 2015, djerius wrote:
> > This is a bug report for perl from djer...@cpan.org,> generated with the help of perlbug 1.39 running under perl 5.16.3.> > > -----------------------------------------------------------------> [Please describe your issue here]> > Hash::Util::unlock_hashref_recurse doesn't actually unlock the hashref>  due to a typo; it calls> > Internals::SvREADONLY($value,1);> > instead of> > Internals::SvREADONLY($value,0);> > > Here's some sample code:> > use Hash::Util;> > my %hash = ( a => 1 );> > Hash::Util::lock_hashref_recurse( \%hash );> Hash::Util::unlock_hashref_recurse( \%hash );> > $hash{a} = 3;> > and the result:> > % perl bug.pl> Modification of a read-only value attempted at bug.pl line 8.> > While I'm using 5.16.3, this problem seems to exist under 5.22.0 as> well.> 

Some additional cases in attachment.  Problem appears to be restricted to lock_hash_recurse|unlock_hash_recurse and lock_hashref_recurse|unlock_hashref_recurse; the corresponding non-*_recurse functions appear to be okay.


-- 
James E Keenan (jkee...@cpan.org)

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=125721

#!/usr/bin/env perl
use strict;
use warnings;
use 5.10.1;
use Hash::Util;

my %hash = ( a => 1, b => { hello => 'world'} );

{
    say "lock_hash_recurse|unlock_hash_recurse";
    local $@;
    Hash::Util::lock_hash_recurse( %hash );
    Hash::Util::unlock_hash_recurse( %hash );
    eval { $hash{b} = { hello => 'jupiter' }; };
    say "<$@>";
}

{
    say "lock_hashref_recurse|unlock_hashref_recurse";
    local $@;
    Hash::Util::lock_hashref_recurse( \%hash );
    Hash::Util::unlock_hashref_recurse( \%hash );
    eval { $hash{b} = { hello => 'jupiter' }; };
    say "<$@>";
}

{
    say "lock_hash|unlock_hash";
    local $@;
    Hash::Util::lock_hash( %hash );
    Hash::Util::unlock_hash( %hash );
    eval { $hash{a} = 'foo'; };
    say "<$@>";
}

{
    say "lock_hashref|unlock_hashref";
    local $@;
    Hash::Util::lock_hashref( \%hash );
    Hash::Util::unlock_hashref( \%hash );
    eval { $hash{a} = 'foo'; };
    say "<$@>";
}

%hash = ( a => 1 );

{
    say "lock_hash|unlock_hash";
    local $@;
    Hash::Util::lock_hash( %hash );
    Hash::Util::unlock_hash( %hash );
    eval { $hash{a} = 'foo'; };
    say "<$@>";
}

{
    say "lock_hashref|unlock_hashref";
    local $@;
    Hash::Util::lock_hashref( \%hash );
    Hash::Util::unlock_hashref( \%hash );
    eval { $hash{a} = 'foo'; };
    say "<$@>";
}


Recent Messages in this Thread
Diab Jerius (via RT) Jul 29, 2015 08:24 pm
James E Keenan via RT Jul 29, 2015 11:26 pm
James E Keenan via RT Jul 30, 2015 01:11 am
James E Keenan via RT Aug 05, 2015 12:18 am
Tony Cook via RT Aug 03, 2015 05:29 am
Messages in this thread