pike.git / src / array.c

version» Context lines:

pike.git/src/array.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: array.c,v 1.175 2004/10/16 22:03:45 nilsson Exp $ + || $Id: array.c,v 1.176 2004/10/18 00:42:36 bill Exp $   */      #include "global.h"   #include "svalue.h"   #include "array.h"   #include "object.h"   #include "las.h"   #include "stralloc.h"   #include "interpret.h"   #include "opcodes.h"
pike.git/src/array.c:71:    * Allocate an array. This might be changed in the future to allocate    * linked lists or something. The new array has zero references.    *    * When building arrays, it is recommended that you push the values on    * the stack and call aggregate_array or f_aggregate instead of    * allocating and filling in the values 'by hand'.    *    * @param size The size of the new array, in elements.    * @param extra_space The number of extra elements space    * should be reserved for. +  * @return A pointer to the allocated array struct.    */   PMOD_EXPORT struct array *real_allocate_array(ptrdiff_t size,    ptrdiff_t extra_space)   {    struct array *v;    ptrdiff_t e;       if(size+extra_space == 0)    {    add_ref(&empty_array);
pike.git/src/array.c:123:    ITEM(v)[e].type=T_INT;    ITEM(v)[e].subtype=NUMBER_NUMBER;    ITEM(v)[e].u.integer=0;    }       return v;   }      /**    * Free an array without freeing the values inside it. +  * Any values inside of the array will be kept. +  * @param v The array to be freed.    */   static void array_free_no_free(struct array *v)   {    DOUBLEUNLINK (first_array, v);       free((char *)v);       GC_FREE(v);   }      /**    * Free an array. Call this when the array has zero references. -  +  * @param v The array to free.    */   PMOD_EXPORT void really_free_array(struct array *v)   {   #ifdef PIKE_DEBUG    if(v == & empty_array || v == &weak_empty_array)    Pike_fatal("Tried to free some *_empty_array.\n");    if (v->refs) {   #ifdef DEBUG_MALLOC    describe_something(v, T_ARRAY, 0,2,0, NULL);   #endif
pike.git/src/array.c:160:    if(d_flag > 1) array_check_type_field(v);   #endif       add_ref(v);    EXIT_PIKE_MEMOBJ(v);    free_svalues(ITEM(v), v->size, v->type_field);    sub_ref(v);    array_free_no_free(v);   }    + /** +  * Decrement the references (and free if unused) an array if it is not null. +  */   PMOD_EXPORT void do_free_array(struct array *a)   {    if (a)    free_array(a);   }    -  + /** +  * Set flags on an array. If the array is empty, +  */   PMOD_EXPORT struct array *array_set_flags(struct array *a, int flags)   {    if (a->size)    a->flags = flags;    else {    free_array(a);    switch (flags) {    case 0:    add_ref(a = &empty_array); break;    case ARRAY_WEAK_FLAG:    add_ref(a = &weak_empty_array); break;    default:    Pike_fatal("Invalid flags %x\n", flags);    }    }    return a;   }         /** -  * Extract an svalue from an array. +  * Extract an svalue from an array. This function frees the contents of +  * of the svalue 's' and replaces it with a copy of the +  * contents from index 'index' in the array 'v'. +  * +  * @param index The index of the array to be extracted. +  * @param s The recipient of the extracted array element. +  * @param v The array to extract the element from. +  * +  * This function is similar to +  * assign_svalue(s, v->item + n); +  * except that it adds debug and safety measures. Usually, this function +  * is not needed. +  * +  * @note If n is out of bounds, Pike will dump core. If Pike was compiled +  * with DEBUG, a message will be written first stating what the problem was.    */   PMOD_EXPORT void array_index(struct svalue *s,struct array *v,INT32 index)   {   #ifdef PIKE_DEBUG    if(index<0 || index>=v->size)    Pike_fatal("Illegal index in low level index routine.\n");   #endif       add_ref(v);    assign_svalue(s, ITEM(v) + index);
pike.git/src/array.c:471:    a->size=0;    free_array(a);    return ret;    }    } else {    return array_shrink(a, size);    }   }      /** -  * Remove an index from an array and shrink the array. +  * Remove an index from an array and shrink the array destructively. +  * Because this function is destructive, and might free the region for 'v', +  * do not use this function on arrays that might have been sent to a +  * Pike function. +  * +  * @param v The array to operate on. +  * @param index The index of the element to remove +  * @return a new array with the contents of the input minus the removed index.    */   PMOD_EXPORT struct array *array_remove(struct array *v,INT32 index)   {    struct array *a;      #ifdef PIKE_DEBUG    if(index<0 || index >= v->size)    Pike_fatal("Illegal argument to array_remove.\n");   #endif   
pike.git/src/array.c:1986:    }    my_strcat(buf);    describe_array_low(a,&doing,indent);    my_putchar('\n');    for(e=2; e<indent; e++) my_putchar(' ');    my_strcat("})");   }      /**    * Pops a number of arguments off of the stack an puts them in an array. +  * The 'top' of the stack will be the last element in the array.    * @argument args The number of arguments to aggregate.    */   PMOD_EXPORT struct array *aggregate_array(INT32 args)   {    struct array *a;       a=allocate_array_no_init(args,0);    if (args) {    MEMCPY((char *)ITEM(a),(char *)(Pike_sp-args),args*sizeof(struct svalue));    array_fix_type_field (a);