[perl #36434] assigning shared consts (eg __PACKAGE__) to magic vars
authorDave Mitchell <davem@fdisolutions.com>
Thu, 30 Jun 2005 22:41:07 +0000 (22:41 +0000)
committerDave Mitchell <davem@fdisolutions.com>
Thu, 30 Jun 2005 22:41:07 +0000 (22:41 +0000)
p4raw-id: //depot/perl@25032

sv.c
t/op/magic.t

diff --git a/sv.c b/sv.c
index 101f8b6..35af580 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -4984,7 +4984,12 @@ Perl_sv_magic(pTHX_ register SV *sv, SV *obj, int how, const char *name, I32 nam
         sv_force_normal_flags(sv, 0);
 #endif
     if (SvREADONLY(sv)) {
-       if (IN_PERL_RUNTIME
+       if (
+           /* its okay to attach magic to shared strings; the subsequent
+            * upgrade to PVMG will unshare the string */
+           !(SvFAKE(sv) && SvTYPE(sv) < SVt_PVMG)
+
+           && IN_PERL_RUNTIME
            && how != PERL_MAGIC_regex_global
            && how != PERL_MAGIC_bm
            && how != PERL_MAGIC_fm
index 154a3cc..c8a2224 100755 (executable)
@@ -36,7 +36,7 @@ sub skip {
     return 1;
 }
 
-print "1..56\n";
+print "1..57\n";
 
 $Is_MSWin32  = $^O eq 'MSWin32';
 $Is_NetWare  = $^O eq 'NetWare';
@@ -432,9 +432,12 @@ ok "@+" eq "10 1 6 10";
     local @ISA;
     local %ENV;
     eval { push @ISA, __PACKAGE__ };
-    ok( $@ eq '', 'Push a constant on a magic array', '#36434' );
+    ok( $@ eq '', 'Push a constant on a magic array');
     $@ and print "# $@";
     eval { %ENV = (PATH => __PACKAGE__) };
-    ok( $@ eq '', 'Assign a constant to a magic hash', '#36434' );
+    ok( $@ eq '', 'Assign a constant to a magic hash');
+    $@ and print "# $@";
+    eval { my %h = qw(A B); %ENV = (PATH => (keys %h)[0]) };
+    ok( $@ eq '', 'Assign a shared key to a magic hash');
     $@ and print "# $@";
 }