pike.git / src / array.c

version» Context lines:

pike.git/src/array.c:9:   #include "object.h"   #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"      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 */
pike.git/src/array.c:39:   struct array *allocate_array_no_init(INT32 size,INT32 extra_space)   {    struct array *v;       if(size == 0)    {    empty_array.refs++;    return &empty_array;    }    +  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->malloced_size=size+extra_space;    v->size=size;    v->flags=0;    v->refs=1;    v->prev=&empty_array;    v->next=empty_array.next;    empty_array.next=v;
pike.git/src/array.c:87:   {    struct array *next,*prev;       next = v->next;    prev = v->prev;       v->prev->next=next;    v->next->prev=prev;       free((char *)v); +  +  GC_FREE();   }      /*    * Free an array, call this when the array has zero references    */   void really_free_array(struct array *v)   {      #ifdef DEBUG    if(v == & empty_array)
pike.git/src/array.c:1238:      void array_replace(struct array *a,    struct svalue *from,    struct svalue *to)   {    INT32 i = -1;       while((i=array_search(a,from,i+1)) >= 0) array_set_index(a,i,to);   }    - #ifdef GC -  - void array_gc_clear_mark() + #ifdef DEBUG + void check_array(struct array *a)   { -  struct array *a; -  a=&empty_array; -  do -  { -  a->flags &=~ ARRAY_FLAG_MARK; -  check_array(a, pass); +  INT32 e;    -  a=a->next; +  if(a->next->prev != a) +  fatal("Array check: a->next->prev != a\n");    - #ifdef DEBUG -  if(!a) fatal("Null pointer in array list.\n"); - #endif -  } while (a != & empty_array); - } +  if(a->size > a->malloced_size) +  fatal("Array is larger than malloced block!\n");    - void array_gc_mark(struct array *a) +  if(a->refs <=0 ) +  fatal("Array has zero refs.\n"); +  +  for(e=0;e<a->size;e++)    { -  INT32 e; -  if(a->flags & ARRAY_FLAG_MARK) return; -  a->flags |= ARRAY_FLAG_MARK; +  if(! ( (1 << ITEM(a)[e].type) & (a->type_field) )) +  fatal("Type field lies.\n");    -  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); +  check_svalue(ITEM(a)+e);    } -  + }    - void array_gc_sweep() + void check_all_arrays()   { -  struct array *a, *next; +  struct array *a;       a=&empty_array;    do    { -  a->refs++; +  check_array(a);    -  if(!(a->flags & ARRAY_FLAG_MARK)) -  { -  free_svalues(ITEM(a), a->size, a->type_field); -  a->size=0; /* Don't free them again */ +  a=a->next; +  if(!a) +  fatal("Null pointer in array list.\n"); +  } while (a != & empty_array);   } -  + #endif /* DEBUG */    -  next=a->next; -  free_array(a); + #ifdef GC2    -  a=next; - #ifdef DEBUG -  if(!a) fatal("Null pointer in array list.\n"); - #endif -  } while (a != & empty_array); + void gc_check_array(struct array *a) + { +  if(a == gc_ptr) gc_refs++; +  if(a->flags & GC_MARK) return; +  a->flags |= GC_MARK; +  if(!(a->type_field & BIT_COMPLEX)) return; +  gc_check_svalues(ITEM(a), a->size);   }       - #ifdef DEBUG - void array_gc_sweep2() + void gc_check_all_arrays()   { -  struct array *a; -  if(!d_flag) return; +  struct array *a,*n;       a=&empty_array;    do    { -  if(!(a->flags & ARRAY_FLAG_MARK)) -  fatal("Array ref count incorrect!\n"); +  if(!(a->flags & GC_MARK) && a->type_field & BIT_COMPLEX) +  { +  gc_ptr=a; +  gc_refs=0;    -  a=a->next +  gc_check_array(a);    - #ifdef DEBUG -  if(!a) fatal("Null pointer in array list.\n"); - #endif -  } while (a != & empty_array); - } - #endif /* DEBUG */ - #endif /* GC */ +  a->refs++;    -  - #ifdef DEBUG - void check_array(struct array *a, int pass) +  if(gc_refs == a->refs)    { -  INT32 e; -  if(pass) -  { -  e=checked((void *)a,0); -  if(e!=a->refs) -  { -  simple_describe_array(a); -  fatal("Above array has wrong number of references. (%ld != %ld)\n", -  (long)e,(long)a->refs); -  } -  return; -  } +  /* This structure contains as many references to itself as +  * it has referenes, which means that it is circular and +  * should be destroyed, so please go away. +  */    -  if(a->next->prev != a) -  fatal("Array check: a->next->prev != a\n"); +  free_svalues(ITEM(a), a->size, a->type_field);    -  if(a->size > a->malloced_size) -  fatal("Array is larger than malloced block!\n"); +  a->size=0;    -  if(a->refs <=0 ) -  fatal("Array has zero refs.\n"); +  }    -  for(e=0;e<a->size;e++) -  { -  if(! ( (1 << ITEM(a)[e].type) & (a->type_field) )) -  fatal("Type field lies.\n"); +  if(!(n=a->next)) +  fatal("Null pointer in array list.\n");    -  check_svalue(ITEM(a)+e); +  free_array(a); +  a=n; +  }else{ +  a=a->next;    } -  +  } while (a != & empty_array);   }    - void check_all_arrays(int pass) + void gc_clear_array_marks()   {    struct array *a;       a=&empty_array;    do    { -  check_array(a, pass); -  +  a->flags &=~ GC_MARK;    a=a->next; -  if(!a) -  fatal("Null pointer in array list.\n"); -  } while (a != & empty_array); +     -  if(!pass) -  { -  checked((void *)&empty_array,1); +  } while (a != & empty_array);   } - } - #endif /* DEBUG */ +     -  +  +  + #endif /* GC2 */ +