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.194 2006/08/06 14:28:16 mast Exp $ + || $Id: array.c,v 1.195 2007/12/15 21:30:36 grubba 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:387:    * Insert an svalue into an array and grow the array if nessesary.    */   PMOD_EXPORT struct array *array_insert(struct array *v,struct svalue *s,INT32 index)   {   #ifdef PIKE_DEBUG    if(index<0 || index>v->size)    Pike_fatal("Illegal index in low level insert routine.\n");   #endif       /* Can we fit it into the existing block? */ -  if(v->refs<=1 && v->malloced_size > v->size) +  if(v->refs<=1 && (v->malloced_size > v->size))    { -  +  if ((v->item != v->real_item) && +  (((index<<1) < v->size) || +  ((v->item + v->size) == (v->real_item + v->malloced_size)))) { +  MEMMOVE((char *)(ITEM(v)-1), +  (char *)(ITEM(v)), +  index * sizeof(struct svalue)); +  v->item--; +  } else {    MEMMOVE((char *)(ITEM(v)+index+1),    (char *)(ITEM(v)+index),    (v->size-index) * sizeof(struct svalue)); -  +  }    ITEM(v)[index].type=T_INT;   #ifdef __CHECKER__    ITEM(v)[index].subtype=0;    ITEM(v)[index].u.refs=0;   #endif    v->size++;    }else{    struct array *ret;    -  ret = array_set_flags(allocate_array_no_init(v->size+1, v->size), +  ret = array_set_flags(allocate_array_no_init(v->size+1, v->size + 1),    v->flags);    ret->type_field = v->type_field;       MEMCPY(ITEM(ret), ITEM(v), sizeof(struct svalue) * index);    MEMCPY(ITEM(ret)+index+1, ITEM(v)+index, sizeof(struct svalue) * (v->size-index));    ITEM(ret)[index].type=T_INT;   #ifdef __CHECKER__    ITEM(ret)[index].subtype=0;    ITEM(ret)[index].u.refs=0;   #endif
pike.git/src/array.c:481: Inside #if defined(PIKE_DEBUG)
  {   #ifdef PIKE_DEBUG    if(d_flag > 1) array_check_type_field(a);   #endif       if(a->size == size) return a;    if(size > a->size)    {    /* We should grow the array */    -  if(a->malloced_size >= size) +  if((a->malloced_size >= size) && +  ((a->item + size) <= (a->real_item + a->malloced_size)))    {    for(;a->size < size; a->size++)    {    ITEM(a)[a->size].type=T_INT;    ITEM(a)[a->size].subtype=NUMBER_NUMBER;    ITEM(a)[a->size].u.integer=0;    }    a->type_field |= BIT_INT;    return a;    } else {    struct array *ret; -  ret = array_set_flags(low_allocate_array(size, (size>>1) + 4), -  a->flags); +  ret = array_set_flags(low_allocate_array(size, size + 1), a->flags);    MEMCPY(ITEM(ret), ITEM(a), sizeof(struct svalue)*a->size);    ret->type_field = DO_NOT_WARN((TYPE_FIELD)(a->type_field | BIT_INT));    a->size=0;    free_array(a);    return ret;    }    } else {    return array_shrink(a, size);    }   }
pike.git/src/array.c:1468:      /** 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; +  struct array *v2 = NULL;       for(size=e=0;e<args;e++)    size+=argp[e].u.array->size;      #if 1    {    INT32 tmp=0; -  +  INT32 tmp2 = size + 1; +  INT32 e2 = -1; +     for(e=0;e<args;e++)    {    v=argp[e].u.array;    if(v->refs == 1 && -  (v->item - v->real_item) >= tmp && -  v->malloced_size >= size - tmp) +  v->malloced_size >= size)    { -  +  if ((v->item - v->real_item) >= tmp) {    debug_malloc_touch(v);    argp[e].type=T_INT;    for(tmp=e-1;tmp>=0;tmp--)    {    debug_malloc_touch(argp[tmp].u.array);    v->type_field|=argp[tmp].u.array->type_field;    assign_svalues_no_free(ITEM(v) - argp[tmp].u.array->size,    ITEM(argp[tmp].u.array),    argp[tmp].u.array->size,    argp[tmp].u.array->type_field);    v->item-=argp[tmp].u.array->size; -  v->malloced_size+=argp[tmp].u.array->size; +  v->size+=argp[tmp].u.array->size;    }       for(tmp=e+1;tmp<args;tmp++)    {    debug_malloc_touch(argp[tmp].u.array);    v->type_field|=argp[tmp].u.array->type_field;    assign_svalues_no_free(ITEM(v) + v->size,    ITEM(argp[tmp].u.array),    argp[tmp].u.array->size,    argp[tmp].u.array->type_field);    v->size+=argp[tmp].u.array->size;    }   #ifdef PIKE_DEBUG    if(d_flag>1)    check_array(v);   #endif    return v;    } -  +  if (tmp - (v->item - v->real_item) < tmp2) { +  /* Got a potential candidate. */ +  tmp2 = tmp - (v->item - v->real_item); +  v2 = v; +  e2 = e; +  } +  }    tmp+=v->size;    } -  +  if (v2) { +  debug_malloc_touch(v2); +  argp[e2].type=T_INT; +  MEMMOVE((char *)(ITEM(v2)+tmp2), (char *)ITEM(v2), +  v2->size * sizeof(struct svalue)); +  v2->item += tmp2; +  for(tmp=e2-1;tmp>=0;tmp--) +  { +  debug_malloc_touch(argp[tmp].u.array); +  v2->type_field|=argp[tmp].u.array->type_field; +  assign_svalues_no_free(ITEM(v2) - argp[tmp].u.array->size, +  ITEM(argp[tmp].u.array), +  argp[tmp].u.array->size, +  argp[tmp].u.array->type_field); +  v2->item-=argp[tmp].u.array->size; +  v2->size+=argp[tmp].u.array->size;    } -  +  for(tmp=e2+1;tmp<args;tmp++) +  { +  debug_malloc_touch(argp[tmp].u.array); +  v2->type_field|=argp[tmp].u.array->type_field; +  assign_svalues_no_free(ITEM(v2) + v2->size, +  ITEM(argp[tmp].u.array), +  argp[tmp].u.array->size, +  argp[tmp].u.array->type_field); +  v2->size+=argp[tmp].u.array->size; +  } + #ifdef PIKE_DEBUG +  if(d_flag>1) +  check_array(v2);   #endif -  +  return v2; +  } +  } + #endif       if(args && argp[0].u.array->refs==1)    {    e=argp[0].u.array->size;    v=resize_array(argp[0].u.array, size);    argp[0].type=T_INT;    size=e;    e=1;    }else{    v=allocate_array_no_init(size, 0);
pike.git/src/array.c:1952:    if(array_is_constant(a,0))    {    debug_malloc_touch(a);    s.type=T_ARRAY;    s.subtype=0;    s.u.array=a;    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)); +  for(e = a->size; e--;) { +  if (ret) { +  ret = mknode(F_ARG_LIST, mksvaluenode(ITEM(a)+e), ret); +  } else { +  ret = mksvaluenode(ITEM(a)+e); +  } +  }    return mkefuncallnode("aggregate",ret);    }   }      /** 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);
pike.git/src/array.c:2384: Inside #if defined(PIKE_DEBUG)
      if(a->size > a->malloced_size)    Pike_fatal("Array is larger than malloced block!\n");       if(a->size < 0)    Pike_fatal("Array size is negative!\n");       if(a->malloced_size < 0)    Pike_fatal("Array malloced size is negative!\n");    +  if((a->item + a->size) > (a->real_item + a->malloced_size)) +  Pike_fatal("Array uses memory outside of the malloced block!\n"); +     if(a->item < a->real_item)    {   #ifdef DEBUG_MALLOC    describe(a);   #endif    Pike_fatal("Array item pointer is too small!\n");    }       if(a->refs <=0 )    Pike_fatal("Array has zero refs.\n");