8 BEGIN { require "./test.pl"; }
12 # Used to segfault (bug #15479)
15 'Odd number of elements in hash assignment at - line 1.',
16 { switches => [ '-w' ] },
17 'delete $::{STDERR} and print a warning',
22 'BEGIN { $::{"X::"} = 2 }',
24 { switches => [ '-w' ] },
25 q(Insert a non-GV in a stash, under warnings 'once'),
29 no warnings 'deprecated';
30 ok( !defined %oedipa::maas::, q(stashes aren't defined if not used) );
31 ok( !defined %{"oedipa::maas::"}, q(- work with hard refs too) );
33 ok( defined %tyrone::slothrop::, q(stashes are defined if seen at compile time) );
34 ok( defined %{"tyrone::slothrop::"}, q(- work with hard refs too) );
36 ok( defined %bongo::shaftsbury::, q(stashes are defined if a var is seen at compile time) );
37 ok( defined %{"bongo::shaftsbury::"}, q(- work with hard refs too) );
40 package tyrone::slothrop;
41 $bongo::shaftsbury::scalar = 1;
46 # Unbalanced string table refcount: (1) for "A::" during global destruction.
49 local $ENV{PERL_DESTRUCT_LEVEL} = 2;
51 'package A; sub a { // }; %::=""',
59 ok( !eval { no warnings 'deprecated'; defined %achtfaden:: }, 'works in eval{}' );
60 ok( !eval q{ no warnings 'deprecated'; defined %schoenmaker:: }, 'works in eval("")' );
62 # now tests with strictures
66 no warnings 'deprecated';
67 ok( !defined %pig::, q(referencing a non-existent stash doesn't produce stricture errors) );
68 ok( !exists $pig::{bodine}, q(referencing a non-existent stash element doesn't produce stricture errors) );
72 eval { require B; 1 } or skip "no B", 18;
74 *b = \&B::svref_2object;
75 my $CVf_ANON = B::CVf_ANON();
84 isa_ok( $gv, "B::GV", "deleted stash entry leaves CV with valid GV");
85 is( b($sub)->CvFLAGS & $CVf_ANON, $CVf_ANON, "...and CVf_ANON set");
86 is( eval { $gv->NAME }, "__ANON__", "...and an __ANON__ name");
87 is( eval { $gv->STASH->NAME }, "one", "...but leaves stash intact");
96 isa_ok( $gv, "B::GV", "cleared stash leaves CV with valid GV");
97 is( b($sub)->CvFLAGS & $CVf_ANON, $CVf_ANON, "...and CVf_ANON set");
98 is( eval { $gv->NAME }, "__ANON__", "...and an __ANON__ name");
99 is( eval { $gv->STASH->NAME }, "__ANON__", "...and an __ANON__ stash");
108 isa_ok( $gv, "B::GV", "undefed stash leaves CV with valid GV");
109 is( b($sub)->CvFLAGS & $CVf_ANON, $CVf_ANON, "...and CVf_ANON set");
110 is( eval { $gv->NAME }, "__ANON__", "...and an __ANON__ name");
111 is( eval { $gv->STASH->NAME }, "__ANON__", "...and an __ANON__ stash");
114 local $TODO = "anon CVs not accounted for yet";
116 my @results = split "\n", runperl(
117 switches => [ "-MB", "-l" ],
125 my $gv = B::svref_2object($sub)->GV;
126 print $gv->isa(q/B::GV/) ? q/ok/ : q/not ok/;
128 my $st = eval { $gv->STASH->NAME };
129 print $st eq q/__ANON__/ ? q/ok/ : q/not ok/;
137 $gv = B::svref_2object($sub)->GV;
138 print $gv->isa(q/B::GV/) ? q/ok/ : q/not ok/;
140 $st = eval { $gv->STASH->NAME };
141 print $st eq q/__ANON__/ ? q/ok/ : q/not ok/;
145 ($^O eq 'VMS') ? (stderr => 1) : ()
148 ok( @results == 5 && $results[4] eq "done",
149 "anon CVs in undefed stash don't segfault" )
150 or todo_skip $TODO, 4;
152 ok( $results[0] eq "ok",
153 "cleared stash leaves anon CV with valid GV");
154 ok( $results[1] eq "ok",
155 "...and an __ANON__ stash");
157 ok( $results[2] eq "ok",
158 "undefed stash leaves anon CV with valid GV");
159 ok( $results[3] eq "ok",
160 "...and an __ANON__ stash");
165 'sub foo { 1 }; use overload q/""/ => \&foo;' .
166 'delete $main::{foo}; bless []',
169 "no segfault with overload/deleted stash entry [#58530]",