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.32 1998/05/13 00:24:29 hubbe Exp $"); + RCSID("$Id: mapping.c,v 1.33 1998/05/14 21:45:21 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"   #include "interpret.h"   #include "las.h"   #include "gc.h"   #include "stralloc.h"      #define AVG_LINK_LENGTH 4   #define MIN_LINK_LENGTH 1   #define MAP_SLOTS(X) ((X)?((X)+((X)>>4)+8):0) - #define LOOP(m) for(e=0;e<m->hashsize;e++) for(k=m->hash[e];k;k=k->next) +     - struct keypair - { -  struct keypair *next; -  struct svalue ind, val; - }; -  +    struct mapping *first_mapping;         #ifdef DEBUG   /* This function checks that the type field isn't lacking any bits.    * It is used for debugging purposes only.    */   static void check_mapping_type_fields(struct mapping *m)   {    INT32 e;    struct keypair *k,**prev;    TYPE_FIELD ind_types, val_types;       ind_types=val_types=0;    -  LOOP(m) +  MAPPING_LOOP(m)    {    val_types |= 1 << k->val.type;    ind_types |= 1 << k->ind.type;    }       if(val_types & ~(m->val_types))    fatal("Mapping value types out of order!\n");       if(ind_types & ~(m->ind_types))    fatal("Mapping indices types out of order!\n");
pike.git/src/mapping.c:130:    */   void really_free_mapping(struct mapping *m)   {    INT32 e;    struct keypair *k;   #ifdef DEBUG    if(m->refs)    fatal("really free mapping on mapping with nonzero refs.\n");   #endif    -  LOOP(m) +  MAPPING_LOOP(m)    {    free_svalue(& k->val);    free_svalue(& k->ind);    }       if(m->prev)    m->prev->next = m->next;    else    first_mapping = m->next;   
pike.git/src/mapping.c:222:    * very often.    */   void mapping_fix_type_field(struct mapping *m)   {    INT32 e;    struct keypair *k;    TYPE_FIELD ind_types, val_types;       val_types = ind_types = 0;    -  LOOP(m) +  MAPPING_LOOP(m)    {    val_types |= 1 << k->val.type;    ind_types |= 1 << k->ind.type;    }      #ifdef DEBUG    if(val_types & ~(m->val_types))    fatal("Mapping value types out of order!\n");       if(ind_types & ~(m->ind_types))
pike.git/src/mapping.c:536:   struct array *mapping_indices(struct mapping *m)   {    INT32 e;    struct array *a;    struct svalue *s;    struct keypair *k;       a=allocate_array(m->size);    s=ITEM(a);    -  LOOP(m) assign_svalue(s++, & k->ind); +  MAPPING_LOOP(m) assign_svalue(s++, & k->ind);       a->type_field = m->ind_types;      #ifdef DEBUG    if(d_flag > 1) check_mapping_type_fields(m);   #endif       return a;   }      struct array *mapping_values(struct mapping *m)   {    INT32 e;    struct keypair *k;    struct array *a;    struct svalue *s;       a=allocate_array(m->size);    s=ITEM(a);    -  LOOP(m) assign_svalue(s++, & k->val); +  MAPPING_LOOP(m) assign_svalue(s++, & k->val);       a->type_field = m->val_types;      #ifdef DEBUG    if(d_flag > 1) check_mapping_type_fields(m);   #endif       return a;   }      struct array *mapping_to_array(struct mapping *m)   {    INT32 e;    struct keypair *k;    struct array *a;    struct svalue *s;    a=allocate_array(m->size);    s=ITEM(a); -  LOOP(m) +  MAPPING_LOOP(m)    {    struct array *b=allocate_array(2);    assign_svalue(b->item+0, & k->ind);    assign_svalue(b->item+1, & k->val);    s->u.array=b;    s->type=T_ARRAY;    s++;    }    a->type_field = BIT_ARRAY;       return a;   }      void mapping_replace(struct mapping *m,struct svalue *from, struct svalue *to)   {    INT32 e;    struct keypair *k;    -  LOOP(m) +  MAPPING_LOOP(m)    if(is_eq(& k->val, from))    assign_svalue(& k->val, to);       m->val_types |= 1 << to->type;      #ifdef DEBUG    if(d_flag > 1) check_mapping_type_fields(m);   #endif      }
pike.git/src/mapping.c:634:   }      struct mapping *copy_mapping(struct mapping *m)   {    INT32 e;    struct mapping *n;    struct keypair *k;       n=allocate_mapping(MAP_SLOTS(m->size));    -  LOOP(m) mapping_insert(n, &k->ind, &k->val); +  MAPPING_LOOP(m) mapping_insert(n, &k->ind, &k->val);       return n;   }      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;
pike.git/src/mapping.c:695:      struct mapping *add_mappings(struct svalue *argp, INT32 args)   {    INT32 e,d;    struct mapping *ret;    struct keypair *k;       for(e=d=0;d<args;d++) e+=argp[d].u.mapping->size;    ret=allocate_mapping(MAP_SLOTS(e));    for(d=0;d<args;d++) -  LOOP(argp[d].u.mapping) +  MAPPING_LOOP(argp[d].u.mapping)    mapping_insert(ret, &k->ind, &k->val);    return ret;   }      int mapping_equal_p(struct mapping *a, struct mapping *b, struct processing *p)   {    struct processing curr;    struct keypair *k;    INT32 e;   
pike.git/src/mapping.c:720:    curr.pointer_b = b;    curr.next = p;       for( ;p ;p=p->next)    if(p->pointer_a == (void *)a && p->pointer_b == (void *)b)    return 1;       check_mapping_for_destruct(a);    check_mapping_for_destruct(b);    -  LOOP(a) +  MAPPING_LOOP(a)    {    struct svalue *s;    if((s=low_mapping_lookup(b, & k->ind)))    {    if(!low_is_equal(s, &k->val, &curr)) return 0;    }else{    return 0;    }    }    return 1;
pike.git/src/mapping.c:763:    my_strcat(buf);    return;    }    }       sprintf(buf,"([ /* %ld elements */\n",(long) m->size);    my_strcat(buf);       q=0;    -  LOOP(m) +  MAPPING_LOOP(m)    {    if(q)    {    my_putchar(',');    my_putchar('\n');    } else {    q=1;    }    for(d=0; d<indent; d++) my_putchar(' ');    describe_svalue(& k->ind, indent+2, p);
pike.git/src/mapping.c:867:    add_ref(ret=(struct mapping *)p->pointer_b);    return ret;    }    }       ret=allocate_mapping(MAP_SLOTS(m->size));    doing.pointer_b=ret;       check_stack(2);    -  LOOP(m) +  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++;       mapping_insert(ret, sp-2, sp-1);    pop_n_elems(2);    }   
pike.git/src/mapping.c:986:      void gc_mark_mapping_as_referenced(struct mapping *m)   {    INT32 e;    struct keypair *k;       if(gc_mark(m))    {    if((m->ind_types | m->val_types) & BIT_COMPLEX)    { -  LOOP(m) +  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))    continue;       gc_mark_svalues(&k->ind, 1);    gc_mark_svalues(&k->val, 1);
pike.git/src/mapping.c:1012:   void gc_check_all_mappings(void)   {    INT32 e;    struct keypair *k;    struct mapping *m;       for(m=first_mapping;m;m=m->next)    {    if((m->ind_types | m->val_types) & BIT_COMPLEX)    { -  LOOP(m) +  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))    continue;       debug_gc_check_svalues(&k->ind, 1, T_MAPPING, m);    m->val_types |= debug_gc_check_svalues(&k->val, 1, T_MAPPING, m);