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.187 2006/03/01 11:53:07 nilsson Exp $ + || $Id: array.c,v 1.188 2006/03/04 19:38:23 nilsson 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:1833: 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:1859:    }else{    if(a->refs == 1)    {    add_ref(a);    return a;    }    return slice_array(a,0,a->size);    }   }    - /** -  * and two arrays + /** And two arrays together.    */   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);       if((a->type_field & b->type_field) ||    ((a->type_field | b->type_field) & BIT_OBJECT)) -  { +     return merge_array_with_order(a, b, PIKE_ARRAY_OP_AND_LEFT); -  }else{ +  else    return allocate_array_no_init(0,0);   } - } +       int array_is_constant(struct array *a,    struct processing *p)   {    return svalues_are_constant(ITEM(a),    a->size,    array_fix_type_field(a),    p);   }   
pike.git/src/array.c:1962:    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. + /** Push elements of an array onto the stack. The array will be freed.   */   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;
pike.git/src/array.c:2076:    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. + /** 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 + /** Explode a string into an array 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;
pike.git/src/array.c:2183:    (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 + /** 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 +  * @param a The array containing elements to be imploded +  * @param del The delimiter used to separate the array's elements in the resulting string +  * @return The imploded string    *    */ - PMOD_EXPORT struct pike_string *implode(struct array *a,struct pike_string *del) + PMOD_EXPORT struct pike_string *implode(struct array *a, +  struct pike_string *del)   { -  INT32 len,e, inited; +  INT32 len, e, inited;    PCHARP r; -  struct pike_string *ret,*tmp; -  int max_shift=0; +  struct pike_string *ret, *tmp; +  int max_shift = del->size_shift;       len=0;       for(e=0;e<a->size;e++)    {    if(ITEM(a)[e].type==T_STRING)    {    len+=ITEM(a)[e].u.string->len + del->len;    if(ITEM(a)[e].u.string->size_shift > max_shift)    max_shift=ITEM(a)[e].u.string->size_shift;    }    } -  if(del->size_shift > max_shift) max_shift=del->size_shift; +     if(len) len-=del->len;       ret=begin_wide_shared_string(len,max_shift);    r=MKPCHARP_STR(ret);    inited=0;    for(e=0;e<a->size;e++)    {    if(ITEM(a)[e].type==T_STRING)    {    if(inited)
pike.git/src/array.c:2234:    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 + /** Deeply copy an array. The mapping is used for temporary storage.    */   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:2269:    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 + /** Apply the elements of an array. Arguments the array should be +  * applied with should be on the stack before the call and the +  * resulting array will be on the stack after the call.    */   PMOD_EXPORT void apply_array(struct array *a, INT32 args)   {    INT32 e, hash = 0;    struct svalue *argp = Pike_sp-args;    struct array *aa;    struct array *cycl;    TYPE_FIELD new_types = 0;    DECLARE_CYCLIC();   
pike.git/src/array.c:2348:    return a;    }       ret=allocate_array_no_init(a->size,0);    for(e=0;e<a->size;e++)    assign_svalue_no_free(ITEM(ret)+e,ITEM(a)+a->size+~e);    ret->type_field = a->type_field;    return ret;   }    + /** Replaces all from elements in array a with to elements. Called +  * from replaces when first argument is an array. The replace is applied +  * desctructivly. +  */   void array_replace(struct array *a,    struct svalue *from,    struct svalue *to)   {    ptrdiff_t i = -1;       while((i=array_search(a,from,i+1)) >= 0) array_set_index(a,i,to);   }      #ifdef PIKE_DEBUG
pike.git/src/array.c:2630: Inside #if defined(PIKE_DEBUG)
   a == &weak_empty_array ? " (the weak_empty_array)" :    "");    fprintf(stderr,"Type field =");    debug_dump_type_field(a->type_field);    fprintf(stderr,"\n");    simple_describe_array(a);   }   #endif       + /** Returns (by argument) the number of arrays and the total amount of +  * memory allocated for arrays (array structs + svalues). Called from +  * _memory_usage, which is exposed through Debug.memory_usage(). +  */   void count_memory_in_arrays(INT32 *num_, INT32 *size_)   {    INT32 num=0, size=0;    struct array *m;    for(m=first_array;m;m=m->next)    {    num++;    size+=sizeof(struct array)+    sizeof(struct svalue) * (m->malloced_size - 1);    }    *num_=num;    *size_=size;   }    -  + /** Segments an array into several elements in an array based on the +  * sequence in the second array argument. This function is called +  * when an array is divided by another array. Pike level example, ({ +  * "hello", " ", "world", "!" }) / ({ " " }) -> ({ ({ "hello" }), ({ +  * "world", "!" }) }) +  */   PMOD_EXPORT struct array *explode_array(struct array *a, struct array *b)   {    INT32 e,d,start;    struct array *tmp;       start=0;   #if 0    if(!a->size)    {    return allocate_array_no_init(0,0);
pike.git/src/array.c:2693:    DO_AGGREGATE_ARRAY(120);    }    } END_AGGREGATE_ARRAY;    }    tmp=(--Pike_sp)->u.array;    debug_malloc_touch(tmp);    if(tmp->size) tmp->type_field=BIT_ARRAY;    return tmp;   }    + /** Joins array elements of an array into a new array with the +  * elements of the second array as joiners. Performs the opposite +  * action from explode_array and is called when an array is +  * multiplied by another array. +  */   PMOD_EXPORT struct array *implode_array(struct array *a, struct array *b)   {    INT32 e, size;    struct array *ret;       if (!a->size) {    add_ref(a);    return a;    }