Skip to content

Commit a991bd3

Browse files
author
Father Chrysostomos
committed
Make Storable freeze COWs properly
It was freezing them as read-only scalars.
1 parent 4ab5bd5 commit a991bd3

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

dist/Storable/Storable.xs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,7 +2435,8 @@ static int store_hash(pTHX_ stcxt_t *cxt, HV *hv)
24352435

24362436
/* Implementation of restricted hashes isn't nicely
24372437
abstracted: */
2438-
if ((hash_flags & SHV_RESTRICTED) && SvREADONLY(val)) {
2438+
if ((hash_flags & SHV_RESTRICTED)
2439+
&& SvREADONLY(val) && !SvIsCOW(val)) {
24392440
flags |= SHV_K_LOCKED;
24402441
}
24412442

@@ -2527,7 +2528,7 @@ static int store_hash(pTHX_ stcxt_t *cxt, HV *hv)
25272528
abstracted: */
25282529
flags
25292530
= (((hash_flags & SHV_RESTRICTED)
2530-
&& SvREADONLY(val))
2531+
&& SvREADONLY(val) && !SvIsCOW(val))
25312532
? SHV_K_LOCKED : 0);
25322533

25332534
if (val == &PL_sv_placeholder) {

dist/Storable/t/restrict.t

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ sub BEGIN {
3636

3737
use Storable qw(dclone freeze thaw);
3838
use Hash::Util qw(lock_hash unlock_value);
39-
use Test::More tests => 100;
39+
use Test::More tests => 104;
4040

4141
my %hash = (question => '?', answer => 42, extra => 'junk', undef => undef);
4242
lock_hash %hash;
@@ -110,5 +110,11 @@ for $Storable::canonical (0, 1) {
110110
eval { $copy->{$k} = undef } ;
111111
is($@, '', "Can assign to reserved key '$k'?");
112112
}
113+
114+
my %hv;
115+
$hv{a} = __PACKAGE__;
116+
lock_hash %hv;
117+
my $hv2 = &$cloner(\%hv);
118+
ok eval { $$hv2{a} = 70 }, 'COWs do not become read-only';
113119
}
114120
}

0 commit comments

Comments
 (0)