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.50 2000/01/28 00:46:26 hubbe Exp $"); + RCSID("$Id: mapping.c,v 1.51 2000/01/28 21:00:44 grubba 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:177:       return m;   }         void really_free_mapping_data(struct mapping_data *md)   {    INT32 e;    struct keypair *k;    debug_malloc_touch(md); + #ifdef PIKE_DEBUG +  if (md->refs) { +  fatal("really_free_mapping_data(): md has non-zero refs: %d\n", +  md->refs); +  } + #endif /* PIKE_DEBUG */    NEW_MAPPING_LOOP(md)    {    free_svalue(& k->val);    free_svalue(& k->ind);    }       free((char *) md);   }      /* This function is used to rehash a mapping without loosing the internal
pike.git/src/mapping.c:224:   static struct mapping *rehash(struct mapping *m, int new_size)   {    struct mapping_data *md;   #ifdef PIKE_DEBUG    INT32 tmp=m->data->size;   #endif    INT32 e;      #ifdef PIKE_DEBUG    if(m->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");       if(d_flag>1) check_mapping(m);   #endif       /* This can be optimized to do rehash and copy    * in one operation.. -Hubbe    */    md=m->data;    if(md->refs>1)    { -  +  debug_malloc_touch(md);    md=m->data=copy_mapping_data(m->data);    debug_malloc_touch(md);    }      #ifdef PIKE_DEBUG    if(d_flag>1) check_mapping(m);   #endif       init_mapping(m, new_size);   
pike.git/src/mapping.c:474:   void mapping_insert(struct mapping *m,    struct svalue *key,    struct svalue *val)   {    unsigned INT32 h,h2;    struct keypair *k, **prev;    struct mapping_data *md, *omd;      #ifdef PIKE_DEBUG    if(m->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");   #endif       h2=hash_svalue(key);      #ifdef PIKE_DEBUG    if(d_flag>1) check_mapping(m);   #endif       LOW_FIND(is_eq, key,    struct svalue *tmp=&k->ind;
pike.git/src/mapping.c:564:   union anything *mapping_get_item_ptr(struct mapping *m,    struct svalue *key,    TYPE_T t)   {    unsigned INT32 h, h2;    struct keypair *k, **prev;    struct mapping_data *md,*omd;      #ifdef PIKE_DEBUG    if(m->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");       if(d_flag>1) check_mapping(m);       debug_malloc_touch(m);    debug_malloc_touch(m->data);   #endif       h2=hash_svalue(key);       LOW_FIND(is_eq, key,
pike.git/src/mapping.c:664:   void map_delete_no_free(struct mapping *m,    struct svalue *key,    struct svalue *to)   {    unsigned INT32 h,h2;    struct keypair *k, **prev;    struct mapping_data *md,*omd;      #ifdef PIKE_DEBUG    if(m->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");    if(d_flag>1) check_mapping(m);   #endif       h2=hash_svalue(key);       LOW_FIND(is_eq, key,    struct svalue *tmp=&k->ind;    SAME_DATA(goto md_remove_value,    omd=md;    LOW_FIND(is_identical, tmp,
pike.git/src/mapping.c:734:      void check_mapping_for_destruct(struct mapping *m)   {    INT32 e;    struct keypair *k, **prev;    TYPE_FIELD ind_types, val_types;    struct mapping_data *md=m->data;      #ifdef PIKE_DEBUG    if(m->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");    if(d_flag>1) check_mapping(m);   #endif       /* no is_eq -> no locking */       if(!md->size) return;       if((md->ind_types | md->val_types) & (BIT_OBJECT | BIT_FUNCTION))    {    val_types = ind_types = 0;
pike.git/src/mapping.c:789:      struct svalue *low_mapping_lookup(struct mapping *m,    struct svalue *key)   {    unsigned INT32 h,h2;    struct keypair *k=0, **prev=0;    struct mapping_data *md, *omd;      #ifdef PIKE_DEBUG    if(m->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");    if(d_flag>1) check_mapping(m);   #endif       h2=hash_svalue(key);   #ifdef PIKE_DEBUG    if(d_flag > 1) check_mapping_type_fields(m);   #endif    FIND();    if(k)    {
pike.git/src/mapping.c:856:    struct svalue *key2,    int create)   {    struct svalue tmp;    struct mapping *m2;    struct svalue *s=low_mapping_lookup(m, key1);    debug_malloc_touch(m);      #ifdef PIKE_DEBUG    if(m->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");   #endif       if(!s || !s->type==T_MAPPING)    {    if(!create) return 0;    tmp.u.mapping=allocate_mapping(5);    tmp.type=T_MAPPING;    mapping_insert(m, key1, &tmp);    debug_malloc_touch(m);    debug_malloc_touch(tmp.u.mapping);
pike.git/src/mapping.c:931:      struct array *mapping_indices(struct mapping *m)   {    INT32 e;    struct array *a;    struct svalue *s;    struct keypair *k;      #ifdef PIKE_DEBUG    if(m->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");   #endif       a=allocate_array(m->data->size);    s=ITEM(a);       /* no locking required */    NEW_MAPPING_LOOP(m->data) assign_svalue(s++, & k->ind);       a->type_field = m->data->ind_types;   
pike.git/src/mapping.c:958:      struct array *mapping_values(struct mapping *m)   {    INT32 e;    struct keypair *k;    struct array *a;    struct svalue *s;      #ifdef PIKE_DEBUG    if(m->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");   #endif       a=allocate_array(m->data->size);    s=ITEM(a);       /* no locking required */    NEW_MAPPING_LOOP(m->data) assign_svalue(s++, & k->val);       a->type_field = m->data->val_types;   
pike.git/src/mapping.c:985:      struct array *mapping_to_array(struct mapping *m)   {    INT32 e;    struct keypair *k;    struct array *a;    struct svalue *s;      #ifdef PIKE_DEBUG    if(m->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");   #endif       a=allocate_array(m->data->size);    s=ITEM(a);       /* no locking required */    NEW_MAPPING_LOOP(m->data)    {    struct array *b=allocate_array(2);    assign_svalue(b->item+0, & k->ind);
pike.git/src/mapping.c:1014:   }      void mapping_replace(struct mapping *m,struct svalue *from, struct svalue *to)   {    INT32 e;    struct keypair *k;    struct mapping_data *md;      #ifdef PIKE_DEBUG    if(m->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");   #endif       md=m->data;    if(md->size)    {    add_ref(md);    NEW_MAPPING_LOOP(md)    {    if(is_eq(& k->val, from))    {
pike.git/src/mapping.c:1085:   }   #else      /* deferred mapping copy! */   struct mapping *copy_mapping(struct mapping *m)   {    struct mapping *n;      #ifdef PIKE_DEBUG    if(m->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");   #endif       n=allocate_mapping(0); -  +  debug_malloc_touch(n->data);    free_mapping_data(n->data);    n->data=m->data;    n->data->refs++;    n->data->valrefs++;    n->data->hardlinks++; -  +  debug_malloc_touch(n->data);    return n;   }      #endif      struct mapping *merge_mappings(struct mapping *a, struct mapping *b, INT32 op)   {    struct array *ai, *av;    struct array *bi, *bv;    struct array *ci, *cv;    INT32 *zipper;    struct mapping *m;      #ifdef PIKE_DEBUG    if(a->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");    if(b->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");   #endif       ai=mapping_indices(a);    av=mapping_values(a);    if(ai->size > 1)    {    zipper=get_set_order(ai);    order_array(ai, zipper);    order_array(av, zipper);    free((char *)zipper);
pike.git/src/mapping.c:1191:      int mapping_equal_p(struct mapping *a, struct mapping *b, struct processing *p)   {    struct processing curr;    struct keypair *k;    struct mapping_data *md;    INT32 e,eq=1;      #ifdef PIKE_DEBUG    if(a->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");    if(b->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");   #endif       if(a==b) return 1;    if(m_sizeof(a) != m_sizeof(b)) return 0;       curr.pointer_a = a;    curr.pointer_b = b;    curr.next = p;       for( ;p ;p=p->next)
pike.git/src/mapping.c:1246:    struct processing doing;    struct array *a;    JMP_BUF catch;    ONERROR err;    INT32 e,d;    struct keypair *k;    char buf[40];      #ifdef PIKE_DEBUG    if(m->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");   #endif       if(! m->data->size)    {    my_strcat("([ ])");    return;    }       doing.next=p;    doing.pointer_a=(void *)m;
pike.git/src/mapping.c:1305:    }       UNSET_ONERROR(err);    free_array(a);       my_putchar('\n');    for(e=2; e<indent; e++) my_putchar(' ');    my_strcat("])");   }    - node * make_node_from_mapping(struct mapping *m) + node *make_node_from_mapping(struct mapping *m)   {    struct keypair *k;    INT32 e;      #ifdef PIKE_DEBUG    if(m->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");   #endif       mapping_fix_type_field(m);       if((m->data->ind_types | m->data->val_types) & (BIT_FUNCTION | BIT_OBJECT))    {    struct array *ind, *val;    node *n;    ind=mapping_indices(m);    val=mapping_values(m);
pike.git/src/mapping.c:1385:    struct processing *p)   {    struct processing doing;    struct mapping *ret;    INT32 e;    struct keypair *k;    struct mapping_data *md;      #ifdef PIKE_DEBUG    if(m->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");   #endif       doing.next=p;    doing.pointer_a=(void *)m;    for(;p;p=p->next)    {    if(p->pointer_a == (void *)m)    {    add_ref(ret=(struct mapping *)p->pointer_b);    return ret;
pike.git/src/mapping.c:1411:       ret=allocate_mapping(MAP_SLOTS(m->data->size));    ret->flags=m->flags;    doing.pointer_b=ret;       check_stack(2);       md=m->data;    md->valrefs++;    add_ref(md); -  MAPPING_LOOP(m) +  MAPPING_LOOP(m) /* FIXME: Shouldn't NEW_MAPPING_LOOP() be used? */    {    copy_svalues_recursively_no_free(sp,&k->ind, 1, p);    sp++;    copy_svalues_recursively_no_free(sp,&k->val, 1, p);    sp++;       mapping_insert(ret, sp-2, sp-1);    pop_n_elems(2);    }    md->valrefs--;
pike.git/src/mapping.c:1437:      void mapping_search_no_free(struct svalue *to,    struct mapping *m,    struct svalue *look_for,    struct svalue *key /* start */)   {    struct mapping_data *md, *omd;      #ifdef PIKE_DEBUG    if(m->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");   #endif    md=m->data;       if(md->size)    {    unsigned INT32 h2,h=0;    struct keypair *k=md->hash[0], **prev;       if(key)    {
pike.git/src/mapping.c:1518: Inside #if defined(PIKE_DEBUG)
   struct mapping_data *md;    md=m->data;       if(m->refs <=0)    fatal("Mapping has zero refs.\n");          if(!m->data)    fatal("Mapping has no data block.\n");    +  if (!m->data->refs) +  fatal("Mapping data block has zero refs.\n"); +     if(m->next && m->next->prev != m)    fatal("Mapping ->next->prev != mapping.\n");       if(m->prev)    {    if(m->prev->next != m)    fatal("Mapping ->prev->next != mapping.\n");    }else{    if(first_mapping != m)    fatal("Mapping ->prev == 0 but first_mapping != mapping.\n");
pike.git/src/mapping.c:1598:   #endif         void gc_mark_mapping_as_referenced(struct mapping *m)   {    INT32 e;    struct keypair *k;      #ifdef PIKE_DEBUG    if(m->data->refs <=0) -  fatal("Zero refs i mapping->data\n"); +  fatal("Zero refs in mapping->data\n");   #endif       if(gc_mark(m))    {    if((m->data->ind_types | m->data->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