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.103 2001/07/01 22:30:36 grubba Exp $"); + RCSID("$Id: encode.c,v 1.104 2001/07/02 01:45:25 mast 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:743:    case T_FUNCTION:    if (data->canonic)    Pike_error("Canonical encoding of functions not supported.\n");    check_stack(1);    push_svalue(val);    apply(data->codec,"nameof", 1);    if(Pike_sp[-1].type == T_INT && Pike_sp[-1].subtype==NUMBER_UNDEFINED)    {    if(val->subtype != FUNCTION_BUILTIN)    { -  int eq; -  -  code_entry(type_to_tag(val->type), 1, data); -  push_svalue(val); -  Pike_sp[-1].type=T_OBJECT; -  ref_push_string(ID_FROM_INT(val->u.object->prog, val->subtype)->name); -  f_arrow(2); -  eq=is_eq(Pike_sp-1, val); -  pop_stack(); -  if(eq) -  { +     /* We have to remove ourself from the cache for now */    struct svalue tmp=data->counter;    tmp.u.integer--;    map_delete(data->encoded, val);    -  +  code_entry(type_to_tag(val->type), 1, data);    push_svalue(val);    Pike_sp[-1].type=T_OBJECT;    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");    } -  } +        code_entry(type_to_tag(val->type), 0,data);    encode_value2(Pike_sp-1, data);    pop_stack();    break;          case T_PROGRAM:    {    int d;
pike.git/src/encode.c:942:    *! Code a value into a string.    *!    *! This function takes a value, and converts it to a string. This string    *! can then be saved, sent to another Pike process, packed or used in    *! any way you like. When you want your value back you simply send this    *! string to @[decode_value()] and it will return the value you encoded.    *!    *! Almost any value can be coded, mappings, floats, arrays, circular    *! structures etc.    *! -  *! To encode objects, programs and functions a codec object must be provided. +  *! To encode objects, programs and functions, a codec object must be +  *! provided.    *! -  +  *! @note +  *! +  *! When only simple types like int, floats, strings, mappings, +  *! multisets and arrays are encoded, the produced string is very +  *! portable between pike versions. It can at least be read by any +  *! later version. +  *! +  *! The portability when objects, programs and functions are involved +  *! depends mostly on the codec. If the byte code is encoded, i.e. +  *! when Pike programs are actually dumped in full, then the string +  *! can probably only be read by the same pike version. +  *!    *! @seealso    *! @[decode_value()], @[sprintf()], @[encode_value_canonic()]    */   void f_encode_value(INT32 args)   {    ONERROR tmp;    struct encode_data d, *data;    data=&d;       check_all_args("encode_value", args, BIT_MIXED, BIT_VOID | BIT_OBJECT, 0);
pike.git/src/encode.c:1504:    tmp.type = T_INT;    tmp = data->counter;    data->counter.u.integer++;    }    break;       case TAG_ARRAY:    {    struct array *a;    if(num < 0) -  Pike_error("Failed to decode string. (array size is negative)\n"); +  Pike_error("Failed to decode array. (array size is negative)\n");       /* Heruetical */    if(data->ptr + num > data->len)    Pike_error("Failed to decode array. (not enough data)\n");       tmp.type=T_ARRAY;    tmp.u.array=a=allocate_array(num);    mapping_insert(data->decoded, & data->counter, &tmp);    data->counter.u.integer++;   
pike.git/src/encode.c:1674:    {    case 0:    if(data->codec)    {    apply(data->codec,"functionof", 1);    }else{    fallback_codec();    }    break;    -  case 1: +  case 1: { +  struct program *p;    decode_value2(data); -  if(Pike_sp[-2].type==T_INT) -  { -  pop_stack(); -  }else{ -  f_arrow(2); +  if (Pike_sp[-2].type == T_OBJECT && +  Pike_sp[-1].type == T_STRING && +  (p = Pike_sp[-2].u.object->prog)) { +  int f = find_shared_string_identifier(Pike_sp[-1].u.string, p); +  if (f >= 0) { +  struct svalue func; +  low_object_index_no_free(&func, Pike_sp[-2].u.object, f); + #ifdef PIKE_SECURITY +  /* FIXME: Check access to the function. */ + #endif +  pop_n_elems(2); +  *Pike_sp++ = func; +  break;    } -  +  } +  pop_stack();    break; -  +  }       default:    Pike_error("Function coding not compatible.\n");    break;    }    if(data->pickyness && Pike_sp[-1].type != T_FUNCTION)    Pike_error("Failed to decode function.\n");    break;