From d8084ca508cc868d52c8d8d4fcfc637d4dbec9d0 Mon Sep 17 00:00:00 2001 From: Dave Mitchell Date: Thu, 30 Jun 2005 22:41:07 +0000 Subject: [PATCH] [perl #36434] assigning shared consts (eg __PACKAGE__) to magic vars p4raw-id: //depot/perl@25032 --- sv.c | 7 ++++++- t/op/magic.t | 9 ++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/sv.c b/sv.c index 101f8b631b..35af580364 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 154a3cccd4..c8a2224703 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 "# $@"; }