diff options
author | David Mitchell <davem@iabyn.com> | 2015-12-18 15:09:42 +0000 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2016-02-03 09:18:35 +0000 |
commit | 6d3ca00e6379e48bc8092acc7a90d9ce838df013 (patch) | |
tree | 97811991ffda1b0b526c49cf892c3be80292d593 /pp_ctl.c | |
parent | 2c49879ec3c26fea291b0d87fd14cdea3709bcc9 (diff) | |
download | perl-6d3ca00e6379e48bc8092acc7a90d9ce838df013.tar.gz |
fix *_ = "" for 0 .. 1;
RT #123994
pp_iter couldn't handle GvSv(gv) being NULL.
In that ticket, Tony Cook suggested two possible fixes. First,
always instantiate the GvSV slot at the start of pp_iter by using
GvSVn rather than GvSV in the CxITERVAR() macro;
Second, test for it being null within the two 'range' branches,
(for(1..9), for('a'..'z')), and if so create it. One advantage of doing
it there is that there's already code for (re)creating the SV if the
reference count is != 1. It also means that the list and array cases
(for(@a), for(1,3,5)) which always put the next iterated SV into the
pad/GvSV slot don't waste time creating and then immediately discarding an
SV if GvSV was NULL.
I went for the second fix.
It also means that's there's no longer any need in pp_enteriter to
initially poulate GvSV is it was null, as this will be detected during
the first pp_iter() anyway.
Diffstat (limited to 'pp_ctl.c')
-rw-r--r-- | pp_ctl.c | 8 |
1 files changed, 2 insertions, 6 deletions
@@ -2123,12 +2123,8 @@ PP(pp_enteriter) SV * const sv = POPs; itervarp = (void *)sv; if (LIKELY(isGV(sv))) { /* symbol table variable */ - SV** svp = &GvSV(sv); - itersave = *svp; - if (LIKELY(itersave)) - SvREFCNT_inc_simple_void_NN(itersave); - else - *svp = newSV(0); + itersave = GvSV(sv); + SvREFCNT_inc_simple_void(itersave); cxflags = CXp_FOR_GV; } else { /* LV ref: for \$foo (...) */ |