summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2010-09-28 08:47:07 -0700
committerFather Chrysostomos <sprout@cpan.org>2010-09-28 11:00:19 -0700
commitcffb36981555111f364a511fb5763f65ea748c0e (patch)
tree93e5a57f9fc7ea352ed4352ea3fa168a50e2c94f
parente45e19666b263919849d25adcf99e39712aa36be (diff)
downloadperl-cffb36981555111f364a511fb5763f65ea748c0e.tar.gz
[perl #77928] Glob slot assignment and set-magic
Stop set-magic from being called after ref-to-glob assignment.
-rw-r--r--pod/perldelta.pod5
-rw-r--r--sv.h18
-rw-r--r--t/op/gv.t15
3 files changed, 35 insertions, 3 deletions
diff --git a/pod/perldelta.pod b/pod/perldelta.pod
index cfde5d43ed..a1430ad4aa 100644
--- a/pod/perldelta.pod
+++ b/pod/perldelta.pod
@@ -624,6 +624,11 @@ function. On other systems, new threads simply do not inherit directory
handles from their parent threads
L<[perl #75154]|http://rt.perl.org/rt3/Public/Bug/Display.html?id=75154>.
+=item *
+
+Assignment through a glob no longer triggers set-magic on the glob itself
+L<[perl #77928]|http://rt.perl.org/rt3/Public/Bug/Display.html?id=77928>.
+
=back
=head1 Known Problems
diff --git a/sv.h b/sv.h
index f309d362e1..be41ac1a2e 100644
--- a/sv.h
+++ b/sv.h
@@ -1945,9 +1945,23 @@ Returns a pointer to the character buffer.
SvSetSV_nosteal_and(dst,src,/*nothing*/;)
#define SvSetMagicSV(dst,src) \
- SvSetSV_and(dst,src,SvSETMAGIC(dst))
+ SvSetSV_and(dst,src, \
+ if (SvSMAGICAL(dst) \
+ && ( \
+ !isGV_with_GP(dst) || !SvROK(src) || isGV_with_GP(SvRV(src)) \
+ ) \
+ ) \
+ mg_set(dst) \
+ )
#define SvSetMagicSV_nosteal(dst,src) \
- SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst))
+ SvSetSV_nosteal_and(dst,src, \
+ if (SvSMAGICAL(dst) \
+ && ( \
+ !isGV_with_GP(dst) || !SvROK(src) || isGV_with_GP(SvRV(src)) \
+ ) \
+ ) \
+ mg_set(dst) \
+ )
#if !defined(SKIP_DEBUGGING)
diff --git a/t/op/gv.t b/t/op/gv.t
index 32afdff69b..b8363d2454 100644
--- a/t/op/gv.t
+++ b/t/op/gv.t
@@ -12,7 +12,7 @@ BEGIN {
use warnings;
-plan( tests => 219 );
+plan( tests => 220 );
# type coersion on assignment
$foo = 'foo';
@@ -783,6 +783,19 @@ EOF
}}->($h{k});
}
+# [perl #77928] Glob slot assignment and set-magic
+{
+ package Readonly::Alias;
+ sub TIESCALAR { bless \(my $x = \pop) }
+ sub FETCH { $${$_[0]} }
+ sub STORE { die "Assignment to read-only value" }
+ package main;
+ tie my $alias, "Readonly::Alias", my $var;
+ $var = *bength;
+ # Now modify a glob slot, not the alias itself:
+ ok(scalar eval { *$alias = [] }, 'glob slot assignment skips set-magic');
+}
+
__END__
Perl
Rules