[perl #119043] Exempt shared hash key consts from ro
authorFather Chrysostomos <sprout@cpan.org>
Sun, 28 Jul 2013 20:19:33 +0000 (13:19 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 28 Jul 2013 20:19:33 +0000 (13:19 -0700)
Commit 19130678b4 stopped copy-on-write scalars from being exempt from
readonliness in ck_svconst (called for every OP_CONST).  That was for
the sake of consistency.

It turns out this breaks CPAN modules, so change it back, but only for
shared hash key scalars, not other COW scalars.

This is an historical artefact left over from when copy-on-write used
the read-only flag without the scalar actually being read-only.

lib/overload.t
op.c

index 3af969b..e9ceb50 100644 (file)
@@ -1293,16 +1293,15 @@ foreach my $op (qw(<=> == != < <= > >=)) {
 }
 
 {
-    # Check readonliness of constants, whether shared hash key
-    # scalars or no (brought up in bug #109744)
+    # Check readonliness of constants (brought up in bug #109744)
+    # For historical reasons, shared hash key scalars are exempt
     BEGIN { overload::constant integer => sub { "main" }; }
     eval { ${\5} = 'whatever' };
     like $@, qr/^Modification of a read-only value attempted at /,
        'constant overloading makes read-only constants';
     BEGIN { overload::constant integer => sub { __PACKAGE__ }; }
     eval { ${\5} = 'whatever' };
-    like $@, qr/^Modification of a read-only value attempted at /,
-       '... even with shared hash key scalars';
+    is $@, "", 'except with shared hash key scalars';
 }
 
 {
diff --git a/op.c b/op.c
index 7576509..9ae0812 100644 (file)
--- a/op.c
+++ b/op.c
@@ -10568,7 +10568,9 @@ Perl_ck_svconst(pTHX_ OP *o)
 {
     PERL_ARGS_ASSERT_CK_SVCONST;
     PERL_UNUSED_CONTEXT;
-    SvREADONLY_on(cSVOPo->op_sv);
+    /* For historical reasons, shared hash scalars are not made read-only.
+     */
+    if (!SvIsCOW_shared_hash(cSVOPo->op_sv)) SvREADONLY_on(cSVOPo->op_sv);
     return o;
 }