From: Dave Mitchell Date: Thu, 30 Jun 2005 22:41:07 +0000 (+0000) Subject: [perl #36434] assigning shared consts (eg __PACKAGE__) to magic vars X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d8084ca508cc868d52c8d8d4fcfc637d4dbec9d0;p=p5sagit%2Fp5-mst-13.2.git [perl #36434] assigning shared consts (eg __PACKAGE__) to magic vars p4raw-id: //depot/perl@25032 --- diff --git a/sv.c b/sv.c index 101f8b6..35af580 100644 --- 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 diff --git a/t/op/magic.t b/t/op/magic.t index 154a3cc..c8a2224 100755 --- a/t/op/magic.t +++ b/t/op/magic.t @@ -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 "# $@"; }