Let av_push accept NULL values
authorFather Chrysostomos <sprout@cpan.org>
Sat, 7 Sep 2013 06:21:56 +0000 (23:21 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 7 Sep 2013 06:25:51 +0000 (23:25 -0700)
Now that NULL is used for a nonexistent element, it is easy for XS
code to pass it to av_push().  av_store already accepts NULL, and
av_push already works with it on non-debugging builds, so there is
really no need for this restriction.

MANIFEST
embed.fnc
ext/XS-APItest/APItest.xs
ext/XS-APItest/t/av.t [new file with mode: 0644]
proto.h

index 4679c95..d1cc4f1 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -3941,6 +3941,7 @@ ext/XS-APItest/README             XS::APItest extension
 ext/XS-APItest/t/addissub.t    test op check wrapping
 ext/XS-APItest/t/arrayexpr.t   test recursive descent expression parsing
 ext/XS-APItest/t/autoload.t    Test XS AUTOLOAD routines
+ext/XS-APItest/t/av.t          Test AV functions
 ext/XS-APItest/t/BHK.pm                Helper for ./blockhooks.t
 ext/XS-APItest/t/blockasexpr.t test recursive descent block parsing
 ext/XS-APItest/t/blockhooks-csc.t      XS::APItest: more tests for PL_blockhooks
index 11425ad..4940ae4 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -219,7 +219,7 @@ ApdR        |SSize_t|av_len         |NN AV *av
 ApdR   |AV*    |av_make        |SSize_t size|NN SV **strp
 Apd    |SV*    |av_pop         |NN AV *av
 ApdoxM |void   |av_create_and_push|NN AV **const avp|NN SV *const val
-Apd    |void   |av_push        |NN AV *av|NN SV *val
+Apd    |void   |av_push        |NN AV *av|NULLOK SV *val
 : Used in scope.c, and by Data::Alias
 EXp    |void   |av_reify       |NN AV *av
 ApdR   |SV*    |av_shift       |NN AV *av
index 16d26de..85e2b01 100644 (file)
@@ -3467,6 +3467,11 @@ alias_av(AV *av, IV ix, SV *sv)
     CODE:
        av_store(av, ix, SvREFCNT_inc(sv));
 
+void
+av_pushnull(AV *av)
+    CODE:
+       av_push(av, NULL);
+
 MODULE = XS::APItest PACKAGE = XS::APItest::AUTOLOADtest
 
 int
diff --git a/ext/XS-APItest/t/av.t b/ext/XS-APItest/t/av.t
new file mode 100644 (file)
index 0000000..03e2aa6
--- /dev/null
@@ -0,0 +1,14 @@
+#!perl
+
+use Test::More tests => 4;
+use XS::APItest;
+
+av_pushnull \@_;
+is $#_, 0, '$#_ after av_push(@_, NULL)';
+ok !exists $_[0], '!exists $_[0] after av_push(@_,NULL)';
+
+use Tie::Array;
+tie @tied, 'Tie::StdArray';
+av_pushnull \@tied;
+is $#tied, 0, '$#tied after av_push(@tied, NULL)';
+is $tied[0], undef, '$tied[0] is undef after av_push(@tied,NULL)';
diff --git a/proto.h b/proto.h
index 7819f21..388fa64 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -221,10 +221,9 @@ PERL_CALLCONV SV*  Perl_av_pop(pTHX_ AV *av)
        assert(av)
 
 PERL_CALLCONV void     Perl_av_push(pTHX_ AV *av, SV *val)
-                       __attribute__nonnull__(pTHX_1)
-                       __attribute__nonnull__(pTHX_2);
+                       __attribute__nonnull__(pTHX_1);
 #define PERL_ARGS_ASSERT_AV_PUSH       \
-       assert(av); assert(val)
+       assert(av)
 
 PERL_CALLCONV void     Perl_av_reify(pTHX_ AV *av)
                        __attribute__nonnull__(pTHX_1);