X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/60edcf09a5cb026822f99270a4bfbe3149cfbb52..77d38c8d80370651198e27f063fd889851daf560:/av.c diff --git a/av.c b/av.c index 472600b..0551668 100644 --- a/av.c +++ b/av.c @@ -249,18 +249,12 @@ Perl_av_fetch(pTHX_ register AV *av, I32 key, I32 lval) return NULL; } - if (key > AvFILLp(av)) { - if (!lval) - return NULL; - return av_store(av,key,newSV(0)); - } - if (AvARRAY(av)[key] == &PL_sv_undef) { - emptyness: - if (lval) - return av_store(av,key,newSV(0)); - return NULL; + if (key > AvFILLp(av) || AvARRAY(av)[key] == &PL_sv_undef) { + emptyness: + return lval ? av_store(av,key,newSV(0)) : NULL; } - else if (AvREIFY(av) + + if (AvREIFY(av) && (!AvARRAY(av)[key] /* eg. @_ could have freed elts */ || SvIS_FREED(AvARRAY(av)[key]))) { AvARRAY(av)[key] = &PL_sv_undef; /* 1/2 reify */ @@ -426,8 +420,11 @@ Perl_av_make(pTHX_ register I32 size, register SV **strp) /* =for apidoc av_clear -Clears an array, making it empty. Does not free the memory used by the -array itself. Perl equivalent: C<@myarray = ();>. +Clears an array, making it empty. Does not free the memory the av uses to +store its list of scalars. If any destructors are triggered as a result, +the av itself may be freed when this function returns. + +Perl equivalent: C<@myarray = ();>. =cut */ @@ -488,7 +485,9 @@ Perl_av_clear(pTHX_ register AV *av) /* =for apidoc av_undef -Undefines the array. Frees the memory used by the array itself. +Undefines the array. Frees the memory used by the av to store its list of +scalars. If any destructors are triggered as a result, the av itself may +be freed. =cut */ @@ -1041,8 +1040,8 @@ Perl_av_iter_p(pTHX_ AV *av) { * Local variables: * c-indentation-style: bsd * c-basic-offset: 4 - * indent-tabs-mode: t + * indent-tabs-mode: nil * End: * - * ex: set ts=8 sts=4 sw=4 noet: + * ex: set ts=8 sts=4 sw=4 et: */