This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Hash assignment can zap weak references to the hash
authorFather Chrysostomos (via RT) <perlbug-followup@perl.org>
Sun, 25 Jul 2010 19:46:06 +0000 (12:46 -0700)
committerDavid Mitchell <davem@iabyn.com>
Thu, 29 Jul 2010 12:21:10 +0000 (13:21 +0100)
[perl #76716]

commits 044d8c24f and 64345bb broke backrefs to hashes that are merely
cleared or undeffed, but not freed. Spotted by Father Chrysostomos.
Test for it here (fixes coming next)

t/op/hashassign.t

index 3fa6c41..92ea5ca 100644 (file)
@@ -8,7 +8,7 @@ BEGIN {
 
 # use strict;
 
-plan tests => 215;
+plan tests => 217;
 
 my @comma = ("key", "value");
 
@@ -306,3 +306,14 @@ foreach my $chr (60, 200, 600, 6000, 60000) {
     @expect{map "$_", @refs} = @types;
     ok (eq_hash(\%h, \%expect), 'blessed ref stringification');
 }
+
+# [perl #76716] Hash assignment should not zap weak refs.
+{
+ my %tb;
+ use Scalar::Util;
+ Scalar::Util::weaken(my $p = \%tb);
+ %tb = ();
+ is $p, \%tb, "hash assignment should not zap weak refs";
+ undef %tb;
+ is $p, \%tb, "hash undef should not zap weak refs";
+}