pike.git / src / encode.c

version» Context lines:

pike.git/src/encode.c:18:   #include "pike_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"   #include "bignum.h"    - RCSID("$Id: encode.c,v 1.87 2002/04/12 09:30:12 grubba Exp $"); + RCSID("$Id: encode.c,v 1.88 2002/04/12 11:31:45 grubba Exp $");      /* #define ENCODE_DEBUG */      #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 if (data->debug>=N) {X;} while (0)   #else   #define EDB(N,X) do {} while (0)   #endif
pike.git/src/encode.c:730:    (p->flags & PROGRAM_HAS_C_METHODS))    Pike_error("Cannot encode C programs.\n");       EDB(1,    fprintf(stderr, "%*sencode: encoding program\n",    data->depth, ""));       /* Type 2 -- Portable encoding. */    code_entry(type_to_tag(val->type), 2, data);    -  /* version */ -  f_version(0); -  encode_value2(Pike_sp-1,data); -  pop_stack(); -  +     /* Byte-order. */    code_number(PIKE_BYTEORDER, data);       /* flags */    code_number(p->flags,data);    -  +  /* version */ +  f_version(0); +  encode_value2(Pike_sp-1,data); +  pop_stack(); +     /* num_* */   #define FOO(X,Y,Z) \    code_number( p->PIKE_CONCAT(num_,Z), data);   #include "program_areas.h"       /* Byte-code method    *    * (Forward compatibility)    */    code_number(0, data);
pike.git/src/encode.c:776:       {    struct svalue str_sval;    str_sval.type = T_STRING;    str_sval.subtype = 0;    /* strings */    for(d=0;d<p->num_strings;d++) {    str_sval.u.string = p->strings[d];    encode_value2(&str_sval, data);    } -  -  /* constants */ -  for(d=0;d<p->num_constants;d++) -  { -  /* value */ -  encode_value2(&p->constants[d].sval, data); -  -  /* name */ -  if (p->constants[d].name) { -  str_sval.u.string = p->constants[d].name; -  encode_value2(&str_sval, data); -  } else { -  push_int(0); -  encode_value2(Pike_sp-1, data); -  Pike_sp--; +     } -  } -  } +        EDB(5,    {    fprintf(stderr,    "%*sencode: Reference table:\n"    "%*s ####: Flags Inherit Identifier\n",    data->depth, "", data->depth, "");    for (d=0; d < p->num_identifier_references; d++) {    struct reference *ref = p->identifier_references + d;   
pike.git/src/encode.c:900:    code_number(ID_ENTRY_CONSTANT, data);    code_number(ref->id_flags, data);       /* name */    str_sval.u.string = id->name;    encode_value2(&str_sval, data);       /* offset */    code_number(id->func.offset, data);    +  /* type */ +  str_sval.u.string = id->type; +  str_sval.type = T_TYPE; +  encode_value2(&str_sval, data); +  str_sval.type = T_STRING; +  +  /* run-time type */ +  code_number(id->run_time_type, data); +     /* Verify that we can restore the id */    if (ref->identifier_offset != local_num_identifiers) {    Pike_error("Constant identifier offset mismatch: %d != %d\n",    ref->identifier_offset, local_num_identifiers);    }    local_num_identifiers++;    } else if (IDENTIFIER_IS_PIKE_FUNCTION(id->identifier_flags)) {    /* Pike function */    EDB(3,    fprintf(stderr, "%*s encode: encoding function\n",
pike.git/src/encode.c:1068: Inside #if 0
      /* parent_offset */    code_number(inh->parent_offset);       d += inh->prog->num_identifier_references;    }   #endif /* 0 */    /* End-marker */    code_number(ID_ENTRY_EOT, data);    } +  +  { +  struct svalue str_sval; +  str_sval.type = T_STRING; +  str_sval.subtype = 0; +  +  /* constants */ +  for(d=0;d<p->num_constants;d++) +  { +  /* value */ +  encode_value2(&p->constants[d].sval, data); +  +  /* name */ +  if (p->constants[d].name) { +  str_sval.u.string = p->constants[d].name; +  encode_value2(&str_sval, data); +  } else { +  push_int(0); +  encode_value2(Pike_sp-1, data); +  Pike_sp--; +  } +  } +  }    }else{    code_entry(type_to_tag(val->type), 0,data);    encode_value2(Pike_sp-1, data);    }    pop_stack();    break;    }    }      #ifdef ENCODE_DEBUG
pike.git/src/encode.c:2254:    ONERROR err;    int byteorder;    int bytecode_method;    int entry_type;    INT16 id_flags;    INT16 p_flags;   #define FOO(NUMTYPE,Y,NAME) \    NUMTYPE PIKE_CONCAT(local_num_, NAME) = 0;   #include "program_areas.h"    -  /* Check the version. */ -  decode_value2(data); -  f_version(0); -  if(!is_eq(Pike_sp-1,Pike_sp-2)) -  Pike_error("Cannot decode programs encoded with other pike version.\n"); -  pop_n_elems(2); -  -  debug_malloc_touch(p); -  +     /* Decode byte-order. */    decode_number(byteorder, data);       if ((byteorder != PIKE_BYTEORDER)   #if (PIKE_BYTEORDER == 1234)    && (byteorder != 4321)   #else   #if (PIKE_BYTEORDER == 4321)    && (byteorder != 1234)   #endif
pike.git/src/encode.c:2304:    tmp.u.program=p;    EDB(2,fprintf(stderr, "%*sDecoding a program to <%d>: ",    data->depth, "", data->counter.u.integer);    print_svalue(stderr, &tmp);    fputc('\n', stderr););    mapping_insert(data->decoded, & data->counter, &tmp);    data->counter.u.integer++;       debug_malloc_touch(p);    +  /* Check the version. */ +  decode_value2(data); +  f_version(0); +  if(!is_eq(Pike_sp-1,Pike_sp-2)) +  Pike_error("Cannot decode programs encoded with other pike version.\n"); +  pop_n_elems(2); +  +  debug_malloc_touch(p); +     /* Decode lengths. */   #define FOO(X,Y,NAME) decode_number(PIKE_CONCAT(local_num_, NAME), data);   #include "program_areas.h"       /* Byte-code method */    decode_number(bytecode_method, data);    if (bytecode_method) {    Pike_error("Unsupported byte-code method: %d\n", bytecode_method);    }   
pike.git/src/encode.c:2369:    /* Decode strings */    for (e=0; e<local_num_strings; e++) {    decode_value2(data);    if (Pike_sp[-1].type != T_STRING) {    Pike_error("Non strings in string table.\n");    }    add_to_strings(Pike_sp[-1].u.string);    Pike_sp--;    }    -  /* Decode constants */ -  for (e=0; e<local_num_constants; e++) { +  /* Place holder constants. +  * +  * These will be replaced later on. +  */ +  {    struct program_constant constant; -  /* value */ -  decode_value2(data); -  constant.sval = Pike_sp[-1]; -  /* name */ -  decode_value2(data); -  if (Pike_sp[-1].type == T_STRING) { -  constant.name = Pike_sp[-1].u.string; -  } else if ((Pike_sp[-1].type == T_INT) && -  !Pike_sp[-1].u.integer) { +     constant.name = NULL; -  } else { -  Pike_error("Non strings in string table.\n"); -  } +  constant.sval.type = T_INT; +  constant.sval.subtype = NUMBER_UNDEFINED; +  constant.sval.u.integer = 0;    -  +  for(e=0;e<local_num_constants;e++) {    add_to_constants(constant); -  Pike_sp -= 2; +     } -  +  }       /* Decode identifier_references, inherits and identifiers. */    decode_number(entry_type, data);    while (entry_type != ID_ENTRY_EOT) {    decode_number(id_flags, data);    switch(entry_type) {    case ID_ENTRY_VARIABLE:    {    /* name */    decode_value2(data);
pike.git/src/encode.c:2485:    id.identifier_flags = IDENTIFIER_CONSTANT;       /* offset */    decode_number(id.func.offset, data);       /* FIXME:    * Verify validity of func.offset    */       /* type */ -  push_string(get_type_of_svalue(&p->constants[id.func.offset].sval)); +  decode_value2(data); +  if (Pike_sp[-1].type != T_TYPE) { +  Pike_error("Bad function type (not a type)\n"); +  }    id.type = Pike_sp[-1].u.string;       /* run_time_type */ -  id.run_time_type = p->constants[id.func.offset].sval.type; +  decode_number(id.run_time_type, data);      #ifdef PROFILING    id.self_time=0;    id.num_calls=0;    id.total_time=0;   #endif       /* id_flags */    ref.id_flags = id_flags;   
pike.git/src/encode.c:2589:    end_first_pass(2);       /* Verify... */   #define FOO(NUMTYPE,Y,NAME) \    if (PIKE_CONCAT(local_num_, NAME) != p->PIKE_CONCAT(num_,NAME)) { \    Pike_error("Value mismatch for num_" TOSTR(NAME) ": %d != %d\n", \    PIKE_CONCAT(local_num_, NAME), \    p->PIKE_CONCAT(num_, NAME)); \    }   #include "program_areas.h" +  +  /* Decode the actual constants +  * +  * This must be done after the program has been ended. +  */ +  for (e=0; e<local_num_constants; e++) { +  struct program_constant *constant = p->constants+e; +  /* value */ +  decode_value2(data); +  /* name */ +  decode_value2(data); +  if (Pike_sp[-1].type == T_STRING) { +  constant->name = Pike_sp[-1].u.string; +  } else if ((Pike_sp[-1].type == T_INT) && +  !Pike_sp[-1].u.integer) { +  constant->name = NULL; +  } else { +  Pike_error("Non strings in string table.\n");    } -  +  constant->sval = Pike_sp[-2]; +  Pike_sp -= 2; +  } +  }    break;       default:    Pike_error("Cannot decode program encoding type %d\n",num);    }    break;       default:    Pike_error("Failed to restore string. (Illegal type)\n");    }
pike.git/src/encode.c:2846:    }   }      void f_decode_value(INT32 args)   {    struct pike_string *s;    struct object *codec;      #ifdef ENCODE_DEBUG    int debug; + #endif    check_all_args("decode_value", args,    BIT_STRING, BIT_VOID | BIT_OBJECT | BIT_INT, BIT_VOID | BIT_INT, 0); -  +  + #ifdef ENCODE_DEBUG    debug = args > 2 ? Pike_sp[2-args].u.integer : 0; - #else -  check_all_args("decode_value", args, -  BIT_STRING, BIT_VOID | BIT_OBJECT | BIT_INT, 0); +    #endif       s = Pike_sp[-args].u.string;    if(args<2)    {    codec=get_master();    }    else if(Pike_sp[1-args].type == T_OBJECT)    {    codec=Pike_sp[1-args].u.object;