pike.git / src / mapping.c

version» Context lines:

pike.git/src/mapping.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: mapping.c,v 1.206 2008/06/26 09:30:49 grubba Exp $ + || $Id: mapping.c,v 1.207 2008/06/27 11:32:39 grubba Exp $   */      #include "global.h"   #include "main.h"   #include "object.h"   #include "mapping.h"   #include "svalue.h"   #include "array.h"   #include "pike_macros.h"   #include "pike_error.h"
pike.git/src/mapping.c:198:    mark_free_svalue (&md->free_list[e-1].val);   #endif /* !PIKE_MAPPING_KEYPAIR_LOOP */    md->ind_types = 0;    md->val_types = 0;    md->flags = flags;    md->size = 0;    md->refs=0;    md->valrefs=0;    md->hardlinks=0;    md->num_keypairs=size; -  md->generation_cnt = 0; +     }else{    switch (flags & MAPPING_WEAK) {    case 0: md = &empty_data; break;    case MAPPING_WEAK_INDICES: md = &weak_ind_empty_data; break;    case MAPPING_WEAK_VALUES: md = &weak_val_empty_data; break;    default: md = &weak_both_empty_data; break;    }    }    add_ref(md);    m->data=md;
pike.git/src/mapping.c:413: Inside #if defined(PIKE_DEBUG)
   Pike_fatal("Zero refs in mapping->data\n");       if(d_flag>1) check_mapping(m);   #endif       if (md->hashsize == new_size) return m;       init_mapping(m, new_size, md->flags);    debug_malloc_touch(m);    new_md=m->data; -  new_md->generation_cnt = md->generation_cnt; +        /* This operation is now 100% atomic - no locking required */    if(md->refs>1)    {    /* good */    for(e=0;e<md->hashsize;e++)    mapping_rehash_backwards_good(new_md, md->hash[e]);       unlink_mapping_data(md);    }else{
pike.git/src/mapping.c:498:    RELOC(keypairs[e].next);    add_ref_svalue(& keypairs[e].ind);    add_ref_svalue(& keypairs[e].val);    }   #endif /* PIKE_MAPPING_KEYPAIR_LOOP */       nmd->refs=0;    add_ref(nmd); /* For DMALLOC... */    nmd->valrefs=0;    nmd->hardlinks=0; -  nmd->generation_cnt = md->generation_cnt; +        /* FIXME: What about nmd->flags? */       if(md->hardlinks)    {   #ifdef PIKE_DEBUG    if(md->refs <= 0 || md->valrefs<=0)    Pike_fatal("Hardlink without refs/valrefs!\n");   #endif    md->hardlinks--;
pike.git/src/mapping.c:748:    free_mapping_data(md);    if(!overwrite) return;    PREPARE_FOR_DATA_CHANGE2();    PROPAGATE(); /* propagate after preparing */    md->val_types |= 1 << val->type;    if (overwrite == 2 && key->type == T_OBJECT)    /* Should replace the index too. It's only for objects that it's    * possible to tell the difference. */    assign_svalue (&k->ind, key);    assign_svalue(& k->val, val); -  md->flags |= MAPPING_DIRTY; +    #ifdef PIKE_DEBUG    if(d_flag>1) check_mapping(m);   #endif    return;       mi_insert:   #ifdef PIKE_DEBUG    if(m->data != md)    Pike_fatal("Wrong dataset in mapping_insert!\n");    if(d_flag>1) check_mapping(m);
pike.git/src/mapping.c:797:    md->val_types |= 1 << val->type;    assign_svalue_no_free(& k->ind, key);    assign_svalue_no_free(& k->val, val);    k->hval = h2;    md->size++;   #ifdef MAPPING_SIZE_DEBUG    if(m->data ==md)    m->debug_size++;   #endif    -  md->flags |= MAPPING_DIRTY; -  +    #ifdef PIKE_DEBUG    if(d_flag>1) check_mapping(m);   #endif   }      PMOD_EXPORT void mapping_insert(struct mapping *m,    const struct svalue *key,    const struct svalue *val)   {    low_mapping_insert(m,key,val,1);
pike.git/src/mapping.c:918:    k->next=md->hash[h];    md->hash[h]=k;    assign_svalue_no_free(& k->ind, key);    k->val.type=T_INT;    k->val.subtype=NUMBER_NUMBER;    k->val.u.integer=0;    k->hval = h2;    md->ind_types |= 1 << key->type;    md->val_types |= BIT_INT;    md->size++; -  md->flags |= MAPPING_DIRTY; +    #ifdef MAPPING_SIZE_DEBUG    if(m->data ==md)    m->debug_size++;   #endif      #ifdef PIKE_DEBUG    if(d_flag > 1) check_mapping_type_fields(m);   #endif       return & ( k->val.u );
pike.git/src/mapping.c:1003:       md->size--;   #ifdef MAPPING_SIZE_DEBUG    if(m->data ==md)    m->debug_size--;   #endif       if(md->size < (md->hashsize + 1) * MIN_LINK_LENGTH)    {    debug_malloc_touch(m); -  rehash(m, MAP_SLOTS(m->data->size + !!md->generation_cnt)); -  if (m->data->hashsize) -  m->data->flags |= MAPPING_DIRTY; +  rehash(m, MAP_SLOTS(m->data->size));    } -  else -  md->flags |= MAPPING_DIRTY; +       #ifdef PIKE_DEBUG    if(d_flag>1) check_mapping(m);   #endif    return;   }      PMOD_EXPORT void check_mapping_for_destruct(struct mapping *m)   {    INT32 e;
pike.git/src/mapping.c:1060:    debug_malloc_touch(md);    PREPARE_FOR_INDEX_CHANGE2();    *prev=k->next;    free_svalue(& k->ind);    free_svalue(& k->val);    FREE_KEYPAIR(md, k);    mark_free_svalue (&md->free_list->ind);    mark_free_svalue (&md->free_list->val);    md->size--;    -  md->flags |= MAPPING_DIRTY; -  +    #ifdef MAPPING_SIZE_DEBUG    if(m->data ==md)    {    m->debug_size++;    debug_malloc_touch(m);    }   #endif    debug_malloc_touch(md);    }else{    val_types |= 1 << k->val.type;    ind_types |= 1 << k->ind.type;    prev=&k->next;    }    }    }       md->val_types = val_types;    md->ind_types = ind_types;    -  if(MAP_SLOTS(md->size + !!md->generation_cnt) < -  md->hashsize * MIN_LINK_LENGTH) +  if(MAP_SLOTS(md->size) < md->hashsize * MIN_LINK_LENGTH)    {    debug_malloc_touch(m); -  rehash(m, MAP_SLOTS(md->size + !!md->generation_cnt)); +  rehash(m, MAP_SLOTS(md->size));    }      #ifdef PIKE_DEBUG    if(d_flag>1) check_mapping(m);   #endif    }   }      PMOD_EXPORT struct svalue *low_mapping_lookup(struct mapping *m,    const struct svalue *key)
pike.git/src/mapping.c:1352:    if(md->size)    {    add_ref(md);    NEW_MAPPING_LOOP(md)    {    if(is_eq(& k->val, from))    {    PREPARE_FOR_DATA_CHANGE();    assign_svalue(& k->val, to);    md->val_types|=1<<to->type; -  md->flags |= MAPPING_DIRTY; +     }    }    free_mapping_data(md);    }      #ifdef PIKE_DEBUG    if(d_flag > 1) check_mapping_type_fields(m);   #endif   }   
pike.git/src/mapping.c:2211:       md->valrefs--;    free_mapping_data(md);    }       to->type=T_INT;    to->subtype=NUMBER_UNDEFINED;    to->u.integer=0;   }    - PMOD_EXPORT INT32 mapping_generation(struct mapping *m) - { -  if (m->data->flags & MAPPING_DIRTY) { -  m->data->generation_cnt++; -  m->data->flags &= ~MAPPING_DIRTY; -  } -  return m->data->generation_cnt; - } -  +    #ifdef PIKE_DEBUG      void check_mapping(const struct mapping *m)   {    int e,num;    struct keypair *k;    const struct mapping_data *md;       static int in_check_mapping;    if(in_check_mapping) return;