This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #78194] Make list slices copy PADTMPs in lv cx
authorFather Chrysostomos <sprout@cpan.org>
Tue, 25 Jun 2013 03:16:30 +0000 (20:16 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 26 Jul 2013 06:48:00 +0000 (23:48 -0700)
So that slices that reference the same value multiple times (such as
(...)[1,1]) will exhibit referential identity (\(...)[1,1] will return
two references to the same scalar).

pp.c
t/op/list.t

diff --git a/pp.c b/pp.c
index cadfe96..99f7d1f 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -4773,6 +4773,7 @@ PP(pp_lslice)
     SV ** const firstlelem = PL_stack_base + POPMARK + 1;
     SV ** const firstrelem = lastlelem + 1;
     I32 is_something_there = FALSE;
+    const U8 mod = PL_op->op_flags & OPf_MOD;
 
     const I32 max = lastrelem - lastlelem;
     SV **lelem;
@@ -4804,6 +4805,8 @@ PP(pp_lslice)
            is_something_there = TRUE;
            if (!(*lelem = firstrelem[ix]))
                *lelem = &PL_sv_undef;
+           else if (mod && SvPADTMP(*lelem) && !IS_PADGV(*lelem))
+               *lelem = firstrelem[ix] = sv_mortalcopy(*lelem);
        }
     }
     if (is_something_there)
index 91bf321..0f6e0bc 100644 (file)
@@ -184,7 +184,6 @@ cmp_ok(join('',(1,2),3,(4,5)),'eq','12345','list (..).(..)');
 }
 
 # [perl #78194] list slice aliasing op return values
-$::TODO = 'not fixed yet';
 sub {
  is(\$_[0], \$_[1],
   '[perl #78194] \$_[0] == \$_[1] when @_ aliases elems repeated by lslice'