pike.git / src / encode.c

version» Context lines:

pike.git/src/encode.c:19:   #include "operators.h"   #include "builtin_functions.h"   #include "module_support.h"   #include "fsort.h"   #include "threads.h"   #include "stuff.h"   #include "version.h"   #include "bignum.h"   #include "pikecode.h"    - RCSID("$Id: encode.c,v 1.148 2002/06/11 17:41:36 mast Exp $"); + RCSID("$Id: encode.c,v 1.149 2002/06/25 14:26:40 grubba Exp $");      /* #define ENCODE_DEBUG */      /* Use the old encoding method for programs. */   #define OLD_PIKE_ENCODE_PROGRAM      #ifdef ENCODE_DEBUG   /* Pass a nonzero integer as the third arg to encode_value,    * encode_value_canonic and decode_value to activate this debug. */   #define EDB(N,X) do { debug_malloc_touch(data); if (data->debug>=N) {X;} } while (0)
pike.git/src/encode.c:244:    num >> 4, data);   }      #ifdef _REENTRANT   static void do_enable_threads(void)   {    exit_threads_disable(NULL);   }   #endif    - #ifdef USE_PIKE_TYPE +    /* NOTE: Take care to encode it exactly as the corresponing    * type string would have been encoded (cf TFUNCTION, T_MANY).    */   static void encode_type(struct pike_type *t, struct encode_data *data)   {    one_more_type:    if (t->type == T_MANY) {    addchar(T_FUNCTION);    addchar(T_MANY);    } else if (t->type != PIKE_T_NAME) {
pike.git/src/encode.c:366: Inside #if defined(USE_PIKE_TYPE)
   push_int( id );    }else{    push_int(0);    }    encode_value2(Pike_sp-1, data);    pop_stack();    break;    }    }   } - #else /* !USE_PIKE_TYPE */ - static ptrdiff_t low_encode_type(unsigned char *t, struct encode_data *data) - { -  unsigned char *q = t; - one_more_type: -  addchar(EXTRACT_UCHAR(t)); -  switch(EXTRACT_UCHAR(t++)) -  { -  default: -  fatal("error in type string: %d.\n", t[-1]); -  /*NOTREACHED*/ +     -  break; -  -  case T_ASSIGN: -  addchar(EXTRACT_UCHAR(t++)); -  goto one_more_type; -  -  case T_FUNCTION: -  while(EXTRACT_UCHAR(t)!=T_MANY) -  t += low_encode_type(t, data); -  addchar(EXTRACT_UCHAR(t++)); -  -  case T_MAPPING: -  case T_OR: -  case T_AND: -  t += low_encode_type(t, data); -  -  case T_TYPE: -  case T_PROGRAM: -  case T_ARRAY: -  case T_MULTISET: -  case T_NOT: -  goto one_more_type; -  -  case T_INT: -  { -  int i; -  /* FIXME: I assume the type is saved in network byte order. Is it? -  * /grubba 1999-03-07 -  * Yes - Hubbe -  */ -  for(i = 0; i < (int)(2*sizeof(INT32)); i++) { -  addchar(EXTRACT_UCHAR(t++)); -  } -  } -  break; -  -  case '0': -  case '1': -  case '2': -  case '3': -  case '4': -  case '5': -  case '6': -  case '7': -  case '8': -  case '9': -  case T_FLOAT: -  case T_STRING: -  case T_MIXED: -  case T_ZERO: -  case T_VOID: -  case PIKE_T_UNKNOWN: -  break; -  -  case T_OBJECT: -  { -  INT32 x; -  addchar(EXTRACT_UCHAR(t++)); -  x=EXTRACT_INT(t); -  t+=sizeof(INT32); -  if(x >= PROG_DYNAMIC_ID_START) -  { -  struct program *p=id_to_program(x); -  if(p) -  { -  ref_push_program(p); -  }else{ -  push_int(0); -  } -  }else{ -  push_int(x); -  } -  encode_value2(Pike_sp-1, data); -  pop_stack(); -  break; -  } -  } -  return t-q; - } -  - static void encode_type(struct pike_type *t, struct encode_data *data) - { -  low_encode_type(t->str, data); - } - #endif /* USE_PIKE_TYPE */ -  +    static void zap_unfinished_program(struct program *p)   {    int e;    debug_malloc_touch(p);    if(p->flags & PROGRAM_FIXED) return; /* allow natural zapping */    if(p->parent)    {    free_program(p->parent);    p->parent=0;    }
pike.git/src/encode.c:1860: Inside #if 0
  {   #if 0    fprintf(stderr, "Restoring type-stack: %p => %p\n",    Pike_compiler->type_stackp, old_stackp);   #endif /* 0 */   #ifdef PIKE_DEBUG    if (old_stackp > Pike_compiler->type_stackp) {    fatal("type stack out of sync!\n");    }   #endif /* PIKE_DEBUG */ - #ifdef USE_PIKE_TYPE +     while(Pike_compiler->type_stackp > old_stackp) {    free_type(*(Pike_compiler->type_stackp--));    } - #else -  Pike_compiler->type_stackp = old_stackp; - #endif +    }      static void restore_type_mark(struct pike_type ***old_type_mark_stackp)   {   #if 0    fprintf(stderr, "Restoring type-mark: %p => %p\n",    Pike_compiler->pike_type_mark_stackp, old_type_mark_stackp);   #endif /* 0 */   #ifdef PIKE_DEBUG    if (old_type_mark_stackp > Pike_compiler->pike_type_mark_stackp) {
pike.git/src/encode.c:1894:   {    /* FIXME: Probably ought to use the tag encodings too. */       int tmp;    ONERROR err1;    ONERROR err2;       SET_ONERROR(err1, restore_type_stack, Pike_compiler->type_stackp);    SET_ONERROR(err2, restore_type_mark, Pike_compiler->pike_type_mark_stackp);    - #ifndef USE_PIKE_TYPE - one_more_type: - #endif /* !USE_PIKE_TYPE */ +     tmp = GETC();    switch(tmp)    {    default:    Pike_error("decode_value(): Error in type string (%d).\n", tmp);    /*NOTREACHED*/    break;       case T_ASSIGN:    tmp = GETC();    if ((tmp < '0') || (tmp > '9')) {    Pike_error("decode_value(): Bad marker in type string (%d).\n", tmp);    } - #ifdef USE_PIKE_TYPE +     low_decode_type(data);    push_assign_type(tmp); /* Actually reverse, but they're the same */    break; - #else /* !USE_PIKE_TYPE */ -  push_type(T_ASSIGN); -  push_type(tmp); -  goto one_more_type; - #endif /* USE_PIKE_TYPE */ +        case T_FUNCTION: - #ifdef USE_PIKE_TYPE +     {    int narg = 0;       while (GETC() != T_MANY) {    data->ptr--;    low_decode_type(data);    narg++;    }    low_decode_type(data); /* Many */    low_decode_type(data); /* Return */    push_reverse_type(T_MANY);    while(narg-- > 0) {    push_reverse_type(T_FUNCTION);    }    }    break; - #else /* !USE_PIKE_TYPE */ -  push_type(tmp); -  while(GETC()!=T_MANY) -  { -  data->ptr--; -  low_decode_type(data); -  } -  push_type(T_MANY); -  low_decode_type(data); -  goto one_more_type; - #endif /* USE_PIKE_TYPE */ +        case T_MAPPING:    case T_OR:    case T_AND: - #ifdef USE_PIKE_TYPE +     low_decode_type(data);    low_decode_type(data);    push_reverse_type(tmp);    break; - #else /* !USE_PIKE_TYPE */ -  push_type(tmp); -  low_decode_type(data); -  goto one_more_type; - #endif /* USE_PIKE_TYPE */ +        case T_TYPE:    case T_PROGRAM:    case T_ARRAY:    case T_MULTISET:    case T_NOT: - #ifdef USE_PIKE_TYPE +     low_decode_type(data);    push_type(tmp);    break; - #else /* !USE_PIKE_TYPE */ -  push_type(tmp); -  goto one_more_type; - #endif /* USE_PIKE_TYPE */ +        case T_INT: - #ifdef USE_PIKE_TYPE +     {    INT32 min=0, max=0;    min = GETC();    min = (min<<8)|GETC();    min = (min<<8)|GETC();    min = (min<<8)|GETC();    max = GETC();    max = (max<<8)|GETC();    max = (max<<8)|GETC();    max = (max<<8)|GETC();    push_int_type(min, max);    } - #else /* !USE_PIKE_TYPE */ -  { -  int i; -  push_type(tmp); -  /* FIXME: I assume the type is saved in network byte order. Is it? -  * /grubba 1999-03-07 -  */ -  for(i = 0; i < (int)(2*sizeof(INT32)); i++) { -  push_type(GETC()); -  } -  } - #endif /* USE_PIKE_TYPE */ +     break;       case '0':    case '1':    case '2':    case '3':    case '4':    case '5':    case '6':    case '7':
pike.git/src/encode.c:2106:    mapping_insert(data->decoded, & data->counter, &tmp); \    /* Since a reference to the object is stored in the mapping, we can \    * safely decrease this reference here. Thus it will be automatically \    * freed if something goes wrong. \    */ \    VAR->refs--; \    } \    data->counter.u.integer++; \   }while(0)    - #ifdef USE_PIKE_TYPE +    /* This really needs to disable threads.... */   #define decode_type(X,data) do { \    type_stack_mark(); \    low_decode_type(data); \    (X)=pop_unfinished_type(); \   } while(0) - #else /* !USE_PIKE_TYPE */ - /* This really needs to disable threads.... */ - #define decode_type(X,data) do { \ -  type_stack_mark(); \ -  type_stack_mark(); \ -  low_decode_type(data); \ -  type_stack_reverse(); \ -  (X)=pop_unfinished_type(); \ - } while(0) - #endif /* USE_PIKE_TYPE */ +       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) fatal("decode_value2 failed!\n"); } while(0)   #endif         {