From: Vincent Pit Date: Mon, 16 Mar 2009 17:52:44 +0000 (+0100) Subject: Fix reap() clobbering the return stack, as reported by Torsten Foertsch in RT #44204 X-Git-Tag: rt44204 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=d4747dcc9ef7a82848fc684f7a4d91f94e5aa161;p=perl%2Fmodules%2FScope-Upper.git Fix reap() clobbering the return stack, as reported by Torsten Foertsch in RT #44204 --- diff --git a/Upper.xs b/Upper.xs index afb1275..8f6bda8 100644 --- a/Upper.xs +++ b/Upper.xs @@ -310,7 +310,6 @@ STATIC void su_call(pTHX_ void *ud_) { --cxstack_ix; #endif - SPAGAIN; PUTBACK; FREETMPS; diff --git a/t/13-reap-ctl.t b/t/13-reap-ctl.t index cff7601..7ec492a 100644 --- a/t/13-reap-ctl.t +++ b/t/13-reap-ctl.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 38; +use Test::More tests => 38 + 4 * 7; use Scope::Upper qw/reap UP HERE/; @@ -157,3 +157,42 @@ $y = undef; is $x, 1, 'die in reap inside eval [ok - x]'; is $y, 1, 'die in reap inside eval [ok - y]'; } + +sub hijacked { + my ($cb, $desc) = @_; + local $x = 2; + sub { + local $x = 3; + &reap($cb => UP); + is $x, 3, "$desc [not yet 1 - x]"; + is $y, undef, "$desc [not yet 1 - y]"; + }->(); + is $x, 2, "$desc [not yet 2 - x]"; + is $y, undef, "$desc [not yet 2 - y]"; + 11, 12; +} + +for ([ sub { ++$y; 15, 16, 17, 18 }, 'implicit ' ], + [ sub { ++$y; return 15, 16, 17, 18 }, '' ]) { + my ($cb, $imp) = @$_; + $imp = "RT #44204 - ${imp}return from reap"; + my $desc; + $y = undef; + { + $desc = "$imp in list context"; + local $x = 1; + my @l = hijacked($cb, $desc); + is $x, 1, "$desc [ok - x]"; + is $y, 1, "$desc [ok - y]"; + is_deeply \@l, [ 11, 12 ], "$desc [ok - l]"; + } + $y = undef; + { + $desc = "$imp in list context"; + local $x = 1; + my $s = hijacked($cb, $desc); + is $x, 1, "$desc [ok - x]"; + is $y, 1, "$desc [ok - y]"; + is $s, 12, "$desc [ok - s]"; + } +}