pike.git / src / mapping.c

version» Context lines:

pike.git/src/mapping.c:7:   #include "types.h"   #include "mapping.h"   #include "svalue.h"   #include "array.h"   #include "macros.h"   #include "language.h"   #include "error.h"   #include "memory.h"   #include "dynamic_buffer.h"   #include "interpret.h" + #include "gc.h"      struct mapping *first_mapping;      /*    * This function puts looks up an index in a mapping and assigns    * the value to dest. It does not free dest first though    */   void mapping_index_no_free(struct svalue *dest,    struct mapping *m,    struct svalue *ind)
pike.git/src/mapping.c:60: Inside #if 0
   free_mapping(m);   }   #endif      /*    * allocate and init a new mapping    */   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;    m->refs = 1;    m->ind=ind;    m->val=val;    if(first_mapping) first_mapping->prev = m;    first_mapping=m;       return m;
pike.git/src/mapping.c:90:   #endif       free_array(m->ind);    free_array(m->val);       if(m->prev) m->prev->next = m->next;    if(m->next) m->next->prev = m->prev;    if(first_mapping == m) first_mapping = 0;       free((char *)m); +  +  GC_FREE();   }      static void order_mapping(struct mapping *m)   {    INT32 *order;    order = get_set_order(m->ind);    if(!order) return;    m->ind = order_array(m->ind, order);    m->val = order_array(m->val, order);    free((char *)order);
pike.git/src/mapping.c:362:    for(;p;p=p->next)    {    if(p->pointer_a == (void *)m)    {    ret=(struct mapping *)p->pointer_b;    ret->refs++;    return ret;    }    }    -  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);    ret->val=copy_array_recursively(m->val,&doing);       order_mapping(ret);       return ret;   }   
pike.git/src/mapping.c:429: Inside #if defined(DEBUG)
   }   }      void check_all_mappings()   {    struct mapping *m;    for(m=first_mapping;m;m=m->next)    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 */