|
|
b8876f |
From 27a8a9e2a55ccc148582006396a9c35bafa5f0b3 Mon Sep 17 00:00:00 2001
|
|
|
b8876f |
From: David Mitchell <davem@iabyn.com>
|
|
|
b8876f |
Date: Wed, 30 Nov 2016 08:59:01 +0000
|
|
|
b8876f |
Subject: [PATCH] split was leaving PL_sv_undef in unused ary slots
|
|
|
b8876f |
MIME-Version: 1.0
|
|
|
b8876f |
Content-Type: text/plain; charset=UTF-8
|
|
|
b8876f |
Content-Transfer-Encoding: 8bit
|
|
|
b8876f |
|
|
|
b8876f |
Petr Pisar: Ported to 5.24.0:
|
|
|
b8876f |
|
|
|
b8876f |
commit 71ca73e5fa9639ac33e9f2e74cd0c32288a5040d
|
|
|
b8876f |
Author: David Mitchell <davem@iabyn.com>
|
|
|
b8876f |
Date: Wed Nov 30 08:59:01 2016 +0000
|
|
|
b8876f |
|
|
|
b8876f |
split was leaving PL_sv_undef in unused ary slots
|
|
|
b8876f |
|
|
|
b8876f |
This:
|
|
|
b8876f |
|
|
|
b8876f |
@a = split(/-/,"-");
|
|
|
b8876f |
$a[1] = undef;
|
|
|
b8876f |
$a[0] = 0;
|
|
|
b8876f |
|
|
|
b8876f |
was giving
|
|
|
b8876f |
|
|
|
b8876f |
Modification of a read-only value attempted at foo line 3.
|
|
|
b8876f |
|
|
|
b8876f |
This is because:
|
|
|
b8876f |
|
|
|
b8876f |
1) unused slots in AvARRAY between AvFILL and AvMAX should always be
|
|
|
b8876f |
null; av_clear(), av_extend() etc do this; while av_store(), if storing
|
|
|
b8876f |
to a slot N somewhere between AvFILL and AvMAX, doesn't bother to clear
|
|
|
b8876f |
between (AvFILL+1)..(N-1) on the assumption that everyone else plays
|
|
|
b8876f |
nicely.
|
|
|
b8876f |
|
|
|
b8876f |
2) pp_split() when splitting directly to an array, sometimes over-splits
|
|
|
b8876f |
and has to null out the excess elements;
|
|
|
b8876f |
|
|
|
b8876f |
3) Since perl 5.19.4, unused AV slots are now marked with NULL rather than
|
|
|
b8876f |
&PL_sv_undef;
|
|
|
b8876f |
|
|
|
b8876f |
4) pp_split was still using &PL_sv_undef;
|
|
|
b8876f |
|
|
|
b8876f |
The fault was with (4), and is easily fixed.
|
|
|
b8876f |
|
|
|
b8876f |
Signed-off-by: Petr Písař <ppisar@redhat.com>
|
|
|
b8876f |
---
|
|
|
b8876f |
pp.c | 2 +-
|
|
|
b8876f |
t/op/split.t | 13 ++++++++++++-
|
|
|
b8876f |
2 files changed, 13 insertions(+), 2 deletions(-)
|
|
|
b8876f |
|
|
|
b8876f |
diff --git a/pp.c b/pp.c
|
|
|
b8876f |
index 4153482..70345ce 100644
|
|
|
b8876f |
--- a/pp.c
|
|
|
b8876f |
+++ b/pp.c
|
|
|
b8876f |
@@ -6212,7 +6212,7 @@ PP(pp_split)
|
|
|
b8876f |
while (iters > 0 && (!TOPs || !SvANY(TOPs) || SvCUR(TOPs) == 0)) {
|
|
|
b8876f |
if (TOPs && !make_mortal)
|
|
|
b8876f |
sv_2mortal(TOPs);
|
|
|
b8876f |
- *SP-- = &PL_sv_undef;
|
|
|
b8876f |
+ *SP-- = NULL;
|
|
|
b8876f |
iters--;
|
|
|
b8876f |
}
|
|
|
b8876f |
}
|
|
|
b8876f |
diff --git a/t/op/split.t b/t/op/split.t
|
|
|
b8876f |
index fb73271..b7846a1 100644
|
|
|
b8876f |
--- a/t/op/split.t
|
|
|
b8876f |
+++ b/t/op/split.t
|
|
|
b8876f |
@@ -7,7 +7,7 @@ BEGIN {
|
|
|
b8876f |
set_up_inc('../lib');
|
|
|
b8876f |
}
|
|
|
b8876f |
|
|
|
b8876f |
-plan tests => 131;
|
|
|
b8876f |
+plan tests => 133;
|
|
|
b8876f |
|
|
|
b8876f |
$FS = ':';
|
|
|
b8876f |
|
|
|
b8876f |
@@ -523,3 +523,14 @@ is "@a", '1 2 3', 'assignment to split-to-array (pmtarget/package array)';
|
|
|
b8876f |
}
|
|
|
b8876f |
(@{\@a} = split //, "abc") = 1..10;
|
|
|
b8876f |
is "@a", '1 2 3', 'assignment to split-to-array (stacked)';
|
|
|
b8876f |
+
|
|
|
b8876f |
+# splitting directly to an array wasn't filling unused AvARRAY slots with
|
|
|
b8876f |
+# NULL
|
|
|
b8876f |
+
|
|
|
b8876f |
+{
|
|
|
b8876f |
+ my @a;
|
|
|
b8876f |
+ @a = split(/-/,"-");
|
|
|
b8876f |
+ $a[1] = 'b';
|
|
|
b8876f |
+ ok eval { $a[0] = 'a'; 1; }, "array split filling AvARRAY: assign 0";
|
|
|
b8876f |
+ is "@a", "a b", "array split filling AvARRAY: result";
|
|
|
b8876f |
+}
|
|
|
b8876f |
--
|
|
|
b8876f |
2.7.4
|
|
|
b8876f |
|