This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In sv.c:sv_magic don’t allow tying ro COWs
authorFather Chrysostomos <sprout@cpan.org>
Sat, 10 Aug 2013 13:06:56 +0000 (06:06 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 11 Aug 2013 14:41:27 +0000 (07:41 -0700)
Read-only COWs are read-only and should not be treated as though they
were not.  This logic is left over from when READONLY+FAKE meant
copy-on-write.

sv.c
t/op/tie.t

diff --git a/sv.c b/sv.c
index fc22350..d6fffa6 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -5490,10 +5490,7 @@ Perl_sv_magic(pTHX_ SV *const sv, SV *const obj, const int how,
 #endif
     if (SvREADONLY(sv)) {
        if (
-           /* its okay to attach magic to shared strings */
-           !SvIsCOW(sv)
-
-           && IN_PERL_RUNTIME
+              IN_PERL_RUNTIME
            && !PERL_MAGIC_TYPE_READONLY_ACCEPTABLE(how)
           )
        {
index 7aff015..eb53030 100644 (file)
@@ -1030,6 +1030,13 @@ EXPECT
 ok
 Modification of a read-only value attempted at - line 16.
 ########
+#
+# And one should not be able to tie read-only COWs
+for(__PACKAGE__) { tie $_, "" }
+sub TIESCALAR {bless []}
+EXPECT
+Modification of a read-only value attempted at - line 3.
+########
 
 # Similarly, read-only regexps cannot be tied.
 sub TIESCALAR { bless [] }