Branch: Tag:

1996-03-28

1996-03-28 21:33:36 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

garbage collect rewritten

Rev: src/array.c:1.9
Rev: src/array.h:1.6
Rev: src/gc.c:1.2
Rev: src/gc.h:1.2
Rev: src/list.c:1.3
Rev: src/list.h:1.2
Rev: src/mapping.c:1.4
Rev: src/mapping.h:1.3
Rev: src/object.c:1.8
Rev: src/object.h:1.5
Rev: src/program.c:1.8
Rev: src/program.h:1.4
Rev: src/svalue.c:1.8

14:   #include "memory.h"   #include "dynamic_buffer.h"   #include "interpret.h" + #include "gc.h"      struct mapping *first_mapping;   
67:   static struct mapping *allocate_mapping(struct array *ind, struct array *val)   {    struct mapping *m; +  GC_ALLOC();    m=ALLOC_STRUCT(mapping);    m->next = first_mapping;    m->prev = 0;
97:    if(first_mapping == m) first_mapping = 0;       free((char *)m); +  +  GC_FREE();   }      static void order_mapping(struct mapping *m)
369:    }    }    -  ret=allocate_mapping(0,0); +  ret=allocate_mapping(&empty_array, &empty_array);    doing.pointer_b=(void *)ret;       ret->ind=copy_array_recursively(m->ind,&doing);
436: Inside #if defined(DEBUG)
   check_mapping(m);   }   #endif +  +  + #ifdef GC2 +  + void gc_mark_mapping_as_referenced(struct mapping *m) + { +  if(gc_mark(m)) +  { +  gc_mark_array_as_referenced(m->ind); +  gc_mark_array_as_referenced(m->val); +  } + } +  + void gc_check_all_mappings() + { +  struct mapping *m; +  for(m=first_mapping;m;m=m->next) +  { +  gc_check(m->ind); +  gc_check(m->val); +  } + } +  + void gc_mark_all_mappings() + { +  struct mapping *m; +  for(m=first_mapping;m;m=m->next) +  if(gc_is_referenced(m)) +  gc_mark_mapping_as_referenced(m); + } +  + void gc_free_all_unreferenced_mappings() + { +  struct mapping *m,*next; +  +  for(m=first_mapping;m;m=next) +  { +  if(gc_do_free(m)) +  { +  m->refs++; +  free_svalues(ITEM(m->ind), m->ind->size, m->ind->type_field); +  free_svalues(ITEM(m->val), m->val->size, m->val->type_field); +  m->ind->size=0; +  m->val->size=0; +  next=m->next; +  +  free_mapping(m); +  }else{ +  next=m->next; +  } +  } + } +  + #endif /* GC2 */