pike.git / src / encode.c

version» Context lines:

pike.git/src/encode.c:2174:    *! when Pike programs are actually dumped in full, then the string    *! can probably only be read by the same pike version.    *!    *! @seealso    *! @[decode_value()], @[sprintf()], @[encode_value_canonic()]    */   void f_encode_value(INT32 args)   {    ONERROR tmp;    struct encode_data d, *data; + #ifdef ENCODE_DEBUG    struct string_builder debug_buf; -  + #endif    int i;    data=&d;       check_all_args(NULL, args,    BIT_MIXED,    BIT_VOID | BIT_OBJECT | BIT_ZERO,   #ifdef ENCODE_DEBUG    /* This argument is only an internal debug helper.    * It's intentionally not part of the function    * prototype, to keep the argument position free for    * other uses in the future. */ -  BIT_VOID | BIT_INT, +  BIT_VOID | BIT_INT | BIT_OBJECT,   #endif    0);       buffer_init(&data->buf);    data->canonic = 0;    data->encoded=allocate_mapping(128);    data->encoded->data->flags |= MAPPING_FLAG_NO_SHRINK;    data->delayed = allocate_array (0);    SET_SVAL(data->counter, T_INT, NUMBER_NUMBER, integer, COUNTER_START);      #ifdef ENCODE_DEBUG    data->debug_buf = NULL;    data->debug_pos = 0; -  data->debug = args > 2 ? Pike_sp[2-args].u.integer : 0; -  data->depth = -2; -  if (data->debug) { +  data->debug = 0; +  if (args > 2) { +  if (TYPEOF(Pike_sp[2-args]) == PIKE_T_OBJECT) { +  struct object *sb = Pike_sp[2-args].u.object; +  if ((data->debug_buf = string_builder_from_string_buffer(sb))) { +  data->debug = 1; +  } +  } else { +  if ((data->debug = Pike_sp[2-args].u.integer)) {    init_string_builder(&debug_buf, 0);    data->debug_buf = &debug_buf;    } -  +  } +  } +  data->depth = -2;   #endif       if(args > 1 && TYPEOF(Pike_sp[1-args]) == T_OBJECT)    {    if (SUBTYPEOF(Pike_sp[1-args]))    Pike_error("The codec may not be a subtyped object yet.\n");       data->codec=Pike_sp[1-args].u.object;    add_ref (data->codec);    }else{
pike.git/src/encode.c:2256:    UNSET_ONERROR(tmp);       EDB(1, {    ENCODE_FLUSH();    });       if (data->codec) free_object (data->codec);    free_mapping(data->encoded);    free_array (data->delayed);    -  EDB(1, { + #ifdef ENCODE_DEBUG +  if (data->debug_buf == &debug_buf) {    write_and_reset_string_builder(2, data->debug_buf);    free_string_builder(data->debug_buf); -  }); +  } + #endif       pop_n_elems(args);    push_string(buffer_finish_pike_string(&data->buf));   }      /*! @decl string encode_value_canonic(mixed value, object|void codec)    *!    *! Code a value into a string on canonical form.    *!    *! Takes a value and converts it to a string on canonical form, much like
pike.git/src/encode.c:2287:    *! respect to the types of values it can encode. It will throw an error    *! if it can't encode to a canonical form.    *!    *! @seealso    *! @[encode_value()], @[decode_value()]    */   void f_encode_value_canonic(INT32 args)   {    ONERROR tmp;    struct encode_data d, *data; + #ifdef ENCODE_DEBUG +  struct string_builder debug_buf; + #endif    int i;    data=&d;       check_all_args(NULL, args,    BIT_MIXED,    BIT_VOID | BIT_OBJECT | BIT_ZERO,   #ifdef ENCODE_DEBUG    /* This argument is only an internal debug helper.    * It's intentionally not part of the function    * prototype, to keep the argument position free for    * other uses in the future. */ -  BIT_VOID | BIT_INT, +  BIT_VOID | BIT_INT | BIT_OBJECT,   #endif    0);       buffer_init(&data->buf);    data->canonic = 1;    data->encoded=allocate_mapping(128);    data->delayed = allocate_array (0);    SET_SVAL(data->counter, T_INT, NUMBER_NUMBER, integer, COUNTER_START);      #ifdef ENCODE_DEBUG -  data->debug = args > 2 ? Pike_sp[2-args].u.integer : 0; +  data->debug_buf = NULL; +  data->debug_pos = 0; +  data->debug = 0; +  if (args > 2) { +  if (TYPEOF(Pike_sp[2-args]) == PIKE_T_OBJECT) { +  struct object *sb = Pike_sp[2-args].u.object; +  if ((data->debug_buf = string_builder_from_string_buffer(sb))) { +  data->debug = 1; +  } +  } else { +  if ((data->debug = Pike_sp[2-args].u.integer)) { +  init_string_builder(&debug_buf, 0); +  data->debug_buf = &debug_buf; +  } +  } +  }    data->depth = -2;   #endif       if(args > 1 && TYPEOF(Pike_sp[1-args]) == T_OBJECT)    {    if (SUBTYPEOF(Pike_sp[1-args]))    Pike_error("The codec may not be a subtyped object yet.\n");       data->codec=Pike_sp[1-args].u.object;    add_ref (data->codec);    }else{    data->codec=NULL;    }       SET_ONERROR(tmp, free_encode_data, data);    addstr("\266ke0", 4);    -  +  EDB(1, { +  string_builder_append_disassembly(data->debug_buf, +  data->debug_pos, +  ((char *)data->buf.end) - +  (data->buf.length - data->debug_pos), +  data->buf.dst, +  ".format 0", +  NULL, +  "Encoding #0."); +  data->debug_pos = data->buf.length - +  (((char *)data->buf.end) - ((char *)data->buf.dst)); +  }); +     encode_value2(Pike_sp-args, data, 1);    -  for (i = 0; i < data->delayed->size; i++) +  for (i = 0; i < data->delayed->size; i++) { +  EDB(1, { +  string_builder_sprintf(data->debug_buf, +  "0x%016x # Delayed item #%d\n", +  data->debug_pos, i); +  });    encode_value2 (ITEM(data->delayed) + i, data, 2); -  +  }       UNSET_ONERROR(tmp);    -  +  EDB(1, { +  ENCODE_FLUSH(); +  }); +     if (data->codec) free_object (data->codec);    free_mapping(data->encoded);    free_array (data->delayed);    -  + #ifdef ENCODE_DEBUG +  if (data->debug_buf == &debug_buf) { +  write_and_reset_string_builder(2, data->debug_buf); +  free_string_builder(data->debug_buf); +  } + #endif +     pop_n_elems(args);    push_string(buffer_finish_pike_string(&data->buf));   }         struct unfinished_prog_link   {    struct unfinished_prog_link *next;    struct program *prog;   };