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.93 2000/07/18 05:48:20 mast Exp $"); + RCSID("$Id: mapping.c,v 1.94 2000/07/28 17:16:55 hubbe Exp $");   #include "main.h"   #include "object.h"   #include "mapping.h"   #include "svalue.h"   #include "array.h"   #include "pike_macros.h"   #include "error.h"   #include "pike_memory.h"   #include "dynamic_buffer.h"   #include "interpret.h"
pike.git/src/mapping.c:163:    }    add_ref(md);    m->data=md;   #ifdef PIKE_DEBUG    m->debug_size = md->size;   #endif   }      /* This function allocates an empty mapping with room for 'size' values    */ - struct mapping *debug_allocate_mapping(int size) + 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);       m->refs = 1;    m->flags = 0;       DOUBLELINK(first_mapping, m);       return m;   }       - void really_free_mapping_data(struct mapping_data *md) + PMOD_EXPORT 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);   }    - void do_free_mapping(struct mapping *m) + PMOD_EXPORT void do_free_mapping(struct mapping *m)   {    if (m)    free_mapping(m);   }      /* This function is used to rehash a mapping without loosing the internal    * order in each hash chain. This is to prevent mappings from becoming    * inefficient just after being rehashed.    */   static void mapping_rehash_backwards_evil(struct mapping_data *md,
pike.git/src/mapping.c:507:   #define PREPARE_FOR_DATA_CHANGE() \    if(md->valrefs) COPYMAP()      #define PREPARE_FOR_INDEX_CHANGE() \    if(md->refs>1) COPYMAP()      /* This function brings the type fields in the mapping up to speed.    * I only use it when the type fields MUST be correct, which is not    * very often.    */ - void mapping_fix_type_field(struct mapping *m) + PMOD_EXPORT void mapping_fix_type_field(struct mapping *m)   {    INT32 e;    struct keypair *k;    TYPE_FIELD ind_types, val_types;       val_types = ind_types = 0;       NEW_MAPPING_LOOP(m->data)    {    val_types |= 1 << k->val.type;
pike.git/src/mapping.c:535: Inside #if defined(PIKE_DEBUG)
   if(ind_types & ~(m->data->ind_types))    fatal("Mapping indices types out of order!\n");   #endif    m->data->val_types = val_types;    m->data->ind_types = ind_types;   }      /* This function inserts key:val into the mapping m.    * Same as doing m[key]=val; in pike.    */ - void low_mapping_insert(struct mapping *m, + PMOD_EXPORT void low_mapping_insert(struct mapping *m,    struct svalue *key,    struct svalue *val,    int overwrite)   {    unsigned INT32 h,h2;    struct keypair *k, **prev;    struct mapping_data *md, *omd;      #ifdef PIKE_DEBUG    if(m->data->refs <=0)
pike.git/src/mapping.c:633: Inside #if defined(PIKE_DEBUG)
  #ifdef PIKE_DEBUG    if(m->data ==md)    m->debug_size++;   #endif      #ifdef PIKE_DEBUG    if(d_flag>1) check_mapping(m);   #endif   }    - void mapping_insert(struct mapping *m, + PMOD_EXPORT void mapping_insert(struct mapping *m,    struct svalue *key,    struct svalue *val)   {    low_mapping_insert(m,key,val,1);   }    - union anything *mapping_get_item_ptr(struct mapping *m, + PMOD_EXPORT 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 in mapping->data\n");
pike.git/src/mapping.c:746:    m->debug_size++;   #endif      #ifdef PIKE_DEBUG    if(d_flag > 1) check_mapping_type_fields(m);   #endif       return & ( k->val.u );   }    - void map_delete_no_free(struct mapping *m, + PMOD_EXPORT 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 in mapping->data\n");
pike.git/src/mapping.c:827:    debug_malloc_touch(m);    rehash(m, MAP_SLOTS(m->data->size));    }      #ifdef PIKE_DEBUG    if(d_flag>1) check_mapping(m);   #endif    return;   }    - void check_mapping_for_destruct(struct mapping *m) + PMOD_EXPORT 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 in mapping->data\n");    if(d_flag>1) check_mapping(m);
pike.git/src/mapping.c:899:    }       md->val_types = val_types;    md->ind_types = ind_types;   #ifdef PIKE_DEBUG    if(d_flag>1) check_mapping(m);   #endif    }   }    - struct svalue *low_mapping_lookup(struct mapping *m, + PMOD_EXPORT 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 in mapping->data\n");    if(d_flag>1) check_mapping(m);
pike.git/src/mapping.c:925:   #endif    FIND();    if(k)    {    PROPAGATE();    return &k->val;    }    return 0;   }    - struct svalue *low_mapping_string_lookup(struct mapping *m, + PMOD_EXPORT struct svalue *low_mapping_string_lookup(struct mapping *m,    struct pike_string *p)   {    struct svalue tmp;    tmp.type=T_STRING;    tmp.u.string=p;    return low_mapping_lookup(m, &tmp);   }    - void mapping_string_insert(struct mapping *m, + PMOD_EXPORT void mapping_string_insert(struct mapping *m,    struct pike_string *p,    struct svalue *val)   {    struct svalue tmp;    tmp.type=T_STRING;    tmp.u.string=p;    mapping_insert(m, &tmp, val);   }    - void mapping_string_insert_string(struct mapping *m, + PMOD_EXPORT void mapping_string_insert_string(struct mapping *m,    struct pike_string *p,    struct pike_string *val)   {    struct svalue tmp;    tmp.type=T_STRING;    tmp.u.string=val;    mapping_string_insert(m, p, &tmp);   }    - struct svalue *simple_mapping_string_lookup(struct mapping *m, + PMOD_EXPORT struct svalue *simple_mapping_string_lookup(struct mapping *m,    char *p)   {    struct pike_string *tmp;    if((tmp=findstring(p)))    return low_mapping_string_lookup(m,tmp);    return 0;   }    - struct svalue *mapping_mapping_lookup(struct mapping *m, + PMOD_EXPORT struct svalue *mapping_mapping_lookup(struct mapping *m,    struct svalue *key1,    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
pike.git/src/mapping.c:1007:    tmp.subtype=NUMBER_UNDEFINED;    tmp.u.integer=0;       mapping_insert(m2, key2, &tmp);    debug_malloc_touch(m2);       return low_mapping_lookup(m2, key2);   }       - struct svalue *mapping_mapping_string_lookup(struct mapping *m, + PMOD_EXPORT struct svalue *mapping_mapping_string_lookup(struct mapping *m,    struct pike_string *key1,    struct pike_string *key2,    int create)   {    struct svalue k1,k2;    k1.type=T_STRING;    k1.u.string=key1;    k2.type=T_STRING;    k2.u.string=key2;    return mapping_mapping_lookup(m,&k1,&k2,create);   }          - void mapping_index_no_free(struct svalue *dest, + PMOD_EXPORT void mapping_index_no_free(struct svalue *dest,    struct mapping *m,    struct svalue *key)   {    struct svalue *p;       if((p=low_mapping_lookup(m,key)))    {    if(p->type==T_INT)    p->subtype=NUMBER_NUMBER;       assign_svalue_no_free(dest, p);    }else{    dest->type=T_INT;    dest->u.integer=0;    dest->subtype=NUMBER_UNDEFINED;    }   }    - struct array *mapping_indices(struct mapping *m) + PMOD_EXPORT 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 in mapping->data\n");   #endif
pike.git/src/mapping.c:1068:       a->type_field = m->data->ind_types;      #ifdef PIKE_DEBUG    if(d_flag > 1) check_mapping_type_fields(m);   #endif       return a;   }    - struct array *mapping_values(struct mapping *m) + PMOD_EXPORT 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 in mapping->data\n");   #endif
pike.git/src/mapping.c:1095:       a->type_field = m->data->val_types;      #ifdef PIKE_DEBUG    if(d_flag > 1) check_mapping_type_fields(m);   #endif       return a;   }    - struct array *mapping_to_array(struct mapping *m) + PMOD_EXPORT 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 in mapping->data\n");   #endif
pike.git/src/mapping.c:1125:    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) + PMOD_EXPORT 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 in mapping->data\n");   #endif   
pike.git/src/mapping.c:1157:    }    }    free_mapping_data(md);    }      #ifdef PIKE_DEBUG    if(d_flag > 1) check_mapping_type_fields(m);   #endif   }    - struct mapping *mkmapping(struct array *ind, struct array *val) + PMOD_EXPORT struct mapping *mkmapping(struct array *ind, struct array *val)   {    struct mapping *m;    struct svalue *i,*v;    INT32 e;      #ifdef PIKE_DEBUG    if(ind->size != val->size)    fatal("mkmapping on different sized arrays.\n");   #endif       m=allocate_mapping(MAP_SLOTS(ind->size));    i=ITEM(ind);    v=ITEM(val);    for(e=0;e<ind->size;e++) mapping_insert(m, i++, v++);       return m;   }      #if 0 - struct mapping *copy_mapping(struct mapping *m) + PMOD_EXPORT struct mapping *copy_mapping(struct mapping *m)   {    INT32 e;    struct mapping *n;    struct keypair *k;    struct mapping_data *md;       md=m->data;    n=allocate_mapping(MAP_SLOTS(md->size));       md->valrefs++;    add_ref(md);    NEW_MAPPING_LOOP(md) mapping_insert(n, &k->ind, &k->val);    md->valrefs--;    free_mapping_data(md);       return n;   }   #else      /* deferred mapping copy! */ - struct mapping *copy_mapping(struct mapping *m) + PMOD_EXPORT struct mapping *copy_mapping(struct mapping *m)   {    struct mapping *n;      #ifdef PIKE_DEBUG    if(m->data->refs <=0)    fatal("Zero refs in mapping->data\n");   #endif       n=allocate_mapping(0);    if(!m_sizeof(m)) return n; /* done */
pike.git/src/mapping.c:1224:   #endif    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) + PMOD_EXPORT 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 in mapping->data\n");
pike.git/src/mapping.c:1278:       free((char *)zipper);       m=mkmapping(ci, cv);    free_array(ci);    free_array(cv);       return m;   }    - struct mapping *merge_mapping_array_ordered(struct mapping *a, + PMOD_EXPORT struct mapping *merge_mapping_array_ordered(struct mapping *a,    struct array *b, INT32 op)   {    struct array *ai, *av;    struct array *ci, *cv;    INT32 *zipper;    struct mapping *m;       ai=mapping_indices(a);    av=mapping_values(a);    if(ai->size > 1)
pike.git/src/mapping.c:1324:       free((char *)zipper);       m=mkmapping(ci, cv);    free_array(ci);    free_array(cv);       return m;   }    - struct mapping *merge_mapping_array_unordered(struct mapping *a, + PMOD_EXPORT struct mapping *merge_mapping_array_unordered(struct mapping *a,    struct array *b, INT32 op)   {    struct array *b_temp;    INT32 *zipper;    struct mapping *m;       if (b->size>1)    {    zipper=get_set_order(b);    b_temp=reorder_and_copy_array(b,zipper);    m=merge_mapping_array_ordered(a,b_temp,op);    free_array(b_temp);    }    else    m=merge_mapping_array_ordered(a,b,op);       return m;   }    - struct mapping *add_mappings(struct svalue *argp, INT32 args) + PMOD_EXPORT 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++)    {   #ifdef PIKE_DEBUG    if(d_flag>1) check_mapping(argp[d].u.mapping);   #endif
pike.git/src/mapping.c:1381:    }else{    ret=allocate_mapping(MAP_SLOTS(e));    d=0;    }    for(;d<args;d++)    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) + PMOD_EXPORT 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 in mapping->data\n");    if(b->data->refs <=0)
pike.git/src/mapping.c:1542:    if(!m->data->size)    return mkefuncallnode("aggregate_mapping",0);       s.type=T_MAPPING;    s.subtype=0;    s.u.mapping=m;    return mkconstantsvaluenode(&s);    }   }    - void f_aggregate_mapping(INT32 args) + PMOD_EXPORT void f_aggregate_mapping(INT32 args)   {    INT32 e;    struct keypair *k;    struct mapping *m;       if(args & 1)    error("Uneven number of arguments to aggregate_mapping.\n");       m=allocate_mapping(MAP_SLOTS(args / 2));       for(e=-args;e<0;e+=2) mapping_insert(m, sp+e, sp+e+1);    pop_n_elems(args);   #ifdef PIKE_DEBUG    if(d_flag)    check_mapping(m);   #endif    push_mapping(m);   }    - struct mapping *copy_mapping_recursively(struct mapping *m, + PMOD_EXPORT struct mapping *copy_mapping_recursively(struct mapping *m,    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)
pike.git/src/mapping.c:1620:    mapping_insert(ret, sp-2, sp-1);    pop_n_elems(2);    }    md->valrefs--;    free_mapping_data(md);       return ret;   }       - void mapping_search_no_free(struct svalue *to, + PMOD_EXPORT 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 in mapping->data\n");   #endif