Branch: Tag:

2000-09-30

2000-09-30 15:58:30 by Martin Stjernholm <mast@lysator.liu.se>

We shouldn't do any weak ref freeing for internal objects (i.e. in the
cycle check pass). Also added a bit more gc debug.

Rev: src/array.c:1.89
Rev: src/mapping.c:1.108

23:   #include "stuff.h"   #include "bignum.h"    - RCSID("$Id: array.c,v 1.88 2000/09/17 19:53:52 grubba Exp $"); + RCSID("$Id: array.c,v 1.89 2000/09/30 15:58:30 mast Exp $");      PMOD_EXPORT struct array empty_array=   {
1793:   {    if(a->type_field & BIT_COMPLEX)    { -  if (a->flags & ARRAY_WEAK_FLAG) +  if (a->flags & ARRAY_WEAK_FLAG) {    debug_gc_check_weak_svalues(ITEM(a), a->size, T_ARRAY, a); -  +  gc_checked_as_weak(a); +  }    else    debug_gc_check_svalues(ITEM(a), a->size, T_ARRAY, a);    }
1859:       if (a->type_field & BIT_COMPLEX)    { -  if (a->flags & ARRAY_WEAK_FLAG) -  gc_recurse_weak_array(a, gc_mark_weak_svalues); +  if (a->flags & ARRAY_WEAK_FLAG) { +  int e; +  TYPE_FIELD t; +  +  if(a->flags & ARRAY_WEAK_SHRINK) { +  int d=0; + #ifdef PIKE_DEBUG +  if (a->refs != 1) +  fatal("Got %d refs to weak shrink array " +  "which we'd like to change the size on.\n", a->refs); + #endif +  t = 0; +  for(e=0;e<a->size;e++) +  if (!gc_mark_weak_svalues(a->item+e, 1)) { +  a->item[d++]=a->item[e]; +  t |= 1 << a->item[e].type; +  } +  a->size=d; +  } +  else +  if (!(t = gc_mark_weak_svalues(a->item, a->size))) +  t = a->type_field; +  +  /* Ugly, but we are not allowed to change type_field +  * at the same time as the array is being built... +  * Actually we just need better primitives for building arrays. +  */ +  if(!(a->type_field & BIT_UNFINISHED) || a->refs!=1) +  a->type_field = t; +  else +  a->type_field |= t; +  +  gc_assert_checked_as_weak(a); +  }    else {    TYPE_FIELD t;    if ((t = gc_mark_svalues(ITEM(a), a->size))) {
1869:    else    a->type_field |= t;    } +  gc_assert_checked_as_nonweak(a);    }    }    }
1884:       if (a->type_field & BIT_COMPLEX)    { -  if (a->flags & ARRAY_WEAK_FLAG) -  gc_recurse_weak_array(a, gc_cycle_check_weak_svalues); +  if (a->flags & ARRAY_WEAK_FLAG) { +  if (gc_cycle_check_weak_svalues(ITEM(a), a->size)) { + #ifdef PIKE_DEBUG +  fatal("Didn't expect an svalue zapping now.\n"); + #endif +  } +  gc_assert_checked_as_weak(a); +  }    else {    TYPE_FIELD t;    if ((t = gc_cycle_check_svalues(ITEM(a), a->size))) {
1894:    else    a->type_field |= t;    } +  gc_assert_checked_as_nonweak(a);    }    }    } GC_CYCLE_LEAVE;
2008: Inside #if defined(PIKE_DEBUG)
     void debug_dump_array(struct array *a)   { -  fprintf(stderr,"Location=%p Refs=%d, next=%p, prev=%p, size=%d, malloced_size=%d\n", +  fprintf(stderr,"Location=%p Refs=%d, next=%p, prev=%p, " +  "flags=0x%x, size=%d, malloced_size=%d%s\n",    a,    a->refs,    a->next,    a->prev, -  +  a->flags,    a->size, -  a->malloced_size); +  a->malloced_size, +  a == &empty_array ? " (the empty_array)" : "");    fprintf(stderr,"Type field = ");    debug_dump_type_field(a->type_field);    fprintf(stderr,"\n");