SvGETMAGIC(paths);
if ((!SvROK(paths))
|| (SvTYPE(SvRV(paths)) != SVt_PVAV)
- || ((numpaths = av_len((AV *)SvRV(paths))) < 0))
+ || ((numpaths = av_top_index((AV *)SvRV(paths))) < 0))
{
XSRETURN_UNDEF;
}
checking C<SvROK> won't trigger FETCH on a tied variable.) It
then verifies that the object referenced by paths is an array, using C<SvRV>
to dereference paths, and C<SvTYPE> to discover its type. As an added test,
-it checks that the array referenced by paths is non-empty, using the C<av_len>
+it checks that the array referenced by paths is non-empty, using the C<av_top_index>
function (which returns -1 if the array is empty). The XSRETURN_UNDEF macro
is used to abort the XSUB and return the undefined value whenever all three of
these conditions are not met.
We manipulate several arrays in this XSUB. Note that an array is represented
internally by an AV* pointer. The functions and macros for manipulating
-arrays are similar to the functions in Perl: C<av_len> returns the highest
+arrays are similar to the functions in Perl: C<av_top_index> returns the highest
index in an AV*, much like $#array; C<av_fetch> fetches a single scalar value
from an array, given its index; C<av_push> pushes a scalar value onto the
end of the array, automatically extending the array as necessary.
Sort an array. Here is an example:
- sortsv(AvARRAY(av), av_len(av)+1, Perl_sv_cmp_locale);
+ sortsv(AvARRAY(av), av_top_index(av)+1, Perl_sv_cmp_locale);
Currently this always uses mergesort. See sortsv_flags for a more
flexible routine.