Skip to content

Commit fb2352e

Browse files
author
Father Chrysostomos
committed
Allow restricted hashes containing COWs to be cleared
1 parent e5accad commit fb2352e

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

dist/base/t/fields.t

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ BEGIN {
66
}
77

88
use strict;
9-
use Test::More tests => 17;
9+
use Test::More tests => 18;
1010

1111
BEGIN { use_ok('fields'); }
1212

@@ -108,8 +108,10 @@ package main;
108108
ok(exists $x->{b}, 'x has b');
109109

110110
SKIP: {
111-
skip "This test triggers a perl bug", 1 if $] < 5.014001;
111+
skip "These tests trigger a perl bug", 1 if $] < 5.014001;
112112
$x->{a} = __PACKAGE__;
113113
ok eval { delete $x->{a}; 1 }, 'deleting COW values';
114+
$x->{a} = __PACKAGE__;
115+
ok eval { %$x = (); 1 }, 'clearing a restr hash containing COWs';
114116
}
115117
}

hv.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,8 @@ Perl_hv_clear(pTHX_ HV *hv)
15541554
for (; entry; entry = HeNEXT(entry)) {
15551555
/* not already placeholder */
15561556
if (HeVAL(entry) != &PL_sv_placeholder) {
1557-
if (HeVAL(entry) && SvREADONLY(HeVAL(entry))) {
1557+
if (HeVAL(entry) && SvREADONLY(HeVAL(entry))
1558+
&& !SvIsCOW(HeVAL(entry))) {
15581559
SV* const keysv = hv_iterkeysv(entry);
15591560
Perl_croak(aTHX_
15601561
"Attempt to delete readonly key '%"SVf"' from a restricted hash",

0 commit comments

Comments
 (0)