pike.git / src / encode.c

version» Context lines:

pike.git/src/encode.c:18:   #include "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.54 2000/02/16 03:58:16 per Exp $"); + RCSID("$Id: encode.c,v 1.55 2000/03/26 01:55:11 mast Exp $");      /* #define ENCODE_DEBUG */      #ifdef ENCODE_DEBUG   #define EDB(X) X   #else   #define EDB(X)   #endif      #ifdef _AIX
pike.git/src/encode.c:96:   #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);      #define addstr(s, l) low_my_binary_strcat((s), (l), &(data->buf))   #define addchar(t) low_my_putchar((t),&(data->buf))
pike.git/src/encode.c:353:    * Gmp.mpz objects    */    code_entry(TAG_INT, val->u.integer,data);    break;       case T_STRING:    adddata(val->u.string);    break;       case T_TYPE: -  error("Encoding of the type type not supported yet!"); +  if (data->canonic) +  error("Canonical encoding of the type type not supported.\n"); +  error("Encoding of the type type not supported yet!\n");    break;       case T_FLOAT:    {    if(val->u.float_number==0.0)    {    code_entry(TAG_FLOAT,0,data);    code_entry(TAG_FLOAT,0,data);    }else{    INT32 x;
pike.git/src/encode.c:397:    break;       case T_MAPPING:    check_stack(2);    ref_push_mapping(val->u.mapping);    f_indices(1);       ref_push_mapping(val->u.mapping);    f_values(1);    +  if (data->canonic) { +  INT32 *order; +  if (val->u.mapping->data->ind_types & ~(BIT_BASIC & ~BIT_TYPE)) { +  mapping_fix_type_field(val->u.mapping); +  if (val->u.mapping->data->ind_types & ~(BIT_BASIC & ~BIT_TYPE)) +  /* This doesn't let bignums through. That's necessary as +  * long as they aren't handled deterministically by the +  * sort function. */ +  error("Canonical encoding requires basic types in indices.\n"); +  } +  order = get_switch_order(sp[-2].u.array); +  order_array(sp[-2].u.array, order); +  order_array(sp[-1].u.array, order); +  free((char *) order); +  } +     code_entry(TAG_MAPPING, sp[-2].u.array->size,data);    for(i=0; i<sp[-2].u.array->size; i++)    {    encode_value2(ITEM(sp[-2].u.array)+i, data); /* indices */    encode_value2(ITEM(sp[-1].u.array)+i, data); /* values */    }    pop_n_elems(2);    break;       case T_MULTISET:    code_entry(TAG_MULTISET, val->u.multiset->ind->size,data); -  +  if (data->canonic) { +  INT32 *order; +  if (val->u.multiset->ind->type_field & ~(BIT_BASIC & ~BIT_TYPE)) { +  array_fix_type_field(val->u.multiset->ind); +  if (val->u.multiset->ind->type_field & ~(BIT_BASIC & ~BIT_TYPE)) +  /* This doesn't let bignums through. That's necessary as +  * long as they aren't handled deterministically by the +  * sort function. */ +  error("Canonical encoding requires basic types in indices.\n"); +  } +  check_stack(1); +  ref_push_array(val->u.multiset->ind); +  order = get_switch_order(sp[-1].u.array); +  order_array(sp[-1].u.array, order); +  free((char *) order); +  for (i = 0; i < sp[-1].u.array->size; i++) +  encode_value2(ITEM(sp[-1].u.array)+i, data); +  pop_stack(); +  } +  else    for(i=0; i<val->u.multiset->ind->size; i++)    encode_value2(ITEM(val->u.multiset->ind)+i, data);    break;       case T_OBJECT:    check_stack(1);      #ifdef AUTO_BIGNUM    /* This could be implemented a lot more generic,    * but that will have to wait until next time. /Hubbe
pike.git/src/encode.c:435: Inside #if defined(AUTO_BIGNUM)
   push_int(36);    apply(val->u.object,"digits",1);    if(sp[-1].type != T_STRING)    error("Gmp.mpz->digits did not return a string!\n");    encode_value2(sp-1, data);    pop_stack();    break;    }   #endif    +  if (data->canonic) +  error("Canonical encoding of objects not supported.\n");    push_svalue(val);    apply(data->codec, "nameof", 1);    switch(sp[-1].type)    {    case T_INT:    if(sp[-1].subtype == NUMBER_UNDEFINED)    {    pop_stack();    push_svalue(val);    f_object_program(1);
pike.git/src/encode.c:465:       default:    code_entry(type_to_tag(val->type), 0,data);    break;    }    encode_value2(sp-1, data);    pop_stack();    break;       case T_FUNCTION: +  if (data->canonic) +  error("Canonical encoding of functions not supported.\n");    check_stack(1);    push_svalue(val);    apply(data->codec,"nameof", 1);    if(sp[-1].type == T_INT && sp[-1].subtype==NUMBER_UNDEFINED)    {    if(val->subtype != FUNCTION_BUILTIN)    {    int eq;       code_entry(type_to_tag(val->type), 1, data);
pike.git/src/encode.c:511:       code_entry(type_to_tag(val->type), 0,data);    encode_value2(sp-1, data);    pop_stack();    break;          case T_PROGRAM:    {    int d; +  if (data->canonic) +  error("Canonical encoding of programs not supported.\n");    check_stack(1);    push_svalue(val);    apply(data->codec,"nameof", 1);    if(sp[-1].type == val->type)    error("Error in master()->nameof(), same type returned.\n");    if(sp[-1].type == T_INT && sp[-1].subtype == NUMBER_UNDEFINED)    {    INT32 e;    struct program *p=val->u.program;    if(p->init || p->exit || p->gc_marked || p->gc_check ||
pike.git/src/encode.c:620:      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);       initialize_buf(&data->buf); +  data->canonic = 0;    data->encoded=allocate_mapping(128);    data->counter.type=T_INT;    data->counter.u.integer=COUNTER_START;    if(args > 1)    {    data->codec=sp[1-args].u.object;    }else{    data->codec=get_master();    }   
pike.git/src/encode.c:641:    addstr("\266ke0", 4);    encode_value2(sp-args, data);    UNSET_ONERROR(tmp);       free_mapping(data->encoded);       pop_n_elems(args);    push_string(low_free_buf(&data->buf));   }    + void f_encode_value_canonic(INT32 args) + { +  ONERROR tmp; +  struct encode_data d, *data; +  data=&d; +  +  check_all_args("encode_value_canonic", args, BIT_MIXED, BIT_VOID | BIT_OBJECT, 0); +  +  initialize_buf(&data->buf); +  data->canonic = 1; +  data->encoded=allocate_mapping(128); +  data->counter.type=T_INT; +  data->counter.u.integer=COUNTER_START; +  if(args > 1) +  { +  data->codec=sp[1-args].u.object; +  }else{ +  data->codec=get_master(); +  } +  +  SET_ONERROR(tmp, free_encode_data, data); +  addstr("\266ke0", 4); +  encode_value2(sp-args, data); +  UNSET_ONERROR(tmp); +  +  free_mapping(data->encoded); +  +  pop_n_elems(args); +  push_string(low_free_buf(&data->buf)); + } +    struct decode_data   {    unsigned char *data;    INT32 len;    INT32 ptr;    struct mapping *decoded;    struct svalue counter;    struct object *codec;    int pickyness;   };