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.181 2003/06/05 15:54:23 mast Exp $ + || $Id: encode.c,v 1.182 2003/06/05 16:01:26 mast 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:20:   #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"   #include "pikecode.h"    - RCSID("$Id: encode.c,v 1.181 2003/06/05 15:54:23 mast Exp $"); + RCSID("$Id: encode.c,v 1.182 2003/06/05 16:01:26 mast Exp $");      /* #define ENCODE_DEBUG */      /* Use the old encoding method for programs. */   /* #define OLD_PIKE_ENCODE_PROGRAM */      #ifdef ENCODE_DEBUG   /* Pass a nonzero integer as the third arg to encode_value,    * encode_value_canonic and decode_value to activate this debug. */   #define EDB(N,X) do { debug_malloc_touch(data); if (data->debug>=N) {X;} } while (0)
pike.git/src/encode.c:840: Inside #if defined(AUTO_BIGNUM)
   if(Pike_sp[-1].type != T_STRING)    Pike_error("Gmp.mpz->digits did not return a string!\n");    encode_value2(Pike_sp-1, data, 0);    pop_stack();    break;    }   #endif       if (data->canonic)    Pike_error("Canonical encoding of objects not supported.\n"); -  if (data->codec) { +     push_svalue(val);    apply(data->codec, "nameof", 1); -  } else { -  push_undefined(); -  } +     EDB(5, fprintf(stderr, "%*s->nameof: ", data->depth, "");    print_svalue(stderr, Pike_sp-1);    fputc('\n', stderr););    switch(Pike_sp[-1].type)    {    case T_INT:    if(Pike_sp[-1].subtype == NUMBER_UNDEFINED)    {    int to_change = data->buf.s.len;    struct svalue tmp = entry_id;
pike.git/src/encode.c:915:    }    encode_value2(Pike_sp-1, data, 0);    pop_stack();    break;       case T_FUNCTION:    /* FIXME: Ought to have special treatment of trampolines. */    if (data->canonic)    Pike_error("Canonical encoding of functions not supported.\n");    check_stack(1); -  if (data->codec) { +     push_svalue(val);    apply(data->codec,"nameof", 1); -  } else { -  push_undefined(); -  } +     if(Pike_sp[-1].type == T_INT && Pike_sp[-1].subtype==NUMBER_UNDEFINED)    {    if(val->subtype != FUNCTION_BUILTIN)    {    if(find_shared_string_identifier(ID_FROM_INT(val->u.object->prog, val->subtype)->name,    val->u.object->prog)==val->subtype)    {    /* We have to remove ourself from the cache for now */    struct svalue tmp = entry_id;    map_delete(data->encoded, val);
pike.git/src/encode.c:967:    if (val->u.program->id < PROG_DYNAMIC_ID_START) {    code_entry(TAG_PROGRAM, 3, data);    push_int(val->u.program->id);    encode_value2(Pike_sp-1, data, 0);    pop_stack();    break;    }    if (data->canonic)    Pike_error("Canonical encoding of programs not supported.\n");    check_stack(1); -  if (data->codec) { +     push_svalue(val);    apply(data->codec,"nameof", 1); -  } else { -  push_undefined(); -  } +     if(Pike_sp[-1].type == val->type)    Pike_error("Error in master()->nameof(), same type returned.\n");    if(Pike_sp[-1].type == T_INT && Pike_sp[-1].subtype == NUMBER_UNDEFINED)    {    struct program *p=val->u.program;    pop_stack();    if( (p->flags & PROGRAM_HAS_C_METHODS) || p->event_handler )    {    if(p->parent)    {
pike.git/src/encode.c:1660:    *! @seealso    *! @[encode_value()], @[decode_value()]    */   void f_encode_value_canonic(INT32 args)   {    ONERROR tmp;    struct encode_data d, *data;    int i;    data=&d;    -  check_all_args("encode_value_canonic", args, BIT_MIXED, BIT_VOID | BIT_OBJECT, +  check_all_args("encode_value_canonic", args, +  BIT_MIXED, +  BIT_VOID | BIT_OBJECT | BIT_ZERO,   #ifdef ENCODE_DEBUG    /* This argument is only an internal debug helper.    * It's intentionally not part of the function    * prototype, to keep the argument position free for    * other uses in the future. */    BIT_VOID | BIT_INT,   #endif    0);       initialize_buf(&data->buf);
pike.git/src/encode.c:1682:    data->encoded=allocate_mapping(128);    data->delayed = allocate_array (0);    data->counter.type=T_INT;    data->counter.u.integer=COUNTER_START;      #ifdef ENCODE_DEBUG    data->debug = args > 2 ? Pike_sp[2-args].u.integer : 0;    data->depth = -2;   #endif    -  if(args > 1) +  if(args > 1 && Pike_sp[1-args].type == T_OBJECT)    {    data->codec=Pike_sp[1-args].u.object;    }else{    data->codec=get_master();    if (!data->codec) {    /* Use a dummy if there's no master around yet, to avoid checks. */    push_object (clone_object (null_program, 0));    args++;    data->codec = Pike_sp[-1].u.object;    }
pike.git/src/encode.c:2410:    goto decode_done;    }       case TAG_OBJECT:    {    decode_value2(data);       switch(num)    {    case 0: -  if (data->codec) { +     apply(data->codec,"objectof", 1); -  } else { -  decode_error(NULL, Pike_sp-1, -  "Failed to decode object (no codec). Got: "); -  } +     break;       case 1:    {    int fun;    /* decode_value_clone_object does not call __INIT, so    * we want to do that ourselves...    */    struct object *o=decode_value_clone_object(Pike_sp-1);   
pike.git/src/encode.c:2522:       break;    }       case TAG_FUNCTION:    decode_value2(data);       switch(num)    {    case 0: -  if (data->codec) { +     apply(data->codec,"functionof", 1); -  } else { -  decode_error(NULL, Pike_sp-1, -  "Failed to decode function (no codec). Got: "); -  } +     break;       case 1: {    struct program *p;    if(Pike_sp[-1].type != T_OBJECT && data->pickyness)    decode_error(NULL, Pike_sp - 1,    "Failed to decode function object. Got: ");       decode_value2(data);    if(Pike_sp[-1].type != T_STRING && data->pickyness)
pike.git/src/encode.c:2590:    EDB(3,    fprintf(stderr, "%*s TAG_PROGRAM(%d)\n",    data->depth, "", num));    switch(num)    {    case 0:    {    struct program *p;       decode_value2(data); -  if (data->codec) { +     apply(data->codec,"programof", 1); -  } else { -  decode_error(NULL, Pike_sp-1, -  "Failed to decode program (no codec). Got: "); -  } +        p = program_from_svalue(Pike_sp-1);       if (!p) {    if(data->pickyness)    decode_error(NULL, Pike_sp - 1,    "Failed to decode program. Got: ");    pop_stack();    push_undefined();    break;
pike.git/src/encode.c:2647:       SET_ONERROR(err3, zap_unfinished_program, p);       if(data->pass == 1)    {    if(! data->supporter.prog)    data->supporter.prog = p;       debug_malloc_touch(p);    ref_push_program(p); -  if (data->codec) { +     apply(data->codec, "__register_new_program", 1); -  } +        /* return a placeholder */    if(Pike_sp[-1].type == T_OBJECT)    {    placeholder=Pike_sp[-1].u.object;    if(placeholder->prog != null_program)    Pike_error("Placeholder object is not a __null_program clone.\n");    dmalloc_touch_svalue(Pike_sp-1);    Pike_sp--;    }