From 031c6d827a20d62a99481765d8e1b1686025aa2b Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Wed, 28 Aug 2013 18:34:22 -0700 Subject: [PATCH] Make vivify_defelem allow &PL_sv_undef array entries MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This is something I failed to change in commit ce0d59f. I don’t know of a way to trigger this in pure-Perl code, hence the use of XS in the test. It did show up in pure-Perl code due to a bug fixed by the previous commit. --- ext/XS-APItest/APItest.xs | 5 +++++ mg.c | 2 +- t/op/for.t | 13 ++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ext/XS-APItest/APItest.xs b/ext/XS-APItest/APItest.xs index 2db7b4f..38d4364 100644 --- a/ext/XS-APItest/APItest.xs +++ b/ext/XS-APItest/APItest.xs @@ -3462,6 +3462,11 @@ sv_mortalcopy(SV *sv) SV * newRV(SV *sv) +void +alias_av(AV *av, IV ix, SV *sv) + CODE: + av_store(av, ix, SvREFCNT_inc(sv)); + MODULE = XS::APItest PACKAGE = XS::APItest::AUTOLOADtest int diff --git a/mg.c b/mg.c index 604fe6b..543af81 100644 --- a/mg.c +++ b/mg.c @@ -2381,7 +2381,7 @@ Perl_vivify_defelem(pTHX_ SV *sv) LvTARG(sv) = NULL; /* array can't be extended */ else { SV* const * const svp = av_fetch(av, LvSTARGOFF(sv), TRUE); - if (!svp || (value = *svp) == &PL_sv_undef) + if (!svp || !(value = *svp)) Perl_croak(aTHX_ PL_no_aelem, LvSTARGOFF(sv)); } } diff --git a/t/op/for.t b/t/op/for.t index 6cd0224..18fedeb 100644 --- a/t/op/for.t +++ b/t/op/for.t @@ -4,7 +4,7 @@ BEGIN { require "test.pl"; } -plan(105); +plan(106); # A lot of tests to check that reversed for works. @@ -568,3 +568,14 @@ sub { is eval { \$_ }, \undef, 'foreach (@array_containing_undef)' } }->(undef); + +SKIP: { + skip "No XS::APItest under miniperl", 1, if is_miniperl; + my @a; + sub { + require XS::APItest; + XS::APItest::alias_av(\@a, 0, undef); + eval { \$_[0] } + }->($a[0]); + is $@, "", 'vivify_defelem does not croak on &PL_sv_undef elements'; +} -- 2.7.4