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.26 1998/01/13 01:51:28 grubba Exp $"); + RCSID("$Id: mapping.c,v 1.27 1998/01/25 08:25:10 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"
pike.git/src/mapping.c:617:   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;       ai=mapping_indices(a);    av=mapping_values(a); +  if(ai->size > 1) +  {    zipper=get_set_order(ai);    order_array(ai, zipper);    order_array(av, zipper);    free((char *)zipper); -  +  }       bi=mapping_indices(b);    bv=mapping_values(b); -  +  if(bi->size > 1) +  {    zipper=get_set_order(bi);    order_array(bi, zipper);    order_array(bv, zipper);    free((char *)zipper); -  +  }       zipper=merge(ai,bi,op);       ci=array_zip(ai,bi,zipper);    free_array(ai);    free_array(bi);       cv=array_zip(av,bv,zipper);    free_array(av);    free_array(bv);
pike.git/src/mapping.c:707:    }else{    return 0;    }    }    return 1;   }      void describe_mapping(struct mapping *m,struct processing *p,int indent)   {    struct processing doing; -  INT32 e,d; +  INT32 e,d,q;    struct keypair *k;    char buf[40];       if(! m->size)    {    my_strcat("([ ])");    return;    }       doing.next=p;
pike.git/src/mapping.c:732:    {    sprintf(buf,"@%ld",(long)e);    my_strcat(buf);    return;    }    }       sprintf(buf,"([ /* %ld elements */\n",(long) m->size);    my_strcat(buf);    -  d=0; +  q=0;       LOOP(m)    { -  if(d) +  if(q)    { -  my_strcat(",\n"); +  my_putchar(','); +  my_putchar('\n');    } else { -  d=1; +  q=1;    }    for(d=0; d<indent; d++) my_putchar(' ');    describe_svalue(& k->ind, indent+2, p);    my_putchar(':');    describe_svalue(& k->val, indent+2, p);    }       my_putchar('\n');    for(e=2; e<indent; e++) my_putchar(' ');    my_strcat("])");
pike.git/src/mapping.c:931: Inside #if defined(DEBUG)
      if(m->hashsize < 0)    fatal("Assert: I don't think he's going to make it Jim.\n");       if(m->size < 0)    fatal("Core breach, evacuate ship!\n");       if(m->size > (m->hashsize + 3) * AVG_LINK_LENGTH)    fatal("Pretty mean hashtable there buster!.\n");    -  if(m->size < (m->hashsize - 3) * MIN_LINK_LENGTH) -  fatal("Hashsize is too small for mapping.\n"); -  +     if(m->size > 0 && (!m->ind_types || !m->val_types))    fatal("Mapping type fields are... wrong.\n");       if(!m->hash && m->size)    fatal("Hey! where did my hashtable go??\n");      }      void check_all_mappings(void)   {
pike.git/src/mapping.c:1058:       next=m->next;       free_mapping(m);    }else{    next=m->next;    }    }   }    + #ifdef DEBUG +  + void simple_describe_mapping(struct mapping *m) + { +  char *s; +  init_buf(); +  describe_mapping(m,0,2); +  s=simple_free_buf(); +  fprintf(stderr,"%s\n",s); +  free(s); + } +  +  + void debug_dump_mapping(struct mapping *m) + { +  fprintf(stderr,"Refs=%d, next=%p, prev=%p, size=%d, hashsize=%d\n", +  m->refs, +  m->next, +  m->prev, +  m->size, +  m->hashsize); +  fprintf(stderr,"Indices type field = "); +  debug_dump_type_field(m->ind_types); +  fprintf(stderr,"\n"); +  fprintf(stderr,"Values type field = "); +  debug_dump_type_field(m->val_types); +  fprintf(stderr,"\n"); +  simple_describe_mapping(m); + } + #endif +    void zap_all_mappings(void)   {    INT32 e;    struct keypair *k;    struct mapping *m,*next;       for(m=first_mapping;m;m=next)    {    m->refs++;    -  + #if defined(DEBUG) && defined(DEBUG_MALLOC) +  if(verbose_debug_exit) +  debug_dump_mapping(m); + #endif +     for(e=0;e<m->hashsize;e++)    {    while((k=m->hash[e]))    {    m->hash[e]=k->next;    k->next=m->free_list;    m->free_list=k;    free_svalue(&k->ind);    free_svalue(&k->val);    }