Branch: Tag:

2004-05-28

2004-05-28 16:08:24 by Henrik Grubbström (Grubba) <grubba@grubba.org>

copy_svalues_recursively_no_free() et al now preserve identity relations.
Fixes [bug 3693 (#3693)].
Note that this is a (minor) API change (struct processing * ==> struct mapping *).
Added a few const's.

Rev: src/array.c:1.160
Rev: src/array.h:1.61
Rev: src/mapping.c:1.181
Rev: src/mapping.h:1.56
Rev: src/multiset.c:1.86
Rev: src/multiset.h:1.35
Rev: src/svalue.c:1.194
Rev: src/svalue.h:1.129

2:   || 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.180 2004/04/15 00:12:04 nilsson Exp $ + || $Id: mapping.c,v 1.181 2004/05/28 16:08:24 grubba Exp $   */      #include "global.h" - RCSID("$Id: mapping.c,v 1.180 2004/04/15 00:12:04 nilsson Exp $"); + RCSID("$Id: mapping.c,v 1.181 2004/05/28 16:08:24 grubba Exp $");   #include "main.h"   #include "object.h"   #include "mapping.h"
648:    * 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, +  const struct svalue *key, +  const struct svalue *val,    int overwrite)   {    unsigned INT32 h,h2;
759:   }      PMOD_EXPORT void mapping_insert(struct mapping *m, -  struct svalue *key, -  struct svalue *val) +  const struct svalue *key, +  const struct svalue *val)   {    low_mapping_insert(m,key,val,1);   }
1040:   }      PMOD_EXPORT struct svalue *low_mapping_lookup(struct mapping *m, -  struct svalue *key) +  const struct svalue *key)   {    unsigned INT32 h,h2;    struct keypair *k=0, **prev=0;
2010:   }      PMOD_EXPORT struct mapping *copy_mapping_recursively(struct mapping *m, -  struct processing *p) +  struct mapping *p)   { -  struct processing doing; +     struct mapping *ret;    INT32 e;    struct keypair *k;    struct mapping_data *md; -  +  struct svalue aa, bb;      #ifdef PIKE_DEBUG    if(m->data->refs <=0)    Pike_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; -  } -  } -  +    #ifdef PIKE_DEBUG    if(d_flag > 1) check_mapping_type_fields(m);   #endif
2042:    return copy_mapping(m);       ret=allocate_mapping(MAP_SLOTS(m->data->size)); -  doing.pointer_b=ret; +     -  +  aa.type = T_MAPPING; +  aa.subtype = 0; +  aa.u.mapping = m; +  bb.type = T_MAPPING; +  bb.subtype = 0; +  bb.u.mapping = ret; +  mapping_insert(p, &aa, &bb); +     ret->data->flags = m->data->flags;       check_stack(2);
2053:    add_ref(md);    NEW_MAPPING_LOOP(md)    { -  copy_svalues_recursively_no_free(Pike_sp,&k->ind, 1, &doing); +  copy_svalues_recursively_no_free(Pike_sp,&k->ind, 1, p);    Pike_sp++;    dmalloc_touch_svalue(Pike_sp-1); -  copy_svalues_recursively_no_free(Pike_sp,&k->val, 1, &doing); +  copy_svalues_recursively_no_free(Pike_sp,&k->val, 1, p);    Pike_sp++;    dmalloc_touch_svalue(Pike_sp-1);