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.272 2008/05/26 12:15:35 grubba Exp $ + || $Id: encode.c,v 1.273 2008/05/26 15:38:56 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:2026:      struct decode_data   {    struct pike_string *data_str;    unsigned char *data;    ptrdiff_t len;    ptrdiff_t ptr;    struct mapping *decoded;    struct unfinished_prog_link *unfinished_programs;    struct unfinished_obj_link *unfinished_objects; +  struct unfinished_obj_link *unfinished_placeholders;    struct svalue counter;    struct object *codec;    int pickyness;    int pass; -  +  int delay_counter;    struct pike_string *raw;    struct decode_data *next;   #ifdef PIKE_THREADS    struct thread_state *thread_state;    struct object *thread_obj;   #endif   #ifdef ENCODE_DEBUG    int debug, depth;   #endif   #if TWO_PASS_DECODE_WORKS
pike.git/src/encode.c:3728:    struct program *p = low_allocate_program();       push_program (p);    EDB(2,    fprintf (stderr, "%*sInited an embryo for a delay encoded program "    "to <%d>: ",    data->depth, "", entry_id.u.integer);    print_svalue (stderr, Pike_sp - 1);    fputc ('\n', stderr););    +  data->delay_counter++; +    #if 0    /* Is this necessary? In that case, how do we pass an    * adequate context to __register_new_program so that it    * knows which program is being decoded? */    if (data->codec) {    ref_push_program (p);    apply (data->codec, "__register_new_program", 1);       /* Returns a placeholder. */    if (Pike_sp[-1].type == T_OBJECT) {
pike.git/src/encode.c:3887:    if (!delayed_enc_val) {    struct svalue prog;    prog.type=T_PROGRAM;    prog.u.program=p;    EDB(2,fprintf(stderr, "%*sDecoding a program to <%d>: ",    data->depth, "", entry_id.u.integer);    print_svalue(stderr, &prog);    fputc('\n', stderr););    mapping_insert(data->decoded, &entry_id, &prog);    debug_malloc_touch(p); +  } else { +  data->delay_counter--;    }       debug_malloc_touch(p);       /* Check the version. */    decode_value2(data);    push_compact_version();    if(!is_eq(Pike_sp-1,Pike_sp-2))    Pike_error("Cannot decode programs encoded with other pike version.\n");    pop_n_elems(2);
pike.git/src/encode.c:4627:    if (placeholder->prog != null_program) {    Pike_error("Placeholder has been zapped during decoding.\n");    }    debug_malloc_touch(placeholder);    free_program(placeholder->prog);    add_ref(placeholder->prog = p);    placeholder->storage = p->storage_needed ?    (char *)xalloc(p->storage_needed) :    (char *)NULL;    call_c_initializers(placeholder); +  if (!data->delay_counter) {    call_pike_initializers(placeholder, 0); -  +  } else { +  /* It's not safe to call __INIT() or create() yet, since +  * there are delayed programs left. +  */ +  struct unfinished_obj_link *up = +  ALLOC_STRUCT(unfinished_obj_link); +  up->next = data->unfinished_placeholders; +  data->unfinished_placeholders = up; +  add_ref(up->o = placeholder); +  }    pop_stack();    }    -  +  if (!data->delay_counter) { +  /* Call the Pike initializers for the delayed placeholders. */ +  struct unfinished_obj_link *up; +  +  while ((up = data->unfinished_placeholders)) { +  struct object *o; +  data->unfinished_placeholders = up->next; +  push_object(o = up->o); +  free(up); +  call_pike_initializers(o, 0); +  pop_stack(); +  } +  } +    #ifdef ENCODE_DEBUG    data->depth -= 2;   #endif    goto decode_done;    }       default:    Pike_error("Cannot decode program encoding type %d\n",num);    }    break;
pike.git/src/encode.c:4723: Inside #if defined(PIKE_DEBUG)
   !(k->val.u.program->flags & PROGRAM_FINISHED)) {    decode_error (NULL, &k->val,    "Got unfinished program <%"PRINTPIKEINT"d> "    "after decode: ", k->ind.u.integer);    }    }    if(data->unfinished_programs)    Pike_fatal("We have unfinished programs left in decode()!\n");    if(data->unfinished_objects)    Pike_fatal("We have unfinished objects left in decode()!\n"); +  if(data->unfinished_placeholders) +  Pike_fatal("We have unfinished placeholders left in decode()!\n");    }   #endif       free_string (data->data_str);    free_object (data->codec);    free_mapping(data->decoded);       while(data->unfinished_programs)    {    struct unfinished_prog_link *tmp=data->unfinished_programs;
pike.git/src/encode.c:4746:       while(data->unfinished_objects)    {    struct unfinished_obj_link *tmp=data->unfinished_objects;    data->unfinished_objects=tmp->next;    free_svalue(&tmp->decode_arg);    free_object(tmp->o);    free((char *)tmp);    }    +  while(data->unfinished_placeholders) +  { +  struct unfinished_obj_link *tmp=data->unfinished_placeholders; +  data->unfinished_placeholders=tmp->next; +  free_object(tmp->o); +  free((char *)tmp); +  } +    #ifdef PIKE_THREADS    data->thread_state = NULL;    free_object (data->thread_obj);   #endif       free( (char *) data);   }      static void low_do_decode (struct decode_data *data)   {
pike.git/src/encode.c:4854:    data->counter.u.integer=COUNTER_START;    data->data_str = tmp;    data->data=(unsigned char *)tmp->str;    data->len=tmp->len;    data->ptr=0;    data->codec=codec;    data->pickyness=0;    data->pass=1;    data->unfinished_programs=0;    data->unfinished_objects=0; +  data->unfinished_placeholders = NULL; +  data->delay_counter = 0;    data->raw = tmp;    data->next = current_decode;   #ifdef PIKE_THREADS    data->thread_state = Pike_interpreter.thread_state;    data->thread_obj = Pike_interpreter.thread_state->thread_obj;   #endif   #ifdef ENCODE_DEBUG    data->debug = debug;    data->depth = -2;   #endif