pike.git / src / encode.c

version» Context lines:

pike.git/src/encode.c:284:   } while(0)   #endif      #define adddata(S) do { \    const struct pike_string *__str = (S); \    if(__str->size_shift) \    { \    int q; \    code_entry(TAG_STRING,-1, data); \    code_entry(__str->size_shift, __str->len, data); \ +  EDB(1, { \ +  ENCODE_WERR(".string %ld<<%d", \ +  __str->len, __str->size_shift); \ +  }); \    ENCODE_DATA(__str); \    }else{ \    code_entry(TAG_STRING, __str->len, data); \ -  +  EDB(1, { \ +  ENCODE_WERR(".string %ld", __str->len); \ +  }); \    addstr((char *)(__str->str),__str->len); \    } \ -  +  EDB(1, { \ +  ENCODE_FLUSH(); \ +  }); \   }while(0)      #ifdef ENCODE_DEBUG   /* NOTE: Fix when type encodings change. */   static int tag_to_type(int tag)   {    if (tag == TAG_FLOAT) return T_FLOAT;    if (tag == TAG_TYPE) return T_TYPE;    if (tag <= MAX_TYPE) return tag ^ MIN_REF_TYPE;    return tag;
pike.git/src/encode.c:638:    using / and % instead. Doing it like this is actually    only slightly slower, however, and saves on code size.    */    mpz_init_set_si( &tmp, i );    mpz_get_str( buffer, 36, &tmp );    mpz_clear( &tmp );    l = strlen(buffer);    code_entry(TAG_OBJECT, 2, data);    code_entry(TAG_STRING, l, data);    addstr(buffer,l); +  +  EDB(1, { +  ENCODE_WERR(".bignum %ld", i); +  });    }    else   #endif -  +  {    code_entry(TAG_INT, i, data); -  +  +  EDB(1, { +  ENCODE_WERR(".integer %ld", i); +  });    } -  +  }    break;       case T_STRING:    adddata(val->u.string);    break;       case T_TYPE:    /* NOTE: Types are added to the encoded mapping AFTER they have    * been encoded, to simplify decoding.    */    if (data->canonic)    Pike_error("Canonical encoding of the type type not supported.\n"); -  +     code_entry(TAG_TYPE, 0, data); /* Type encoding #0 */ -  +  EDB(1, { +  ENCODE_WERR(".entry type"); +  }); +     encode_type(val->u.type, data);    EDB(2,fprintf(stderr, "%*sEncoded type to <%d>: ",    data->depth, "", data->counter.u.integer);    print_svalue(stderr, val);    fputc('\n', stderr););    mapping_insert(data->encoded, val, &data->counter);    data->counter.u.integer++;    break;       case T_FLOAT:
pike.git/src/encode.c:684:   #define Pike_FP_NZERO 1 /* Negative Zero */   #define Pike_FP_PZERO 0 /* Positive zero */   #define Pike_FP_UNKNOWN -4711 /* Positive zero */         #ifdef HAVE_FPCLASS    switch(fpclass(d)) {    case FP_SNAN:    code_entry(TAG_FLOAT,0,data);    code_entry(TAG_FLOAT,Pike_FP_SNAN,data); +  EDB(1, { +  ENCODE_WERR(".float snan"); +  });    break;       case FP_QNAN:    code_entry(TAG_FLOAT,0,data);    code_entry(TAG_FLOAT,Pike_FP_QNAN,data); -  +  EDB(1, { +  ENCODE_WERR(".float qnan"); +  });    break;       case FP_NINF:    code_entry(TAG_FLOAT,0,data);    code_entry(TAG_FLOAT,Pike_FP_NINF,data); -  +  EDB(1, { +  ENCODE_WERR(".float -inf"); +  });    break;       case FP_PINF:    code_entry(TAG_FLOAT,0,data);    code_entry(TAG_FLOAT,Pike_FP_PINF,data); -  +  EDB(1, { +  ENCODE_WERR(".float inf"); +  });    break;       case FP_NZERO:    code_entry(TAG_FLOAT,0,data);    code_entry(TAG_FLOAT,Pike_FP_NZERO,data); -  +  EDB(1, { +  ENCODE_WERR(".float -0.0"); +  });    break;       case FP_PZERO:    code_entry(TAG_FLOAT,0,data);    code_entry(TAG_FLOAT,Pike_FP_ZERO,data); /* normal zero */ -  +  EDB(1, { +  ENCODE_WERR(".float 0.0"); +  });    break;       /* Ugly, but switch gobbles breaks -Hubbe */    default:    goto encode_normal_float;    }    break;    encode_normal_float:      #else
pike.git/src/encode.c:755: Inside #if defined(HAVE_ISZERO)
   pike_ftype=Pike_FP_NZERO;    break;   #endif    }    }       if(pike_ftype != Pike_FP_UNKNOWN)    {    code_entry(TAG_FLOAT,0,data);    code_entry(TAG_FLOAT,pike_ftype,data); +  EDB(1, { +  ENCODE_WERR(".float %d", pike_ftype); +  });    break;    }    }   #endif       if(d == 0.0)    {    code_entry(TAG_FLOAT,0,data);    code_entry(TAG_FLOAT,0,data); -  +  EDB(1, { +  ENCODE_WERR(".float 0.0"); +  });    }else{    INT64 x;    int y;    double tmp;       tmp = frexp(d, &y);    x = (INT64)((((INT64)1)<<(sizeof(INT64)*8 - 2))*tmp);    y -= sizeof(INT64)*8 - 2;       EDB(2,fprintf(stderr,
pike.git/src/encode.c:785:    tmp, x, y));       x >>= 32;    y += 32;       EDB(2,fprintf(stderr,    "Reducing float... x: 0x%08llx, y: %d\n",    x, y));    code_entry(TAG_FLOAT,x,data);    code_entry(TAG_FLOAT,y,data); +  EDB(1, { +  ENCODE_WERR(".float %ld, %ld", x, y); +  });    }    break;    }       case T_ARRAY:    code_entry(TAG_ARRAY, val->u.array->size, data); -  +  EDB(1, { +  ENCODE_WERR(".entry array, %ld", val->u.array->size); +  });    for(i=0; i<val->u.array->size; i++)    encode_value2(ITEM(val->u.array)+i, data, 0);    break;       case T_MAPPING:    check_stack(2);    ref_push_mapping(val->u.mapping);    f_indices(1);       ref_push_mapping(val->u.mapping);
pike.git/src/encode.c:821:    /* They should be handled deterministically now - Hubbe */    Pike_error("Canonical encoding requires basic types in indices.\n");    }    order = get_switch_order(Pike_sp[-2].u.array);    order_array(Pike_sp[-2].u.array, order);    order_array(Pike_sp[-1].u.array, order);    free(order);    }       code_entry(TAG_MAPPING, Pike_sp[-2].u.array->size,data); +  EDB(1, { +  ENCODE_WERR(".entry mapping, %ld", Pike_sp[-2].u.array->size); +  });    for(i=0; i<Pike_sp[-2].u.array->size; i++)    {    encode_value2(ITEM(Pike_sp[-2].u.array)+i, data, 0); /* indices */    encode_value2(ITEM(Pike_sp[-1].u.array)+i, data, 0); /* values */    }    pop_n_elems(2);    /* FIXME: What about flags? */    break;       case T_MULTISET: {    struct multiset *l = val->u.multiset;       if (TYPEOF(*multiset_get_cmp_less(l)) != T_INT)    Pike_error ("FIXME: Encoding of multisets with "    "custom sort function not yet implemented.\n");    else {    /* Encode valueless multisets without compare functions in a    * compatible way. */    code_entry(TAG_MULTISET, multiset_sizeof (l), data); -  +  EDB(1, { +  ENCODE_WERR(".entry multiset, %ld", multiset_sizeof(l)); +  });    if (data->canonic) {    INT32 *order;    if (multiset_ind_types(l) & ~(BIT_BASIC & ~BIT_TYPE)) {    multiset_fix_type_field(l);    if (multiset_ind_types(l) & ~(BIT_BASIC & ~BIT_TYPE))    /* This doesn't let bignums through. That's necessary as    * long as they aren't handled deterministically by the    * sort function. */    Pike_error("Canonical encoding requires basic types in indices.\n");    }
pike.git/src/encode.c:887:    MP_INT *i = (MP_INT*)val->u.object->storage;    char *buffer;    size_t l;       buffer = xalloc(mpz_sizeinbase(i, 36)+2);    mpz_get_str( buffer, 36, i );    l = strlen(buffer);    code_entry(TAG_OBJECT, 2, data);    code_entry(TAG_STRING, l, data);    addstr(buffer,l); +  EDB(1, { +  ENCODE_WERR(".bignum"); +  });    free(buffer);    break;    }       if (data->canonic)    Pike_error("Canonical encoding of objects not supported.\n");    push_svalue(val);    apply(encoder_codec (data), "nameof", 1);    EDB(5, fprintf(stderr, "%*s->nameof: ", data->depth, "");    print_svalue(stderr, Pike_sp-1);
pike.git/src/encode.c:914:    struct svalue tmp = entry_id;       EDB(5,fprintf(stderr, "%*s(UNDEFINED)\n", data->depth, ""));       if (SUBTYPEOF(*val)) {    /* Subtyped object.    *    * Encode the subtype, and then try encoding the plain object.    */    code_entry(TAG_OBJECT, 4, data); +  EDB(1, { +  ENCODE_WERR(".entry object, 4"); +  });    code_number(SUBTYPEOF(*val), data);    pop_stack();    ref_push_object(val->u.object);    break;    }       /* We have to remove ourself from the cache */    map_delete(data->encoded, val);       pop_stack();    push_svalue(val);    f_object_program(1);       /* Code the program */    code_entry(TAG_OBJECT, 3,data); -  +  EDB(1, { +  ENCODE_WERR(".entry object, 3"); +  });    encode_value2(Pike_sp-1, data, 1);    pop_stack();       push_svalue(val);       /* If we do not exist in cache, use backwards-    * compatible method, otherwise use newfangled    * style=3. -Hubbe    */    if(!low_mapping_lookup(data->encoded, val))
pike.git/src/encode.c:966:       /* Put value back in cache for future reference -Hubbe */    mapping_insert(data->encoded, val, &tmp);    }    break;    }    /* FALLTHRU */       default:    code_entry(TAG_OBJECT, 0,data); +  EDB(1, { +  ENCODE_WERR(".entry object"); +  });    break;    }    encode_value2(Pike_sp-1, data, 0);    pop_stack();    break;       case T_FUNCTION:    /* FIXME: Ought to have special treatment of trampolines. */    if (data->canonic)    Pike_error("Canonical encoding of functions not supported.\n");
pike.git/src/encode.c:994:    if(really_low_find_shared_string_identifier(    ID_FROM_INT(val->u.object->prog, SUBTYPEOF(*val))->name,    val->u.object->prog,    SEE_PROTECTED|SEE_PRIVATE) == SUBTYPEOF(*val))    {    /* We have to remove ourself from the cache for now */    struct svalue tmp = entry_id;    map_delete(data->encoded, val);       code_entry(TAG_FUNCTION, 1, data); +  EDB(1, { +  ENCODE_WERR(".entry function, 1"); +  });    ref_push_object(val->u.object);    encode_value2(Pike_sp-1, data, 0);    ref_push_string(ID_FROM_INT(val->u.object->prog,    SUBTYPEOF(*val))->name);    encode_value2(Pike_sp-1, data, 0);    pop_n_elems(3);       /* Put value back in cache */    mapping_insert(data->encoded, val, &tmp);    goto encode_done;    }    else {    /* FIXME: Encode the object, the inherit and the name. */    Pike_error("Cannot encode overloaded functions (yet).\n");    }    }    Pike_error("Cannot encode builtin functions.\n");    }       code_entry(TAG_FUNCTION, 0, data); -  +  EDB(1, { +  ENCODE_WERR(".entry function"); +  });    encode_value2(Pike_sp-1, data, 0);    pop_stack();    break;          case T_PROGRAM:    {    int d;    if ((val->u.program->id < PROG_DYNAMIC_ID_START) &&    (val->u.program->id >= 0)) {    code_entry(TAG_PROGRAM, 3, data); -  +  EDB(1, { +  ENCODE_WERR(".entry program, 3"); +  });    push_int(val->u.program->id);    encode_value2(Pike_sp-1, data, 0);    pop_stack();    break;    }    if (data->canonic)    Pike_error("Canonical encoding of programs not supported.\n");    if (!(val->u.program->flags & PROGRAM_FIXED))    Pike_error("Encoding of unfixated programs not supported.\n");    check_stack(1);
pike.git/src/encode.c:1067:    if(p->parent)    {    /* We have to remove ourselves from the cache for now */    struct svalue tmp = entry_id;    EDB(1, fprintf(stderr,    "%*sencode: encoding C program via parent.\n",    data->depth, ""));    map_delete(data->encoded, val);       code_entry(TAG_PROGRAM, 2, data); +  EDB(1, { +  ENCODE_WERR(".entry program, 2"); +  });    ref_push_program(p->parent);    encode_value2(Pike_sp-1, data, 0);       ref_push_program(p);    f_function_name(1);    encode_value2(Pike_sp-1, data, 0);       pop_n_elems(2);       /* Put value back in cache */
pike.git/src/encode.c:1096:    }    }       /* Portable encoding (4 and 5). */       if (!force_encode) {    /* Encode later (5). */    EDB(1, fprintf(stderr, "%*sencode: delayed encoding of program\n",    data->depth, ""));    code_entry (TAG_PROGRAM, 5, data); +  EDB(1, { +  ENCODE_WERR(".entry program, 5"); +  });    data->delayed = append_array (data->delayed, val);    tmp = low_mapping_lookup (data->encoded, val);    if (!tmp)    Pike_error("Internal error in delayed encoder of programs.\n");    tmp->u.integer = CONVERT_ENTRY_ID (tmp->u.integer);    goto encode_done;    }       EDB(1, fprintf(stderr, "%*sencode: encoding program in new style\n",    data->depth, ""));    code_entry(TAG_PROGRAM, 4, data); -  +  EDB(1, { +  ENCODE_WERR(".entry program, 4"); +  });       /* Byte-order. */    code_number(PIKE_BYTEORDER, data);       /* flags */    code_number(p->flags,data);       /* version */    push_compact_version();    encode_value2(Pike_sp-1, data, 0);
pike.git/src/encode.c:1768:       /* name */    push_int(0);    encode_value2(Pike_sp-1, data, 0);    dmalloc_touch_svalue(Pike_sp-1);    Pike_sp--;    }    }    }else{    code_entry(TAG_PROGRAM, 0, data); +  EDB(1, { +  ENCODE_WERR(".entry program"); +  });    encode_value2(Pike_sp-1, data, 0);    pop_stack();    }    break;    }    }      encode_done:;      #ifdef ENCODE_DEBUG