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.181 2005/05/19 22:35:23 mast Exp $ + || $Id: array.c,v 1.182 2005/09/12 07:45:47 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:221: Inside #if defined(PIKE_DEBUG)
  #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);    free_array(v);   }    - /* Is destructive on data if destructive is set and it only has one ref. */ + /** Is destructive on data if destructive is set and it only has one ref. */   PMOD_EXPORT struct array *array_column (struct array *data, struct svalue *index,    int destructive)   {    int e;    struct array *a;    TYPE_FIELD types = 0;       DECLARE_CYCLIC();       /* Optimization */
pike.git/src/array.c:327:   PMOD_EXPORT void array_free_index(struct array *v,INT32 index)   {   #ifdef PIKE_DEBUG    if(index<0 || index>=v->size)    Pike_fatal("Illegal index in low level free index routine.\n");   #endif       free_svalue(ITEM(v) + index);   }    -  + /** set an element in an array to a value. +  * +  * @param a the array whose element is to be set +  * @param ind an int or string containing the index to set +  * @param s the value to set +  */   PMOD_EXPORT void simple_set_index(struct array *a,struct svalue *ind,struct svalue *s)   {    switch (ind->type) {    case T_INT: {    INT_TYPE p = ind->u.integer;    INT_TYPE i = p < 0 ? p + a->size : p;    if(i<0 || i>=a->size) {    if (a->size) {    Pike_error("Index %"PRINTPIKEINT"d is out of array range "    "%d..%d.\n", p, -a->size, a->size-1);
pike.git/src/array.c:543:    (char *)(ITEM(v)+index+1),    (v->size-index-1)*sizeof(struct svalue));    }    v->size--;    return v;    }   }      /**    * Search for in svalue in an array. +  * @param v the array to search +  * @param s the value to search for +  * @param start the index to start search at    * @return the index if found, -1 otherwise    */   PMOD_EXPORT ptrdiff_t array_search(struct array *v, struct svalue *s,    ptrdiff_t start)   {    ptrdiff_t e;      #ifdef PIKE_DEBUG    if(start<0)    Pike_fatal("Start of find_index is less than zero.\n");
pike.git/src/array.c:587:    t |= 1<<ITEM(v)[e].type;    }    v->type_field=t;    }    }    return -1;   }      /**    * Slice a piece of an array (nondestructively) +  * @param v the array to slice +  * @param start the beginning element to be included +  * @param end the element beyond the end of the slice    * @return an array consisting of v[start..end-1]    */   PMOD_EXPORT struct array *slice_array(struct array *v, ptrdiff_t start,    ptrdiff_t end)   {    struct array *a;      #ifdef PIKE_DEBUG    if(start > end || end>v->size || start<0)    Pike_fatal("Illegal arguments to slice_array()\n");
pike.git/src/array.c:660:    a=allocate_array_no_init(end-start,0);    a->type_field = v->type_field;       assign_svalues_no_free(ITEM(a), ITEM(v)+start, end-start, v->type_field);       return a;   }      /**    * Copy an array. +  * @param v the array to be copied. +  * @returns the copy of the input array.    */   PMOD_EXPORT struct array *copy_array(struct array *v)   {    struct array *a;       if (!v->size) {    /* Empty array. */    add_ref(&empty_array);    return &empty_array;    }
pike.git/src/array.c:1434:    if(*zipper >= 0)    assign_svalue_no_free(ITEM(ret)+e, ITEM(a)+*zipper);    else    assign_svalue_no_free(ITEM(ret)+e, ITEM(b)+~*zipper);    zipper++;    }    ret->type_field = a->type_field | b->type_field;    return ret;   }    + /** add an arbitrary number of arrays together + * @param argp an array of svalues containing the arrays to be concatenated + * @param args the number of elements in argp + * @returns the resulting struct array. + */   PMOD_EXPORT struct array *add_arrays(struct svalue *argp, INT32 args)   {    INT32 e, size;    struct array *v;       for(size=e=0;e<args;e++)    size+=argp[e].u.array->size;      #if 1    {
pike.git/src/array.c:1763:    UNSET_ONERROR(r2);    free_array(b);       UNSET_ONERROR(r1);    free_array(a);       return ret;   }       - /* merge two arrays without paying attention to the order + /** merge two arrays without paying attention to the order    * the elements has presently    */   PMOD_EXPORT struct array *merge_array_without_order(struct array *a,    struct array *b,    INT32 op)   {   #if 0    /* FIXME: If this routine is ever reinstated, it has to be    * fixed to use ONERROR    */
pike.git/src/array.c:1804: Inside #if 0
   free((char *)zipper);    return ret;      #else    add_ref(a);    add_ref(b);    return merge_array_without_order2(a,b,op);   #endif   }    - /* subtract an array from another */ -  + /** subtract an array from another + */   PMOD_EXPORT struct array *subtract_arrays(struct array *a, struct array *b)   {   #ifdef PIKE_DEBUG    if(d_flag > 1)    {    array_check_type_field(b);    }   #endif    check_array_for_destruct(a);   
pike.git/src/array.c:1830:    }else{    if(a->refs == 1)    {    add_ref(a);    return a;    }    return slice_array(a,0,a->size);    }   }    - /* and two arrays */ + /** +  * and two arrays +  */   PMOD_EXPORT struct array *and_arrays(struct array *a, struct array *b)   {   #ifdef PIKE_DEBUG    if(d_flag > 1)    {    array_check_type_field(b);    }   #endif    check_array_for_destruct(a);   
pike.git/src/array.c:1931:    return mkconstantsvaluenode(&s);    }else{    node *ret=0;    debug_malloc_touch(a);    for(e=0; e<a->size; e++)    ret=mknode(F_ARG_LIST,ret,mksvaluenode(ITEM(a)+e));    return mkefuncallnode("aggregate",ret);    }   }    + /** + * push elements of an array onto the stack. + */   PMOD_EXPORT void push_array_items(struct array *a)   {    check_stack(a->size);    check_array_for_destruct(a);    if(a->refs == 1)    {    MEMCPY(Pike_sp,ITEM(a),sizeof(struct svalue)*a->size);    Pike_sp += a->size;    a->size=0;    free_array(a);
pike.git/src/array.c:2042:    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);    Pike_sp-=args;    DO_IF_DMALLOC(while(args--) dmalloc_touch_svalue(Pike_sp + args));    }    return a;   }    + /** add an element to the end of an array by resizing the array. +  * +  * @param a the array to be appended +  * @param s the value to be added to the new element in the array +  */   PMOD_EXPORT struct array *append_array(struct array *a, struct svalue *s)   {    a=resize_array(a,a->size+1);    array_set_index(a, a->size-1, s);    return a;   }      typedef char *(* explode_searchfunc)(void *,void *,size_t);    -  + /** explode a string by a delimiter +  * +  * @param str the string to be split +  * @param del the string to split str by +  * @returns an array containing the elements of the split string +  */   PMOD_EXPORT struct array *explode(struct pike_string *str,    struct pike_string *del)   {    INT32 e;    struct array *ret;    char *s, *end, *tmp;      #if 0    if(!str->len)    {
pike.git/src/array.c:2138:    (end-s)>>str->size_shift);       ITEM(ret)[ret->size].type=T_STRING;    ret->size++;    mojt.vtab->freeme(mojt.data);    }    ret->type_field=BIT_STRING;    return ret;   }    + /** implode an array by creating a string with all of the array's elements +  * separated by a delimiter +  * +  * @param a the array containing elements to be imploded +  * @param del the delimiter used to separate the array's elements in the resulting string +  * @returns the imploded string +  * +  */   PMOD_EXPORT struct pike_string *implode(struct array *a,struct pike_string *del)   {    INT32 len,e, inited;    PCHARP r;    struct pike_string *ret,*tmp;    int max_shift=0;       len=0;       for(e=0;e<a->size;e++)
pike.git/src/array.c:2181:    inited=1;    tmp=ITEM(a)[e].u.string;    pike_string_cpy(r,tmp);    INC_PCHARP(r,tmp->len);    len++;    }    }    return low_end_shared_string(ret);   }    + /** deeply copy an array +  */   PMOD_EXPORT struct array *copy_array_recursively(struct array *a,    struct mapping *m)   {    struct array *ret;    struct svalue aa, bb;      #ifdef PIKE_DEBUG    if(d_flag > 1) array_check_type_field(a);   #endif   
pike.git/src/array.c:2214:    low_mapping_insert(m, &aa, &bb, 1);       ret->flags = a->flags & ~ARRAY_LVALUE;       copy_svalues_recursively_no_free(ITEM(ret),ITEM(a),a->size,m);       ret->type_field=a->type_field;    return ret;   }    + /** apply the elements of an array +  */   PMOD_EXPORT void apply_array(struct array *a, INT32 args)   {    INT32 e;    struct svalue *argp = Pike_sp-args;    TYPE_FIELD new_types = 0;    struct array *cycl;    DECLARE_CYCLIC();       check_array_for_destruct(a);    check_stack(120 + args + 1);
pike.git/src/array.c:2251: Inside #if defined(PIKE_DEBUG)
  #ifdef PIKE_DEBUG    array_check_type_field(Pike_sp[-1].u.array);   #endif    } else {    ref_push_array(cycl);    }    END_CYCLIC();    stack_pop_n_elems_keep_top(args);   }    + /** reverse the elements in an array +  * if the array has more than one reference, the array will be reversed +  * into a new array. otherwise, the same array is reversed. +  */   PMOD_EXPORT struct array *reverse_array(struct array *a)   {    INT32 e;    struct array *ret;       if(a->refs == 1)    /* Reverse in-place. */    {    struct svalue *tmp0, *tmp1, swap;