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.210 2004/03/14 05:45:44 nilsson Exp $ + || $Id: encode.c,v 1.211 2004/04/06 15:37:55 nilsson 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:25:   #include "fsort.h"   #include "threads.h"   #include "stuff.h"   #include "version.h"   #include "bignum.h"   #include "pikecode.h"   #include "pike_types.h"   #include "opcodes.h"   #include "peep.h"    - RCSID("$Id: encode.c,v 1.210 2004/03/14 05:45:44 nilsson Exp $"); + RCSID("$Id: encode.c,v 1.211 2004/04/06 15:37:55 nilsson 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:780:    {    encode_value2(ITEM(Pike_sp[-2].u.array)+i, data, 0); /* indices */    encode_value2(ITEM(Pike_sp[-1].u.array)+i, data, 0); /* values */    }    pop_n_elems(2);    break;       case T_MULTISET: {    struct multiset *l = val->u.multiset;    - #ifdef PIKE_NEW_MULTISETS +     if (multiset_indval (l) || multiset_get_cmp_less (l)->type != T_INT)    Pike_error ("FIXME: Encoding of multisets with values and/or "    "custom sort function not yet implemented.\n");    else {    /* Encode valueless multisets without compare functions in a    * compatible way. */ - #endif +     code_entry(TAG_MULTISET, multiset_sizeof (l), data);    if (data->canonic) {    INT32 *order;    if (multiset_ind_types(l) & ~(BIT_BASIC & ~BIT_TYPE)) {    multiset_fix_type_field(l);    if (multiset_ind_types(l) & ~(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. */    Pike_error("Canonical encoding requires basic types in indices.\n");    }    check_stack(1); - #ifdef PIKE_NEW_MULTISETS +     push_array(multiset_indices(l)); - #else -  push_array(copy_array(l->ind)); - #endif +     order = get_switch_order(Pike_sp[-1].u.array);    order_array(Pike_sp[-1].u.array, order);    free((char *) order);    for (i = 0; i < Pike_sp[-1].u.array->size; i++)    encode_value2(ITEM(Pike_sp[-1].u.array)+i, data, 0);    pop_stack();    }    else { - #ifdef PIKE_NEW_MULTISETS +     struct svalue ind;    union msnode *node = low_multiset_first (l->msd);    for (; node; node = low_multiset_next (node))    encode_value2 (low_use_multiset_index (node, ind), data, 0); - #else -  for(i=0; i<l->ind->size; i++) -  encode_value2(ITEM(l->ind)+i, data, 0); - #endif +     } - #ifdef PIKE_NEW_MULTISETS +     } - #endif +     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:2512:    Pike_error("Failed to decode multiset. (multiset size is negative)\n");       /* Heruetical */    if(data->ptr + num > data->len)    Pike_error("Failed to decode multiset. (not enough data)\n");       /* NOTE: This code knows stuff about the implementation of multisets...*/       EDB(2,fprintf(stderr, "%*sDecoding multiset of size %d to <%d>\n",    data->depth, "", num, entry_id.u.integer)); - #ifdef PIKE_NEW_MULTISETS +     SETUP_DECODE_MEMOBJ (T_MULTISET, multiset, m,    allocate_multiset (0, 0, NULL), ;);    /* FIXME: This array could be avoided by building the multiset directly. */    a = low_allocate_array (num, 0); - #else -  SETUP_DECODE_MEMOBJ(T_MULTISET, multiset, m, -  allocate_multiset(low_allocate_array(num, 0)), ;); -  a=m->ind; - #endif +        types = 0;    for(e=0;e<num;e++)    {    decode_value2(data);    stack_pop_to_no_free (ITEM(a) + e);    types |= 1 << ITEM(a)[e].type;    }    a->type_field = types; - #ifdef PIKE_NEW_MULTISETS +     {    struct multiset *l = mkmultiset (a);    free_array (a);    /* This special case is handled efficiently by merge_multisets. */    merge_multisets (m, l, PIKE_MERGE_DESTR_A | PIKE_ARRAY_OP_ADD);    free_multiset (l);    } - #else -  order_multiset(m); - #endif +     ref_push_multiset(m);    goto decode_done;    }       case TAG_OBJECT:    {    decode_value2(data);       switch(num)    {