13 # This will crash perl if it fails
15 use constant PVBM => 'foo';
17 my $dummy = index 'foo', PVBM;
18 eval { my %h = (a => PVBM); 1 };
20 ok (!$@, 'fbm scalar can be inserted into a hash');
24 { package Class; DESTROY { ++$destroyed; } }
30 $h{key} = bless({}, 'Class');
32 is($destroyed, 1, 'Timely hash destruction with lvalue keys');
35 # [perl #79178] Hash keys must not be stringified during compilation
36 # Run perl -MO=Concise -e '$a{\"foo"}' on a non-threaded pre-5.13.8 version
41 sub TIEHASH { bless {}, $_[0] }
42 sub FETCH { $key = $_[1] }
46 is ref $key, SCALAR =>
47 'hash keys are not stringified during compilation';
50 # Part of RT #85026: Deleting the current iterator in void context does not
55 local *::DESTROY = sub { ++$gone };
57 each %a; # make the entry with the obj the current iterator
59 ok $gone, 'deleting the current iterator in void context frees the val'
62 # [perl #99660] Deleted hash element visible to destructor
67 local *::DESTROY = sub { my $x = $h{k}; ++$normal_exit };
68 delete $h{k}; # must be in void context to trigger the bug
69 ok $normal_exit, 'freed hash elems are not visible to DESTROY';
72 # [perl #100340] Similar bug: freeing a hash elem during a delete
78 return bless \$callback, "guard"
92 ok eval { delete $t{stash}{guard}; # must be in void context
94 'freeing a hash elem from destructor called by delete does not die';
95 diag $@ if $@; # panic: free from wrong pool
96 is $ok, 1, 'the destructor was called';
99 # Weak references to pad hashes
101 skip_if_miniperl("No Scalar::Util::weaken under miniperl", 1);
103 require Scalar::Util;
106 Scalar::Util::weaken($ref = \%hash);
107 1; # the previous statement must not be the last
109 is $ref, undef, 'weak refs to pad hashes go stale on scope exit';
113 sub A::DESTROY { $::ra = 0 }
114 $::ra = {a=>bless [], 'A'};
116 pass 'no crash when freeing hash that is being undeffed';
117 $::ra = {a=>bless [], 'A'};
119 pass 'no crash when freeing hash that is being exonerated, ahem, cleared';