pike.git / src / encode.c

version» Context lines:

pike.git/src/encode.c:17:   #include "dynamic_buffer.h"   #include "error.h"   #include "operators.h"   #include "builtin_functions.h"   #include "module_support.h"   #include "fsort.h"   #include "threads.h"   #include "stuff.h"   #include "version.h"    - RCSID("$Id: encode.c,v 1.35 1999/09/17 23:36:57 hubbe Exp $"); + RCSID("$Id: encode.c,v 1.36 1999/09/18 09:20:44 hubbe Exp $");      #ifdef _AIX   #include <net/nh.h>   #endif      #ifdef HAVE_NETINET_IN_H   #include <netinet/in.h>   #endif      #include <math.h>
pike.git/src/encode.c:71:    struct mapping *encoded;    dynamic_buffer buf;   };      static void encode_value2(struct svalue *val, struct encode_data *data);      #define addstr(s, l) low_my_binary_strcat((s), (l), &(data->buf))   #define addchar(t) low_my_putchar((t),&(data->buf))      /* Code a pike string */ - /* FIXME: Wide strings! */ - #define adddata(S) do { \ -  code_entry(T_STRING, (S)->len, data); \ -  addstr((char *)((S)->str),(S)->len); \ +  + #if BYTEORDER == 4321 + #define ENCODE_DATA(S) \ +  addstr( (S)->str, (S)->len << (S)->size_shift ); + #else + #define ENCODE_DATA(S) \ +  switch((S)->size_shift) \ +  { \ +  case 1: \ +  for(q=0;q<(S)->len;q++) { \ +  INT16 s=htons( STR1(S)[q] ); \ +  addstr( (char *)&s, sizeof(s)); \ +  } \ +  break; \ +  case 2: \ +  for(q=0;q<(S)->len;q++) { \ +  INT32 s=htonl( STR2(S)[q] ); \ +  addstr( (char *)&s, sizeof(s)); \ +  } \ +  break; \ +  } + #endif +  + #define adddata(S) do { \ +  if((S)->size_shift) \ +  { \ +  int q; \ +  code_entry(T_STRING,-1, data); \ +  code_entry((S)->size_shift, (S)->len, data); \ +  ENCODE_DATA(S); \ +  }else{ \ +  code_entry(T_STRING, (S)->len, data); \ +  addstr((char *)((S)->str),(S)->len); \ +  } \   }while(0)      /* Like adddata, but allows null pointers */      #define adddata3(S) do { \    if(S) { \ -  code_entry(T_STRING, (S)->len, data); \ -  addstr((char *)((S)->str),(S)->len); \ +  adddata(S); \    } else { \    code_entry(T_INT, 0, data); \    } \   }while(0)      #define adddata2(s,l) addstr((char *)(s),(l) * sizeof(s[0]));      /* Current encoding: ┬Âik0 */   #define T_AGAIN 15   #define T_MASK 15
pike.git/src/encode.c:273:    }          switch(val->type)    {    case T_INT:    code_entry(T_INT, val->u.integer,data);    break;       case T_STRING: -  code_entry(T_STRING, val->u.string->len,data); -  addstr(val->u.string->str, val->u.string->len); +  adddata(val->u.string);    break;       case T_FLOAT:    {    if(val->u.float_number==0.0)    {    code_entry(T_FLOAT,0,data);    code_entry(T_FLOAT,0,data);    }else{    INT32 x;
pike.git/src/encode.c:488:    for(d=0;d<p->num_identifiers;d++)    {    adddata(p->identifiers[d].name);    encode_type(p->identifiers[d].type->str, data);    code_number(p->identifiers[d].identifier_flags,data);    code_number(p->identifiers[d].run_time_type,data);    code_number(p->identifiers[d].func.offset,data);    }       for(d=0;d<p->num_constants;d++) -  encode_value2(p->constants+d, data); +  { +  encode_value2(& p->constants[d].sval, data); +  adddata3(p->constants[d].name); +  }       for(d=0;d<NUM_LFUNS;d++)    code_number(p->lfuns[d], data);    }else{    code_entry(val->type, 0,data);    encode_value2(sp-1, data);    }    pop_stack();    break;    }
pike.git/src/encode.c:588:    (Y)=num; \    } while(0);      #define getdata2(S,L) do { \    if(data->ptr + (long)(sizeof(S[0])*(L)) > data->len) \    error("Failed to decode string. (string range error)\n"); \    MEMCPY((S),(data->data + data->ptr), sizeof(S[0])*(L)); \    data->ptr+=sizeof(S[0])*(L); \    }while(0)    - #define getdata(X) do { \ -  long length; \ -  decode_entry(T_STRING, length,data); \ -  if(data->ptr + length > data->len || length <0) \ -  error("Failed to decode string. (string range error)\n"); \ -  X=make_shared_binary_string((char *)(data->data + data->ptr), length); \ -  data->ptr+=length; \ + #if BYTEORDER == 4123 + #define BITFLIP(S) + #else + #define BITFLIP(S) \ +  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; \ +  DECODE(); \ +  what&=T_MASK; \ +  if(data->ptr + num > data->len || num <0) \ +  error("Failed to decode string. (string range error)\n"); \ +  STR=begin_wide_shared_string(num, what); \ +  MEMCPY(STR->str, data->data + data->ptr, num << what); \ +  data->ptr+=(num << what); \ +  BITFLIP(STR); \ +  STR=end_shared_string(STR); \ +  }else{ \ +  if(data->ptr + (LEN) > data->len || (LEN) <0) \ +  error("Failed to decode string. (string range error)\n"); \ +  STR=make_shared_binary_string((char *)(data->data + data->ptr), (LEN)); \ +  data->ptr+=(LEN); \ +  } \   }while(0)    -  + #define getdata(X) do { \ +  long length; \ +  decode_entry(T_STRING, length,data); \ +  get_string_data(X, length, data); \ +  }while(0) +    #define getdata3(X) do { \ -  long length; \ -  int what, e, num; \ +  INT32 what, e, num; \    DECODE(); \ -  length=num; \ +     switch(what & T_MASK) \    { \    case T_INT: \    X=0; \    break; \    \    case T_STRING: \ -  if(data->ptr + length > data->len || length <0) \ -  error("Failed to decode string. (string range error)\n"); \ -  X=make_shared_binary_string((char *)(data->data + data->ptr), length); \ -  data->ptr+=length; \ +  get_string_data(X,num,data); \    break; \    \    default: \    error("Failed to decode string, type is wrong: %d\n",what & T_MASK); \    } \   }while(0)      #define decode_number(X,data) do { \    int what, e, num; \    DECODE(); \
pike.git/src/encode.c:762:    }    return;       case T_INT:    tmp=data->counter;    data->counter.u.integer++;    push_int(num);    break;       case T_STRING: +  { +  struct pike_string *str;    tmp=data->counter;    data->counter.u.integer++; -  if(data->ptr + num > data->len) -  error("Failed to decode string. (string range error)\n"); -  push_string(make_shared_binary_string((char *)(data->data + data->ptr), num)); -  data->ptr+=num; +  get_string_data(str, num, data); +  push_string(str);    break; -  +  }       case T_FLOAT:    {    INT32 num2=num;       tmp=data->counter;    data->counter.u.integer++;       DECODE();    push_float(LDEXP((double)num2, num));
pike.git/src/encode.c:1006:    debug_malloc_touch(dat);    MEMSET(dat,0,size);    size=0;   #define FOO(NUMTYPE,TYPE,NAME) \    size=DO_ALIGN(size, ALIGNOF(TYPE)); \    p->NAME=(TYPE *)(dat+size); \    size+=p->PIKE_CONCAT(num_,NAME)*sizeof(p->NAME[0]);   #include "program_areas.h"       for(e=0;e<p->num_constants;e++) -  p->constants[e].type=T_INT; +  p->constants[e].sval.type=T_INT;       debug_malloc_touch(dat);       p->total_size=size + sizeof(struct program);       p->flags |= PROGRAM_OPTIMIZED;       getdata2(p->program, p->num_program);    getdata2(p->linenumbers, p->num_linenumbers);   
pike.git/src/encode.c:1110:    decode_number(p->identifiers[d].identifier_flags,data);    decode_number(p->identifiers[d].run_time_type,data);    decode_number(p->identifiers[d].func.offset,data);    }       debug_malloc_touch(dat);       for(d=0;d<p->num_constants;d++)    {    decode_value2(data); -  p->constants[d]=*--sp; +  p->constants[d].sval=*--sp; +  getdata3(p->constants[d].name);    }    data->pickyness--;       debug_malloc_touch(dat);       for(d=0;d<NUM_LFUNS;d++)    decode_number(p->lfuns[d],data);       debug_malloc_touch(dat);