av.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/* av.c
*
* Copyright (c) 1991-2001, Larry Wall
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
/*
* "...for the Entwives desired order, and plenty, and peace (by which they
* meant that things should remain where they had set them)." --Treebeard
*/
#include "EXTERN.h"
#define PERL_IN_AV_C
#include "perl.h"
void
{
return;
#ifdef DEBUGGING
#endif
while (key) {
if (sv != &PL_sv_undef)
(void)SvREFCNT_inc(sv);
}
while (key)
}
/*
=for apidoc av_extend
Pre-extend an array. The C<key> is the index to which the array should be
extended.
=cut
*/
void
{
dSP;
return;
}
while (tmp)
}
goto resize;
}
}
else {
#ifndef STRANGE_MALLOC
#endif
goto resized;
#endif
#if defined(STRANGE_MALLOC) || defined(MYMALLOC)
#else
#define MALLOC_OVERHEAD 16
itmp -= MALLOC_OVERHEAD;
else
#endif
}
}
else {
}
while (tmp)
}
}
}
}
/*
=for apidoc av_fetch
Returns the SV at the specified index in the array. The C<key> is the
index. If C<lval> is set then the fetch will be part of a store. Check
that the return value is non-null before dereferencing it to a C<SV*>.
See L<perlguts/"Understanding the Magic of Tied Hashes and Arrays"> for
more information on how to use this function on tied arrays.
=cut
*/
SV**
{
if (!av)
return 0;
if (key < 0) {
if (key < 0)
return 0;
}
if (SvRMAGICAL(av)) {
sv = sv_newmortal();
PL_av_fetch_sv = sv;
return &PL_av_fetch_sv;
}
}
if (!lval)
return 0;
}
if (lval) {
}
return 0;
}
goto emptyness;
}
}
/*
=for apidoc av_store
Stores an SV in an array. The array index is specified as C<key>. The
return value will be NULL if the operation failed or if the value did not
need to be actually stored within the array (as in the case of tied
arrays). Otherwise it can be dereferenced to get the original C<SV*>. Note
that the caller is responsible for suitably incrementing the reference
count of C<val> before the call, and decrementing it if the function
returned NULL.
See L<perlguts/"Understanding the Magic of Tied Hashes and Arrays"> for
more information on how to use this function on tied arrays.
=cut
*/
SV**
{
if (!av)
return 0;
if (!val)
val = &PL_sv_undef;
if (key < 0) {
if (key < 0)
return 0;
}
if (SvRMAGICAL(av)) {
if (val != &PL_sv_undef) {
}
return 0;
}
}
do
}
}
if (SvSMAGICAL(av)) {
if (val != &PL_sv_undef) {
}
}
}
/*
=for apidoc newAV
Creates a new AV. The reference count is set to 1.
=cut
*/
AV *
{
return av;
}
/*
=for apidoc av_make
Creates a new AV and populates it with a list of SVs. The SVs are copied
into the array, so they may be freed after the call to av_make. The new AV
will have a reference count of 1.
=cut
*/
AV *
{
register I32 i;
if (size) { /* `defined' was returning undef for size==0 anyway. */
for (i = 0; i < size; i++) {
strp++;
}
}
return av;
}
AV *
{
while (size--) {
SvTEMP_off(*strp);
strp++;
}
return av;
}
/*
=for apidoc av_clear
Clears an array, making it empty. Does not free the memory used by the
array itself.
=cut
*/
void
{
#ifdef DEBUGGING
}
#endif
if (!av)
return;
/*SUPPRESS 560*/
if (SvREADONLY(av))
/* Give any tie a chance to cleanup first */
if (SvRMAGICAL(av))
return;
while (key) {
}
}
}
}
/*
=for apidoc av_undef
Undefines the array. Frees the memory used by the array itself.
=cut
*/
void
{
if (!av)
return;
/*SUPPRESS 560*/
/* Give any tie a chance to cleanup first */
while (key)
}
}
}
/*
=for apidoc av_push
Pushes an SV onto the end of the array. The array will grow automatically
to accommodate the addition.
=cut
*/
void
{
if (!av)
return;
if (SvREADONLY(av))
dSP;
return;
}
}
/*
=for apidoc av_pop
Pops an SV off the end of the array. Returns C<&PL_sv_undef> if the array
is empty.
=cut
*/
SV *
{
return &PL_sv_undef;
if (SvREADONLY(av))
dSP;
} else {
retval = &PL_sv_undef;
}
return retval;
}
if (SvSMAGICAL(av))
return retval;
}
/*
=for apidoc av_unshift
Unshift the given number of C<undef> values onto the beginning of the
array. The array will grow automatically to accommodate the addition. You
must then use C<av_store> to assign values to these new elements.
=cut
*/
void
{
register I32 i;
return;
if (SvREADONLY(av))
dSP;
while (num-- > 0) {
PUSHs(&PL_sv_undef);
}
return;
}
if (i) {
if (i > num)
i = num;
num -= i;
}
if (num) {
/* Create extra elements */
slide = i > 0 ? i : 0;
do {
} while (num);
/* Make extra elements into a buffer */
}
}
/*
=for apidoc av_shift
Shifts an SV off the beginning of the array.
=cut
*/
SV *
{
return &PL_sv_undef;
if (SvREADONLY(av))
dSP;
} else {
retval = &PL_sv_undef;
}
return retval;
}
if (SvSMAGICAL(av))
return retval;
}
/*
=for apidoc av_len
Returns the highest index in the array. Returns -1 if the array is
empty.
=cut
*/
{
}
/*
=for apidoc av_fill
Ensure than an array has a given number of elements, equivalent to
Perl's C<$#array = $fill;>.
=cut
*/
void
{
if (!av)
if (fill < 0)
fill = -1;
dSP;
return;
}
}
}
else {
}
if (SvSMAGICAL(av))
}
else
}
/*
=for apidoc av_delete
Deletes the element indexed by C<key> from the array. Returns the
deleted element. C<flags> is currently ignored.
=cut
*/
SV *
{
if (!av)
return Nullsv;
if (SvREADONLY(av))
if (key < 0) {
if (key < 0)
return Nullsv;
}
if (SvRMAGICAL(av)) {
{
return sv;
}
return Nullsv; /* element cannot be deleted */
}
}
return Nullsv;
else {
do {
}
else
if (SvSMAGICAL(av))
}
}
return sv;
}
/*
=for apidoc av_exists
Returns true if the element indexed by C<key> has been initialized.
This relies on the fact that uninitialized array elements are set to
C<&PL_sv_undef>.
=cut
*/
bool
{
if (!av)
return FALSE;
if (key < 0) {
if (key < 0)
return FALSE;
}
if (SvRMAGICAL(av)) {
if (mg) {
}
}
}
{
return TRUE;
}
else
return FALSE;
}
/* AVHV: Support for treating arrays as if they were hashes. The
* first element of the array should be a hash reference that maps
* hash keys to array indices.
*/
{
if (index < 1)
return index;
}
{
if (!he)
}
HV*
{
if (keysp) {
if (SvGMAGICAL(sv))
}
}
return Nullhv;
}
SV**
{
}
SV**
{
}
SV *
{
return Nullsv;
}
/* Check for the existence of an element named by a given key.
*
*/
bool
{
return FALSE;
}
HE *
{
return hv_iternext(keys);
}
SV *
{
}