pike.git / src / encode.c

version» Context lines:

pike.git/src/encode.c:18:   #include "pike_error.h"   #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"    - RCSID("$Id: encode.c,v 1.98 2001/04/14 09:44:19 hubbe Exp $"); + RCSID("$Id: encode.c,v 1.99 2001/05/14 03:26:57 hubbe Exp $");      /* #define ENCODE_DEBUG */      #ifdef ENCODE_DEBUG   #define EDB(X) X   #else   #define EDB(X)   #endif      /* The sp macro conflicts with Solaris 2.5.1's <sys/conf.h>. */
pike.git/src/encode.c:476:    }    return t-q;   }      static void encode_type(struct pike_type *t, struct encode_data *data)   {    low_encode_type(t->str, data);   }   #endif /* USE_PIKE_TYPE */    + static void zap_unfinished_program(struct program *p) + { +  int e; +  debug_malloc_touch(p); +  if(p->parent) +  { +  free_program(p->parent); +  p->parent=0; +  } +  for(e=0;e<p->num_constants;e++) +  { +  free_svalue(& p->constants[e].sval); +  p->constants[e].sval.type=T_INT; +  DO_IF_DMALLOC(p->constants[e].sval.u.refs=(void *)-1); +  } +  +  for(e=0;e<p->num_inherits;e++) +  { +  if(p->inherits[e].parent) +  { +  free_object(p->inherits[e].parent); +  p->inherits[e].parent=0; +  } +  if(e) +  { +  if(p->inherits[e].prog) +  { +  free_program(p->inherits[e].prog); +  p->inherits[e].prog=0; +  } +  } +  } + } +    static void encode_value2(struct svalue *val, struct encode_data *data)      #ifdef PIKE_DEBUG   #undef encode_value2   #define encode_value2(X,Y) do { struct svalue *_=Pike_sp; encode_value2_(X,Y); if(Pike_sp!=_) fatal("encode_value2 failed!\n"); } while(0)   #endif      {    static struct svalue dested = { T_INT, NUMBER_DESTRUCTED };    INT32 i;
pike.git/src/encode.c:1146: Inside #if 0
  {   #if 0    fprintf(stderr, "Restoring type-stack: %p => %p\n",    Pike_compiler->type_stackp, old_stackp);   #endif /* 0 */   #ifdef PIKE_DEBUG    if (old_stackp > Pike_compiler->type_stackp) {    fatal("type stack out of sync!\n");    }   #endif /* PIKE_DEBUG */ + #ifdef USE_PIKE_TYPE +  while(Pike_compiler->type_stackp > old_stackp) { +  free_type(*(Pike_compiler->type_stackp--)); +  } + #else    Pike_compiler->type_stackp = old_stackp; -  + #endif   }      static void restore_type_mark(struct pike_type ***old_type_mark_stackp)   {   #if 0    fprintf(stderr, "Restoring type-mark: %p => %p\n",    Pike_compiler->pike_type_mark_stackp, old_type_mark_stackp);   #endif /* 0 */   #ifdef PIKE_DEBUG    if (old_type_mark_stackp > Pike_compiler->pike_type_mark_stackp) {
pike.git/src/encode.c:1682:    stack_swap();    pop_stack();    break;    }    case 1:    {    int d;    size_t size=0;    char *dat;    struct program *p; -  ONERROR err1; -  ONERROR err2; +  ONERROR err1, err2, err3;      #ifdef _REENTRANT    ONERROR err;    low_init_threads_disable();    SET_ONERROR(err, do_enable_threads, 0);   #endif       p=low_allocate_program(); -  +  SET_ONERROR(err3, zap_unfinished_program, p); +     debug_malloc_touch(p);    tmp.type=T_PROGRAM;    tmp.u.program=p;    mapping_insert(data->decoded, & data->counter, &tmp);    data->counter.u.integer++;    p->refs--;       decode_value2(data);    f_version(0);    if(!is_eq(Pike_sp-1,Pike_sp-2))    Pike_error("Cannot decode programs encoded with other pike version.\n");    pop_n_elems(2);    -  +  debug_malloc_touch(p);    decode_number(p->flags,data);    p->flags &= ~(PROGRAM_FINISHED | PROGRAM_OPTIMIZED);    p->flags |= PROGRAM_AVOID_CHECK;    decode_number(p->storage_needed,data);    decode_number(p->xstorage,data);    decode_number(p->parent_info_storage,data);    decode_number(p->alignment_needed,data);    decode_number(p->timestamp.tv_sec,data);    decode_number(p->timestamp.tv_usec,data);    -  +  debug_malloc_touch(p);    decode_value2(data);    switch(Pike_sp[-1].type)    {    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:    Pike_error("Program decode failed!\n");    }    if(p->parent) add_ref(p->parent);    pop_stack();    -  +  debug_malloc_touch(p); +    #define FOO(X,Y,Z) \    decode_number( p->num_##Z, data);   #include "program_areas.h"      #define FOO(NUMTYPE,TYPE,NAME) \    size=DO_ALIGN(size, ALIGNOF(TYPE)); \    size+=p->PIKE_CONCAT(num_,NAME)*sizeof(p->NAME[0]);   #include "program_areas.h"       dat=xalloc(size);
pike.git/src/encode.c:1756:   #define FOO(NUMTYPE,TYPE,NAME) \    size=DO_ALIGN(size, ALIGNOF(TYPE)); \    p->NAME=(TYPE *)(dat+size); \    size+=p->PIKE_CONCAT(num_,NAME)*sizeof(p->NAME[0]);   #include "program_areas.h"       for(e=0;e<p->num_constants;e++)    p->constants[e].sval.type=T_INT;       debug_malloc_touch(dat); +  debug_malloc_touch(p);       p->total_size=size + sizeof(struct program);       p->flags |= PROGRAM_OPTIMIZED;       getdata2(p->program, p->num_program);    getdata2(p->linenumbers, p->num_linenumbers);      #ifdef DEBUG_MALLOC    if(p->num_linenumbers && p->linenumbers &&
pike.git/src/encode.c:1779: Inside #if defined(DEBUG_MALLOC)
   extern int get_small_number(char **);    foo=p->linenumbers+1;    foo+=strlen(foo)+1;    get_small_number(&foo); /* pc offset */    debug_malloc_name(p, p->linenumbers+1,    get_small_number(&foo));    }   #endif       +  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;    Pike_error("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;    Pike_error("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;    Pike_error("Malformed program in decode.\n");    }    decode_number(p->identifier_references[d].identifier_offset,data);    decode_number(p->identifier_references[d].id_flags,data);    }    -  +  debug_malloc_touch(p);    for(d=0;d<p->num_strings;d++)    getdata(p->strings[d]);    -  +  debug_malloc_touch(p);    debug_malloc_touch(dat);       data->pickyness++;         /* p->inherits[0].prog=p;    p->inherits[0].parent_offset=1;   */    -  +  debug_malloc_touch(p);    for(d=0;d<p->num_inherits;d++)    {    decode_number(p->inherits[d].inherit_level,data);    decode_number(p->inherits[d].identifier_level,data);    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)
pike.git/src/encode.c:1873:    }       getdata3(p->inherits[d].name);    }       debug_malloc_touch(dat);       SET_ONERROR(err1, restore_type_stack, Pike_compiler->type_stackp);    SET_ONERROR(err2, restore_type_mark, Pike_compiler->pike_type_mark_stackp);    +  debug_malloc_touch(p);    for(d=0;d<p->num_identifiers;d++)    {    getdata(p->identifiers[d].name);    decode_type(p->identifiers[d].type,data);    decode_number(p->identifiers[d].identifier_flags,data);    decode_number(p->identifiers[d].run_time_type,data);    decode_number(p->identifiers[d].opt_flags,data);    decode_number(p->identifiers[d].func.offset,data);    }       UNSET_ONERROR(err2);    UNSET_ONERROR(err1);       debug_malloc_touch(dat);    -  +  debug_malloc_touch(p);    for(d=0;d<p->num_constants;d++)    {    decode_value2(data);    p->constants[d].sval=*--Pike_sp;    dmalloc_touch_svalue(Pike_sp);    getdata3(p->constants[d].name);    }    data->pickyness--;       debug_malloc_touch(dat);    -  +  debug_malloc_touch(p);    for(d=0;d<NUM_LFUNS;d++)    decode_number(p->lfuns[d],data);       debug_malloc_touch(dat);    -  +  debug_malloc_touch(p);    {    struct program *new_program_save=Pike_compiler->new_program;    Pike_compiler->new_program=p;    fsort((void *)p->identifier_index,    p->num_identifier_index,    sizeof(unsigned short),(fsortfun)program_function_index_compare);    Pike_compiler->new_program=new_program_save;    } -  +  UNSET_ONERROR(err3);    p->flags &=~ PROGRAM_AVOID_CHECK;    p->flags |= PROGRAM_FINISHED;    ref_push_program(p);      #ifdef PIKE_DEBUG    check_program(p);   #endif /* PIKE_DEBUG */      #ifdef _REENTRANT    UNSET_ONERROR(err);