From: Hugo van der Sanden Date: Fri, 5 Mar 2004 17:42:25 +0000 (+0000) Subject: Fix bug [perl #27839] returning @+ out of scope loses its value : X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=547d1dd82362229be47f8169355ee7b5b98dd403;p=p5sagit%2Fp5-mst-13.2.git Fix bug [perl #27839] returning @+ out of scope loses its value : Subject: Re: Wondering about returned regex special arrays on going out of scope Message-Id: <200403051742.i25HgPd11240@zen.crypt.org> plus a test case. p4raw-id: //depot/perl@22564 --- diff --git a/pp_hot.c b/pp_hot.c index f0ea572..452c3a9 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -778,7 +778,10 @@ PP(pp_rv2av) U32 i; for (i=0; i < (U32)maxarg; i++) { SV **svp = av_fetch(av, i, FALSE); - SP[i+1] = (svp) ? *svp : &PL_sv_undef; + /* See note in pp_helem, and bug id #27839 */ + SP[i+1] = svp + ? SvGMAGICAL(*svp) ? sv_mortalcopy(*svp) : *svp + : &PL_sv_undef; } } else { diff --git a/t/op/magic.t b/t/op/magic.t index 04cf718..dda07df 100755 --- a/t/op/magic.t +++ b/t/op/magic.t @@ -36,7 +36,7 @@ sub skip { return 1; } -print "1..53\n"; +print "1..54\n"; $Is_MSWin32 = $^O eq 'MSWin32'; $Is_NetWare = $^O eq 'NetWare'; @@ -411,3 +411,15 @@ ok "@+" eq "10 1 6 10"; } ok $ok; } + +# Test for bug [perl #27839] +{ + my $x; + sub f { + "abc" =~ /(.)./; + $x = "@+"; + return @+; + }; + my @y = f(); + ok( $x eq "@y", "return a magic array ($x) vs (@y)" ); +}