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.168 2003/02/24 19:03:03 mast Exp $ + || $Id: encode.c,v 1.169 2003/03/14 15:53:09 grubba Exp $   */      #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:20:   #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"   #include "pikecode.h"    - RCSID("$Id: encode.c,v 1.168 2003/02/24 19:03:03 mast Exp $"); + RCSID("$Id: encode.c,v 1.169 2003/03/14 15:53:09 grubba Exp $");      /* #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. */   #define EDB(N,X) do { debug_malloc_touch(data); if (data->debug>=N) {X;} } while (0)
pike.git/src/encode.c:676:    f_values(1);       if (data->canonic) {    INT32 *order;    if (val->u.mapping->data->ind_types & ~(BIT_BASIC & ~BIT_TYPE)) {    mapping_fix_type_field(val->u.mapping);    if (val->u.mapping->data->ind_types & ~(BIT_BASIC & ~BIT_TYPE))    /* This doesn't let bignums through. That's necessary as    * long as they aren't handled deterministically by the    * sort function. */ -  /* They should be hanled deterministically now - Hubbe */ +  /* They should be handled deterministically now - Hubbe */    Pike_error("Canonical encoding requires basic types in indices.\n");    }    order = get_switch_order(Pike_sp[-2].u.array);    order_array(Pike_sp[-2].u.array, order);    order_array(Pike_sp[-1].u.array, order);    free((char *) order);    }       code_entry(TAG_MAPPING, Pike_sp[-2].u.array->size,data);    for(i=0; i<Pike_sp[-2].u.array->size; i++)
pike.git/src/encode.c:1427:    /* 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); +  dmalloc_touch_svalue(Pike_sp-1);    Pike_sp--;    }    }    }   #endif /* OLD_PIKE_ENCODE_PROGRAM */    }else{    code_entry(TAG_PROGRAM, 0, data);    encode_value2(Pike_sp-1, data);    }    pop_stack();
pike.git/src/encode.c:1630:   };      static void decode_value2(struct decode_data *data);      static void fallback_codec(void)   {    size_t x;    push_constant_text(".");    f_divide(2);    f_reverse(1); +  dmalloc_touch_svalue(Pike_sp-1);    Pike_sp--;    x=Pike_sp->u.array->size;    push_array_items(Pike_sp->u.array);    ref_push_mapping(get_builtin_constants());    while(x--)    {    stack_swap();    f_arrow(2);    }   }
pike.git/src/encode.c:1986:    VAR=tmp.u.U; \    SCOUR; \    }else{ \    tmp.type=TYPE; \    tmp.u.U=VAR=ALLOCATE; \    mapping_insert(data->decoded, & data->counter, &tmp); \    /* Since a reference to the object is stored in the mapping, we can \    * safely decrease this reference here. Thus it will be automatically \    * freed if something goes wrong. \    */ \ -  VAR->refs--; \ +  sub_ref(VAR); \    } \    data->counter.u.integer++; \   }while(0)      /* This really needs to disable threads.... */   #define decode_type(X,data) do { \    type_stack_mark(); \    low_decode_type(data); \    (X)=pop_unfinished_type(); \   } while(0)
pike.git/src/encode.c:2391:    (p = Pike_sp[-2].u.object->prog)) {    int f = find_shared_string_identifier(Pike_sp[-1].u.string, p);    if (f >= 0) {    struct svalue func;    low_object_index_no_free(&func, Pike_sp[-2].u.object, f);   #ifdef PIKE_SECURITY    /* FIXME: Check access to the function. */   #endif    pop_n_elems(2);    *Pike_sp++ = func; +  dmalloc_touch_svalue(Pike_sp-1);    break;    }    }    pop_stack();    break;    }       default:    Pike_error("Function coding not compatible.\n");    break;
pike.git/src/encode.c:2496:    {    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"); +  dmalloc_touch_svalue(Pike_sp-1);    Pike_sp--;    }else{    pop_stack();    }    }    }       if(placeholder)    SET_ONERROR(err4, zap_placeholder, placeholder);   
pike.git/src/encode.c:2713:    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)    Pike_error("Program decode failed!\n"); -  p->refs--; +  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:2824:       p->flags |= PROGRAM_PASS_1_DONE | PROGRAM_FIXED;    for(d=0;d<p->num_constants;d++)    {    decode_value2(data);    if(data->pass > 1)    {    assign_svalue(& p->constants[d].sval , Pike_sp -1 );    pop_stack();    }else{ +  dmalloc_touch_svalue(Pike_sp-1);    p->constants[d].sval=*--Pike_sp;    }    dmalloc_touch_svalue(Pike_sp);    getdata3(p->constants[d].name);    }      #ifdef PIKE_DEBUG    {    int q;    for(q=0;q<p->num_inherits;q++)
pike.git/src/encode.c:3097:    decode_value2(data);    if (Pike_sp[-1].type == T_PROGRAM) {    p->parent = Pike_sp[-1].u.program;    } 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",    get_name_of_type(Pike_sp[-1].type));    } +  dmalloc_touch_svalue(Pike_sp-1);    Pike_sp--;       /* 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_BYTECODE_METHOD) {    Pike_error("Unsupported byte-code method: %d\n", bytecode_method);
pike.git/src/encode.c:3155:    * 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) {    Pike_error("Non strings in string table.\n");    }    add_to_strings(Pike_sp[-1].u.string); +  dmalloc_touch_svalue(Pike_sp-1);    Pike_sp--;    }       /* Place holder constants.    *    * These will be replaced later on.    */    {    struct program_constant constant;    constant.name = NULL;
pike.git/src/encode.c:3410:       if (no != n) {    if (id.name->size_shift)    Pike_error("Bad constant identifier offset: %d\n", no);    else    Pike_error("Bad constant identifier offset %d for %s\n",    no, id.name->str);    }       add_to_identifiers(id); +  dmalloc_touch_svalue(Pike_sp-1); +  dmalloc_touch_svalue(Pike_sp-2);    Pike_sp -= 2;    }    break;    case ID_ENTRY_INHERIT:    {    struct program *prog;    struct object *parent = NULL;    int parent_identifier;    int parent_offset;    struct pike_string *name = NULL;
pike.git/src/encode.c:3540:    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("Name of constant is not a string.\n");    }    constant->sval = Pike_sp[-2]; +  dmalloc_touch_svalue(Pike_sp-1); +  dmalloc_touch_svalue(Pike_sp-2);    Pike_sp -= 2;    }       /* The program should be consistent now. */    p->flags &= ~PROGRAM_AVOID_CHECK;       EDB(5, fprintf(stderr, "%*sProgram flags: 0x%04x\n",    data->depth, "", p->flags));      #ifdef ENCODE_DEBUG
pike.git/src/encode.c:4005:    *!    *! If no codec is specified, the current master object will be used as codec.    *!    *! @seealso    *! @[encode_value()], @[encode_value_canonic()]    */   void f_decode_value(INT32 args)   {    struct pike_string *s;    struct object *codec; +  struct pike_frame *new_frame;      #ifdef ENCODE_DEBUG    int debug;   #endif /* ENCODE_DEBUG */       check_all_args("decode_value", args,    BIT_STRING, BIT_VOID | BIT_OBJECT | BIT_INT,   #ifdef ENCODE_DEBUG    /* This argument is only an internal debug helper.    * It's intentionally not part of the function