From: Eric Brine Date: Fri, 23 Oct 2009 23:05:40 +0000 (-0400) Subject: Avoid adding magic with rvalue $#a X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=02d85cc37a4acecafdc2f0b45640b03cd1f4ac71;p=p5sagit%2Fp5-mst-13.2.git Avoid adding magic with rvalue $#a --- diff --git a/pp.c b/pp.c index a2704af..80bb590 100644 --- a/pp.c +++ b/pp.c @@ -321,12 +321,19 @@ PP(pp_av2arylen) { dVAR; dSP; AV * const av = MUTABLE_AV(TOPs); - SV ** const sv = Perl_av_arylen_p(aTHX_ MUTABLE_AV(av)); - if (!*sv) { - *sv = newSV_type(SVt_PVMG); - sv_magic(*sv, MUTABLE_SV(av), PERL_MAGIC_arylen, NULL, 0); + const I32 lvalue = PL_op->op_flags & OPf_MOD || LVRET; + if (lvalue) { + SV ** const sv = Perl_av_arylen_p(aTHX_ MUTABLE_AV(av)); + if (!*sv) { + *sv = newSV_type(SVt_PVMG); + sv_magic(*sv, MUTABLE_SV(av), PERL_MAGIC_arylen, NULL, 0); + } + SETs(*sv); + } else { + SETs(sv_2mortal(newSViv( + AvFILL(MUTABLE_AV(av)) + CopARYBASE_get(PL_curcop) + ))); } - SETs(*sv); RETURN; }