pike.git / src / mapping.c

version» Context lines:

pike.git/src/mapping.c:2137:    free_mapping_data(bmd);       if(!eq) break;    }    }    md->valrefs--;    free_mapping_data(md);    return eq;   }    - void describe_mapping(struct mapping *m,struct processing *p,int indent) + void describe_mapping(struct byte_buffer *b, struct mapping *m,struct processing *p,int indent)   {    struct processing doing;    struct array *a;    JMP_BUF catch;    ONERROR err;    INT32 e,d;    char buf[40];      #ifdef PIKE_DEBUG    if(m->data->refs <=0)    Pike_fatal("Zero refs in mapping->data\n");   #endif       if(! m->data->size)    { -  my_strcat("([ ])"); +  buffer_add_str(b, "([ ])");    return;    }       doing.next=p;    doing.pointer_a=(void *)m;    for(e=0;p;e++,p=p->next)    {    if(p->pointer_a == (void *)m)    {    sprintf(buf,"@%ld",(long)e); -  my_strcat(buf); +  buffer_add_str(b, buf);    return;    }    }       if (Pike_in_gc > GC_PASS_PREPARE && Pike_in_gc < GC_PASS_FREE) {    /* Have to do without any temporary allocations. */    struct keypair *k;    int notfirst = 0;       if (m->data->size == 1) { -  my_strcat("([ /* 1 element */\n"); +  buffer_add_str(b, "([ /* 1 element */\n");    } else {    sprintf(buf, "([ /* %ld elements */\n", (long)m->data->size); -  my_strcat(buf); +  buffer_add_str(b, buf);    }       NEW_MAPPING_LOOP(m->data) { -  if (notfirst) my_strcat(",\n"); +  if (notfirst) buffer_add_str(b, ",\n");    else notfirst = 1;    for(d = 0; d < indent; d++) -  my_putchar(' '); -  describe_svalue(&k->ind, indent+2, &doing); -  my_strcat (": "); -  describe_svalue(&k->val, indent+2, &doing); +  buffer_add_char(b, ' '); +  describe_svalue(b, &k->ind, indent+2, &doing); +  buffer_add_str (b, ": "); +  describe_svalue(b, &k->val, indent+2, &doing);    }    -  my_putchar('\n'); -  for(e=2; e<indent; e++) my_putchar(' '); -  my_strcat("])"); +  buffer_add_char(b, '\n'); +  for(e=2; e<indent; e++) buffer_add_char(b, ' '); +  buffer_add_str(b, "])");    return;    }       a = mapping_indices(m);    SET_ONERROR(err, do_free_array, a);       if(! m->data->size) { /* mapping_indices may remove elements */ -  my_strcat("([ ])"); +  buffer_add_str(b, "([ ])");    }    else {    int save_t_flag = Pike_interpreter.trace_level; -  dynamic_buffer save_buf; +        if (m->data->size == 1) { -  my_strcat("([ /* 1 element */\n"); +  buffer_add_str(b, "([ /* 1 element */\n");    } else {    sprintf(buf, "([ /* %ld elements */\n", (long)m->data->size); -  my_strcat(buf); +  buffer_add_str(b, buf);    }    -  save_buffer (&save_buf); +     Pike_interpreter.trace_level = 0;    if(SETJMP(catch)) {    free_svalue(&throw_value);    mark_free_svalue (&throw_value);    }    else    sort_array_destructively(a);    UNSETJMP(catch);    Pike_interpreter.trace_level = save_t_flag; -  restore_buffer (&save_buf); +        for(e = 0; e < a->size; e++)    {    struct svalue *tmp;    if(e) -  my_strcat(",\n"); +  buffer_add_str(b, ",\n");       for(d = 0; d < indent; d++) -  my_putchar(' '); +  buffer_add_char(b, ' ');    -  describe_svalue(ITEM(a)+e, indent+2, &doing); -  my_strcat (": "); +  describe_svalue(b, ITEM(a)+e, indent+2, &doing); +  buffer_add_str (b, ": ");       {    int save_t_flag=Pike_interpreter.trace_level;    Pike_interpreter.trace_level=0;       tmp=low_mapping_lookup(m, ITEM(a)+e);       Pike_interpreter.trace_level=save_t_flag;    }    if(tmp) -  describe_svalue(tmp, indent+2, &doing); +  describe_svalue(b, tmp, indent+2, &doing);    else -  my_strcat("** gone **"); +  buffer_add_str(b, "** gone **");    }    -  my_putchar('\n'); -  for(e=2; e<indent; e++) my_putchar(' '); -  my_strcat("])"); +  buffer_add_char(b, '\n'); +  for(e=2; e<indent; e++) buffer_add_char(b, ' '); +  buffer_add_str(b, "])");    }       UNSET_ONERROR(err);    free_array(a);   }      node *make_node_from_mapping(struct mapping *m)   {   #ifdef PIKE_DEBUG    if(m->data->refs <=0)
pike.git/src/mapping.c:3061:    unreferenced++;    }       return unreferenced;   }      #ifdef PIKE_DEBUG      void simple_describe_mapping(struct mapping *m)   { -  dynamic_buffer save_buf; -  char *s; -  init_buf(&save_buf); -  describe_mapping(m,0,2); -  s=simple_free_buf(&save_buf); -  fprintf(stderr,"%s\n",s); -  free(s); +  struct byte_buffer buf = BUFFER_INIT(); +  describe_mapping(&buf,m,0,2); +  buffer_add_str(&buf, "\n"); +  fputs(buffer_get_string(&buf), stderr); +  buffer_free(&buf);   }         void debug_dump_mapping(struct mapping *m)   {    fprintf(stderr, "Refs=%d, next=%p, prev=%p",    m->refs, m->next, m->prev);    if (((ptrdiff_t)m->data) & 3) {    fprintf(stderr, ", data=%p (unaligned)\n", m->data);    } else {