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.106 2001/07/03 08:04:59 hubbe Exp $"); + RCSID("$Id: encode.c,v 1.107 2001/07/03 15:04:51 grubba 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:762:    encode_value2(Pike_sp-1, data);    ref_push_string(ID_FROM_INT(val->u.object->prog, val->subtype)->name);    encode_value2(Pike_sp-1, data);    pop_n_elems(3);       /* Put value back in cache */    mapping_insert(data->encoded, val, &tmp);    return;    }    } -  Pike_error("Failed to encode function.\n"); +  Pike_error("Encoding of efuns is not supported yet.\n");    }       code_entry(type_to_tag(val->type), 0,data);    encode_value2(Pike_sp-1, data);    pop_stack();    break;          case T_PROGRAM:    {
pike.git/src/encode.c:843:    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);    pop_stack();      #define FOO(X,Y,Z) \ -  code_number( p->num_##Z, data); +  code_number( p->PIKE_CONCAT(num_,Z), data);   #include "program_areas.h"       adddata2(p->program, p->num_program);    adddata2(p->linenumbers, p->num_linenumbers);       for(d=0;d<p->num_identifier_index;d++)    code_number(p->identifier_index[d],data);       for(d=0;d<p->num_variable_index;d++)    code_number(p->variable_index[d],data);
pike.git/src/encode.c:887:    if(p->inherits[d].parent)    {    ref_push_object(p->inherits[d].parent);    Pike_sp[-1].subtype=p->inherits[d].parent_identifier;    Pike_sp[-1].type=T_FUNCTION;    EDB(fprintf(stderr,"INHERIT%x coded as func { %p, %d }\n",    p->id, p->inherits[d].parent, p->inherits[d].parent_identifier);)    }else if(p->inherits[d].prog){    ref_push_program(p->inherits[d].prog);    }else{ +  Pike_error("Failed to encode inherit #%d\n", d);    push_int(0);    }    encode_value2(Pike_sp-1,data);    pop_stack();       adddata3(p->inherits[d].name);       EDB(fprintf(stderr,"INHERIT%x > %d: %d id=%d\n",    p->id,d,    p->inherits[d].prog->num_identifiers,    p->inherits[d].prog->id);)    }       for(d=0;d<p->num_identifiers;d++)    {    adddata(p->identifiers[d].name);    encode_type(p->identifiers[d].type, data);    code_number(p->identifiers[d].identifier_flags,data);    code_number(p->identifiers[d].run_time_type,data);    code_number(p->identifiers[d].opt_flags,data); -  +  if (!(p->identifiers[d].identifier_flags & IDENTIFIER_C_FUNCTION)) {    code_number(p->identifiers[d].func.offset,data); -  +  } else { +  Pike_error("Cannot encode functions implemented in C " +  "(identifier='%s').\n", +  p->identifiers[d].name->str);    } -  +  }       for(d=0;d<p->num_constants;d++)    {    encode_value2(& p->constants[d].sval, data);    adddata3(p->constants[d].name);    }       for(d=0;d<NUM_LFUNS;d++)    code_number(p->lfuns[d], data);    }else{
pike.git/src/encode.c:1061:   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; +  struct pike_string *raw; +  struct decode_data *next;   };      static void decode_value2(struct decode_data *data);      static void fallback_codec(void)   {    size_t x;    push_constant_text(".");    f_divide(2);    f_reverse(1);
pike.git/src/encode.c:1822:    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); +  if(p->parent) { +  add_ref(p->parent); +  p->parent_program_id = p->parent->id; +  }    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)); \
pike.git/src/encode.c:1997:    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); +  if (!(p->identifiers[d].identifier_flags & IDENTIFIER_C_FUNCTION)) +  {    decode_number(p->identifiers[d].func.offset,data); -  +  } else { +  Pike_error("Cannot decode functions implemented in C " +  "(identifier='%s').\n", +  p->identifiers[d].name->str);    } -  +  }          UNSET_ONERROR(err2);    UNSET_ONERROR(err1);       debug_malloc_touch(dat);       debug_malloc_touch(p);    for(d=0;d<p->num_constants;d++)    {
pike.git/src/encode.c:2144:    break;       default:    Pike_error("Failed to restore string. (Illegal type)\n");    }       mapping_insert(data->decoded, & tmp, Pike_sp-1);   }       + static struct decode_data *current_decode = NULL; +    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);    } -  +  if (current_decode == data) { +  current_decode = data->next; +  } else { +  struct decode_data *d; +  for (d = current_decode; d; d=d->next) { +  if (d->next == data) { +  d->next = d->next->next; +  break;    } -  +  } + #ifdef PIKE_DEBUG +  if (!d) { +  fatal("Decode data fell off the stack!\n"); +  } + #endif /* PIKE_DEBUG */ +  } + }      static INT32 my_decode(struct pike_string *tmp,    struct object *codec)   {    ONERROR err;    struct decode_data d, *data; -  +  +  /* Attempt to avoid infinite recursion on circular structures. */ +  for (data = current_decode; data; data=data->next) { +  if (data->raw == tmp) { +  struct svalue *res; +  struct svalue val = { +  T_INT, NUMBER_NUMBER, + #ifdef HAVE_UNION_INIT +  {0}, /* Only to avoid warnings. */ + #endif /* HAVE_UNION_INIT */ +  }; +  val.u.integer = 0; +  if ((res = low_mapping_lookup(data->decoded, &val))) { +  push_svalue(res); +  return 1; +  } +  /* Possible recursion detected. */ +  /* return 0; */ +  } +  } +     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; -  +  data->raw = tmp; +  data->next = current_decode;       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);    -  +  current_decode = data; +     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); +  CALL_AND_UNSET_ONERROR(err);    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)--;    (*v)++;