Branch: Tag:

2002-04-12

2002-04-12 11:31:45 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Fixed type for decode_value().
Fixed decoding of circular references to programs.
Fixed decoding of program constants.

Rev: src/builtin_functions.c:1.358
Rev: src/encode.c:1.88

25:   #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 */   
737:    /* 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);
783:    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,    {
907:    /* 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",
1075:    /* 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);
2261:    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);   
2311:       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"
2376:    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);
2492:    */       /* 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;
2596:    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:
2853: Inside #if defined(ENCODE_DEBUG)
     #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;