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'),
28 ok( !defined %oedipa::maas::, q(stashes aren't defined if not used) );
29 ok( !defined %{"oedipa::maas::"}, q(- work with hard refs too) );
31 ok( defined %tyrone::slothrop::, q(stashes are defined if seen at compile time) );
32 ok( defined %{"tyrone::slothrop::"}, q(- work with hard refs too) );
34 ok( defined %bongo::shaftsbury::, q(stashes are defined if a var is seen at compile time) );
35 ok( defined %{"bongo::shaftsbury::"}, q(- work with hard refs too) );
37 package tyrone::slothrop;
38 $bongo::shaftsbury::scalar = 1;
43 # Unbalanced string table refcount: (1) for "A::" during global destruction.
46 local $ENV{PERL_DESTRUCT_LEVEL} = 2;
48 'package A; sub a { // }; %::=""',
56 ok( !eval { defined %achtfaden:: }, 'works in eval{}' );
57 ok( !eval q{ defined %schoenmaker:: }, 'works in eval("")' );
59 # now tests with strictures
63 ok( !defined %pig::, q(referencing a non-existent stash doesn't produce stricture errors) );
64 ok( !exists $pig::{bodine}, q(referencing a non-existent stash element doesn't produce stricture errors) );
68 eval { require B; 1 } or skip "no B", 18;
70 *b = \&B::svref_2object;
71 my $CVf_ANON = B::CVf_ANON();
80 isa_ok( $gv, "B::GV", "deleted stash entry leaves CV with valid GV");
81 is( b($sub)->CvFLAGS & $CVf_ANON, $CVf_ANON, "...and CVf_ANON set");
82 is( eval { $gv->NAME }, "__ANON__", "...and an __ANON__ name");
83 is( eval { $gv->STASH->NAME }, "one", "...but leaves stash intact");
92 isa_ok( $gv, "B::GV", "cleared stash leaves CV with valid GV");
93 is( b($sub)->CvFLAGS & $CVf_ANON, $CVf_ANON, "...and CVf_ANON set");
94 is( eval { $gv->NAME }, "__ANON__", "...and an __ANON__ name");
95 is( eval { $gv->STASH->NAME }, "__ANON__", "...and an __ANON__ stash");
104 isa_ok( $gv, "B::GV", "undefed stash leaves CV with valid GV");
105 is( b($sub)->CvFLAGS & $CVf_ANON, $CVf_ANON, "...and CVf_ANON set");
106 is( eval { $gv->NAME }, "__ANON__", "...and an __ANON__ name");
107 is( eval { $gv->STASH->NAME }, "__ANON__", "...and an __ANON__ stash");
110 local $TODO = "anon CVs not accounted for yet";
112 my @results = split "\n", runperl(
113 switches => [ "-MB", "-l" ],
121 my $gv = B::svref_2object($sub)->GV;
122 print $gv->isa(q/B::GV/) ? q/ok/ : q/not ok/;
124 my $st = eval { $gv->STASH->NAME };
125 print $st eq q/__ANON__/ ? q/ok/ : q/not ok/;
133 $gv = B::svref_2object($sub)->GV;
134 print $gv->isa(q/B::GV/) ? q/ok/ : q/not ok/;
136 $st = eval { $gv->STASH->NAME };
137 print $st eq q/__ANON__/ ? q/ok/ : q/not ok/;
141 ($^O eq 'VMS') ? (stderr => 1) : ()
144 ok( @results == 5 && $results[4] eq "done",
145 "anon CVs in undefed stash don't segfault" )
146 or todo_skip $TODO, 4;
148 ok( $results[0] eq "ok",
149 "cleared stash leaves anon CV with valid GV");
150 ok( $results[1] eq "ok",
151 "...and an __ANON__ stash");
153 ok( $results[2] eq "ok",
154 "undefed stash leaves anon CV with valid GV");
155 ok( $results[3] eq "ok",
156 "...and an __ANON__ stash");
161 'sub foo { 1 }; use overload q/""/ => \&foo;' .
162 'delete $main::{foo}; bless []',
165 "no segfault with overload/deleted stash entry [#58530]",