I repeat my plea for someone with knowlege about using TARG to look at this. Should the rvalue case just create a new mortal sv to return if TARG is a PVLV? On Wed, Oct 15, 2003 at 12:18:16AM -0700, Yitzchak Scott-Thoennes <sthoenna@efn.org> wrote: > On Mon, Oct 13, 2003 at 05:28:49PM -0000, "mconst@csua.berkeley.edu (via RT)" <perlbug-followup@perl.org> wrote: > > Under perl v5.8.1 on my i386 Debian Linux system, this script: > > > > $foo = "a"; > > sub bar: lvalue { substr $foo, 0 } > > bar = "XXX"; > > print bar, "\n"; > > > > produces the output "X". I would have expected it to output "XXX", > > like it does if you make the calls to substr directly instead of > > through the lvalue function. > > Looks like substr is expecting to always or never return an lvalue. > It gets confused if you first make it return a PVLV TARG and then > reuse the TARG not considering it is a PVLV. > > This is a start: > > --- perl/pp.c.orig 2003-10-14 23:55:45.673918400 -0700 > +++ perl/pp.c 2003-10-14 23:58:14.748276800 -0700 > @@ -3079,6 +3079,8 @@ > SvREFCNT_dec(LvTARG(TARG)); > LvTARG(TARG) = SvREFCNT_inc(sv); > } > + } > + if (SvTYPE(TARG) == SVt_PVLV) { > LvTARGOFF(TARG) = upos; > LvTARGLEN(TARG) = urem; > } > End of Patch. > > but it needs more. The non-lvalue but a PVLV case needs to handle > TARG REFCNT > 1. (Is that check in the right place in the lvalue > case? Its already done stuff to TARG at the point it decides to do > TARG = sv_newmortal(). And does it leak? Seems like it should be > decrementing the old TARGs refcnt before reassigning it.) > > Can someone more familiar with TARG reuse take a look at this? >Thread Previous