pike.git / src / mapping.c

version» Context lines:

pike.git/src/mapping.c:123: Inside #if defined(PIKE_DEBUG)
   INT32 e;    const struct keypair *k=0;    const struct mapping_data *md;    TYPE_FIELD ind_types, val_types;       ind_types=val_types=0;       md = m->data;    NEW_MAPPING_LOOP(md)    { -  if (k->val.type > MAX_TYPE) +  if (TYPEOF(k->val) > MAX_TYPE)    Pike_fatal("Invalid mapping keypair value type: %s\n", -  get_name_of_type(k->val.type)); -  val_types |= 1 << k->val.type; -  if (k->ind.type > MAX_TYPE) +  get_name_of_type(TYPEOF(k->val))); +  val_types |= 1 << TYPEOF(k->val); +  if (TYPEOF(k->ind) > MAX_TYPE)    Pike_fatal("Invalid maping keypair index type: %s\n", -  get_name_of_type(k->ind.type)); -  ind_types |= 1 << k->ind.type; +  get_name_of_type(TYPEOF(k->ind))); +  ind_types |= 1 << TYPEOF(k->ind);    }       if(val_types & ~(m->data->val_types))    Pike_fatal("Mapping value types out of order!\n");       if(ind_types & ~(m->data->ind_types))    Pike_fatal("Mapping indices types out of order!\n");   }   #endif   
pike.git/src/mapping.c:328:    /* initialize */    *k=*from;       /* link */    h=k->hval;    h&=md->hashsize - 1;    k->next=md->hash[h];    md->hash[h]=k;       /* update */ -  md->ind_types |= 1<< (k->ind.type); -  md->val_types |= 1<< (k->val.type); +  md->ind_types |= 1<< (TYPEOF(k->ind)); +  md->val_types |= 1<< (TYPEOF(k->val));    md->size++;       /* Reverse */    prev = from->next;    from->next = next;    next = from;    from = prev;    }   }   
pike.git/src/mapping.c:383:    assign_svalue_no_free(&k->ind, &from->ind);    assign_svalue_no_free(&k->val, &from->val);       /* link */    h=k->hval;    h&=md->hashsize - 1;    k->next=md->hash[h];    md->hash[h]=k;       /* update */ -  md->ind_types |= 1<< (k->ind.type); -  md->val_types |= 1<< (k->val.type); +  md->ind_types |= 1<< (TYPEOF(k->ind)); +  md->val_types |= 1<< (TYPEOF(k->val));    md->size++;       /* Reverse */    prev = from->next;    from->next = next;    next = from;    from = prev;    }   }   
pike.git/src/mapping.c:538:      #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 - 1); \    DO_IF_DEBUG( if(d_flag > 1) check_mapping_type_fields(m); ) \ -  if(md->ind_types & ((1 << key->type) | BIT_OBJECT)) \ +  if(md->ind_types & ((1 << TYPEOF(*key)) | 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:561:         #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-1); \    DO_IF_DEBUG( if(d_flag > 1) check_mapping_type_fields(m); ) \ -  if(md->ind_types & ((1 << key->type) | BIT_OBJECT)) \ +  if(md->ind_types & ((1 << TYPEOF(*key)) | BIT_OBJECT)) \    { \    k2=omd->hash[h2 & (omd->hashsize - 1)]; \    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:664:   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; -  ind_types |= 1 << k->ind.type; +  val_types |= 1 << TYPEOF(k->val); +  ind_types |= 1 << TYPEOF(k->ind);    }      #ifdef PIKE_DEBUG    if(val_types & ~(m->data->val_types))    Pike_fatal("Mapping value types out of order!\n");       if(ind_types & ~(m->data->ind_types))    Pike_fatal("Mapping indices types out of order!\n");   #endif    m->data->val_types = val_types;
pike.git/src/mapping.c:755: Inside #if defined(PIKE_DEBUG)
   mi_set_value:   #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) +  md->val_types |= 1 << TYPEOF(*val); +  if (overwrite == 2 && TYPEOF(*key) == 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:
pike.git/src/mapping.c:798:    /* no need to lock here since we are not calling is_eq - Hubbe */       k=md->free_list;   #ifndef PIKE_MAPPING_KEYPAIR_LOOP    md->free_list=k->next;   #else /* PIKE_MAPPING_KEYPAIR_LOOP */    md->free_list++;   #endif /* !PIKE_MAPPING_KEYPAIR_LOOP */    k->next=md->hash[h];    md->hash[h]=k; -  md->ind_types |= 1 << key->type; -  md->val_types |= 1 << val->type; +  md->ind_types |= 1 << TYPEOF(*key); +  md->val_types |= 1 << TYPEOF(*val);    assign_svalue_no_free(& k->ind, key);    assign_svalue_no_free(& k->val, val);    k->hval = h2;    md->size++;   #ifdef MAPPING_SIZE_DEBUG    if(m->data ==md)    m->debug_size++;   #endif      #ifdef PIKE_DEBUG
pike.git/src/mapping.c:876:    return 0;       mg_set_value:   #ifdef PIKE_DEBUG    if(m->data != md)    Pike_fatal("Wrong dataset in mapping_get_item_ptr!\n");    if(d_flag)    check_mapping(m);   #endif    free_mapping_data(md); -  if(k->val.type == t) +  if(TYPEOF(k->val) == t)    {    PREPARE_FOR_DATA_CHANGE2();    PROPAGATE(); /* prepare then propagate */       return & ( k->val.u );    }       return 0;       mg_insert:
pike.git/src/mapping.c:921:       k=md->free_list;   #ifndef PIKE_MAPPING_KEYPAIR_LOOP    md->free_list=k->next;   #else /* PIKE_MAPPING_KEYPAIR_LOOP */    md->free_list++;   #endif /* !PIKE_MAPPING_KEYPAIR_LOOP */    k->next=md->hash[h];    md->hash[h]=k;    assign_svalue_no_free(& k->ind, key); -  k->val.type=T_INT; -  k->val.subtype=NUMBER_NUMBER; -  k->val.u.integer=0; +  SET_SVAL(k->val, T_INT, NUMBER_NUMBER, integer, 0);    k->hval = h2; -  md->ind_types |= 1 << key->type; +  md->ind_types |= 1 << TYPEOF(*key);    md->val_types |= BIT_INT;    md->size++;   #ifdef MAPPING_SIZE_DEBUG    if(m->data ==md)    m->debug_size++;   #endif      #ifdef PIKE_DEBUG    if(d_flag > 1) check_mapping_type_fields(m);   #endif
pike.git/src/mapping.c:973:    goto md_remove_value,    free_mapping_data(omd);    goto md_do_nothing)),    goto md_do_nothing);       md_do_nothing:    debug_malloc_touch(m);    free_mapping_data(md);    if(to)    { -  to->type=T_INT; -  to->subtype=NUMBER_UNDEFINED; -  to->u.integer=0; +  SET_SVAL(*to, T_INT, NUMBER_UNDEFINED, integer, 0);    }    return;       md_remove_value:   #ifdef PIKE_DEBUG    if(md->refs <= 1)    Pike_fatal("Too few refs i mapping->data\n");    if(m->data != md)    Pike_fatal("Wrong dataset in mapping_delete!\n");    if(d_flag>1) check_mapping(m);
pike.git/src/mapping.c:1051:    if((md->ind_types | md->val_types) & (BIT_OBJECT | BIT_FUNCTION))    {    val_types = ind_types = 0;    md->val_types |= BIT_INT;    for(e=0;e<md->hashsize;e++)    {    for(prev= md->hash + e;(k=*prev);)    {    check_destructed(& k->val);    -  if((k->ind.type == T_OBJECT || k->ind.type == T_FUNCTION) && +  if((TYPEOF(k->ind) == T_OBJECT || TYPEOF(k->ind) == T_FUNCTION) &&    !k->ind.u.object->prog)    {    debug_malloc_touch(m);    debug_malloc_touch(md);    PREPARE_FOR_INDEX_CHANGE2();    *prev=k->next;    free_svalue(& k->ind);    free_svalue(& k->val);    FREE_KEYPAIR(md, k);    mark_free_svalue (&md->free_list->ind);
pike.git/src/mapping.c:1074: Inside #if defined(MAPPING_SIZE_DEBUG)
     #ifdef MAPPING_SIZE_DEBUG    if(m->data ==md)    {    m->debug_size++;    debug_malloc_touch(m);    }   #endif    debug_malloc_touch(md);    }else{ -  val_types |= 1 << k->val.type; -  ind_types |= 1 << k->ind.type; +  val_types |= 1 << TYPEOF(k->val); +  ind_types |= 1 << TYPEOF(k->ind);    prev=&k->next;    }    }    }       md->val_types = val_types;    md->ind_types = ind_types;       if(MAP_SLOTS(md->size) < md->hashsize * MIN_LINK_LENGTH)    {
pike.git/src/mapping.c:1126:    PROPAGATE();    return &k->val;    }    return 0;   }      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; +  SET_SVAL(tmp, T_STRING, 0, string, p);    return low_mapping_lookup(m, &tmp);   }      PMOD_EXPORT void mapping_string_insert(struct mapping *m,    struct pike_string *p,    const struct svalue *val)   {    struct svalue tmp; -  tmp.type=T_STRING; -  tmp.u.string=p; +  SET_SVAL(tmp, T_STRING, 0, string, p);    mapping_insert(m, &tmp, val);   }      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; +  SET_SVAL(tmp, T_STRING, 0, string, val);    mapping_string_insert(m, p, &tmp);   }      PMOD_EXPORT struct svalue *simple_mapping_string_lookup(struct mapping *m,    const char *p)   {    struct pike_string *tmp;    if((tmp=findstring(p)))    return low_mapping_string_lookup(m,tmp);    return 0;
pike.git/src/mapping.c:1176:    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)    Pike_fatal("Zero refs in mapping->data\n");   #endif    -  if(!s || !s->type==T_MAPPING) +  if(!s || TYPEOF(*s) != T_MAPPING)    {    if(!create) return 0; -  tmp.u.mapping=allocate_mapping(5); -  tmp.type=T_MAPPING; +  SET_SVAL(tmp, T_MAPPING, 0, mapping, allocate_mapping(5));    mapping_insert(m, key1, &tmp);    debug_malloc_touch(m);    debug_malloc_touch(tmp.u.mapping);    free_mapping(tmp.u.mapping); /* There is one ref in 'm' */    s=&tmp;    }       m2=s->u.mapping;    debug_malloc_touch(m2);    s=low_mapping_lookup(m2, key2);    if(s) return s;    if(!create) return 0;    -  tmp.type=T_INT; -  tmp.subtype=NUMBER_UNDEFINED; -  tmp.u.integer=0; +  SET_SVAL(tmp, T_INT, NUMBER_UNDEFINED, integer, 0);       mapping_insert(m2, key2, &tmp);    debug_malloc_touch(m2);       return low_mapping_lookup(m2, key2);   }         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; +  SET_SVAL(k1, T_STRING, 0, string, key1); +  SET_SVAL(k2, T_STRING, 0, string, key2);    return mapping_mapping_lookup(m,&k1,&k2,create);   }            PMOD_EXPORT void mapping_index_no_free(struct svalue *dest,    struct mapping *m,    const struct svalue *key)   {    struct svalue *p;       if(!IS_DESTRUCTED (key) && (p=low_mapping_lookup(m,key)))    {    assign_svalue_no_free(dest, p);       /* Never return NUMBER_UNDEFINED for existing entries. */    /* Note: There is code that counts on storing UNDEFINED in mapping    * values (using e.g. low_mapping_lookup to get them), so we have    * to fix the subtype here rather than in mapping_insert. */ -  if(p->type==T_INT) -  dest->subtype=NUMBER_NUMBER; +  if(TYPEOF(*p) == T_INT) +  SET_SVAL_SUBTYPE(*dest, NUMBER_NUMBER);    }else{ -  dest->type=T_INT; -  dest->u.integer=0; -  dest->subtype=NUMBER_UNDEFINED; +  SET_SVAL(*dest, T_INT, NUMBER_UNDEFINED, integer, 0);    }   }      PMOD_EXPORT struct array *mapping_indices(struct mapping *m)   {    INT32 e;    struct array *a;    struct svalue *s;    struct keypair *k;   
pike.git/src/mapping.c:1322:       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);    assign_svalue(b->item+1, & k->val); -  b->type_field = (1 << k->ind.type) | (1 << k->val.type); -  s->u.array=b; -  s->type=T_ARRAY; +  b->type_field = (1 << TYPEOF(k->ind)) | (1 << TYPEOF(k->val)); +  SET_SVAL(*s, T_ARRAY, 0, array, b);    s++;    }    a->type_field = BIT_ARRAY;       return a;   }      PMOD_EXPORT void mapping_replace(struct mapping *m,struct svalue *from, struct svalue *to)   {    INT32 e;
pike.git/src/mapping.c:1353:    md=m->data;    if(md->size)    {    add_ref(md);    NEW_MAPPING_LOOP(md)    {    if(is_eq(& k->val, from))    {    PREPARE_FOR_DATA_CHANGE();    assign_svalue(& k->val, to); -  md->val_types|=1<<to->type; +  md->val_types |= 1<<TYPEOF(*to);    }    }    free_mapping_data(md);    }      #ifdef PIKE_DEBUG    if(d_flag > 1) check_mapping_type_fields(m);   #endif   }   
pike.git/src/mapping.c:2091:    make_node_from_array(val)));    free_array(ind);    free_array(val);    return n;    }else{    struct svalue s;       if(!m->data->size)    return mkefuncallnode("aggregate_mapping",0);    -  s.type=T_MAPPING; -  s.subtype=0; -  s.u.mapping=m; +  SET_SVAL(s, T_MAPPING, 0, mapping, m);    return mkconstantsvaluenode(&s);    }   }      /*! @decl mapping aggregate_mapping(mixed ... elems)    *!    *! Construct a mapping.    *!    *! Groups the arguments together two and two in key-index pairs and    *! creates a mapping of those pairs. Generally, the mapping literal
pike.git/src/mapping.c:2161:    not_complex = 0;    ret=allocate_mapping(MAP_SLOTS(m->data->size));    }    else {    not_complex = 1;    ret = copy_mapping(m);    }       if (p) {    struct svalue aa, bb; -  aa.type = T_MAPPING; -  aa.u.mapping = m; -  bb.type = T_MAPPING; -  bb.u.mapping = ret; +  SET_SVAL(aa, T_MAPPING, 0, mapping, m); +  SET_SVAL(bb, T_MAPPING, 0, mapping, ret);    mapping_insert(p, &aa, &bb);    }       if (not_complex)    return ret;       ret->data->flags = m->data->flags;       check_stack(2);   
pike.git/src/mapping.c:2227:    struct keypair *k=md->hash[0], **prev;       if(key)    {    h2=hash_svalue(key);       FIND();       if(!k)    { -  to->type=T_INT; -  to->subtype=NUMBER_UNDEFINED; -  to->u.integer=0; +  SET_SVAL(*to, T_INT, NUMBER_UNDEFINED, integer, 0);    return;    }    k=k->next;    }          md=m->data;    if(md->size)    {    md->valrefs++;
pike.git/src/mapping.c:2270:    break;    k=md->hash[h];    }    }    }       md->valrefs--;    free_mapping_data(md);    }    -  to->type=T_INT; -  to->subtype=NUMBER_UNDEFINED; -  to->u.integer=0; +  SET_SVAL(*to, T_INT, NUMBER_UNDEFINED, integer, 0);   }      #ifdef PIKE_DEBUG      void check_mapping(const struct mapping *m)   {    int e,num;    struct keypair *k;    const struct mapping_data *md;   
pike.git/src/mapping.c:2368: Inside #if defined(PIKE_DEBUG)
   Pike_fatal("Mapping from hell detected, attempting to send it back...\n");       if(md->size > 0 && (!md->ind_types || !md->val_types))    Pike_fatal("Mapping type fields are... wrong.\n");       num=0;    NEW_MAPPING_LOOP(md)    {    num++;    -  if (k->ind.type > MAX_TYPE) +  if (TYPEOF(k->ind) > MAX_TYPE)    Pike_fatal("Invalid maping keypair index type: %s\n", -  get_name_of_type(k->ind.type)); -  if(! ( (1 << k->ind.type) & (md->ind_types) )) +  get_name_of_type(TYPEOF(k->ind))); +  if(! ( (1 << TYPEOF(k->ind)) & (md->ind_types) ))    Pike_fatal("Mapping indices type field lies.\n");    -  if (k->val.type > MAX_TYPE) +  if (TYPEOF(k->val) > MAX_TYPE)    Pike_fatal("Invalid mapping keypair value type: %s\n", -  get_name_of_type(k->val.type)); -  if(! ( (1 << k->val.type) & (md->val_types) )) +  get_name_of_type(TYPEOF(k->val))); +  if(! ( (1 << TYPEOF(k->val)) & (md->val_types) ))    Pike_fatal("Mapping values type field lies.\n");       check_svalue(& k->ind);    check_svalue(& k->val);       /* FIXME add check for k->hval    * beware that hash_svalue may be threaded and locking    * is required!!    */    }
pike.git/src/mapping.c:2468:      #define GC_RECURSE_MD_IN_USE(MD, RECURSE_FN, IND_TYPES, VAL_TYPES) do { \    INT32 e; \    struct keypair *k; \    IND_TYPES = MD->ind_types; \    NEW_MAPPING_LOOP(MD) { \    if (!IS_DESTRUCTED(&k->ind) && RECURSE_FN(&k->ind, 1)) { \    DO_IF_DEBUG(Pike_fatal("Didn't expect an svalue zapping now.\n")); \    } \    RECURSE_FN(&k->val, 1); \ -  VAL_TYPES |= 1 << k->val.type; \ +  VAL_TYPES |= 1 << TYPEOF(k->val); \    } \   } while (0)      #ifdef PIKE_MAPPING_KEYPAIR_LOOP   #error Broken code below!   #define GC_RECURSE(M, MD, REC_KEYPAIR, TYPE, IND_TYPES, VAL_TYPES) do { \    int remove; \    struct keypair *k,**prev_; \    /* no locking required (no is_eq) */ \    for(k = MD_KEYPAIRS(md, md->hashsize);k < MD->free_list;) \
pike.git/src/mapping.c:2513:    (*prev_)->next = k->next; \    FREE_KEYPAIR(MD, k); \    mark_free_svalue (&MD->free_list->ind); \    mark_free_svalue (&MD->free_list->val); \    MD->size--; \    DO_IF_MAPPING_SIZE_DEBUG( \    if(M->data ==MD) \    M->debug_size--; \    ); \    } else { \ -  VAL_TYPES |= 1 << k->val.type; \ -  IND_TYPES |= 1 << k->ind.type; \ +  VAL_TYPES |= 1 << TYPEOF(k->val); \ +  IND_TYPES |= 1 << TYPEOF(k->ind); \    k++; \    } \    } \    } while (0)   #else /* !PIKE_MAPPING_KEYPAIR_LOOP */   #define GC_RECURSE(M, MD, REC_KEYPAIR, TYPE, IND_TYPES, VAL_TYPES) do { \    INT32 e; \    int remove; \    struct keypair *k,**prev; \    /* no locking required (no is_eq) */ \
pike.git/src/mapping.c:2546:    *prev=k->next; \    FREE_KEYPAIR(MD, k); \    mark_free_svalue (&MD->free_list->ind); \    mark_free_svalue (&MD->free_list->val); \    MD->size--; \    DO_IF_MAPPING_SIZE_DEBUG( \    if(M->data ==MD) \    M->debug_size--; \    ); \    }else{ \ -  VAL_TYPES |= 1 << k->val.type; \ -  IND_TYPES |= 1 << k->ind.type; \ +  VAL_TYPES |= 1 << TYPEOF(k->val); \ +  IND_TYPES |= 1 << TYPEOF(k->ind); \    prev=&k->next; \    } \    } \    } \   } while (0)   #endif /* PIKE_MAPPING_KEYPAIR_LOOP */      #define GC_REC_KP(REMOVE, N_REC, W_REC, N_TST, W_TST) do { \    if ((REMOVE = N_REC(&k->ind, 1))) \    gc_free_svalue(&k->val); \