pike.git / src / mapping.c

version» Context lines:

pike.git/src/mapping.c:1:   /*\   ||| This file a part of Pike, and is copyright by Fredrik Hubinette   ||| Pike is distributed as GPL (General Public License)   ||| See the files COPYING and DISCLAIMER for more information.   \*/   #include "global.h" - RCSID("$Id: mapping.c,v 1.38 1999/01/21 09:15:05 hubbe Exp $"); + RCSID("$Id: mapping.c,v 1.39 1999/02/05 01:03:53 hubbe Exp $");   #include "main.h"   #include "object.h"   #include "mapping.h"   #include "svalue.h"   #include "array.h"   #include "pike_macros.h"   #include "language.h"   #include "error.h"   #include "pike_memory.h"   #include "dynamic_buffer.h"
pike.git/src/mapping.c:69:    if(size < 0) fatal("init_mapping with negative value.\n");   #endif    if(size)    {    hashsize=size / AVG_LINK_LENGTH + 1;    if(!(hashsize & 1)) hashsize++;    hashspace=hashsize+1;    e=sizeof(struct keypair)*size+ sizeof(struct keypair *)*hashspace;    tmp=(char *)xalloc(e);    +  m->flags=0;    m->hash=(struct keypair **) tmp;    m->hashsize=hashsize;       tmp+=sizeof(struct keypair *)*hashspace;       MEMSET((char *)m->hash, 0, sizeof(struct keypair *) * m->hashsize);       m->free_list=(struct keypair *) tmp;    for(e=1;e<size;e++)    m->free_list[e-1].next = m->free_list + e;
pike.git/src/mapping.c:860:    for(;p;p=p->next)    {    if(p->pointer_a == (void *)m)    {    add_ref(ret=(struct mapping *)p->pointer_b);    return ret;    }    }       ret=allocate_mapping(MAP_SLOTS(m->size)); +  ret->flags=m->flags;    doing.pointer_b=ret;       check_stack(2);       MAPPING_LOOP(m)    {    copy_svalues_recursively_no_free(sp,&k->ind, 1, p);    sp++;    copy_svalues_recursively_no_free(sp,&k->val, 1, p);    sp++;
pike.git/src/mapping.c:999: Inside #if defined(PIKE_DEBUG)
   check_mapping(m);   }   #endif         void gc_mark_mapping_as_referenced(struct mapping *m)   {    INT32 e;    struct keypair *k;    -  if(gc_mark(m)) +  if(gc_mark(m) && !( m->flags & MAPPING_FLAG_WEAK))    {    if((m->ind_types | m->val_types) & BIT_COMPLEX)    {    MAPPING_LOOP(m)    {    /* We do not want to count this key:index pair if    * the index is a destructed object or function    */    if(((1 << k->ind.type) & (BIT_OBJECT | BIT_FUNCTION)) &&    !(k->ind.u.object->prog))
pike.git/src/mapping.c:1061:   {    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(void)   {    INT32 e; -  struct keypair *k; +  struct keypair *k,**prev;    struct mapping *m,*next;       for(m=first_mapping;m;m=next)    {    check_mapping_for_destruct(m);    if(gc_do_free(m))    {    add_ref(m);       for(e=0;e<m->hashsize;e++)
pike.git/src/mapping.c:1095:    m->hash[e]=0;    break;    }    }    }    m->size=0;       next=m->next;       free_mapping(m); +  } +  else if(m->flags & MAPPING_FLAG_WEAK) +  { +  add_ref(m); +  for(e=0;e<m->hashsize;e++) +  { +  for(prev= m->hash + e;(k=*prev);) +  { +  if((k->val.type <= MAX_COMPLEX && gc_do_free(k->val.u.refs)) || +  (k->ind.type <= MAX_COMPLEX && gc_do_free(k->ind.u.refs))) +  { +  *prev=k->next; +  free_svalue(& k->ind); +  free_svalue(& k->val); +  k->next=m->free_list; +  m->free_list=k; +  m->size--;    }else{ -  +  prev=&k->next; +  } +  } +  } +  if(MAP_SLOTS(m->size) < m->hashsize * MIN_LINK_LENGTH) +  rehash(m, MAP_SLOTS(m->size));    next=m->next; -  +  free_mapping(m);    } -  +  else +  { +  next=m->next;    }    } -  + }      #ifdef PIKE_DEBUG      void simple_describe_mapping(struct mapping *m)   {    char *s;    init_buf();    describe_mapping(m,0,2);    s=simple_free_buf();    fprintf(stderr,"%s\n",s);