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.114 2001/01/18 02:18:57 hubbe Exp $"); + RCSID("$Id: mapping.c,v 1.115 2001/01/25 08:37:59 hubbe Exp $");   #include "main.h"   #include "object.h"   #include "mapping.h"   #include "svalue.h"   #include "array.h"   #include "pike_macros.h"   #include "pike_error.h"   #include "pike_memory.h"   #include "dynamic_buffer.h"   #include "interpret.h"
pike.git/src/mapping.c:98: Inside #if defined(PIKE_DEBUG)
      if(val_types & ~(m->data->val_types))    fatal("Mapping value types out of order!\n");       if(ind_types & ~(m->data->ind_types))    fatal("Mapping indices types out of order!\n");   }   #endif      static struct mapping_data empty_data = { 1, 1, 0,0,0,0,0,0 }; + static struct mapping_data weak_empty_data = { 1, 1, 0,0,0,0,0,0,1 };      /* This function allocates the hash table and svalue space for a mapping    * struct. The size is the max number of indices that can fit in the    * allocated space.    */ - static void init_mapping(struct mapping *m, INT32 size) + static void init_mapping(struct mapping *m, +  INT32 size, +  INT16 flags)   {    struct mapping_data *md;    char *tmp;    ptrdiff_t e;    INT32 hashsize;       debug_malloc_touch(m);   #ifdef PIKE_DEBUG    if (Pike_in_gc > GC_PASS_PREPARE && Pike_in_gc < GC_PASS_ZAP_WEAK)    fatal("Can't allocate a new mapping_data inside gc.\n");
pike.git/src/mapping.c:142:    {    md->free_list[e-1].next = md->free_list + e;    md->free_list[e-1].ind.type=T_INT;    md->free_list[e-1].val.type=T_INT;    }    md->free_list[e-1].next=0;    md->free_list[e-1].ind.type=T_INT;    md->free_list[e-1].val.type=T_INT;    md->ind_types = 0;    md->val_types = 0; -  md->flags = 0; +  md->flags = flags;    md->size = 0;    md->refs=0;    md->valrefs=0;    md->hardlinks=0;    md->num_keypairs=size;    }else{ -  +  if(flags & MAPPING_FLAG_WEAK) +  { +  md=&weak_empty_data; +  }else{    md=&empty_data;    } -  +  }    add_ref(md);    m->data=md;   #ifdef MAPPING_SIZE_DEBUG    m->debug_size = md->size;   #endif   }      /* This function allocates an empty mapping with room for 'size' values    */   PMOD_EXPORT struct mapping *debug_allocate_mapping(int size)   {    struct mapping *m;       m=alloc_mapping();       GC_ALLOC(m);       INITIALIZE_PROT(m); -  init_mapping(m,size); +  init_mapping(m,size,0);       m->refs = 1;       DOUBLELINK(first_mapping, m);       return m;   }         PMOD_EXPORT void really_free_mapping_data(struct mapping_data *md)
pike.git/src/mapping.c:299:       md=m->data;    debug_malloc_touch(md);   #ifdef PIKE_DEBUG    if(md->refs <=0)    fatal("Zero refs in mapping->data\n");       if(d_flag>1) check_mapping(m);   #endif    -  init_mapping(m, new_size); +  init_mapping(m, new_size, md->flags);    debug_malloc_touch(m);    new_md=m->data; -  new_md->flags = md->flags; +        /* 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:549:    m->data->ind_types = ind_types;   }      PMOD_EXPORT void mapping_set_flags(struct mapping *m, int flags)   {    struct mapping_data *md = m->data;    if (md->refs > 1) {    struct keypair *k = NULL, *prev = NULL;    COPYMAP2();    } + #ifdef PIKE_DEBUG +  if(flags & MAPPING_FLAG_WEAK) +  { +  debug_malloc_touch(m); +  debug_malloc_touch(md); +  } +  else +  { +  debug_malloc_touch(m); +  debug_malloc_touch(md); +  } + #endif    md->flags = flags;   }         /* This function inserts key:val into the mapping m.    * Same as doing m[key]=val; in pike.    */   PMOD_EXPORT void low_mapping_insert(struct mapping *m,    struct svalue *key,    struct svalue *val,