From 7b6e8075e45ebc684565efbe3ce7b70435f20c79 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Fri, 6 Sep 2013 23:21:56 -0700 Subject: [PATCH] Let av_push accept NULL values 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 | 1 + embed.fnc | 2 +- ext/XS-APItest/APItest.xs | 5 +++++ ext/XS-APItest/t/av.t | 14 ++++++++++++++ proto.h | 5 ++--- 5 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 ext/XS-APItest/t/av.t diff --git a/MANIFEST b/MANIFEST index 4679c95..d1cc4f1 100644 --- 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 diff --git a/embed.fnc b/embed.fnc index 11425ad..4940ae4 100644 --- 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 diff --git a/ext/XS-APItest/APItest.xs b/ext/XS-APItest/APItest.xs index 16d26de..85e2b01 100644 --- a/ext/XS-APItest/APItest.xs +++ b/ext/XS-APItest/APItest.xs @@ -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 index 0000000..03e2aa6 --- /dev/null +++ b/ext/XS-APItest/t/av.t @@ -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 --- 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); -- 2.7.4