summaryrefslogtreecommitdiff
path: root/t/op
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-11-05 13:26:41 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-11-05 13:26:41 -0700
commitab97dcc3bf50e847e83b6a2d0f3b3f7cd43f1cf6 (patch)
tree08257993e879ddd571e0748941f419721ef034d4 /t/op
parent6e593c84d6ec5b4c84f0821bb2a897973a81976f (diff)
downloadperl-ab97dcc3bf50e847e83b6a2d0f3b3f7cd43f1cf6.tar.gz
Weak refs to pad hvs should go stale
When a lexical variable goes out of scope, as in { my %lexical_variable; ... } # no longer in scope here it is supposed to disappear as far as Perl code can tell. That the same SV is reused the next time that scope is entered is an implement- ation detail. The move of hashes’ back-references from magic into the HvAUX struc- ture in 5.10 caused this implementation detail to leak through. Normally, weak references to pad variables going out of scope are killed off: { my $scalar; weaken ($global_scalar = \$scalar); } # here $global_scalar is undef When hashes’ back-references were moved, leave_scope was not updated to account. (For non-hash variables, it’s the mg_free call that takes care of it.) So in this case: { my %hash; weaken ($global_scalar = \%hash); } $global_scalar would still reference a hash, but one marked PADSTALE. Modifications to that hash through the reference would be visible the next time the scope was entered.
Diffstat (limited to 't/op')
-rw-r--r--t/op/hash.t15
1 files changed, 14 insertions, 1 deletions
diff --git a/t/op/hash.t b/t/op/hash.t
index b8aeaa7d2e..34bfcde350 100644
--- a/t/op/hash.t
+++ b/t/op/hash.t
@@ -8,7 +8,7 @@ BEGIN {
use strict;
-plan tests => 10;
+plan tests => 11;
my %h;
@@ -168,3 +168,16 @@ is($destroyed, 1, 'Timely hash destruction with lvalue keys');
delete $h{k}; # must be in void context to trigger the bug
ok $normal_exit, 'freed hash elems are not visible to DESTROY';
}
+
+# Weak references to pad hashes
+{
+ skip_if_miniperl("No Scalar::Util::weaken under miniperl", 1);
+ my $ref;
+ require Scalar::Util;
+ {
+ my %hash;
+ Scalar::Util::weaken($ref = \%hash);
+ 1; # the previous statement must not be the last
+ }
+ is $ref, undef, 'weak refs to pad hashes go stale on scope exit';
+}