pike.git / src / encode.c

version» Context lines:

pike.git/src/encode.c:18:   #include "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.43 1999/10/25 10:26:23 hubbe Exp $"); + RCSID("$Id: encode.c,v 1.44 1999/11/03 19:26:30 grubba Exp $");      /* #define ENCODE_DEBUG */      #ifdef ENCODE_DEBUG   #define EDB(X) X   #else   #define EDB(X)   #endif      #ifdef _AIX
pike.git/src/encode.c:732:    } \   }while(0)      #define decode_number(X,data) do { \    int what, e, num; \    DECODE("decode_number"); \    X=(what & T_MASK) | (num<<4); \    }while(0) \       + static void restore_type_stack(unsigned char *old_stackp) + { + #if 0 +  fprintf(stderr, "Restoring type-stack: %p => %p\n", +  type_stackp, old_stackp); + #endif /* 0 */ + #ifdef PIKE_DEBUG +  if (old_stackp > type_stackp) { +  fatal("type stack out of sync!\n"); +  } + #endif /* PIKE_DEBUG */ +  type_stackp = old_stackp; + } +  + static void restore_type_mark(unsigned char **old_type_mark_stackp) + { + #if 0 +  fprintf(stderr, "Restoring type-mark: %p => %p\n", +  pike_type_mark_stackp, old_type_mark_stackp); + #endif /* 0 */ + #ifdef PIKE_DEBUG +  if (old_type_mark_stackp > pike_type_mark_stackp) { +  fatal("type mark_stack out of sync!\n"); +  } + #endif /* PIKE_DEBUG */ +  pike_type_mark_stackp = old_type_mark_stackp; + } +    static void low_decode_type(struct decode_data *data)   {    int tmp; -  +  ONERROR err1; +  ONERROR err2; +  +  SET_ONERROR(err1, restore_type_stack, type_stackp); +  SET_ONERROR(err2, restore_type_mark, pike_type_mark_stackp); +    one_more_type:    push_type(tmp=GETC());    switch(tmp)    {    default:    fatal("error in type string.\n");    /*NOTREACHED*/    break;       case T_ASSIGN:
pike.git/src/encode.c:799:    case T_STRING:    case T_PROGRAM:    case T_MIXED:    case T_VOID:    case T_UNKNOWN:    break;       case T_OBJECT:    {    INT32 x; +     push_type(GETC());    decode_value2(data);    type_stack_mark();    switch(sp[-1].type)    {    case T_INT:    push_type_int(0);    break;       case T_PROGRAM:    push_type_int(sp[-1].u.program->id);    break;       default:    error("Failed to decode type.\n");    }    pop_stack();    type_stack_reverse();    }    } -  +  +  UNSET_ONERROR(err2); +  UNSET_ONERROR(err1);   }      /* This really needs to disable threads.... */   #define decode_type(X,data) do { \    type_stack_mark(); \    type_stack_mark(); \    low_decode_type(data); \    type_stack_reverse(); \    (X)=pop_unfinished_type(); \   } while(0)
pike.git/src/encode.c:914:    * safely decrease this reference here. Thus it will be automatically    * freed if something goes wrong.    */    a->refs--;       for(e=0;e<num;e++)    {    decode_value2(data);    ITEM(a)[e]=sp[-1];    sp--; +  dmalloc_touch_svalue(sp);    }    ref_push_array(a);    return;    }       case T_MAPPING:    {    struct mapping *m;    if(num<0)    error("Failed to decode string. (mapping size is negative)\n");
pike.git/src/encode.c:963:    /* Heruetical */    if(data->ptr + num > data->len)    error("Failed to decode multiset. (not enough data)\n");       m=mkmultiset(low_allocate_array(0, num));    tmp.type=T_MULTISET;    tmp.u.multiset=m;    mapping_insert(data->decoded, & data->counter, &tmp);    data->counter.u.integer++;    m->refs--; +  debug_malloc_touch(m);       for(e=0;e<num;e++)    {    decode_value2(data);    multiset_insert(m, sp-1);    pop_stack();    }    ref_push_multiset(m);    return;    }
pike.git/src/encode.c:1102:    if(data->pickyness && sp[-1].type != T_PROGRAM)    error("Failed to decode program.\n");    break;       case 1:    {    int d;    SIZE_T size=0;    char *dat;    struct program *p; +  ONERROR err1; +  ONERROR err2;      #ifdef _REENTRANT    ONERROR err;    low_init_threads_disable();    SET_ONERROR(err, do_enable_threads, 0);   #endif       p=low_allocate_program();    debug_malloc_touch(p);    tmp.type=T_PROGRAM;
pike.git/src/encode.c:1249:    if(sp[-1].subtype == FUNCTION_BUILTIN)    error("Failed to decode parent.\n");       p->inherits[d].parent_identifier=sp[-1].subtype;    p->inherits[d].prog=program_from_svalue(sp-1);    if(!p->inherits[d].prog)    error("Failed to decode parent.\n");    add_ref(p->inherits[d].prog);    p->inherits[d].parent=sp[-1].u.object;    sp--; +  dmalloc_touch_svalue(sp);    break;       case T_PROGRAM:    p->inherits[d].parent_identifier=0;    p->inherits[d].prog=sp[-1].u.program;    sp--; -  +  dmalloc_touch_svalue(sp);    break;    default:    error("Failed to decode inheritance.\n");    }       getdata3(p->inherits[d].name);    }       debug_malloc_touch(dat);    -  +  SET_ONERROR(err1, restore_type_stack, type_stackp); +  SET_ONERROR(err2, restore_type_mark, pike_type_mark_stackp); +     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].func.offset,data);    }    -  +  UNSET_ONERROR(err2); +  UNSET_ONERROR(err1); +     debug_malloc_touch(dat);       for(d=0;d<p->num_constants;d++)    {    decode_value2(data);    p->constants[d].sval=*--sp; -  +  dmalloc_touch_svalue(sp);    getdata3(p->constants[d].name);    }    data->pickyness--;       debug_malloc_touch(dat);       for(d=0;d<NUM_LFUNS;d++)    decode_number(p->lfuns[d],data);       debug_malloc_touch(dat);
pike.git/src/encode.c:1302:    struct program *new_program_save=new_program;    new_program=p;    fsort((void *)p->identifier_index,    p->num_identifier_index,    sizeof(unsigned short),(fsortfun)program_function_index_compare);    new_program=new_program_save;    }    p->flags |= PROGRAM_FINISHED;    ref_push_program(p);    + #ifdef PIKE_DEBUG +  check_program(p); + #endif /* PIKE_DEBUG */ +    #ifdef _REENTRANT    UNSET_ONERROR(err);    exit_threads_disable(NULL);   #endif    return;    }       default:    error("Cannot decode program encoding type %d\n",num);    }