This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Stop localised ties from becoming ro when COW
authorFather Chrysostomos <sprout@cpan.org>
Sat, 4 Jun 2011 20:10:41 +0000 (13:10 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 4 Jun 2011 21:34:30 +0000 (14:34 -0700)
mg.c
t/op/tie.t

diff --git a/mg.c b/mg.c
index af2c647..bdded26 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -536,7 +536,7 @@ Perl_mg_localize(pTHX_ SV *sv, SV *nsv, bool setmagic)
                            mg->mg_ptr, mg->mg_len);
 
        /* container types should remain read-only across localization */
-       SvFLAGS(nsv) |= SvREADONLY(sv);
+       if (!SvIsCOW(sv)) SvFLAGS(nsv) |= SvREADONLY(sv);
     }
 
     if (SvTYPE(nsv) >= SVt_PVMG && SvMAGIC(nsv)) {
index b485f62..0b53b14 100644 (file)
@@ -1014,3 +1014,19 @@ print "ok\n";
 
 EXPECT
 ok
+########
+#
+# Localising a tied COW scalar should not make it read-only.
+
+sub TIESCALAR { bless [] }
+sub FETCH { __PACKAGE__ }
+sub STORE {}
+tie $x, "";
+"$x";
+{
+    local $x;
+    $x = 3;
+}
+print "ok\n";
+EXPECT
+ok