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.170 2004/05/11 11:09:13 grubba Exp $ + || $Id: encode.c,v 1.171 2004/05/11 11:28:52 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:25:   #include "fsort.h"   #include "threads.h"   #include "stuff.h"   #include "version.h"   #include "bignum.h"   #include "pikecode.h"   #include "pike_types.h"   #include "opcodes.h"   #include "peep.h"    - RCSID("$Id: encode.c,v 1.170 2004/05/11 11:09:13 grubba Exp $"); + RCSID("$Id: encode.c,v 1.171 2004/05/11 11:28:52 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:725:    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:806:    check_stack(1);      #ifdef AUTO_BIGNUM    /* This could be implemented a lot more generic,    * but that will have to wait until next time. /Hubbe    */    if(is_bignum_object(val->u.object))    {    code_entry(TAG_OBJECT, 2, data);    /* 256 would be better, but then negative numbers -  * doesn't work... /Hubbe +  * won't work... /Hubbe    */    push_int(36);    apply(val->u.object,"digits",1);    if(Pike_sp[-1].type != T_STRING)    Pike_error("Gmp.mpz->digits did not return a string!\n");    encode_value2(Pike_sp-1, data, 0);    pop_stack();    break;    }   #endif
pike.git/src/encode.c:916:    code_entry(TAG_FUNCTION, 1, data);    push_svalue(val);    Pike_sp[-1].type=T_OBJECT;    encode_value2(Pike_sp-1, data, 0);    ref_push_string(ID_FROM_INT(val->u.object->prog, val->subtype)->name);    encode_value2(Pike_sp-1, data, 0);    pop_n_elems(3);       /* Put value back in cache */    mapping_insert(data->encoded, val, &tmp); - #ifdef ENCODE_DEBUG -  data->depth -= 2; - #endif -  return; +  goto encode_done;    }    } -  Pike_error("Encoding of efuns is not supported yet.\n"); +  Pike_error("Cannot encode builtin functions.\n");    }       code_entry(TAG_FUNCTION, 0, data);    encode_value2(Pike_sp-1, data, 0);    pop_stack();    break;          case T_PROGRAM:    {
pike.git/src/encode.c:974:    ref_push_program(p);    f_function_name(1);    if(Pike_sp[-1].type == PIKE_T_INT)    Pike_error("Cannot encode C programs.\n");    encode_value2(Pike_sp-1, data, 0);       pop_n_elems(3);       /* Put value back in cache */    mapping_insert(data->encoded, val, &tmp); - #ifdef ENCODE_DEBUG -  data->depth -= 2; - #endif -  return; +  goto encode_done;    }    if( p->event_handler )    Pike_error("Cannot encode programs with event handlers.\n");    Pike_error("Cannot encode C programs.\n");    }       -  + #ifdef OLD_PIKE_ENCODE_PROGRAM +     EDB(1, -  fprintf(stderr, "%*sencode: encoding program\n", +  fprintf(stderr, "%*sencode: encoding program in old style\n",    data->depth, ""));    - #ifdef OLD_PIKE_ENCODE_PROGRAM -  +     /* Type 1 -- Old-style encoding. */       code_entry(TAG_PROGRAM, 1, data);    f_version(0);    encode_value2(Pike_sp-1,data, 0);    pop_stack();    code_number(p->flags,data);    code_number(p->storage_needed,data);    code_number(p->xstorage,data); /**/    code_number(p->parent_info_storage,data); /**/
pike.git/src/encode.c:1013: Inside #if defined(OLD_PIKE_ENCODE_PROGRAM)
   code_number(p->timestamp.tv_sec,data);    code_number(p->timestamp.tv_usec,data);       if(p->parent)    ref_push_program(p->parent);    else    push_int(0);    encode_value2(Pike_sp-1,data, 0); /**/    pop_stack();    - #define FOO(X,Y,Z) \ -  code_number( p->PIKE_CONCAT(num_,Z), data); + #define FOO(NUMTYPE,TYPE,NAME) \ +  code_number( p->PIKE_CONCAT(num_,NAME), data);   #include "program_areas.h"       code_number(PIKE_BYTECODE_METHOD, data);      #ifdef ENCODE_PROGRAM   #ifdef PIKE_DEBUG    {    ptrdiff_t bufpos = data->buf.s.len;   #endif /* PIKE_DEBUG */    ENCODE_PROGRAM(p, &(data->buf));
pike.git/src/encode.c:1124:       for(d=0;d<p->num_constants;d++)    {    encode_value2(& p->constants[d].sval, data, 0);    adddata3(p->constants[d].name);    }      #else /* !OLD_PIKE_ENCODE_PROGRAM */       /* Type 4 -- Portable encoding. */ +  EDB(1, fprintf(stderr, "%*sencode: encoding program in new style\n", +  data->depth, ""));    code_entry(type_to_tag(val->type), 4, data);       /* Byte-order. */    code_number(PIKE_BYTEORDER, data);       /* flags */    code_number(p->flags,data);       /* version */    f_version(0);
pike.git/src/encode.c:1147:    /* parent */    if (p->parent) {    ref_push_program(p->parent);    } else {    push_int(0);    }    encode_value2(Pike_sp-1, data, 0);    pop_stack();       /* num_* */ - #define FOO(X,Y,Z) \ -  code_number( p->PIKE_CONCAT(num_,Z), data); + #define FOO(NUMTYPE,TYPE,NAME) \ +  code_number( p->PIKE_CONCAT(num_,NAME), data);   #include "program_areas.h"       /* Byte-code method    */    code_number(PIKE_BYTECODE_METHOD, data);      #ifdef PIKE_USE_MACHINE_CODE    /* Add the checksum of the instrs array. */    code_number(instrs_checksum, data);   #endif /* PIKE_USE_MACHINE_CODE */
pike.git/src/encode.c:1230:    /* NOTE: d is incremented by hand inside the loop. */    for (d=0; d < p->num_identifier_references;)    {    int d_max = p->num_identifier_references;       /* Find insertion point of next inherit. */    if (inherit_num < p->num_inherits) {    d_max = p->inherits[inherit_num].identifier_ref_offset;    }    +  EDB (4, fprintf (stderr, "%*sencode: inherit_num: %d, d_max: %d\n", +  data->depth, "", inherit_num, d_max);); +     /* Fix locally defined identifiers. */    for (; d < d_max; d++) {    struct reference *ref = p->identifier_references + d;    struct inherit *inh = INHERIT_FROM_PTR(p, ref);    struct identifier *id = ID_FROM_PTR(p, ref);       /* Skip identifiers that haven't been overloaded. */    if (ref->id_flags & ID_INHERITED) continue;       EDB(3,
pike.git/src/encode.c:1482:    /* value */    encode_value2(&p->constants[d].sval, data, 0);       /* name */    if (p->constants[d].name) {    str_sval.u.string = p->constants[d].name;    encode_value2(&str_sval, data, 0);    } else {    push_int(0);    encode_value2(Pike_sp-1, data, 0); +  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, 0);    }    pop_stack();    break;    }    }    -  + encode_done:; +    #ifdef ENCODE_DEBUG    data->depth -= 2;   #endif   }      static void free_encode_data(struct encode_data *data)   {    toss_buffer(& data->buf);    free_mapping(data->encoded);   }