Front page | perl.perl5.porters |
Postings from July 2009
Re: [perl #63322] PERL_ARGS_ASSERT_AV_MAKE is too strict
Thread Previous
From:
Dave Mitchell
Date:
July 19, 2009 03:52
Subject:
Re: [perl #63322] PERL_ARGS_ASSERT_AV_MAKE is too strict
Message ID:
20090719104313.GH4204@iabyn.com
On Wed, Feb 18, 2009 at 05:50:58PM -0800, Goro Fuji wrote:
> The PERL_ARGS_ASSERT_AV_MAKE macro could break existing code.
>
> I use av_make() to create a copy of an av, but "av_make(AvFILLp(av),
> AvARRAY(av))" cause assertion failure when AvARRAY(av) is NULL.
> Is it intended? or I have to do "AvFILLp(av) > -1 ?
> av_make(AvFILLp(av), AvARRAY(av)) : newAV()", instead of
> "av_make(AvFILLp(av), AvARRAY(av))"?
>
> See the following:
>
> /* proto.h */
> #define PERL_ARGS_ASSERT_AV_MAKE \
> assert(strp)
>
> /* av.c */
> AV *
> Perl_av_make(pTHX_ register I32 size, register SV **strp)
> {
> register AV * const av = MUTABLE_AV(newSV_type(SVt_PVAV));
> /* sv_upgrade does AvREAL_only() */
> PERL_ARGS_ASSERT_AV_MAKE;
> assert(SvTYPE(av) == SVt_PVAV);
>
> if (size) { /* "defined" was returning undef for size==0 anyway. */
> register SV** ary;
> register I32 i;
> Newx(ary,size,SV*);
> AvALLOC(av) = ary;
> AvARRAY(av) = ary;
> AvFILLp(av) = AvMAX(av) = size - 1;
> for (i = 0; i < size; i++) {
> assert (*strp);
> ary[i] = newSV(0);
> sv_setsv(ary[i], *strp);
> strp++;
> }
> }
> return av;
> }
Well, since 5.8.8, av_make has been declared as
PERL_CALLCONV AV* Perl_av_make(pTHX_ I32 size, SV** svp)
__attribute__warn_unused_result__
__attribute__nonnull__(pTHX_2);
and since 5.10.0, the PERL_ARGS_ASSERT_AV_MAKE has been added to the code.
In addition, I see nowhere in the documentation that indicates that NULL
might be a valid value.
So I think it should stay as it is.
--
"I do not resent criticism, even when, for the sake of emphasis,
it parts for the time with reality".
-- Winston Churchill, House of Commons, 22nd Jan 1941.
Thread Previous