Make vivify_defelem allow &PL_sv_undef array entries
authorFather Chrysostomos <sprout@cpan.org>
Thu, 29 Aug 2013 01:34:22 +0000 (18:34 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 29 Aug 2013 05:26:14 +0000 (22:26 -0700)
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
mg.c
t/op/for.t

index 2db7b4f..38d4364 100644 (file)
@@ -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 (file)
--- 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));
        }
     }
index 6cd0224..18fedeb 100644 (file)
@@ -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';
+}