pike.git / src / encode.c

version» Context lines:

pike.git/src/encode.c:1:   /*   || 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: encode.c,v 1.277 2008/06/09 13:36:04 grubba Exp $ + || $Id: encode.c,v 1.278 2008/06/11 17:25:10 grubba Exp $   */      #include "global.h"   #include "stralloc.h"   #include "pike_macros.h"   #include "object.h"   #include "constants.h"   #include "interpret.h"   #include "svalue.h"   #include "mapping.h"
pike.git/src/encode.c:219:       if(num < MAX_SMALL)    {    tag |= TAG_SMALL | (num << SIZE_SHIFT);    addchar((char)tag);    return;    }else{    num -= MAX_SMALL;    }    -  for(t = 0; (size_t)t < - #if 0 -  (sizeof(INT64)-1); - #else /* !0 */ -  (size_t)3; - #endif /* 0 */ -  t++) +  for(t = 0; (size_t)t < 7; t++)    {    if(num >= (((INT64)256) << (t<<3)))    num -= (((INT64)256) << (t<<3));    else    break;    }       tag |= t << SIZE_SHIFT;    addchar((char)tag);       switch(t)    { - #if 0 +     case 7: addchar(DO_NOT_WARN((char)((num >> 56)&0xff)));    case 6: addchar(DO_NOT_WARN((char)((num >> 48)&0xff)));    case 5: addchar(DO_NOT_WARN((char)((num >> 40)&0xff)));    case 4: addchar(DO_NOT_WARN((char)((num >> 32)&0xff))); - #endif /* 0 */ +     case 3: addchar(DO_NOT_WARN((char)((num >> 24)&0xff)));    case 2: addchar(DO_NOT_WARN((char)((num >> 16)&0xff)));    case 1: addchar(DO_NOT_WARN((char)((num >> 8)&0xff)));    case 0: addchar(DO_NOT_WARN((char)(num&0xff)));    }   }      static void code_number(ptrdiff_t num, struct encode_data *data)   {    EDB(5, fprintf(stderr, "%*scode_number(%d)\n",
pike.git/src/encode.c:2068:   }      #define GETC() my_extract_char(data)      #define DECODE(Z) do { \    EDB(5, \    fprintf(stderr,"%*sdecode(%s) at %d: ", \    data->depth,"",(Z),__LINE__)); \    what=GETC(); \    e=what>>SIZE_SHIFT; \ -  numh=0; \ +     if(what & TAG_SMALL) { \    num=e; \    } else { \ -  INT32 numl; \ -  num=0; \ -  while(e > 4) { \ -  numh = (numh<<8) + (GETC()+1); \ -  e--; \ +  num = 0; \ +  while(e-->=0) num = (num<<8) + (GETC()+1); \ +  num += MAX_SMALL - 1; \    } \ -  while(e-->=0) num=(num<<8) + (GETC()+1); \ -  numl = num + MAX_SMALL - 1; \ -  if (numl < num) numh++; \ -  num = numl; \ -  } \ +     if(what & TAG_NEG) { \    num = ~num; \ -  numh = ~numh; \ +     } \    EDB(5, \ -  fprintf(stderr,"type=%d (%s), num=%ld\n", \ -  (what & TAG_MASK), \ -  get_name_of_type(tag_to_type(what & TAG_MASK)), \ -  (long)num) ); \ +  fprintf(stderr,"type=%d (%s), num=%ld\n", \ +  (what & TAG_MASK), \ +  get_name_of_type(tag_to_type(what & TAG_MASK)), \ +  (long)num) ); \   } while (0)            #define decode_entry(X,Y,Z) \    do { \ -  INT32 what, e, num, numh; \ +  INT32 what, e; \ +  INT64 num; \    DECODE("decode_entry"); \    if((what & TAG_MASK) != (X)) \    Pike_error("Failed to decode, wrong bits (%d).\n", what & TAG_MASK); \    (Y)=num; \    } while(0);      #define getdata2(S,L) do { \    if(data->ptr + (ptrdiff_t)(sizeof(S[0])*(L)) > data->len) \    Pike_error("Failed to decode string. (string range error)\n"); \    MEMCPY((S),(data->data + data->ptr), sizeof(S[0])*(L)); \
pike.git/src/encode.c:2126:    switch(what) \    { \    case 1: for(e=0;e<num;e++) STR1(S)[e]=ntohs(STR1(S)[e]); break; \    case 2: for(e=0;e<num;e++) STR2(S)[e]=ntohl(STR2(S)[e]); break; \    }   #endif      #define get_string_data(STR,LEN, data) do { \    if((LEN) == -1) \    { \ -  INT32 what, e, num, numh; \ +  INT32 what, e; \ +  INT64 num; \    ptrdiff_t sz; \    DECODE("get_string_data"); \    what &= TAG_MASK; \    if(what<0 || what>2) \    Pike_error ("Failed to decode string: Illegal size shift %d.\n", \    what); \    sz = (ptrdiff_t) num << what; \    if (sz < 0) \    Pike_error ("Failed to decode string: Illegal negative size " \    "%"PRINTPTRDIFFT"d.\n", sz); \
pike.git/src/encode.c:2170:   #define getdata(X) do { \    long length; \    decode_entry(TAG_STRING, length,data); \    if(data->pass == 1) \    get_string_data(X, length, data); \    else \    data->ptr+=length; \    }while(0)      #define getdata3(X) do { \ -  INT32 what, e, num, numh; \ +  INT32 what, e; \ +  INT64 num; \    DECODE("getdata3"); \    switch(what & TAG_MASK) \    { \    case TAG_INT: \    X=0; \    break; \    \    case TAG_STRING: \    get_string_data(X,num,data); \    break; \    \    default: \    Pike_error("Failed to decode string, tag is wrong: %d\n", \    what & TAG_MASK); \    } \   }while(0)    - #define decode_number(X,data) do { \ -  INT32 what, e, num, numh; \ + #define decode_number(X,data) do { \ +  INT32 what, e; \ +  INT64 num; \    DECODE("decode_number"); \    X=(what & TAG_MASK) | (num<<4); \    EDB(5, fprintf(stderr, "%*s ==>%ld\n", \    data->depth, "", (long) X)); \    }while(0) \         static void restore_type_stack(struct pike_type **old_stackp)   {   #if 0
pike.git/src/encode.c:2624:      static void decode_value2(struct decode_data *data)      #ifdef PIKE_DEBUG   #undef decode_value2   #define decode_value2(X) do { struct svalue *_=Pike_sp; decode_value2_(X); if(Pike_sp!=_+1) Pike_fatal("decode_value2 failed!\n"); } while(0)   #endif         { -  INT32 what, e, num, numh; +  INT32 what, e; +  INT64 num;    struct svalue entry_id, *tmp2;    struct svalue *delayed_enc_val;      #ifdef ENCODE_DEBUG    data->depth += 2;   #endif       DECODE("decode_value2");       switch(what & TAG_MASK)
pike.git/src/encode.c:2697:    struct pike_string *str;    get_string_data(str, num, data);    push_string(str);    break;    }       case TAG_FLOAT:    {    double res;    -  EDB(2,fprintf(stderr, "Decoding float... numh:0x%08x, num:0x%08x\n", -  numh, num)); +  EDB(2,fprintf(stderr, "Decoding float... num:0x%016" PRINTINT64 "x\n", +  num));    -  res = LDEXP((double)numh, 32) + (double)(unsigned INT32)num; +  res = (double)num;       EDB(2,fprintf(stderr, "Mantissa: %10g\n", res));       DECODE("float");       EDB(2,fprintf(stderr, "Exponent: %d\n", num));       if(!res)    {    DECLARE_INF