pike.git / src / array.c

version» Context lines:

pike.git/src/array.c:33:      /* Allocate an array, this might be changed in the future to    * allocate linked lists or something    * NOTE: the new array have zero references    */      struct array *allocate_array_no_init(INT32 size,INT32 extra_space)   {    struct array *v;    -  if(size == 0 && type == T_MIXED) +  if(size == 0)    {    empty_array.refs++;    return &empty_array;    }       v=(struct array *)malloc(sizeof(struct array)+    (size+extra_space-1)*sizeof(struct svalue));    if(!v)    error("Couldn't allocate array, out of memory.\n");   
pike.git/src/array.c:302:    {    a=allocate_array_no_init(size,0);    a->type_field = v->type_field;       free_svalues(ITEM(v) + size, v->size - size, v->type_field);    MEMCPY(ITEM(a), ITEM(v), size*sizeof(struct svalue));    v->size=0;    free_array(v);    return a;    }else{ -  free_svalues(ITEM(v) + size, v->size - size); +  free_svalues(ITEM(v) + size, v->size - size, v->type_field);    v->size=size;    return v;    }   }      /*    * Remove an index from an array and shrink the array    */   struct array *array_remove(struct array *v,INT32 index)   {
pike.git/src/array.c:479:    (ITEM(v)[e].type == T_FUNCTION && ITEM(v)[e].subtype!=-1)) &&    (!ITEM(v)[e].u.object->prog))    return e;    types |= 1<<ITEM(v)[e].type;    }    v->type_field = types;    }    return -1;   }    -  - static short_cmpfun current_short_cmpfun; - static union anything *current_short_array_p; -  - static int internal_short_cmpfun(INT32 *a,INT32 *b) - { -  return current_short_cmpfun(current_short_array_p + *a, -  current_short_array_p + *b); - } -  +    static struct svalue *current_array_p;   static cmpfun current_cmpfun;      static int internal_cmpfun(INT32 *a,INT32 *b)   {    return current_cmpfun(current_array_p + *a, current_array_p + *b);   }      INT32 *get_order(struct array *v, cmpfun fun)   {
pike.git/src/array.c:610:    else    return c;    }    if(a<v->size && fun(ITEM(v)+a,s)<0) a++;    return ~a;   }      INT32 set_lookup(struct array *a, struct svalue *s)   {    /* face it, it's not there */ -  if( (((2 << s->type) -1) & s->type_field) == 0) +  if( (((2 << s->type) -1) & a->type_field) == 0)    return -1;       /* face it, it's not there */ -  if( ((BIT_MIXED << s->type) & BIT_MIXED & s->type_field) == 0) -  return ~v->size; +  if( ((BIT_MIXED << s->type) & BIT_MIXED & a->type_field) == 0) +  return ~a->size;       return low_lookup(a,s,set_svalue_cmpfun);   }      INT32 switch_lookup(struct array *a, struct svalue *s)   {    /* face it, it's not there */ -  if( (((2 << s->type) -1) & s->type_field) == 0) +  if( (((2 << s->type) -1) & a->type_field) == 0)    return -1;       /* face it, it's not there */ -  if( ((BIT_MIXED << s->type) & BIT_MIXED & s->type_field) == 0) -  return ~v->size; +  if( ((BIT_MIXED << s->type) & BIT_MIXED & a->type_field) == 0) +  return ~a->size;       return low_lookup(a,s,switch_svalue_cmpfun);   }         /*    * reorganize an array in the order specifyed by 'order'    */   struct array *order_array(struct array *v, INT32 *order)   {
pike.git/src/array.c:778:    * This routine merges two arrays in the order specified by 'zipper'    * zipper normally produced by merge() above    */   struct array *array_zip(struct array *a, struct array *b,INT32 *zipper)   {    INT32 size,e;    struct array *ret;    size=zipper[0];    zipper++;    -  ret=allocate_array_no_init(size,0, T_MIXED); +  ret=allocate_array_no_init(size,0);    for(e=0; e<size; e++)    {    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;   }      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(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);    v->type_field=0;
pike.git/src/array.c:964:    }   }      /* and two arrays */   struct array *and_arrays(struct array *a, struct array *b)   {    if(a->type_field & b->type_field)    {    return merge_array_without_order(a, b, OP_AND);    }else{ -  return allocate_array_no_init(0,0,T_MIXED); +  return allocate_array_no_init(0,0);    }   }      int check_that_array_is_constant(struct array *a)   {    array_fix_type_field(a);    if(a->type_field & ((1 << T_FUNCTION) | (1 << T_OBJECT)))    return 0;    return 1;   }      node *make_node_from_array(struct array *a)   {    struct svalue s; -  char *str; +     INT32 e;       array_fix_type_field(a);    if(a->type_field == (1 << T_INT))    {    for(e=0; e<a->size; e++)    if(ITEM(a)[e].u.integer != 0)    break;    if(e == a->size)    {
pike.git/src/array.c:1024:    error("Array does not fit on stack.\n");    check_array_for_destruct(a);    if(a->refs == 1)    {    MEMCPY(sp,ITEM(a),sizeof(struct svalue)*a->size);    sp += a->size;    a->size=0;    free_array(a);    return;    }else{ -  assign_svalues_no_free(sp, ITEM(a), a->size); +  assign_svalues_no_free(sp, ITEM(a), a->size, a->type_field);    }    sp += a->size;    free_array(a);   }      void describe_array_low(struct array *a, struct processing *p, int indent)   {    INT32 e,d;    indent += 2;   
pike.git/src/array.c:1113:      struct array *explode(struct lpc_string *str,    struct lpc_string *del)   {    INT32 e,d;    struct array *ret;    char *s, *end, *tmp;       if(!del->len)    { -  ret=allocate_array_no_init(str->len,0,T_STRING); +  ret=allocate_array_no_init(str->len,0);    ret->type_field |= 1<<T_STRING;    for(e=0;e<str->len;e++) -  SHORT_ITEM(ret)[e].string=make_shared_binary_string(str->str+e,1); +  { +  ITEM(ret)[e].type=T_STRING; +  ITEM(ret)[e].u.string=make_shared_binary_string(str->str+e,1); +  }    }else{       s=str->str;    end=s+str->len;    e=0;       while((s=MEMMEM(del->str, del->len, s, end-s)))    {    s+=del->len;    e++;    }    -  ret=allocate_array_no_init(e+1,0,T_STRING); +  ret=allocate_array_no_init(e+1,0);    ret->type_field |= 1<<T_STRING;       s=str->str;    for(d=0;d<e;d++)    {    tmp=MEMMEM((char *)(del->str), del->len, (char *)s, end-s); -  SHORT_ITEM(ret)[d].string=make_shared_binary_string(s,tmp-s); +  ITEM(ret)[d].type=T_STRING; +  ITEM(ret)[d].u.string=make_shared_binary_string(s,tmp-s);    s=tmp+del->len;    } -  SHORT_ITEM(ret)[d].string=make_shared_binary_string(s,end-s); +  ITEM(ret)[d].type=T_STRING; +  ITEM(ret)[d].u.string=make_shared_binary_string(s,end-s);    }    return ret;   }      struct lpc_string *implode(struct array *a,struct lpc_string *del)   {    INT32 len,e, inited;    char *r;    struct lpc_string *ret,*tmp;   
pike.git/src/array.c:1211:   }      void apply_array(struct array *a, INT32 args)   {    struct svalue *argp;    INT32 e;    struct array *ret;    argp=sp-args;    for(e=0;e<a->size;e++)    { -  assign_svalues_no_free(sp,argp,args); +  assign_svalues_no_free(sp,argp,args,BIT_MIXED);    sp+=args;    apply_svalue(ITEM(a)+e,args);    } -  ret=aggregate_array(a->size,T_MIXED); +  ret=aggregate_array(a->size);    pop_n_elems(args);    push_array(ret);   }      struct array *reverse_array(struct array *a)   {    INT32 e;    struct array *ret;       /* FIXME: Check refs so we might optimize */
pike.git/src/array.c:1260: Inside #if defined(GC)
   check_array(a, pass);       a=a->next;      #ifdef DEBUG    if(!a) fatal("Null pointer in array list.\n");   #endif    } while (a != & empty_array);   }    - void array_gc_mark(array *a) + void array_gc_mark(struct array *a)   {    INT e;    if(a->flags & ARRAY_FLAG_MARK) return;    a->flags |= ARRAY_FLAG_MARK;       if(!(a->type_field & ~(BIT_STRING|BIT_INT|BIT_FLOAT)))    return 0;       for(e=0;e<a->size;e++) svalue_gc_sweep(ITEM(a) + e);   }