pike.git / src / encode.c

version» Context lines:

pike.git/src/encode.c:2072: Inside #if TWO_PASS_DECODE_WORKS
   * but it doesn't seem to really handle that. /mast */    struct Supporter supporter;   #endif   };      static void decode_value2(struct decode_data *data);      static int my_extract_char(struct decode_data *data)   {    if(data->ptr >= data->len) -  Pike_error("Format error, not enough data in string.\n"); +  Pike_error("Decode error: Not enough data in string.\n");    return data->data [ data->ptr++ ];   }    -  + static DECLSPEC(noreturn) void decode_error ( +  struct decode_data *data, struct svalue *decoding, const char *msg, ...) +  ATTRIBUTE((noreturn)); +  + static DECLSPEC(noreturn) void decode_error ( +  struct decode_data *data, struct svalue *decoding, const char *msg, ...) + { +  int n = 0; +  va_list args; +  struct string_builder sb; +  struct object *o = fast_clone_object (decode_error_program); +  struct decode_error_struct *dec = +  (struct decode_error_struct *) (o->storage + decode_error_offset); +  struct generic_error_struct *gen = +  (struct generic_error_struct *) get_storage (o, generic_error_program); +  +  ASSERT_THREAD_SWAPPED_IN(); +  +  copy_shared_string (dec->decode_string, data->data_str); +  +  if (decoding) { +  push_constant_text ("Error while decoding "); n++; +  push_constant_text ("%O"); +  push_svalue (decoding); +  f_sprintf (2); n++; +  push_constant_text (":\n"); n++; +  } +  else { +  push_constant_text ("Decode error: "); n++; +  } +  +  init_string_builder (&sb, 0); +  va_start (args, msg); +  string_builder_vsprintf (&sb, msg, args); +  va_end (args); +  push_string (finish_string_builder (&sb)); n++; +  +  f_add (n); +  gen->error_message = (--Pike_sp)->u.string; +  +  generic_error_va (o, NULL, NULL, 0, NULL, NULL); + } +    #define GETC() my_extract_char(data)      #define DECODE(Z) do { \    EDB(5, \    fprintf(stderr,"%*sdecode(%s) at %d: ", \    data->depth,"",(Z),__LINE__)); \    what=GETC(); \    e=what>>SIZE_SHIFT; \    if(what & TAG_SMALL) { \    num=e; \
pike.git/src/encode.c:2101:    if(what & TAG_NEG) { \    num = ~num; \    } \    EDB(5, \    fprintf(stderr,"type=%d (%s), num=%ld\n", \    (what & TAG_MASK), \    get_name_of_type(tag_to_type(what & TAG_MASK)), \    (long)num) ); \   } while (0)    -  -  +    #define decode_entry(X,Y,Z) \    do { \    INT32 what, e; \    INT64 num; \    DECODE("decode_entry"); \    if((what & TAG_MASK) != (X)) \ -  Pike_error("Failed to decode, wrong bits (%d).\n", what & TAG_MASK); \ -  (Y)=num; \ +  decode_error(data, NULL, "Wrong bits (%d).\n", what & TAG_MASK); \ +  (Y)=num; \    } while(0);      #define getdata2(S,L) do { \    if(data->ptr + (ptrdiff_t)(sizeof(S[0])*(L)) > data->len) \ -  Pike_error("Failed to decode string. (string range error)\n"); \ +  decode_error(data, NULL, "String range error.\n"); \    MEMCPY((S),(data->data + data->ptr), sizeof(S[0])*(L)); \    data->ptr+=sizeof(S[0])*(L); \    }while(0)      #if PIKE_BYTEORDER == 4321   #define BITFLIP(S)   #else   #define BITFLIP(S) \    switch(what) \    { \
pike.git/src/encode.c:2140:      #define get_string_data(STR,LEN, data) do { \    if((LEN) == -1) \    { \    INT32 what, e; \    INT64 num; \    ptrdiff_t sz; \    DECODE("get_string_data"); \    what &= TAG_MASK; \    if(what<0 || what>2) \ -  Pike_error ("Failed to decode string: Illegal size shift %d.\n", \ -  what); \ +  decode_error (data, NULL, "Illegal size shift %d.\n", what); \    sz = (ptrdiff_t) num << what; \    if (sz < 0) \ -  Pike_error ("Failed to decode string: Illegal negative size " \ -  "%"PRINTPTRDIFFT"d.\n", sz); \ +  decode_error (data, NULL, "Illegal negative size %td.\n", sz); \    if (sz > data->len - data->ptr) \ -  Pike_error ("Failed to decode string: Too large size %"PRINTPTRDIFFT"d " \ -  "(max is %"PRINTPTRDIFFT"d).\n", \ +  decode_error (data, NULL, "Too large size %td (max is %td).\n", \    sz, data->len - data->ptr); \    STR=begin_wide_shared_string(num, what); \    MEMCPY(STR->str, data->data + data->ptr, sz); \    data->ptr += sz; \    BITFLIP(STR); \    STR=end_shared_string(STR); \    }else{ \    ptrdiff_t sz = (LEN); \    if (sz < 0) \ -  Pike_error ("Failed to decode string: Illegal negative size " \ -  "%"PRINTPTRDIFFT"d.\n", sz); \ +  decode_error (data, NULL, "Illegal negative size %td.\n", sz); \    if (sz > data->len - data->ptr) \ -  Pike_error ("Failed to decode string: Too large size %"PRINTPTRDIFFT"d " \ -  "(max is %"PRINTPTRDIFFT"d).\n", \ +  decode_error (data, NULL, "Too large size %td (max is %td).\n", \    sz, data->len - data->ptr); \    STR=make_shared_binary_string((char *)(data->data + data->ptr), sz); \    data->ptr += sz; \    } \   }while(0)      #define getdata(X) do { \    long length; \    decode_entry(TAG_STRING, length,data); \    if(data->pass == 1) \
pike.git/src/encode.c:2193:    { \    case TAG_INT: \    X=0; \    break; \    \    case TAG_STRING: \    get_string_data(X,num,data); \    break; \    \    default: \ -  Pike_error("Failed to decode string, tag is wrong: %d\n", \ -  what & TAG_MASK); \ +  decode_error (data, NULL, "Tag is wrong: %d\n", what & TAG_MASK); \    } \   }while(0)      #define decode_number(X,data) do { \    INT32 what, e; \    INT64 num; \    DECODE("decode_number"); \    X=(what & TAG_MASK) | ((INT32) num<<4); \    EDB(5, fprintf(stderr, "%*s ==>%ld\n", \    data->depth, "", (long) X)); \
pike.git/src/encode.c:2253:    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);       tmp = GETC();    switch(tmp)    {    default: -  Pike_error("decode_value(): Error in type string (%d).\n", tmp); +  decode_error(data, NULL, "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); +  decode_error(data, NULL, "Bad marker in type string (%d).\n", tmp);    }    low_decode_type(data);    push_assign_type(tmp); /* Actually reverse, but they're the same */    break;       case T_SCOPE:    tmp = GETC();    low_decode_type(data);    push_scope_type(tmp); /* Actually reverse, but they're the same */    break;
pike.git/src/encode.c:2357:    case T_ZERO:    case T_VOID:    case PIKE_T_UNKNOWN:    push_type(tmp);    break;       case PIKE_T_ATTRIBUTE:    decode_value2(data);       if (Pike_sp[-1].type != PIKE_T_STRING) { -  Pike_error("decode_value(): Type attribute is not a string (%s)\n", -  get_name_of_type(Pike_sp[-1].type)); +  decode_error(data, NULL, "Type attribute is not a string: %O\n", +  Pike_sp - 1);    }    low_decode_type(data);    push_type_attribute(Pike_sp[-1].u.string);    pop_stack();    break;       case PIKE_T_NAME:    decode_value2(data);       if (Pike_sp[-1].type != PIKE_T_STRING) { -  Pike_error("decode_value(): Type name is not a string (%s)\n", -  get_name_of_type(Pike_sp[-1].type)); +  decode_error(data, NULL, "Type name is not a string: %O\n", +  Pike_sp - 1);    }    low_decode_type(data);    push_type_name(Pike_sp[-1].u.string);    pop_stack();    break;       case T_OBJECT:    {    int flag = GETC();   
pike.git/src/encode.c:2396:    break;       case T_PROGRAM:    push_object_type_backwards(flag, Pike_sp[-1].u.program->id);    break;       case T_FUNCTION:    {    struct program *prog;    if (Pike_sp[-1].subtype == FUNCTION_BUILTIN) { -  Pike_error("Failed to decode object type.\n"); +  decode_error(data, NULL, "Failed to decode object type.\n");    }    prog = program_from_svalue(Pike_sp-1);    if (!prog) { -  Pike_error("Failed to decode object type.\n"); +  decode_error(data, NULL, "Failed to decode object type.\n");    }    debug_malloc_touch(prog);    push_object_type_backwards(flag, prog->id);    }    break;       default: -  Pike_error("Failed to decode type " +  decode_error(data, NULL, "Failed to decode type "    "(object(%s), expected object(zero|program)).\n",    get_name_of_type(Pike_sp[-1].type));    }    pop_stack();    }    }       UNSET_ONERROR(err2);    UNSET_ONERROR(err1);   }
pike.git/src/encode.c:2482:    end_first_pass(0);   }      static void restore_current_file(void *save_current_file)   {    struct compilation *c = THIS_COMPILATION;    free_string(c->lex.current_file);    c->lex.current_file = save_current_file;   }    - static DECLSPEC(noreturn) void decode_error (struct svalue *decoding, -  struct svalue *other, -  char *msg, ...) -  ATTRIBUTE((noreturn,format (printf, 3, 4))); -  - static DECLSPEC(noreturn) void decode_error (struct svalue *decoding, -  struct svalue *other, -  char *msg, ...) - { -  int n = 0; -  char buf[4096]; -  va_list args; -  va_start (args, msg); -  VSNPRINTF (buf, sizeof (buf), msg, args); -  va_end (args); -  -  if (decoding) { -  push_constant_text ("Error while decoding "); n++; -  push_constant_text ("%O"); -  push_svalue (decoding); -  f_sprintf (2); n++; -  push_constant_text (":\n"); n++; -  } -  push_text (buf); n++; -  if (other) { -  push_constant_text ("%O (%s)\n"); -  push_svalue (other); -  push_text(get_name_of_type(other->type)); -  f_sprintf (3); n++; -  } -  f_add (n); -  -  f_backtrace (0); -  f_aggregate (2); -  -  free_svalue(& throw_value); -  dmalloc_touch_svalue(Pike_sp-1); -  throw_value = *--Pike_sp; -  throw_severity = THROW_ERROR; -  pike_throw(); - } -  +    /* Decode bytecode string @[string_no].    * Returns resulting offset in p->program.    */ - static INT32 decode_portable_bytecode(INT32 string_no) + static INT32 decode_portable_bytecode(struct decode_data *data, INT32 string_no)   {    struct program *p = Pike_compiler->new_program;    struct pike_string *bytecode;    struct pike_string *current_file=NULL;    INT32 current_line=0;    int e;    ONERROR err;       debug_malloc_touch(p);    if ((string_no < 0) || (string_no >= p->num_strings)) { -  Pike_error("Bad bytecode string number: %d (expected 0 - %d).\n", +  decode_error(data, NULL, +  "Bad bytecode string number: %d (expected 0 - %d).\n",    string_no, p->num_strings-1);    }       bytecode = p->strings[string_no];       if (bytecode->len % 3) { -  Pike_error("Bad bytecode string length: " -  "%"PRINTPTRDIFFT"d (expected multiple of 3).\n", -  bytecode->len); +  decode_error(data, NULL, "Bad bytecode string length: " +  "%td (expected multiple of 3).\n", bytecode->len);    }       init_bytecode();       SET_ONERROR(err, exit_bytecode, NULL);       switch(bytecode->size_shift) {   #define SIGNED_CHAR(X) X       /* The EMIT_BYTECODE2 macro will generate the warning    * "comparison is always false due to limited range of data type"    * if used on STR0. Thus, the need to have two macros here.    */   #define EMIT_BYTECODE2(STR) \    if (STR(bytecode)[e] == F_FILENAME) { \    INT32 strno = STR(bytecode)[e+1]; \    if (SIGNED_CHAR(strno < 0) || \    (strno >= p->num_strings)) { \ -  Pike_error("Bad filename directive number:" \ -  " %d (expected 0 - %d).\n", \ -  strno, p->num_strings); \ +  decode_error(data, NULL, "Bad filename directive number:" \ +  " %d (expected 0 - %d).\n", \ +  strno, p->num_strings); \    } \    current_file = p->strings[strno]; \    } else if (STR(bytecode)[e] == F_LINE) { \    current_line = STR(bytecode)[e+1]; \    } else if (!current_file) { \ -  Pike_error("Missing filename directive in " \ +  decode_error(data, NULL, "Missing filename directive in " \    "byte code.\n"); \    } else if (!current_line) { \ -  Pike_error("Missing line directive in " \ +  decode_error(data, NULL, "Missing line directive in " \    "byte code.\n"); \    } else      #define EMIT_BYTECODE(STR, X) do { \    for (e = 0; e < bytecode->len; e += 3) { \    X(STR) \    { \    insert_opcode2(STR(bytecode)[e], \    STR(bytecode)[e+1], \    STR(bytecode)[e+2], \
pike.git/src/encode.c:2606:    break;   #undef SIGNED_CHAR   #define SIGNED_CHAR(X) 0    case 1:    EMIT_BYTECODE(STR1, EMIT_BYTECODE2);    break;    case 0:   #undef EMIT_BYTECODE2   #define EMIT_BYTECODE2(X) \    if (!current_file) { \ -  Pike_error("Missing filename directive in " \ +  decode_error(data, NULL, "Missing filename directive in " \    "byte code.\n"); \    } else if (!current_line) { \ -  Pike_error("Missing line directive in " \ +  decode_error(data, NULL, "Missing line directive in " \    "byte code.\n"); \    } else       EMIT_BYTECODE(STR0, EMIT_BYTECODE2);    break;   #undef SIGNED_CHAR   #undef EMIT_BYTECODE   #undef EMIT_BYTECODE2   #ifdef PIKE_DEBUG    default:
pike.git/src/encode.c:2658:       switch(what & TAG_MASK)    {    case TAG_DELAYED:    EDB (2, fprintf(stderr, "%*sDecoding delay encoded from <%d>\n",    data->depth, "", num););    entry_id.type = T_INT;    entry_id.subtype = NUMBER_NUMBER;    entry_id.u.integer = num;    if (!(delayed_enc_val = low_mapping_lookup (data->decoded, &entry_id))) -  Pike_error ("Failed to find previous record of delay encoded entry <%d>.\n", -  num); +  decode_error (data, NULL, "Failed to find previous record of " +  "delay encoded entry <%d>.\n", num);    DECODE ("decode_value2");    break;       case TAG_AGAIN:    EDB (1, fprintf(stderr, "%*sDecoding TAG_AGAIN from <%d>\n",    data->depth, "", num););    entry_id.type=T_INT;    entry_id.subtype=NUMBER_NUMBER;    entry_id.u.integer=num;    if((tmp2=low_mapping_lookup(data->decoded, &entry_id)))    {    push_svalue(tmp2);    }else{ -  Pike_error("Failed to decode TAG_AGAIN entry <%d>.\n", num); +  decode_error(data, NULL, "Failed to decode TAG_AGAIN entry <%d>.\n", +  num);    }    goto decode_done;       default:    entry_id = data->counter;    data->counter.u.integer++;    /* Fall through. */       case TAG_TYPE:    EDB (2, fprintf(stderr, "%*sDecoding to <%d>: TAG%d (%d)\n",
pike.git/src/encode.c:2776:    entry_id = data->counter;    data->counter.u.integer++;    }    break;       case TAG_ARRAY:    {    struct array *a;    TYPE_FIELD types;    if(num < 0) -  Pike_error("Failed to decode array. (array size is negative)\n"); +  decode_error(data, NULL, +  "Failed to decode array (array size is negative).\n");       /* Heruetical */    if(data->ptr + num > data->len) -  Pike_error("Failed to decode array. (not enough data)\n"); +  decode_error(data, NULL, "Failed to decode array (not enough data).\n");       EDB(2,fprintf(stderr, "%*sDecoding array of size %d to <%d>\n",    data->depth, "", num, entry_id.u.integer));       SETUP_DECODE_MEMOBJ(T_ARRAY, array, a, allocate_array(num),    free_svalues(ITEM(a), a->size, a->type_field));       types = 0;    for(e=0;e<num;e++)    {
pike.git/src/encode.c:2804:    }    a->type_field = types;    ref_push_array(a);    goto decode_done;    }       case TAG_MAPPING:    {    struct mapping *m;    if(num<0) -  Pike_error("Failed to decode mapping. (mapping size is negative)\n"); +  decode_error(data, NULL, "Failed to decode mapping " +  "(mapping size is negative).\n");       /* Heuristical */    if(data->ptr + num > data->len) -  Pike_error("Failed to decode mapping. (not enough data)\n"); +  decode_error(data, NULL, "Failed to decode mapping " +  "(not enough data).\n");       EDB(2,fprintf(stderr, "%*sDecoding mapping of size %d to <%d>\n",    data->depth, "", num, entry_id.u.integer));       SETUP_DECODE_MEMOBJ(T_MAPPING, mapping, m, allocate_mapping(num), ; );       for(e=0;e<num;e++)    {    decode_value2(data);    decode_value2(data);
pike.git/src/encode.c:2832:    ref_push_mapping(m);    goto decode_done;    }       case TAG_MULTISET:    {    struct multiset *m;    struct array *a;    TYPE_FIELD types;    if(num<0) -  Pike_error("Failed to decode multiset. (multiset size is negative)\n"); +  decode_error(data, NULL, "Failed to decode multiset " +  "(multiset size is negative).\n");       /* Heruetical */    if(data->ptr + num > data->len) -  Pike_error("Failed to decode multiset. (not enough data)\n"); +  decode_error(data, NULL, "Failed to decode multiset " +  "(not enough data).\n");       /* NOTE: This code knows stuff about the implementation of multisets...*/       EDB(2,fprintf(stderr, "%*sDecoding multiset of size %d to <%d>\n",    data->depth, "", num, entry_id.u.integer));    SETUP_DECODE_MEMOBJ (T_MULTISET, multiset, m,    allocate_multiset (0, 0, NULL), ;);    /* FIXME: This array could be avoided by building the multiset directly. */    a = low_allocate_array (num, 0);   
pike.git/src/encode.c:2890:    case 1:    {    int fun;    /* decode_value_clone_object does not call __INIT, so    * we want to do that ourselves...    */    struct object *o=decode_value_clone_object(Pike_sp-1);       if (!o) {    if (data->pickyness) -  decode_error (NULL, Pike_sp - 1, -  "Failed to decode program for object. Got: "); +  decode_error (data, NULL, +  "Failed to decode program for object. Got: %O\n", +  Pike_sp - 1);    EDB(1,fprintf(stderr, "%*sDecoded a failed object to <%d>: ",    data->depth, "", entry_id.u.integer);    print_svalue(stderr, Pike_sp-1);    fputc('\n', stderr););    decode_value2(data);    pop_n_elems(2);    push_undefined();    break;    }   
pike.git/src/encode.c:2945:    }       EDB(2,fprintf(stderr, "%*sDecoded an object to <%d>: ",    data->depth, "", entry_id.u.integer);    print_svalue(stderr, Pike_sp-1);    fputc('\n', stderr););       ref_push_object(o);    decode_value2(data);    if(!data->codec) -  decode_error(Pike_sp - 1, NULL, +  decode_error(data, Pike_sp - 1,    "Cannot decode object without codec.\n");       fun = find_identifier("decode_object", data->codec->prog);    if (fun < 0) -  decode_error(Pike_sp - 1, NULL, +  decode_error(data, Pike_sp - 1,    "Cannot decode objects without a "    "\"decode_object\" function in the codec.\n");    apply_low(data->codec,fun,2);    if ((Pike_sp[-1].type == T_ARRAY) && o->prog &&    ((fun = FIND_LFUN(o->prog, LFUN_CREATE)) != -1)) {    /* Call lfun::create(@args). */    INT32 args;    Pike_sp--;    args = Pike_sp->u.array->size;    if (args) {
pike.git/src/encode.c:3003:   #endif    case 3:    pop_stack();    decode_value2(data);    break;       case 4:    /* Subtyped object. */    if ((Pike_sp[-1].type != T_OBJECT) || Pike_sp[-1].subtype ||    !Pike_sp[-1].u.object->prog) { -  decode_error(NULL, Pike_sp-1, "Expected plain object. Got: "); +  decode_error(data, NULL, "Expected plain object. Got: %O\n", +  Pike_sp-1);    }    if ((subtype < 0) ||    (subtype >= Pike_sp[-1].u.object->prog->num_inherits)) { -  decode_error(NULL, Pike_sp-1, -  "Invalid subtype for object: %d (max: %d). Object: ", -  subtype, Pike_sp[-1].u.object->prog->num_inherits); +  decode_error(data, NULL, +  "Invalid subtype for object: %d (max: %d). " +  "Object: %O\n", +  subtype, Pike_sp[-1].u.object->prog->num_inherits, +  Pike_sp-1);    }    Pike_sp[-1].subtype = subtype;    break;       default: -  Pike_error("Object coding not compatible.\n"); +  decode_error(data, NULL, "Object coding not compatible: %d\n", num);    break;    }       if((Pike_sp[-1].type != T_OBJECT) && data->pickyness) {    if (num != 2) { -  decode_error(NULL, Pike_sp - 1, "Failed to decode object. Got: "); +  decode_error(data, NULL, "Failed to decode object. Got: %O\n", +  Pike_sp - 1);    } else if (Pike_sp[-1].type != PIKE_T_INT) { -  decode_error(NULL, Pike_sp - 1, "Failed to decode bignum. Got: "); +  decode_error(data, NULL, "Failed to decode bignum. Got: %O\n", +  Pike_sp - 1);    }    }       break;    }       case TAG_FUNCTION:    decode_value2(data);    stack_dup(); /* For diagnostic purposes... */       switch(num)    {    case 0:    apply(data->codec,"functionof", 1);    break;       case 1: {    struct program *p;    if(Pike_sp[-1].type != T_OBJECT && data->pickyness) -  decode_error(NULL, Pike_sp - 1, -  "Failed to decode function object. Got: "); +  decode_error(data, NULL, +  "Failed to decode function object. Got: %O\n", +  Pike_sp - 1);       decode_value2(data);    if(Pike_sp[-1].type != T_STRING && data->pickyness) -  decode_error(NULL, Pike_sp - 1, -  "Failed to decode function identifier. Got: "); +  decode_error(data, NULL, +  "Failed to decode function identifier. Got: %O\n", +  Pike_sp - 1);       if (Pike_sp[-2].type == T_OBJECT &&    Pike_sp[-1].type == T_STRING &&    (p = Pike_sp[-2].u.object->prog)) {    int f = really_low_find_shared_string_identifier(    Pike_sp[-1].u.string,    p->inherits[Pike_sp[-2].subtype].prog,    SEE_PROTECTED|SEE_PRIVATE);    debug_malloc_touch(p);    if (f >= 0) {
pike.git/src/encode.c:3074:   #endif    debug_malloc_touch(p);    pop_n_elems(2);    *Pike_sp++ = func;    dmalloc_touch_svalue(Pike_sp-1);    break;    }    else if (data->pickyness) {    debug_malloc_touch(p);    if (Pike_sp[-1].u.string->size_shift) -  decode_error(NULL, Pike_sp - 2, "Couldn't find identifier in "); +  decode_error(data, NULL, "Couldn't find identifier in %O.\n", +  Pike_sp - 2);    else -  decode_error(NULL, Pike_sp - 2, "Couldn't find identifier %s in ", -  Pike_sp[-1].u.string->str); +  decode_error(data, NULL, "Couldn't find identifier %s in %O.\n", +  Pike_sp[-1].u.string->str, Pike_sp - 2);    }    debug_malloc_touch(p);    }    pop_stack();    break;    }       default: -  Pike_error("Function coding not compatible.\n"); +  decode_error(data, NULL, "Function coding not compatible: %d\n", num);    break;    }       if((Pike_sp[-1].type != T_FUNCTION) && (Pike_sp[-1].type != T_PROGRAM) &&    data->pickyness) -  decode_error(Pike_sp - 2, Pike_sp - 1, -  "Failed to decode function. Got: "); +  decode_error(data, Pike_sp - 2, +  "Failed to decode function. Got: %O\n", Pike_sp - 1);       stack_pop_keep_top();       break;          case TAG_PROGRAM:    EDB(3,    fprintf(stderr, "%*s TAG_PROGRAM(%d)\n",    data->depth, "", num));
pike.git/src/encode.c:3117:    {    struct program *p;       decode_value2(data);    apply(data->codec,"programof", 1);       p = program_from_svalue(Pike_sp-1);       if (!p) {    if(data->pickyness) -  decode_error(NULL, Pike_sp - 1, -  "Failed to decode program. Got: "); +  decode_error(data, NULL, "Failed to decode program. Got: %O\n", +  Pike_sp - 1);    pop_stack();    push_undefined();    break;    }       add_ref(p);    pop_stack();    push_program(p);    break;    }
pike.git/src/encode.c:3173:       debug_malloc_touch(p);    ref_push_program(p);    apply(data->codec, "__register_new_program", 1);       /* return a placeholder */    if(Pike_sp[-1].type == T_OBJECT)    {    placeholder=Pike_sp[-1].u.object;    if(placeholder->prog != null_program) -  Pike_error("Placeholder object is not a __null_program clone.\n"); +  decode_error(data, NULL, "Placeholder object is not " +  "a __null_program clone.\n");    dmalloc_touch_svalue(Pike_sp-1);    Pike_sp--;    }    else if (Pike_sp[-1].type != T_INT ||    Pike_sp[-1].u.integer) -  Pike_error ("Expected placeholder object or zero " +  decode_error (data, NULL, "Expected placeholder object or zero "    "from __register_new_program.\n");    else {    pop_stack();    }    }       if(placeholder)    SET_ONERROR(err4, zap_placeholder, placeholder);       decode_value2(data);    push_compact_version();    if(!is_eq(Pike_sp-1,Pike_sp-2)   #ifdef ENCODE_DEBUG    && !data->debug   #endif    ) -  Pike_error("Cannot decode programs encoded with other pike version.\n"); +  decode_error(data, NULL, "Cannot decode programs encoded " +  "with other pike version %O.\n", Pike_sp - 2);    pop_n_elems(2);      #ifdef ENCODE_DEBUG    if (!data->debug)   #endif    data->pickyness++;       debug_malloc_touch(p);    decode_number(p->flags,data);   
pike.git/src/encode.c:3241:    p->parent=0;    break;    case T_PROGRAM:    p->parent=Pike_sp[-1].u.program;    break;    case T_FUNCTION:    p->parent=program_from_svalue(Pike_sp-1);    break;    default:    if (data->pickyness) -  decode_error(NULL, Pike_sp - 1, "Program decode failed. Got: "); +  decode_error(data, NULL, "Program decode failed. Got: %O\n", +  Pike_sp - 1);    p->parent = 0;    break;    }    if(p->parent) {    add_ref(p->parent);    }    pop_stack();       debug_malloc_touch(p);   
pike.git/src/encode.c:3299:       p->total_size=size + sizeof(struct program);       p->flags |= PROGRAM_OPTIMIZED;    }       {    INT32 bytecode_method = 0;    decode_number(bytecode_method, data);    if (bytecode_method != PIKE_BYTECODE_METHOD) { -  Pike_error("Unsupported byte-code method: %d. Expected %d\n", +  decode_error(data, NULL, +  "Unsupported byte-code method: %d. Expected %d\n",    bytecode_method, PIKE_BYTECODE_METHOD);    }    }       getdata2(p->program, p->num_program);    getdata2(p->relocations, p->num_relocations);      #ifdef DECODE_PROGRAM    {    int byteorder = PIKE_BYTEORDER; /* FIXME: Used by bytecode.h */
pike.git/src/encode.c:3344:          debug_malloc_touch(p);    for(d=0;d<p->num_identifier_index;d++)    {    decode_number(p->identifier_index[d],data);    if(p->identifier_index[d] > p->num_identifier_references)    {    p->identifier_index[d]=0;    ref_push_program (p); -  decode_error(Pike_sp - 1, NULL, "Malformed program in decode.\n"); +  decode_error(data, Pike_sp - 1, "Malformed program in decode.\n");    }    }       debug_malloc_touch(p);    for(d=0;d<p->num_variable_index;d++)    {    decode_number(p->variable_index[d],data);    if(p->variable_index[d] > p->num_identifiers)    {    p->variable_index[d]=0;    ref_push_program (p); -  decode_error(Pike_sp - 1, NULL, "Malformed program in decode.\n"); +  decode_error(data, Pike_sp - 1, "Malformed program in decode.\n");    }    }       debug_malloc_touch(p);    for(d=0;d<p->num_identifier_references;d++)    {    decode_number(p->identifier_references[d].inherit_offset,data);    if(p->identifier_references[d].inherit_offset > p->num_inherits)    {    p->identifier_references[d].inherit_offset=0;    ref_push_program (p); -  decode_error(Pike_sp - 1, NULL, "Malformed program in decode.\n"); +  decode_error(data, Pike_sp - 1, "Malformed program in decode.\n");    }    decode_number(p->identifier_references[d].identifier_offset,data);    decode_number(p->identifier_references[d].id_flags,data);       EDB(3,fprintf(stderr,"IDREF%x < %d: { %d, %d, %d }\n",    p->id,d,    p->identifier_references[d].inherit_offset,    p->identifier_references[d].identifier_offset,    p->identifier_references[d].id_flags); );    }
pike.git/src/encode.c:3397:   /* p->inherits[0].prog=p;    p->inherits[0].parent_offset=1;   */       if(placeholder && data->pass==1)    {    if(placeholder->prog != null_program)    {    debug_malloc_touch(placeholder);    ref_push_program (p); -  decode_error(Pike_sp - 1, NULL, -  "Placeholder is no longer a __null_program clone.\n"); +  decode_error(data, Pike_sp - 1, "Placeholder is no longer " +  "a __null_program clone.\n");    }else{    free_program(placeholder->prog);    add_ref(placeholder->prog = p);    debug_malloc_touch(placeholder);    }    }       debug_malloc_touch(p);       in=p->num_inherits;
pike.git/src/encode.c:3423:    decode_number(p->inherits[d].parent_offset,data);    decode_number(p->inherits[d].parent_identifier,data);    decode_number(p->inherits[d].storage_offset,data);       decode_value2(data);    if(d==0)    {    if(Pike_sp[-1].type != T_PROGRAM ||    Pike_sp[-1].u.program != p) {    ref_push_program (p); -  decode_error(Pike_sp - 1, Pike_sp - 2, -  "Program decode of self inherit failed. Got: "); +  decode_error(data, Pike_sp - 1, +  "Program decode of self inherit failed. Got: %O\n", +  Pike_sp - 2);    }    sub_ref(p);    }       if(data->pass > 1)    {    if(p->inherits[d].prog)    {    free_program(p->inherits[d].prog);    p->inherits[d].prog=0;
pike.git/src/encode.c:3461:    break;       case T_FUNCTION:    if(Pike_sp[-1].subtype != FUNCTION_BUILTIN) {    EDB(3, fprintf(stderr,"INHERIT%x = func { %p, %d} \n",p->id,Pike_sp[-1].u.object, Pike_sp[-1].subtype); );       p->inherits[d].parent_identifier=Pike_sp[-1].subtype;    p->inherits[d].prog=program_from_svalue(Pike_sp-1);    if(!p->inherits[d].prog) {    ref_push_program (p); -  decode_error(Pike_sp - 1, Pike_sp - 2, -  "Failed to decode inherited program. Got: "); +  decode_error(data, Pike_sp - 1, "Failed to decode " +  "inherited program. Got: %O\n", Pike_sp - 2);    }    add_ref(p->inherits[d].prog);    p->inherits[d].parent=Pike_sp[-1].u.object;    Pike_sp--;    dmalloc_touch_svalue(Pike_sp);    break;    }    /* Fall through */       default:    ref_push_program (p); -  decode_error(Pike_sp - 1, Pike_sp - 2, -  "Failed to decode inherited program. Got: "); +  decode_error(data, Pike_sp - 1, +  "Failed to decode inherited program. Got: %O\n", +  Pike_sp - 2);    }       p->num_inherits=d+1;       getdata3(p->inherits[d].name);       EDB(3, fprintf(stderr,"INHERIT%x < %d: %d id=%d\n",    p->id,d,    p->inherits[d].prog->num_identifiers,    p->inherits[d].prog->id); );
pike.git/src/encode.c:3512:    decode_number(p->identifiers[d].filename_strno, data);    decode_number(p->identifiers[d].linenumber, data);    if (IDENTIFIER_IS_ALIAS(p->identifiers[d].identifier_flags)) {    decode_number(p->identifiers[d].func.ext_ref.depth, data);    decode_number(p->identifiers[d].func.ext_ref.id, data);    } else if (!IDENTIFIER_IS_C_FUNCTION(p->identifiers[d].identifier_flags))    {    decode_number(p->identifiers[d].func.offset,data);    } else {    ref_push_program (p); -  ref_push_string (p->identifiers[d].name); -  decode_error(Pike_sp - 1, Pike_sp - 2, -  "Cannot decode function implemented in C: "); +  decode_error(data, Pike_sp - 1, +  "Cannot decode function implemented in C: %S\n", +  p->identifiers[d].name);    }    }          UNSET_ONERROR(err2);    UNSET_ONERROR(err1);       debug_malloc_touch(dat);       debug_malloc_touch(p);
pike.git/src/encode.c:3574: Inside #if defined(PIKE_DEBUG)
   if(!p->inherits[q].prog)    Pike_fatal("FOOBAR!@!!!\n");    }   #endif       if(placeholder && data->pass == 1)    {    if(placeholder->storage)    {    ref_push_program (p); -  decode_error(Pike_sp - 1, NULL, "Placeholder already has storage!\n"); +  decode_error(data, Pike_sp - 1, +  "Placeholder already has storage!\n");    } else {    placeholder->storage=p->storage_needed ?    (char *)xcalloc(p->storage_needed, 1) :    (char *)NULL;    call_c_initializers(placeholder);    }    }      #ifdef ENCODE_DEBUG    if (!data->debug)
pike.git/src/encode.c:3673:    }       /* Go through the linked list of unfinished objects    * to see what objects are now finished.    */    {    int decode_fun = -1;    struct unfinished_obj_link *l, **ptr;    if (data->unfinished_objects) {    if(!data->codec) -  decode_error(Pike_sp - 1, NULL, +  decode_error(data, Pike_sp - 1,    "Cannot decode object without codec.\n");       decode_fun =    find_identifier("decode_object", data->codec->prog);    if (decode_fun < 0) -  decode_error(Pike_sp - 1, NULL, +  decode_error(data, Pike_sp - 1,    "Cannot decode objects without a "    "\"decode_object\" function in the codec.\n");    }    for(ptr= &data->unfinished_objects ; (l=*ptr);)    {    int fun;    struct object *o=l->o;    if(o->prog)    {    if(o->prog->flags & PROGRAM_FINISHED)
pike.git/src/encode.c:3753:    case 2:    decode_value2(data);    decode_value2(data);    if(Pike_sp[-2].type==T_INT)    {    pop_stack();    }else{    f_arrow(2);    }    if(Pike_sp[-1].type != T_PROGRAM && data->pickyness) -  decode_error(NULL, Pike_sp - 1, "Failed to decode program. Got: "); +  decode_error(data, NULL, "Failed to decode program. Got: %O\n", +  Pike_sp - 1);    break;       case 3:    decode_value2(data);    if ((Pike_sp[-1].type == T_INT) &&    (Pike_sp[-1].u.integer < PROG_DYNAMIC_ID_START) &&    (Pike_sp[-1].u.integer > 0)) {    struct program *p = id_to_program(Pike_sp[-1].u.integer);    if (!p) { -  Pike_error("Failed to get program from ID %"PRINTPIKEINT"d\n", -  Pike_sp[-1].u.integer); +  decode_error(data, NULL, "Failed to get program from ID %O.\n", +  Pike_sp - 1);    }    pop_stack();    ref_push_program(p);    } else { -  decode_error(NULL, Pike_sp - 1, -  "Failed to decode program by ID. Expected integer, got: "); +  decode_error(data, NULL, "Failed to decode program by ID. " +  "Expected integer, got: %O\n", Pike_sp - 1);    }    break;       case 5: { /* Forward reference for new-style encoding. */    struct program *p = low_allocate_program();       push_program (p);    EDB(2,    fprintf (stderr, "%*sInited an embryo for a delay encoded program "    "to <%d>: ",
pike.git/src/encode.c:3798: Inside #if 0
   /* Is this necessary? In that case, how do we pass an    * adequate context to __register_new_program so that it    * knows which program is being decoded? */    if (data->codec) {    ref_push_program (p);    apply (data->codec, "__register_new_program", 1);       /* Returns a placeholder. */    if (Pike_sp[-1].type == T_OBJECT) {    if (Pike_sp[-1].u.object->prog != null_program) -  Pike_error ("Placeholder object is not a null_program clone.\n"); +  decode_error (data, NULL, "Placeholder object is not " +  "a null_program clone.\n");    }    else if (Pike_sp[-1].type != T_INT ||    Pike_sp[-1].u.integer) -  Pike_error ("Expected placeholder object or zero " +  decode_error (data, NULL, "Expected placeholder object or zero "    "from __register_new_program.\n");    pop_stack();    }   #endif       break;    }       case 4: /* New-style encoding. */    {
pike.git/src/encode.c:3850:       if ((byteorder != PIKE_BYTEORDER)   #if (PIKE_BYTEORDER == 1234)    && (byteorder != 4321)   #else   #if (PIKE_BYTEORDER == 4321)    && (byteorder != 1234)   #endif   #endif    ) { -  Pike_error("Unsupported byte-order. Native:%d Encoded:%d\n", -  PIKE_BYTEORDER, byteorder); +  decode_error (data, NULL, "Unsupported byte-order. " +  "Native:%d Encoded:%d\n", PIKE_BYTEORDER, byteorder);    }       /* Decode flags. */    decode_number(p_flags,data);    p_flags &= ~(PROGRAM_FINISHED | PROGRAM_OPTIMIZED |    PROGRAM_FIXED | PROGRAM_PASS_1_DONE);    p_flags |= PROGRAM_AVOID_CHECK;       if (delayed_enc_val) {    EDB(2,fprintf(stderr, "%*sdecoding a delay encoded program: ",    data->depth, "");    print_svalue(stderr, delayed_enc_val);    fputc('\n', stderr););    if (delayed_enc_val->type != T_PROGRAM ||    delayed_enc_val->u.program->flags != PROGRAM_VIRGIN) { -  decode_error (NULL, delayed_enc_val, -  "Didn't get program embryo " -  "for delay encoded program <%"PRINTPIKEINT"d>: ", -  entry_id.u.integer); +  decode_error (data, NULL, "Didn't get program embryo " +  "for delay encoded program <%O>: %O\n", +  &entry_id, delayed_enc_val);    }    /* No new ref here; low_start_new_program will add one for    * Pike_compiler->new_program and we want ride on that one    * just like when it's created there. */    p = delayed_enc_val->u.program;    debug_malloc_touch(p);    }    else    p = NULL;   
pike.git/src/encode.c:3919:       if (fun >= 0) {    ref_push_program(p);    apply_low(data->codec, fun, 1);       /* Returned a placeholder */    if(Pike_sp[-1].type == T_OBJECT)    {    add_ref(c->placeholder=Pike_sp[-1].u.object);    if(c->placeholder->prog != null_program) { -  Pike_error("Placeholder object is not " +  decode_error(data, NULL, "Placeholder object is not "    "a __null_program clone.\n");    }    } else if (Pike_sp[-1].type != T_INT ||    Pike_sp[-1].u.integer) { -  Pike_error ("Expected placeholder object or zero " +  decode_error (data, NULL, "Expected placeholder object or zero "    "from __register_new_program.\n");    }    pop_stack();    }    }       copy_shared_string(save_current_file, c->lex.current_file);    save_current_line = c->lex.current_line;       SET_ONERROR(err2, restore_current_file, save_current_file);
pike.git/src/encode.c:3960:    debug_malloc_touch(p);       /* Check the version. */    decode_value2(data);    push_compact_version();    if(!is_eq(Pike_sp-1,Pike_sp-2)   #ifdef ENCODE_DEBUG    && !data->debug   #endif    ) -  Pike_error("Cannot decode programs encoded with other pike version.\n"); +  decode_error(data, NULL, "Cannot decode programs encoded with " +  "other pike version %O.\n", Pike_sp - 2);    pop_n_elems(2);       debug_malloc_touch(p);      #ifdef ENCODE_DEBUG    if (!data->debug)   #endif    data->pickyness++;       /* parent */    decode_value2(data);    if (Pike_sp[-1].type == T_PROGRAM) {    p->parent = Pike_sp[-1].u.program;    debug_malloc_touch(p->parent);    } else if ((Pike_sp[-1].type == T_INT) &&    (!Pike_sp[-1].u.integer)) {    p->parent = NULL;    } else { -  Pike_error("Bad type for parent program (%s)\n", +  decode_error (data, NULL, "Bad type for parent program (%s).\n",    get_name_of_type(Pike_sp[-1].type));    }    dmalloc_touch_svalue(Pike_sp-1);    Pike_sp--;       /* Decode lengths. */   #define FOO(NUMTYPE,TYPE,ARGTYPE,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_BYTECODE_PORTABLE) {    } else if (bytecode_method != PIKE_BYTECODE_METHOD) { -  Pike_error("Unsupported byte-code method: %d\n", bytecode_method); +  decode_error(data, NULL, "Unsupported byte-code method: %d\n", +  bytecode_method);    } else {      #ifdef PIKE_PORTABLE_BYTECODE    fprintf(stderr, "Warning: Decoding non-portable bytecode.\n");   #endif /* PIKE_PORTABLE_BYTECODE */      #ifdef PIKE_USE_MACHINE_CODE    {    size_t csum;    /* Check the checksum of the instrs array. */    decode_number(csum, data);    if (csum != instrs_checksum) { -  Pike_error("Bad instruction checksum: %d (expected %d)\n", +  decode_error(data, NULL, +  "Bad instruction checksum: %d (expected %d)\n",    csum, instrs_checksum);    }    }   #endif /* PIKE_USE_MACHINE_CODE */       /* Decode program */    if (data->ptr + (int)local_num_program >= data->len) { -  Pike_error("Failed to decode program. (string too short)\n"); +  decode_error(data, NULL, +  "Failed to decode program (string too short).\n");    }    low_add_many_to_program(Pike_compiler,    (PIKE_OPCODE_T *)(data->data + data->ptr),    local_num_program);    data->ptr += local_num_program * sizeof(PIKE_OPCODE_T);       /* Decode relocations */    for (e=0; e<(int)local_num_relocations; e++) {    size_t reloc;    decode_number(reloc, data);
pike.git/src/encode.c:4038:    }       /* Perform relocation. */   #ifdef DECODE_PROGRAM    DECODE_PROGRAM(p);   #endif /* DECODE_PROGRAM */    make_program_executable(p);       /* Decode linenumbers */    if (data->ptr + (int)local_num_linenumbers >= data->len) { -  Pike_error("Failed to decode linenumbers. (string too short)\n"); +  decode_error(data, NULL, "Failed to decode linenumbers " +  "(string too short).\n");    }    for (e=0; e<(int)local_num_linenumbers; e++) {    char lineno_info;    lineno_info = *(data->data + data->ptr++);    add_to_linenumbers(lineno_info);    }       /* Now with the linenumber info in place it gets useful to    * include the program in error messages. */   
pike.git/src/encode.c:4065:       /* identifier_index & variable_index are created by    * fixate_program() and optimize_program().    */       /* Decode strings */    for (e=0; e<local_num_strings; e++) {    decode_value2(data);    if (Pike_sp[-1].type != T_STRING) {    ref_push_program (p); -  decode_error(Pike_sp - 1, Pike_sp - 2, -  "Nonstrings in string table: "); +  decode_error(data, Pike_sp - 1, +  "Nonstrings in string table: %O\n", Pike_sp - 2);    }    add_to_strings(Pike_sp[-1].u.string);    dmalloc_touch_svalue(Pike_sp-1);    Pike_sp--;    }       /* First pass constants.    *    * These will be replaced later on.    */
pike.git/src/encode.c:4107:    while ((entry_type == ID_ENTRY_EFUN_CONSTANT) ||    (entry_type == ID_ENTRY_TYPE_CONSTANT)) {    INT32 efun_no;    struct program_constant *constant;    decode_number(efun_no, data);    EDB(2,    fprintf(stderr, "%*sDecoding efun/type constant #%d.\n",    data->depth, "", efun_no));    if ((efun_no < 0) || (efun_no >= local_num_constants)) {    ref_push_program (p); -  decode_error(Pike_sp - 1, NULL, +  decode_error(data, Pike_sp - 1,    "Bad efun/type number: %d (expected 0 - %d).\n",    efun_no, local_num_constants-1);    }    constant = p->constants+efun_no;    /* value */    decode_value2(data);    switch(entry_type) {    case ID_ENTRY_EFUN_CONSTANT:    if (((Pike_sp[-1].type != T_FUNCTION) ||    (Pike_sp[-1].subtype != FUNCTION_BUILTIN)) &&    data->pickyness) {    ref_push_program (p); -  decode_error(Pike_sp - 1, Pike_sp - 2, -  "Expected efun constant: "); +  decode_error(data, Pike_sp - 1, +  "Expected efun constant: %O\n", Pike_sp - 2);    }    break;    case ID_ENTRY_TYPE_CONSTANT:    if (Pike_sp[-1].type != T_TYPE && data->pickyness) {    ref_push_program (p); -  decode_error(Pike_sp - 1, Pike_sp - 2, -  "Expected type constant: "); +  decode_error(data, Pike_sp - 1, +  "Expected type constant: %O\n", Pike_sp - 2);    }    break;    default:    if (data->pickyness) -  Pike_error("Internal error: Unsupported early constant (%d)\n", +  decode_error(data, NULL, "Internal error: " +  "Unsupported early constant (%d).\n",    entry_type);    break;    }    /* name */    decode_value2(data);   #if 0    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 {    ref_push_program (p); -  decode_error(Pike_sp - 1, Pike_sp - 2, -  "Name of constant is not a string: "); +  decode_error(data, Pike_sp - 1, +  "Name of constant is not a string: %O\n", +  Pike_sp - 2);    }    constant->sval = Pike_sp[-2];    dmalloc_touch_svalue(Pike_sp-1);    dmalloc_touch_svalue(Pike_sp-2);    Pike_sp -= 2;   #else /* !0 */    constant->offset = -1;    pop_stack();    constant->sval = Pike_sp[-1];    dmalloc_touch_svalue(Pike_sp-1);
pike.git/src/encode.c:4176:    if ((entry_type != ID_ENTRY_RAW) &&    (entry_type != ID_ENTRY_INHERIT)) {    /* Common identifier fields. */       unsigned INT32 filename_strno;       /* name */    decode_value2(data);    if (Pike_sp[-1].type != T_STRING) {    ref_push_program (p); -  decode_error(Pike_sp - 1, Pike_sp - 2, -  "Bad identifier name (not a string): "); +  decode_error(data, Pike_sp - 1, +  "Bad identifier name (not a string): %O\n", +  Pike_sp - 2);    }       /* type */    decode_value2(data);    if (Pike_sp[-1].type != T_TYPE) {    ref_push_program (p); -  decode_error(Pike_sp - 1, Pike_sp - 2, -  "Bad identifier type (not a type): "); +  decode_error(data, Pike_sp - 1, +  "Bad identifier type (not a type): %O\n", +  Pike_sp - 2);    }       /* filename */    decode_number(filename_strno, data);    if (filename_strno >= p->num_strings) {    ref_push_program(p); -  decode_error(NULL, NULL, +  decode_error(data, NULL,    "String number out of range: %ld >= %ld",    (long)filename_strno, (long)p->num_strings);    }    free_string(c->lex.current_file);    copy_shared_string(c->lex.current_file,    p->strings[filename_strno]);       /* linenumber */    decode_number(c->lex.current_line, data);   
pike.git/src/encode.c:4235:       ref.run_time_type = PIKE_T_UNKNOWN;    ref.func.offset = 0;       /* Expected identifier reference number */    decode_number(no, data);       if (no > p->num_identifier_references) {    EDB (3, dump_program_tables (p, data->depth));    ref_push_program (p); -  decode_error(Pike_sp - 1, NULL, -  "Bad identifier reference offset: %d != %d\n", no, +  decode_error(data, Pike_sp - 1, +  "Bad identifier reference offset: %d != %d\n", +  no,    Pike_compiler->new_program->    num_identifier_references);    } else if (no == p->num_identifier_references) {    add_to_identifier_references(ref);    }    else {    p->identifier_references[no] = ref;    }    }    break;
pike.git/src/encode.c:4271:    /* Alters    *    * storage, variable_index, identifiers and    * identifier_references    */    n = define_variable(Pike_sp[-2].u.string,    Pike_sp[-1].u.type,    id_flags);    if (no != n) {    ref_push_program (p); -  decode_error(Pike_sp - 1, NULL, -  "Bad variable identifier offset: got %d, expected %d\n", -  n, no); +  decode_error(data, Pike_sp - 1, +  "Bad variable identifier offset " +  "(got %d, expected %d).\n", n, no);    }       pop_n_elems(2);    }    break;    case ID_ENTRY_FUNCTION:    {    union idptr func;    unsigned INT8 func_flags;    unsigned INT16 opt_flags;
pike.git/src/encode.c:4304: Inside #if defined(ENCODE_DEBUG)
  #ifdef ENCODE_DEBUG    int old_a_flag;   #endif    EDB(2,    {    fprintf(stderr, "%*sDecoding portable bytecode.\n",    data->depth, "");    old_a_flag = a_flag;    a_flag = (a_flag > (data->debug-1))?a_flag:(data->debug-1);    }); -  func.offset = decode_portable_bytecode(func.offset); +  func.offset = decode_portable_bytecode(data, func.offset);    EDB(2, a_flag = old_a_flag);    }       /* opt_flags */    decode_number(opt_flags, data);       /* FIXME:    * Verify validity of func_flags, func.offset & opt_flags    */   
pike.git/src/encode.c:4348:    n = define_function(Pike_sp[-2].u.string,    Pike_sp[-1].u.type,    id_flags, func_flags,    &func, opt_flags);    if (no != n &&    (p->identifier_references[no].id_flags != id_flags ||    p->identifier_references[no].identifier_offset !=    p->identifier_references[n].identifier_offset ||    p->identifier_references[no].inherit_offset != 0)) {    ref_push_program (p); -  decode_error(Pike_sp - 1, NULL, +  decode_error(data, Pike_sp - 1,    "Bad function identifier offset: %d\n", no);    }       pop_n_elems(2);    }    break;    case ID_ENTRY_CONSTANT:    {    struct identifier id;    struct reference ref;
pike.git/src/encode.c:4432:    * identifiers, identifier_references    */       if (n < 0 || (n = override_identifier (&ref, id.name)) < 0) {    n = p->num_identifier_references;    add_to_identifier_references(ref);    }       if (no != n) {    ref_push_program (p); -  ref_push_string (id.name); -  decode_error(Pike_sp - 2, Pike_sp - 1, +  decode_error(data, Pike_sp - 1,    "Bad function identifier offset " -  "(expected %d, got %d) for ", no, n); +  "(expected %d, got %d) for %S.\n", +  no, n, id.name);    }       }    break;    case ID_ENTRY_ALIAS:    {    int depth;    int refno;    int no;    int n;
pike.git/src/encode.c:4477:    *    * variable_index, identifiers and    * identifier_references    */    n = low_define_alias(Pike_sp[-2].u.string,    Pike_sp[-1].u.type, id_flags,    depth, refno);       if (no != n) {    ref_push_program (p); -  decode_error(Pike_sp - 1, Pike_sp - 3, +  decode_error(data, Pike_sp - 1,    "Bad alias identifier offset " -  "(expected %d, got %d) for ", no, n); +  "(expected %d, got %d) for %O.\n", +  no, n, Pike_sp - 3);    }       pop_n_elems(2);    }    break;    case ID_ENTRY_INHERIT:    {    struct program *prog;    struct object *parent = NULL;    int parent_identifier;    int parent_offset;    struct pike_string *name = NULL;    int no;       decode_number(no, data);    if (no !=    Pike_compiler->new_program->num_identifier_references) {    ref_push_program (p); -  decode_error(Pike_sp - 1, NULL, +  decode_error(data, Pike_sp - 1,    "Bad inherit identifier offset: %d\n", no);    }       /* name */    decode_value2(data);    if (Pike_sp[-1].type == T_STRING) {    name = Pike_sp[-1].u.string;    } else if ((Pike_sp[-1].type != T_INT) ||    Pike_sp[-1].u.integer) {    ref_push_program (p); -  decode_error(Pike_sp - 1, Pike_sp - 2, -  "Bad inherit name (not a string): "); +  decode_error(data, Pike_sp - 1, +  "Bad inherit name (not a string): %O\n", +  Pike_sp - 2);    }       /* prog */    decode_value2(data);    if (Pike_sp[-1].type != T_PROGRAM) {    ref_push_program (p); -  decode_error(Pike_sp - 1, Pike_sp - 2, -  "Bad inherit: Expected program, got "); +  decode_error(data, Pike_sp - 1, +  "Bad inherit: Expected program, got: %O\n", +  Pike_sp - 2);    }    prog = Pike_sp[-1].u.program;    if (prog == placeholder_program) {    ref_push_program (p); -  decode_error (Pike_sp - 1, NULL, +  decode_error (data, Pike_sp - 1,    "Trying to inherit placeholder program "    "(resolver or codec problem).\n");    }    if(!(prog->flags & (PROGRAM_FINISHED | PROGRAM_PASS_1_DONE))) {    ref_push_program (p); -  decode_error (Pike_sp - 1, Pike_sp - 2, +  decode_error (data, Pike_sp - 1,    "Cannot inherit a program which is not " -  "fully compiled yet (resolver or codec problem):\n"); +  "fully compiled yet (resolver or codec " +  "problem): %O\n", Pike_sp - 2);    }       /* parent */    decode_value2(data);    if (Pike_sp[-1].type == T_OBJECT) {    parent = Pike_sp[-1].u.object;    } else if ((Pike_sp[-1].type != T_INT) ||    Pike_sp[-1].u.integer) {    ref_push_program (p); -  decode_error(Pike_sp - 1, Pike_sp - 2, -  "Bad inherit: Parent isn't an object: "); +  decode_error(data, Pike_sp - 1, +  "Bad inherit: Parent isn't an object: %O\n", +  Pike_sp - 2);    }       /* parent_identifier */    decode_number(parent_identifier, data);       /* parent_offset */    decode_number(parent_offset, data);       /* Expected number of identifier references. */    decode_number(no, data);       if (prog->num_identifier_references != no) {    ref_push_program (p); -  decode_error(Pike_sp - 1, NULL, -  "Bad number of identifiers in inherit: %d != %d\n", +  decode_error(data, Pike_sp - 1, "Bad number of identifiers " +  "in inherit (%d != %d).\n",    no, prog->num_identifier_references);    }       EDB(5,    fprintf(stderr,    "%*slow_inherit(..., \"%s\")\n",    data->depth, "",    name?name->str:"NULL"));       /* Alters    *    * storage, inherits and identifier_references    */    low_inherit(prog, parent, parent_identifier,    parent_offset + 42, id_flags, name);       pop_n_elems(3);    }    break;    default: -  Pike_error("Unsupported id entry type: %d\n", entry_type); +  decode_error(data, NULL, "Unsupported id entry type: %d\n", +  entry_type);    }    decode_number(entry_type, data);    }       /* Restore c->lex. */    CALL_AND_UNSET_ONERROR(err2);    c->lex.current_line = save_current_line;      #ifdef ENCODE_DEBUG    data->depth-=2;
pike.git/src/encode.c:4604:    Pike_compiler->num_parse_error--;       p->flags |= PROGRAM_PASS_1_DONE;       /* Fixate & optimize    *    * lfuns and identifier_index    */    ref_push_program (p);    if (!(p = end_first_pass(2))) { -  decode_error(Pike_sp - 1, NULL, "Failed to decode program.\n"); +  decode_error(data, Pike_sp - 1, "Failed to decode program.\n");    }    pop_stack();    push_program(p);       if (c->placeholder) {    push_object(placeholder = c->placeholder);    c->placeholder = NULL;    }       exit_compiler();
pike.git/src/encode.c:4632:    /* We've regenerated p->program, so these may be off. */    local_num_program = p->num_program;    local_num_relocations = p->num_relocations;    local_num_linenumbers = p->num_linenumbers;    }       /* Verify... */   #define FOO(NUMTYPE,TYPE,ARGTYPE,NAME) \    if (PIKE_CONCAT(local_num_, NAME) != p->PIKE_CONCAT(num_,NAME)) { \    ref_push_program (p); \ -  decode_error(Pike_sp - 1, NULL, \ +  decode_error(data, Pike_sp - 1, \    "Value mismatch for num_" TOSTR(NAME) ": " \ -  "%"PRINTSIZET"d != %"PRINTSIZET"d " \ -  "(bytecode method: %d)\n", \ +  "%zd != %zd (bytecode method: %d)\n", \    (size_t) PIKE_CONCAT(local_num_, NAME), \    (size_t) p->PIKE_CONCAT(num_, NAME), \    bytecode_method); \    }   #include "program_areas.h"       /* Decode the actual constants    *    * This must be done after the program has been ended.    */
pike.git/src/encode.c:4668:    /* name */    decode_value2(data);   #if 0    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 {    ref_push_program (p); -  decode_error(Pike_sp - 1, Pike_sp - 2, -  "Name of constant is not a string: "); +  decode_error(data, Pike_sp - 1, +  "Name of constant is not a string: %O\n", +  Pike_sp - 2);    }    constant->sval = Pike_sp[-2];    dmalloc_touch_svalue(Pike_sp-1);    dmalloc_touch_svalue(Pike_sp-2);    Pike_sp -= 2;   #else /* !0 */    constant->offset = -1;    pop_stack();    constant->sval = Pike_sp[-1];    dmalloc_touch_svalue(Pike_sp-1);
pike.git/src/encode.c:4701:    data->pickyness--;       /* The program should be consistent now. */    p->flags &= ~PROGRAM_AVOID_CHECK;       EDB(5, fprintf(stderr, "%*sProgram flags: 0x%04x\n",    data->depth, "", p->flags));       if (placeholder) {    if (placeholder->prog != null_program) { -  Pike_error("Placeholder has been zapped during decoding.\n"); +  decode_error(data, NULL, +  "Placeholder has been zapped during decoding.\n");    }    debug_malloc_touch(placeholder);    free_program(placeholder->prog);    add_ref(placeholder->prog = p);    placeholder->storage = p->storage_needed ?    (char *)xcalloc(p->storage_needed, 1) :    (char *)NULL;    call_c_initializers(placeholder);    if (!data->delay_counter) {    call_pike_initializers(placeholder, 0);
pike.git/src/encode.c:4746:    }    }      #ifdef ENCODE_DEBUG    data->depth -= 2;   #endif    goto decode_done;    }       default: -  Pike_error("Cannot decode program encoding type %d\n",num); +  decode_error(data, NULL, +  "Cannot decode program encoding type %d\n",num);    }    break;       default: -  Pike_error("Failed to restore string. (Illegal type)\n"); +  decode_error(data, NULL, "Failed to restore string (illegal type %d).\n", +  what & TAG_MASK);    }       mapping_insert(data->decoded, &entry_id, Pike_sp-1);      decode_done:;    EDB(2,fprintf(stderr, "%*sDecoded to <%d>: ", data->depth, "", entry_id.u.integer);    print_svalue(stderr, Pike_sp-1);    fputc('\n', stderr););   #ifdef ENCODE_DEBUG    data->depth -= 2;
pike.git/src/encode.c:4822:    debug_malloc_touch(data);    /* We have been delayed */    return;    }      #ifdef PIKE_DEBUG    if (!free_after_error) {    NEW_MAPPING_LOOP (data->decoded->data) {    if (k->val.type == T_PROGRAM &&    !(k->val.u.program->flags & PROGRAM_FINISHED)) { -  decode_error (NULL, &k->val, -  "Got unfinished program <%"PRINTPIKEINT"d> " -  "after decode: ", k->ind.u.integer); +  decode_error (data, NULL, +  "Got unfinished program <%O> after decode: %O\n", +  &k->ind, &k->val);    }    }    if(data->unfinished_programs)    Pike_fatal("We have unfinished programs left in decode()!\n");    if(data->unfinished_objects)    Pike_fatal("We have unfinished objects left in decode()!\n");    if(data->unfinished_placeholders)    Pike_fatal("We have unfinished placeholders left in decode()!\n");    }   #endif
pike.git/src/encode.c:5024:    call_dependants(& data->supporter, 1);   #else    delay = 0;   #endif    free_decode_data (data, delay, 0);    }       return 1;   }    - /* Compatibilidy decoder */ -  - static unsigned char extract_char(char **v, ptrdiff_t *l) - { -  if(!*l) Pike_error("Format error, not enough place for char.\n"); -  else (*l)--; -  (*v)++; -  return ((unsigned char *)(*v))[-1]; - } -  - static ptrdiff_t extract_int(char **v, ptrdiff_t *l) - { -  INT32 j; -  ptrdiff_t i; -  -  j=extract_char(v,l); -  if(j & 0x80) return (j & 0x7f); -  -  if((j & ~8) > 4) -  Pike_error("Format error: Error in format string, invalid integer.\n"); -  i=0; -  while(j & 7) { i=(i<<8) | extract_char(v,l); j--; } -  if(j & 8) return -i; -  return i; - } -  +    /*! @class MasterObject    */      /*! @decl inherit Codec    *!    *! The master object is used as a fallback codec by @[encode_value()]    *! and @[decode_value()] if no codec was given.    *!    *! It will also be used as a codec if @[decode_value()] encounters    *! old-style @[encode_value()]'ed data.
pike.git/src/encode.c:5174:    *! @returns    *! Returns either zero or a placeholder object. A placeholder    *! object must be a clone of @[__null_program]. When the program is    *! finished, the placeholder object will be converted to a clone of    *! it. This is used for pike module objects.    */      /*! @endclass    */    + /* Compatibility decoder */ +  + static unsigned char extract_char(char **v, ptrdiff_t *l) + { +  if(!*l) decode_error(current_decode, NULL, "Not enough place for char.\n"); +  else (*l)--; +  (*v)++; +  return ((unsigned char *)(*v))[-1]; + } +  + static ptrdiff_t extract_int(char **v, ptrdiff_t *l) + { +  INT32 j; +  ptrdiff_t i; +  +  j=extract_char(v,l); +  if(j & 0x80) return (j & 0x7f); +  +  if((j & ~8) > 4) +  decode_error(current_decode, NULL, "Invalid integer.\n"); +  i=0; +  while(j & 7) { i=(i<<8) | extract_char(v,l); j--; } +  if(j & 8) return -i; +  return i; + } +    static void rec_restore_value(char **v, ptrdiff_t *l)   {    ptrdiff_t t, i;       i = extract_int(v,l);    t = extract_int(v,l);    switch(i)    {    case TAG_INT:    push_int(DO_NOT_WARN(t));    return;       case TAG_FLOAT:    if(sizeof(ptrdiff_t) < sizeof(FLOAT_TYPE)) /* FIXME FIXME FIXME FIXME */ -  Pike_error("Float architecture not supported.\n"); +  decode_error(current_decode, NULL, "Float architecture not supported.\n");    push_int(DO_NOT_WARN(t)); /* WARNING! */    Pike_sp[-1].type = T_FLOAT;    return;       case TAG_TYPE:    { -  Pike_error("Format error: TAG_TYPE not supported yet.\n"); +  decode_error(current_decode, NULL, "TAG_TYPE not supported yet.\n");    }    return;       case TAG_STRING: -  if(t<0) Pike_error("Format error: length of string is negative.\n"); -  if(*l < t) Pike_error("Format error: string too short\n"); +  if(t<0) decode_error(current_decode, NULL, +  "length of string is negative.\n"); +  if(*l < t) decode_error(current_decode, NULL, "string too short\n");    push_string(make_shared_binary_string(*v, t));    (*l)-= t;    (*v)+= t;    return;       case TAG_ARRAY: -  if(t<0) Pike_error("Format error: length of array is negative.\n"); +  if(t<0) decode_error(current_decode, NULL, +  "length of array is negative.\n");    check_stack(t);    for(i=0;i<t;i++) rec_restore_value(v,l);    f_aggregate(DO_NOT_WARN(t)); /* FIXME: Unbounded stack consumption. */    return;       case TAG_MULTISET: -  if(t<0) Pike_error("Format error: length of multiset is negative.\n"); +  if(t<0) decode_error(current_decode, NULL, +  "length of multiset is negative.\n");    check_stack(t);    for(i=0;i<t;i++) rec_restore_value(v,l);    f_aggregate_multiset(DO_NOT_WARN(t)); /* FIXME: Unbounded stack consumption. */    return;       case TAG_MAPPING: -  if(t<0) Pike_error("Format error: length of mapping is negative.\n"); +  if(t<0) decode_error(current_decode, NULL, +  "length of mapping is negative.\n");    check_stack(t*2);    for(i=0;i<t;i++)    {    rec_restore_value(v,l);    rec_restore_value(v,l);    }    f_aggregate_mapping(DO_NOT_WARN(t*2)); /* FIXME: Unbounded stack consumption. */    return;       case TAG_OBJECT: -  if(t<0) Pike_error("Format error: length of object is negative.\n"); -  if(*l < t) Pike_error("Format error: string too short\n"); +  if(t<0) decode_error(current_decode, NULL, +  "length of object is negative.\n"); +  if(*l < t) decode_error(current_decode, NULL, "string too short\n");    push_string(make_shared_binary_string(*v, t));    (*l) -= t; (*v) += t;    APPLY_MASTER("objectof", 1);    return;       case TAG_FUNCTION: -  if(t<0) Pike_error("Format error: length of function is negative.\n"); -  if(*l < t) Pike_error("Format error: string too short\n"); +  if(t<0) decode_error(current_decode, NULL, +  "length of function is negative.\n"); +  if(*l < t) decode_error(current_decode, NULL, "string too short\n");    push_string(make_shared_binary_string(*v, t));    (*l) -= t; (*v) += t;    APPLY_MASTER("functionof", 1);    return;       case TAG_PROGRAM: -  if(t<0) Pike_error("Format error: length of program is negative.\n"); -  if(*l < t) Pike_error("Format error: string too short\n"); +  if(t<0) decode_error(current_decode, NULL, +  "length of program is negative.\n"); +  if(*l < t) decode_error(current_decode, NULL, "string too short\n");    push_string(make_shared_binary_string(*v, t));    (*l) -= t; (*v) += t;    APPLY_MASTER("programof", 1);    return;       default: -  Pike_error("Format error: Unknown type tag %ld:%ld\n", +  decode_error(current_decode, NULL, "Unknown type tag %ld:%ld\n",    PTRDIFF_T_TO_LONG(i), PTRDIFF_T_TO_LONG(t));    }   }    -  + static void restore_current_decode (struct decode_data *old_data) + { +  current_decode = old_data; + } +    /* Defined in builtin.cmod. */   extern struct program *MasterCodec_program;      /*! @decl mixed decode_value(string coded_value, void|Codec codec)    *!    *! Decode a value from the string @[coded_value].    *!    *! This function takes a string created with @[encode_value()] or    *! @[encode_value_canonic()] and converts it back to the value that was    *! coded.
pike.git/src/encode.c:5311:       switch (args) {    default:   #ifdef ENCODE_DEBUG    debug = Pike_sp[2-args].u.integer;    /* Fall through. */    case 2:   #endif    if (Pike_sp[1-args].type == T_OBJECT) {    if (Pike_sp[1-args].subtype) { -  Pike_error("decode_value: " +  struct decode_data data; +  MEMSET (&data, 0, sizeof (data)); +  data.data_str = s; /* Not refcounted. */ +  decode_error(&data, NULL,    "The codec may not be a subtyped object yet.\n");    }    codec = Pike_sp[1-args].u.object;    break;    }    /* Fall through. */    case 1:    codec = get_master();    if (!codec) {    /* The codec used for decoding the master program. */
pike.git/src/encode.c:5336:    }       if(!my_decode(s, codec   #ifdef ENCODE_DEBUG    , debug   #endif    ))    {    char *v=s->str;    ptrdiff_t l=s->len; +  struct decode_data data; +  ONERROR uwp; +  MEMSET (&data, 0, sizeof (data)); +  data.data_str = s; /* Not refcounted. */ +  SET_ONERROR (uwp, restore_current_decode, current_decode); +  current_decode = &data;    rec_restore_value(&v, &l); -  +  CALL_AND_UNSET_ONERROR (uwp);    }    assign_svalue(Pike_sp-args-1, Pike_sp-1);    pop_n_elems(args);   }