pike.git / src / encode.c

version» Context lines:

pike.git/src/encode.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: encode.c,v 1.294 2010/07/01 11:25:18 grubba Exp $ + || $Id$   */      #include "global.h"   #include "stralloc.h"   #include "pike_macros.h"   #include "object.h"   #include "constants.h"   #include "interpret.h"   #include "svalue.h"   #include "mapping.h"
pike.git/src/encode.c:32:   #include "peep.h"   #include "pike_compiler.h"      /* #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. */ +  * encode_value_canonic and decode_value to activate this debug. It +  * both enables debug messages and also lessens the pickyness to +  * sort-of be able to decode programs with the wrong codec. */   #define EDB(N,X) do { debug_malloc_touch(data); if (data->debug>=N) {X;} } while (0)   #ifndef PIKE_DEBUG   #error ENCODE_DEBUG requires PIKE_DEBUG   #endif   #else   #define EDB(N,X) do { debug_malloc_touch(data); } while (0)   #endif      #ifdef _AIX   #include <net/nh.h>
pike.git/src/encode.c:3189:    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)) +  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");    pop_n_elems(2);    -  + #ifdef ENCODE_DEBUG +  if (!data->debug) + #endif    data->pickyness++;       debug_malloc_touch(p);    decode_number(p->flags,data);       if(data->pass == 1)    {    p->flags &= ~(PROGRAM_FINISHED | PROGRAM_OPTIMIZED |    PROGRAM_FIXED | PROGRAM_PASS_1_DONE);    p->flags |= PROGRAM_AVOID_CHECK;
pike.git/src/encode.c:3231:    case T_INT:    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: "); -  +  p->parent = 0; +  break;    }    if(p->parent) {    add_ref(p->parent);    }    pop_stack();       debug_malloc_touch(p);      #define FOO(NUMTYPE,TYPE,ARGTYPE,NAME) \    decode_number( p->PIKE_CONCAT(num_,NAME), data);
pike.git/src/encode.c:3571:    ref_push_program (p);    decode_error(Pike_sp - 1, NULL, "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) + #endif    data->pickyness--;       if(placeholder)    {    free_object(placeholder);    UNSET_ONERROR(err4);    }    UNSET_ONERROR(err3);       ref_push_program(p);
pike.git/src/encode.c:3940:    debug_malloc_touch(p);    } else {    data->delay_counter--;    }       debug_malloc_touch(p);       /* Check the version. */    decode_value2(data);    push_compact_version(); -  if(!is_eq(Pike_sp-1,Pike_sp-2)) +  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");    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;
pike.git/src/encode.c:4094:    ref_push_program (p);    decode_error(Pike_sp - 1, NULL,    "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)) { +  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: ");    }    break;    case ID_ENTRY_TYPE_CONSTANT: -  if (Pike_sp[-1].type != T_TYPE) { +  if (Pike_sp[-1].type != T_TYPE && data->pickyness) {    ref_push_program (p);    decode_error(Pike_sp - 1, Pike_sp - 2,    "Expected type constant: ");    }    break;    default: -  +  if (data->pickyness)    Pike_error("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.git/src/encode.c:4658:    constant->sval = Pike_sp[-1];    dmalloc_touch_svalue(Pike_sp-1);    Pike_sp -= 1;   #endif /* 0 */    EDB(5,    fprintf(stderr, "%*sDecoded constant %d to a %s\n",    data->depth, "",    e, get_name_of_type(constant->sval.type)));    }    + #ifdef ENCODE_DEBUG +  if (!data->debug) + #endif    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) {