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.173 2003/11/09 01:10:14 mast Exp $ + || $Id: mapping.c,v 1.174 2003/11/09 01:31:12 mast Exp $   */      #include "global.h" - RCSID("$Id: mapping.c,v 1.173 2003/11/09 01:10:14 mast Exp $"); + RCSID("$Id: mapping.c,v 1.174 2003/11/09 01:31:12 mast 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:464:      #define MAPPING_DATA_IN_USE(MD) ((MD)->refs != (MD)->hardlinks + 1)      #define LOW_FIND(FUN, KEY, FOUND, NOT_FOUND) do { \    md=m->data; \    add_ref(md); \    if(md->hashsize) \    { \    h=h2 % md->hashsize; \    DO_IF_DEBUG( if(d_flag > 1) check_mapping_type_fields(m); ) \ -  if(md->ind_types & (1 << key->type)) \ +  if(md->ind_types & ((1 << key->type) | BIT_OBJECT)) \    { \    for(prev= md->hash + h;(k=*prev);prev=&k->next) \    { \    if(h2 == k->hval && FUN(& k->ind, KEY)) \    { \    FOUND; \    } \    } \    } \    } \
pike.git/src/mapping.c:487:         #define LOW_FIND2(FUN, KEY, FOUND, NOT_FOUND) do { \    struct keypair *k2; \    md=m->data; \    add_ref(md); \    if(md->hashsize) \    { \    h=h2 % md->hashsize; \    DO_IF_DEBUG( if(d_flag > 1) check_mapping_type_fields(m); ) \ -  if(md->ind_types & (1 << key->type)) \ +  if(md->ind_types & ((1 << key->type) | BIT_OBJECT)) \    { \    k2=omd->hash[h2 % omd->hashsize]; \    prev= md->hash + h; \    for(;(k=*prev) && k2;(prev=&k->next),(k2=k2->next)) \    if(!(h2 == k->hval && is_identical(&k2->ind, &k->ind))) \    break; \    for(;(k=*prev);prev=&k->next) \    { \    if(FUN(& k->ind, KEY)) \    { \
pike.git/src/mapping.c:632: Inside #if defined(PIKE_DEBUG)
   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. +  * +  * overwrite: +  * 0: Do not replace the value if the entry exists. +  * 1: Replace the value if the entry exists. +  * 2: Replace both the index and the value if the entry exists.    */   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;   
pike.git/src/mapping.c:686: Inside #if defined(PIKE_DEBUG)
  #ifdef PIKE_DEBUG    if(m->data != md)    Pike_fatal("Wrong dataset in mapping_insert!\n");    if(d_flag>1) check_mapping(m);   #endif    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);   #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");
pike.git/src/mapping.c:747:   #endif   }      PMOD_EXPORT void mapping_insert(struct mapping *m,    struct svalue *key,    struct svalue *val)   {    low_mapping_insert(m,key,val,1);   }    + /* Inline the above in this file. */ + #define mapping_insert(M, KEY, VAL) low_mapping_insert ((M), (KEY), (VAL), 1) +    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)
pike.git/src/mapping.c:1295:    INT32 e;      #ifdef PIKE_DEBUG    if(ind->size != val->size)    Pike_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++); +  for(e=0;e<ind->size;e++) low_mapping_insert(m, i++, v++, 2);       return m;   }      #if 0   PMOD_EXPORT struct mapping *copy_mapping(struct mapping *m)   {    INT32 e;    struct mapping *n;    struct keypair *k;
pike.git/src/mapping.c:1535:       }       for(;d<args;d++)    {    struct mapping *m=argp[d].u.mapping;    struct mapping_data *md=m->data;       add_ref(md);    NEW_MAPPING_LOOP(md) -  mapping_insert(ret, &k->ind, &k->val); +  low_mapping_insert(ret, &k->ind, &k->val, 2);    free_mapping_data(md);    }   #ifdef PIKE_DEBUG    if(!ret)    Pike_fatal("add_mappings is confused!\n");   #endif    return ret;   }      PMOD_EXPORT int mapping_equal_p(struct mapping *a, struct mapping *b, struct processing *p)
pike.git/src/mapping.c:1806:   PMOD_EXPORT void f_aggregate_mapping(INT32 args)   {    INT32 e;    struct mapping *m;       if(args & 1)    Pike_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, Pike_sp+e, Pike_sp+e+1); +  for(e=-args;e<0;e+=2) low_mapping_insert(m, Pike_sp+e, Pike_sp+e+1, 2);    pop_n_elems(args);   #ifdef PIKE_DEBUG    if(d_flag)    check_mapping(m);   #endif    push_mapping(m);   }      PMOD_EXPORT struct mapping *copy_mapping_recursively(struct mapping *m,    struct processing *p)
pike.git/src/mapping.c:1866:    add_ref(md);    NEW_MAPPING_LOOP(md)    {    copy_svalues_recursively_no_free(Pike_sp,&k->ind, 1, &doing);    Pike_sp++;    dmalloc_touch_svalue(Pike_sp-1);    copy_svalues_recursively_no_free(Pike_sp,&k->val, 1, &doing);    Pike_sp++;    dmalloc_touch_svalue(Pike_sp-1);    -  mapping_insert(ret, Pike_sp-2, Pike_sp-1); +  low_mapping_insert(ret, Pike_sp-2, Pike_sp-1, 2);    pop_n_elems(2);    }    md->valrefs--;    free_mapping_data(md);       return ret;   }         PMOD_EXPORT void mapping_search_no_free(struct svalue *to,