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.104 2001/07/02 01:45:25 mast Exp $"); + RCSID("$Id: encode.c,v 1.105 2001/07/03 04:30:06 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:113:   #define TAG_TYPE 9 /* Not supported yet */      #define TAG_AGAIN 15   #define TAG_MASK 15   #define TAG_NEG 16   #define TAG_SMALL 32   #define SIZE_SHIFT 6   #define MAX_SMALL (1<<(8-SIZE_SHIFT))   #define COUNTER_START -MAX_SMALL    -  -  +    struct encode_data   {    int canonic;    struct object *codec;    struct svalue counter;    struct mapping *encoded;    dynamic_buffer buf;   };      static void encode_value2(struct svalue *val, struct encode_data *data);
pike.git/src/encode.c:1030:    addstr("\266ke0", 4);    encode_value2(Pike_sp-args, data);    UNSET_ONERROR(tmp);       free_mapping(data->encoded);       pop_n_elems(args);    push_string(low_free_buf(&data->buf));   }    +  + struct unfinished_prog_link + { +  struct unfinished_prog_link *next; +  struct program *prog; + }; +    struct decode_data   {    unsigned char *data;    ptrdiff_t len;    ptrdiff_t ptr;    struct mapping *decoded; -  +  struct unfinished_prog_link *unfinished_programs;    struct svalue counter;    struct object *codec;    int pickyness;   };      static void decode_value2(struct decode_data *data);      static void fallback_codec(void)   {    size_t x;
pike.git/src/encode.c:1949:    break;    default:    Pike_error("Failed to decode inheritance.\n");    }       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;
pike.git/src/encode.c:1996:    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); +  +  ref_push_program(p); +  +  /* Logic for the PROGRAM_FINISHED flag: +  * The purpose of this code is to make sure that the PROGRAM_FINISHED +  * flat is not set on the program until all inherited programs also +  * have that flag. -Hubbe +  */ +  for(d=1;d<p->num_inherits;d++) +  if(! (p->inherits[d].prog->flags & PROGRAM_FINISHED)) +  break; +  +  if(d == p->num_inherits) +  { +  int done=0; +  struct unfinished_prog_link *l, **ptr;    p->flags &=~ PROGRAM_AVOID_CHECK;    p->flags |= PROGRAM_FINISHED; -  ref_push_program(p); +       #ifdef PIKE_DEBUG    check_program(p);   #endif /* PIKE_DEBUG */    -  +  /* It is possible that we need to restart loop +  * in some cases... /Hubbe +  */ +  for(ptr= &data->unfinished_programs ; (l=*ptr);) +  { +  struct program *pp=l->prog; +  for(d=1;d<pp->num_inherits;d++) +  if(! (pp->inherits[d].prog->flags & PROGRAM_FINISHED)) +  break; +  +  if(d == pp->num_inherits) +  { +  pp->flags &=~ PROGRAM_AVOID_CHECK; +  pp->flags |= PROGRAM_FINISHED; +  + #ifdef PIKE_DEBUG +  check_program(pp); + #endif /* PIKE_DEBUG */ +  +  *ptr = l->next; +  free((char *)l); +  }else{ +  ptr=&l->next; +  } +  } +  }else{ +  struct unfinished_prog_link *l; +  l=ALLOC_STRUCT(unfinished_prog_link); +  l->prog=p; +  l->next=data->unfinished_programs; +  data->unfinished_programs=l; +  } +    #ifdef _REENTRANT    UNSET_ONERROR(err);    exit_threads_disable(NULL);   #endif    return;    }       case 2:    tmp=data->counter;    data->counter.u.integer++;
pike.git/src/encode.c:2061:    Pike_error("Failed to restore string. (Illegal type)\n");    }       mapping_insert(data->decoded, & tmp, Pike_sp-1);   }         static void free_decode_data(struct decode_data *data)   {    free_mapping(data->decoded); +  while(data->unfinished_programs) +  { +  struct unfinished_prog_link *tmp=data->unfinished_programs; +  data->unfinished_programs=tmp->next; +  free((char *)tmp);    } -  + }      static INT32 my_decode(struct pike_string *tmp,    struct object *codec)   {    ONERROR err;    struct decode_data d, *data;    data=&d;    data->counter.type=T_INT;    data->counter.u.integer=COUNTER_START;    data->data=(unsigned char *)tmp->str;    data->len=tmp->len;    data->ptr=0;    data->codec=codec;    data->pickyness=0; -  +  data->unfinished_programs=0;       if (tmp->size_shift) return 0;    if(data->len < 5) return 0;    if(GETC() != 182 ||    GETC() != 'k' ||    GETC() != 'e' ||    GETC() != '0')    return 0;       data->decoded=allocate_mapping(128);       SET_ONERROR(err, free_decode_data, data);    decode_value2(data);    UNSET_ONERROR(err); -  + #ifdef PIKE_DEBUG +  if(data->unfinished_programs) +  fatal("We have unfinished programs left in decode()! We may need a double loop!\n"); + #endif    free_mapping(data->decoded);    return 1;   }      /* Compatibilidy decoder */      static unsigned char extract_char(char **v, ptrdiff_t *l)   {    if(!*l) Pike_error("Format error, not enough place for char.\n");    else (*l)--;