pike.git / src / array.c

version» Context lines:

pike.git/src/array.c:10:   #include "las.h"   #include "stralloc.h"   #include "interpret.h"   #include "language.h"   #include "error.h"   #include "lpc_types.h"   #include "fsort.h"   #include "builtin_efuns.h"   #include "memory.h"   #include "gc.h" + #include "main.h"      struct array empty_array=   {    1, /* Never free */    &empty_array, /* Next */    &empty_array, /* previous (circular) */    0, /* Size = 0 */    0, /* malloced Size = 0 */    0, /* no types */ -  T_MIXED, /* mixed array */ +    };            /* 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 *low_allocate_array(INT32 size,INT32 extra_space)
pike.git/src/array.c:49:       GC_ALLOC();       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");          /* for now, we don't know what will go in here */ -  v->type_field=BIT_MIXED; +  v->type_field=BIT_MIXED | BIT_UNFINISHED;       v->malloced_size=size+extra_space;    v->size=size;    v->refs=1;    v->prev=&empty_array;    v->next=empty_array.next;    empty_array.next=v;    v->next->prev=v;       for(e=0;e<v->size;e++)
pike.git/src/array.c:178:   void array_set_index(struct array *v,INT32 index, struct svalue *s)   {   #ifdef DEBUG    if(index<0 || index>v->size)    fatal("Illegal index in low level array set routine.\n");   #endif       v->refs++;    check_destructed(s);    -  v->type_field |= 1 << s->type; +  v->type_field = (v->type_field & ~BIT_UNFINISHED) | 1 << s->type;    assign_svalue( ITEM(v) + index, s);    free_array(v);   }         void simple_set_index(struct array *a,struct svalue *ind,struct svalue *s)   {    INT32 i;    if(ind->type != T_INT)    error("Index is not an integer.\n");
pike.git/src/array.c:257:    {    /* We should grow the array */    if(a->malloced_size >= 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=allocate_array_no_init(size, (size>>3)+1);    MEMCPY(ITEM(ret),ITEM(a),sizeof(struct svalue)*a->size); -  +  ret->type_field = a->type_field | BIT_INT;    a->size=0;    free_array(a);    return ret;    }    }else{    /* We should shrink the array */    free_svalues(ITEM(a)+size, a->size - size, a->type_field);    a->size = size;    return a;    }
pike.git/src/array.c:364:   {    INT32 e;   #ifdef DEBUG    if(start<0)    fatal("Start of find_index is less than zero.\n");   #endif       check_destructed(s);       /* Why search for something that is not there? */ + #ifdef DEBUG +  if(d_flag > 1) array_check_type_field(v); + #endif +     if(v->type_field & (1 << s->type))    {    TYPE_FIELD t=0;    for(e=start;e<v->size;e++)    {    if(is_eq(ITEM(v)+e,s)) return e;    t |= 1<<ITEM(v)[e].type;    }    v->type_field=t;    return -1;
pike.git/src/array.c:430:      /*    * Clean an array from destructed objects    */   void check_array_for_destruct(struct array *v)   {    int e;    INT16 types;       types = 0; + #ifdef DEBUG +  if(d_flag > 1) array_check_type_field(v); + #endif    if(v->type_field & (BIT_OBJECT | BIT_FUNCTION))    {    for(e=0; e<v->size; e++)    {    if((ITEM(v)[e].type == T_OBJECT ||    (ITEM(v)[e].type == T_FUNCTION && ITEM(v)[e].subtype!=-1)) &&    (!ITEM(v)[e].u.object->prog))    {    free_svalue(ITEM(v)+e);    ITEM(v)[e].type=T_INT;
pike.git/src/array.c:461:      /*    * This function finds the index of any destructed object in a set    * it could be optimized to search out the object part with a binary    * search lookup if the array is mixed    */   INT32 array_find_destructed_object(struct array *v)   {    INT32 e;    TYPE_FIELD types; + #ifdef DEBUG +  if(d_flag > 1) array_check_type_field(v); + #endif    if(v->type_field & (BIT_OBJECT | BIT_FUNCTION))    {    types=0;    for(e=0; e<v->size; e++)    {    if((ITEM(v)[e].type == T_OBJECT ||    (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;
pike.git/src/array.c:597:    b=c;    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)   { + #ifdef DEBUG +  if(d_flag > 1) array_check_type_field(a); + #endif    /* face it, it's not there */    if( (((2 << s->type) -1) & a->type_field) == 0)    return -1;       /* face it, it's not there */    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 */ -  + #ifdef DEBUG +  if(d_flag > 1) array_check_type_field(a); + #endif    if( (((2 << s->type) -1) & a->type_field) == 0)    return -1;       /* face it, it's not there */    if( ((BIT_MIXED << s->type) & BIT_MIXED & a->type_field) == 0)    return ~a->size;       return low_lookup(a,s,switch_svalue_cmpfun);   }   
pike.git/src/array.c:665:       for(e=0; e<v->size; e++) t |= 1 << ITEM(v)[e].type;      #ifdef DEBUG    if(t & ~(v->type_field))    fatal("Type field out of order!\n");   #endif    v->type_field = t;   }    + #ifdef DEBUG + /* Maybe I should have a 'clean' flag for this computation */ + void array_check_type_field(struct array *v) + { +  int e; +  TYPE_FIELD t; +  +  t=0; +  +  for(e=0; e<v->size; e++) t |= 1 << ITEM(v)[e].type; +  +  if(t & ~(v->type_field)) +  fatal("Type field out of order!\n"); + } + #endif +    struct array *compact_array(struct array *v) { return v; }      /*    * Get a pointer to the 'union anything' specified IF it is of the specified    * type. The 'union anything' may be changed, but not the type.    */   union anything *low_array_get_item_ptr(struct array *a,    INT32 ind,    TYPE_T t)   {
pike.git/src/array.c:710:    * to maintain the order.    * the first item in this array is the size of the result    * the rest is n >= 0 for a[ n ]    * or n < 0 for b[ ~n ]    */   INT32 * merge(struct array *a,struct array *b,INT32 opcode)   {    INT32 ap,bp,i,*ret,*ptr;       ap=bp=0; + #ifdef DEBUG +  if(d_flag > 1) +  { +  array_check_type_field(a); +  array_check_type_field(b); +  } + #endif    if(!(a->type_field & b->type_field))    {    /* do smart optimizations */    switch(opcode)    {    case OP_AND:    ret=(INT32 *)xalloc(sizeof(INT32));    *ret=0;    return ret;   
pike.git/src/array.c:822:      int array_equal_p(struct array *a, struct array *b, struct processing *p)   {    struct processing curr;    INT32 e;       if(a == b) return 1;    if(a->size != b->size) return 0;    if(!a->size) return 1;    + #ifdef DEBUG +  if(d_flag > 1) +  { +  array_check_type_field(a); +  array_check_type_field(b); +  } + #endif +     /* This could be done much better if I KNEW that    * the type fields didn't contain types that    * really aren't in the array    */    if(!(a->type_field & b->type_field)) return 0;       curr.pointer_a = a;    curr.pointer_b = b;    curr.next = p;   
pike.git/src/array.c:935:    ret=array_zip(tmpa,tmpb,zipper);    free_array(tmpa);    free_array(tmpb);    free((char *)zipper);    return ret;   }      /* subtract an array from another */   struct array *subtract_arrays(struct array *a, struct array *b)   { + #ifdef DEBUG +  if(d_flag > 1) +  { +  array_check_type_field(a); +  array_check_type_field(b); +  } + #endif +     if(a->type_field & b->type_field)    {    return merge_array_with_order(a, b, OP_SUB);    }else{    if(a->refs == 1)    {    a->refs++;    return a;    }    return slice_array(a,0,a->size);    }   }      /* and two arrays */   struct array *and_arrays(struct array *a, struct array *b)   { -  + #ifdef DEBUG +  if(d_flag > 1) +  { +  array_check_type_field(a); +  array_check_type_field(b); +  } + #endif +     if(a->type_field & b->type_field)    {    return merge_array_without_order(a, b, OP_AND);    }else{    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))) +  if(a->type_field & (BIT_FUNCTION | BIT_OBJECT))    return 0;    return 1;   }      node *make_node_from_array(struct array *a)   {    struct svalue s;    INT32 e;       array_fix_type_field(a); -  if(a->type_field == (1 << T_INT)) +  if(a->type_field == BIT_INT)    {    for(e=0; e<a->size; e++)    if(ITEM(a)[e].u.integer != 0)    break;    if(e == a->size)    {    return mkefuncallnode("allocate",    mknode(F_ARG_LIST,    mkintnode(a->size),    mkstrnode(make_shared_string("mixed"))
pike.git/src/array.c:1104:   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); -  ret->type_field |= 1<<T_STRING; +  ret->type_field |= BIT_STRING;    for(e=0;e<str->len;e++)    {    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); -  ret->type_field |= 1<<T_STRING; +  ret->type_field |= BIT_STRING;       s=str->str;    for(d=0;d<e;d++)    {    tmp=MEMMEM((char *)(del->str), del->len, (char *)s, end-s);    ITEM(ret)[d].type=T_STRING;    ITEM(ret)[d].u.string=make_shared_binary_string(s,tmp-s);    s=tmp+del->len;    }    ITEM(ret)[d].type=T_STRING;
pike.git/src/array.c:1290: Inside #if defined(GC2)
   if(a->type_field & BIT_COMPLEX)    gc_mark_svalues(ITEM(a), a->size);   }      void gc_check_all_arrays()   {    struct array *a;    a=&empty_array;    do    { + #ifdef DEBUG +  if(d_flag > 1) array_check_type_field(a); + #endif    if(a->type_field & BIT_COMPLEX) -  a->type_field = gc_check_svalues(ITEM(a), a->size); +  { +  TYPE_FIELD t; +  t=gc_check_svalues(ITEM(a), a->size);    -  +  /* Ugly, but we are not allowed to change type_field +  * at the same time as the array is being built... +  */ +  if(!(a->type_field & BIT_UNFINISHED) || a->refs!=1) +  a->type_field = t; +  } +     a=a->next;    } while (a != & empty_array);   }         void gc_mark_all_arrays()   {    struct array *a;       a=&empty_array;