pike.git / src / encode.c

version» Context lines:

pike.git/src/encode.c:173:    if (data->codec) return data->codec;    MAKE_CONST_STRING (encoder_str, "Encoder");    return data->codec = lookup_codec (encoder_str);   }      /* Convert to/from forward reference ID. */   #define CONVERT_ENTRY_ID(ID) (-((ID) - COUNTER_START) - (-COUNTER_START + 1))      static void encode_value2(struct svalue *val, struct encode_data *data, int force_encode);    + #ifdef PIKE_DEBUG + static void debug_dump_mem(size_t offset, const unsigned char *bytes, +  size_t len) + { +  size_t i; +  for (i = 0; i < len; i += 8) { +  size_t j; +  fprintf(stderr, " %08x: ", offset + i); +  for (j = 0; (i+j < len) && (j < 8); j++) { +  fprintf(stderr, "%02x", bytes[i+j]); +  } +  fprintf(stderr, " "); +  for (j = 0; (i+j < len) && (j < 8); j++) { +  int c = bytes[i+j]; +  if (((c & 0177) < ' ') || (c == 0177)) { +  /* Control or DEL */ +  c = '.'; +  } +  if (c < 0177) { +  /* ASCII */ +  fprintf(stderr, "%c", c); +  } else { +  /* Latin-1 ==> Encode to UTF-8. */ +  fprintf(stderr, "%c%c", 0xc0 | (c>>6), 0x80 | (c & 0x3f)); +  } +  } +  fprintf(stderr, "\n"); +  } + } + static void low_addstr(struct byte_buffer *buf, const char *bytes, +  size_t len, int edb) + { +  if (edb >= 6) { +  debug_dump_mem(buf->length - (((char *)buf->end) - ((char *)buf->dst)), +  bytes, len); +  } +  buffer_memcpy(buf, bytes, len); + } + static void low_addchar(struct byte_buffer *buf, int c, int edb) + { +  char byte = c; +  low_addstr(buf, &byte, 1, edb); + } + #define addstr(s, l) low_addstr(&(data->buf), (s), (l), data->debug) + #define addchar(t) low_addchar(&(data->buf), (t), data->debug) + #define addchar_unsafe(t) addchar(t) + #else   #define addstr(s, l) buffer_memcpy(&(data->buf), (s), (l))   #define addchar(t) buffer_add_char(&(data->buf), (char)(t))   #define addchar_unsafe(t) buffer_add_char_unsafe(&(data->buf), t) -  + #endif      /* Code a pike string */      #if PIKE_BYTEORDER == 4321   #define ENCODE_DATA(S) \    addstr( (S)->str, (S)->len << (S)->size_shift );   #else   #define ENCODE_DATA(S) do { \    buffer_ensure_space(&(data->buf), (S)->len << (S)->size_shift); \    if ((S)->size_shift == 1) { \
pike.git/src/encode.c:1928:    MAKE_CONST_STRING (decoder_str, "Decoder");    return data->codec = lookup_codec (decoder_str);   }      static void decode_value2(struct decode_data *data);      static int my_extract_char(struct decode_data *data)   {    if(data->ptr >= data->len)    Pike_error("Not enough data in string.\n"); +  + #ifdef PIKE_DEBUG +  if (data->debug >= 6) { +  debug_dump_mem(data->ptr, data->data + data->ptr, 1); +  } + #endif /* PIKE_DEBUG */    return data->data [ data->ptr++ ];   }      static DECLSPEC(noreturn) void decode_error (    struct decode_data *data, struct svalue *decoding, const char *msg, ...)    ATTRIBUTE((noinline,noreturn));      static DECLSPEC(noreturn) void decode_error (    struct decode_data *data, struct svalue *decoding, const char *msg, ...)   {
pike.git/src/encode.c:1977:    f_add (n);    gen->error_message = (--Pike_sp)->u.string;       generic_error_va (o, NULL, NULL, 0, NULL, NULL);   }      #define GETC() my_extract_char(data)      #define DECODE(Z) do { \    EDB(5, \ -  fprintf(stderr,"%*sdecode(%s) at %d: ", \ +  fprintf(stderr,"%*sdecode(%s) at %d:\n", \    data->depth,"",(Z),__LINE__)); \    what=GETC(); \    e=what>>SIZE_SHIFT; \    if(what & TAG_SMALL) { \    num=e; \    } else { \    num = 0; \    while(e-->=0) num = ((UINT64)num<<8) \    + (GETC()+1); \    num += MAX_SMALL - 1; \    } \    if(what & TAG_NEG) { \    num = ~num; \    } \    EDB(5, \ -  fprintf(stderr,"type=%d (%s), num=%ld\n", \ -  (what & TAG_MASK), \ +  fprintf(stderr,"%*s==> type=%d (%s), num=%ld\n", \ +  data->depth,"",(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; \    INT64 num; \    DECODE("decode_entry"); \    if((what & TAG_MASK) != (X)) \
pike.git/src/encode.c:2038:    if(what<0 || what>2) \    decode_error (data, NULL, "Illegal size shift %d.\n", what); \    sz = (ptrdiff_t) num << what; \    if (sz < 0) \    decode_error (data, NULL, "Illegal negative size %td.\n", sz); \    if (sz > data->len - data->ptr) \    decode_error (data, NULL, "Too large size %td (max is %td).\n", \    sz, data->len - data->ptr); \    STR=begin_wide_shared_string(num, what); \    memcpy(STR->str, data->data + data->ptr, sz); \ +  EDB(6, debug_dump_mem(data->ptr, data->data + data->ptr, sz)); \    data->ptr += sz; \    BITFLIP(STR); \    STR=end_shared_string(STR); \    }else{ \    ptrdiff_t sz = (LEN); \    if (sz < 0) \    decode_error (data, NULL, "Illegal negative size %td.\n", sz); \    if (sz > data->len - data->ptr) \    decode_error (data, NULL, "Too large size %td (max is %td).\n", \    sz, data->len - data->ptr); \    STR=make_shared_binary_string((char *)(data->data + data->ptr), sz); \ -  +  EDB(6, debug_dump_mem(data->ptr, data->data + data->ptr, sz)); \    data->ptr += sz; \    } \   }while(0)      #define decode_number(X,data) do { \    INT32 what, e; \    INT64 num; \    DECODE("decode_number"); \    X=(what & TAG_MASK) | ((UINT64)num<<4); \    EDB(5, fprintf(stderr, "%*s ==>%ld\n", \
pike.git/src/encode.c:2159:    case T_NOT:    low_decode_type(data);    push_type(tmp);    break;       case T_INT:    {    INT32 min=0, max=0;    if(data->ptr + 8 > data->len)    decode_error(data, NULL, "Not enough data.\n"); +  EDB(6, debug_dump_mem(data->ptr, data->data + data->ptr, 8));    min = get_unaligned_be32(data->data + data->ptr);    data->ptr += 4;    max = get_unaligned_be32(data->data + data->ptr);    data->ptr += 4;       if (min > max)    decode_error(data, NULL, "Error in int type (min (%d) > max (%d)).\n", min, max);       push_int_type(min, max);    }