summaryrefslogtreecommitdiff
path: root/pp.c
diff options
context:
space:
mode:
authorEric Brine <ikegami@adaelis.com>2009-10-23 19:05:40 -0400
committerRafael Garcia-Suarez <rgs@consttype.org>2009-10-28 09:44:00 +0100
commit02d85cc37a4acecafdc2f0b45640b03cd1f4ac71 (patch)
treed34568662ba1734cd08f7bb3aa9ea1cde74ada25 /pp.c
parent34861f291d6c548304b74dfc30ff27447f1b582f (diff)
downloadperl-02d85cc37a4acecafdc2f0b45640b03cd1f4ac71.tar.gz
Avoid adding magic with rvalue $#a
Diffstat (limited to 'pp.c')
-rw-r--r--pp.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/pp.c b/pp.c
index a2704af959..80bb590086 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;
}