Skip to content

Commit 9f4ef85

Browse files
committed
Move 4 more tests
Disambiguate variable '$ok' is used several times within this file. It gets confusing. Rename one instance.
1 parent e1381e7 commit 9f4ef85

File tree

2 files changed

+64
-65
lines changed

2 files changed

+64
-65
lines changed

t/op/goto-amp-name.t

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use warnings;
1111
use strict;
1212
use Config;
1313
#plan tests => 'no_plan'; # yet
14-
plan tests => 35;
14+
plan tests => 39;
1515

1616
our $TODO;
1717

@@ -60,6 +60,64 @@ our $foo;
6060

6161
###################
6262

63+
# bug #9990 - don't prematurely free the CV we're &going to.
64+
65+
sub f1 {
66+
my $x;
67+
goto sub { $x=0; ok(1,"don't prematurely free CV\n") }
68+
}
69+
f1();
70+
71+
# bug #99850, which is similar - freeing the subroutine we are about to
72+
# go(in)to during a FREETMPS call should not crash perl.
73+
74+
package _99850 {
75+
sub reftype{}
76+
DESTROY { undef &reftype }
77+
eval { sub { my $guard = bless []; goto &reftype }->() };
78+
}
79+
like $@, qr/^Goto undefined subroutine &_99850::reftype at /,
80+
'goto &foo undefining &foo on sub cleanup';
81+
82+
# When croaking after discovering that the new CV you're about to goto is
83+
# undef, make sure that the old CV isn't doubly freed.
84+
85+
package Do_undef {
86+
my $count;
87+
88+
# creating a new closure here encourages any prematurely freed
89+
# CV to be reallocated
90+
sub DESTROY { undef &undef_sub; my $x = sub { $count } }
91+
92+
sub f {
93+
$count++;
94+
my $guard = bless []; # trigger DESTROY during goto
95+
*undef_sub = sub {};
96+
goto &undef_sub
97+
}
98+
99+
for (1..10) {
100+
eval { f() };
101+
}
102+
::is($count, 10, "goto undef_sub safe");
103+
}
104+
105+
# make sure that nothing nasty happens if the old CV is freed while
106+
# goto'ing
107+
108+
package Free_cv {
109+
my $results;
110+
sub f {
111+
no warnings 'redefine';
112+
*f = sub {};
113+
goto &g;
114+
}
115+
sub g { $results = "(@_)" }
116+
117+
f(1,2,3);
118+
::is($results, "(1 2 3)", "Free_cv");
119+
}
120+
63121
# [perl #29708] - goto &foo could leave foo() at depth two with
64122
# @_ == PL_sv_undef, causing a coredump
65123

t/op/goto.t

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use warnings;
1313
use strict;
1414
use Config;
1515
#plan tests => 134;
16-
plan tests => 100;
16+
plan tests => 96;
1717

1818
our $TODO;
1919

@@ -59,16 +59,16 @@ is($foo, 4, 'second escape while loop');
5959
my $r = run_perl(prog => 'goto foo;', stderr => 1);
6060
like($r, qr/label/, 'cant find label');
6161

62-
my $ok = 0;
62+
my $thisok = 0;
6363
sub foo {
6464
goto bar;
6565
return;
6666
bar:
67-
$ok = 1;
67+
$thisok = 1;
6868
}
6969

7070
&foo;
71-
ok($ok, 'goto in sub');
71+
ok($thisok, 'goto in sub');
7272

7373
sub bar {
7474
my $x = 'bypass';
@@ -139,7 +139,7 @@ FORL2: for($y=1; 1;) {
139139

140140
# Does goto work correctly within a try block?
141141
# (BUG ID 20000313.004) - [perl #2359]
142-
$ok = 0;
142+
my $ok = 0;
143143
eval {
144144
my $variable = 1;
145145
goto LABEL20;
@@ -208,65 +208,6 @@ ok($ok, 'works correctly in a nested eval string');
208208
$deprecated = 0;
209209
}
210210

211-
# bug #9990 - don't prematurely free the CV we're &going to.
212-
213-
sub f1 {
214-
my $x;
215-
goto sub { $x=0; ok(1,"don't prematurely free CV\n") }
216-
}
217-
f1();
218-
219-
# bug #99850, which is similar - freeing the subroutine we are about to
220-
# go(in)to during a FREETMPS call should not crash perl.
221-
222-
package _99850 {
223-
sub reftype{}
224-
DESTROY { undef &reftype }
225-
eval { sub { my $guard = bless []; goto &reftype }->() };
226-
}
227-
like $@, qr/^Goto undefined subroutine &_99850::reftype at /,
228-
'goto &foo undefining &foo on sub cleanup';
229-
230-
# When croaking after discovering that the new CV you're about to goto is
231-
# undef, make sure that the old CV isn't doubly freed.
232-
233-
package Do_undef {
234-
my $count;
235-
236-
# creating a new closure here encourages any prematurely freed
237-
# CV to be reallocated
238-
sub DESTROY { undef &undef_sub; my $x = sub { $count } }
239-
240-
sub f {
241-
$count++;
242-
my $guard = bless []; # trigger DESTROY during goto
243-
*undef_sub = sub {};
244-
goto &undef_sub
245-
}
246-
247-
for (1..10) {
248-
eval { f() };
249-
}
250-
::is($count, 10, "goto undef_sub safe");
251-
}
252-
253-
# make sure that nothing nasty happens if the old CV is freed while
254-
# goto'ing
255-
256-
package Free_cv {
257-
my $results;
258-
sub f {
259-
no warnings 'redefine';
260-
*f = sub {};
261-
goto &g;
262-
}
263-
sub g { $results = "(@_)" }
264-
265-
f(1,2,3);
266-
::is($results, "(1 2 3)", "Free_cv");
267-
}
268-
269-
270211
# bug #22181 - this used to coredump or make $x undefined, due to
271212
# erroneous popping of the inner BLOCK context
272213

0 commit comments

Comments
 (0)