diff options
author | Father Chrysostomos <sprout@cpan.org> | 2013-07-02 13:07:45 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2013-08-20 21:38:07 -0700 |
commit | ce0d59fdd1c7d145efdf6bf8da56a259fed483e4 (patch) | |
tree | 6d7ed09aaf3e1540bf3b408b343713dfe3da8b19 /pp_hot.c | |
parent | 1a33a0598e4c684205d292afcb97de6d79d17e7d (diff) | |
download | perl-ce0d59fdd1c7d145efdf6bf8da56a259fed483e4.tar.gz |
[perl #7508] Use NULL for nonexistent array elems
This commit fixes bug #7508 and provides the groundwork for fixing
several other bugs.
Elements of @_ are aliased to the arguments, so that \$_[0] within
sub foo will reference the same scalar as \$x if the sub is called
as foo($x).
&PL_sv_undef (the global read-only undef scalar returned by the
‘undef’ operator itself) was being used to represent nonexistent
array elements. So the pattern would be broken for foo(undef), where
\$_[0] would vivify a new $_[0] element, treating it as having been
nonexistent.
This also causes other problems with constants under ithreads
(#105906) and causes a pending fix for another bug (#118691) to trig-
ger this bug.
This commit changes the internals to use a null pointer to represent a
nonexistent element.
This requires that Storable be changed to account for it. Also,
IPC::Open3 was relying on the bug. So this commit patches
both modules.
Diffstat (limited to 'pp_hot.c')
-rw-r--r-- | pp_hot.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -339,7 +339,11 @@ S_pushav(pTHX_ AV* const av) } } else { - Copy(AvARRAY(av), SP+1, maxarg, SV*); + U32 i; + for (i=0; i < (U32)maxarg; i++) { + SV * const sv = AvARRAY(av)[i]; + SP[i+1] = sv ? sv : &PL_sv_undef; + } } SP += maxarg; PUTBACK; @@ -1055,8 +1059,8 @@ PP(pp_aassign) i = 0; while (relem <= lastrelem) { /* gobble up all the rest */ SV **didstore; - assert(*relem); - SvGETMAGIC(*relem); /* before newSV, in case it dies */ + if (*relem) + SvGETMAGIC(*relem); /* before newSV, in case it dies */ sv = newSV(0); sv_setsv_nomg(sv, *relem); *(relem++) = sv; @@ -2830,7 +2834,7 @@ PP(pp_aelem) MEM_WRAP_CHECK_1(elem,SV*,oom_array_extend); } #endif - if (!svp || *svp == &PL_sv_undef) { + if (!svp || !*svp) { SV* lv; if (!defer) DIE(aTHX_ PL_no_aelem, elem); |