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.184 2003/06/05 21:53:18 mast Exp $ + || $Id: encode.c,v 1.185 2003/06/10 23:27:04 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.184 2003/06/05 21:53:18 mast Exp $"); + RCSID("$Id: encode.c,v 1.185 2003/06/10 23:27:04 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:93:   #define TAG_INT 8   #define TAG_TYPE 9 /* Not supported yet */      #define TAG_DELAYED 14 /* Note: Coincides with T_ZERO. */   #define TAG_AGAIN 15   #define TAG_MASK 15   #define TAG_NEG 16   #define TAG_SMALL 32   #define SIZE_SHIFT 6   #define MAX_SMALL (1<<(8-SIZE_SHIFT)) - #define COUNTER_START 1 + #define COUNTER_START -4      /* Entries used to encode the identifier_references table. */   #define ID_ENTRY_RAW -2   #define ID_ENTRY_EOT -1   #define ID_ENTRY_VARIABLE 0   #define ID_ENTRY_FUNCTION 1   #define ID_ENTRY_CONSTANT 2   #define ID_ENTRY_INHERIT 3      struct encode_data   {    int canonic;    struct object *codec;    struct svalue counter;    struct mapping *encoded;    /* The encoded mapping maps encoded things to their entry IDs. A -  * negative value means that it's a forward reference to a thing not -  * yet encoded. */ +  * value less than COUNTER_START means that it's a forward reference +  * to a thing not yet encoded. */    struct array *delayed;    dynamic_buffer buf;   #ifdef ENCODE_DEBUG    int debug, depth;   #endif   };    -  + /* Convert to/from forward reference ID. Ugly because of the +  * hysterical historical COUNTER_START value. */ + #define CONVERT_ENTRY_ID(ID) (-((ID) + COUNTER_START) - (COUNTER_START + 1)) +    static void encode_value2(struct svalue *val, struct encode_data *data, int force_encode);      #define addstr(s, l) low_my_binary_strcat((s), (l), &(data->buf))   #define addchar(t) low_my_putchar((char)(t), &(data->buf))      /* Code a pike string */      #if BYTEORDER == 4321   #define ENCODE_DATA(S) \    addstr( (S)->str, (S)->len << (S)->size_shift );
pike.git/src/encode.c:481:   #endif       if((val->type == T_OBJECT ||    (val->type==T_FUNCTION && val->subtype!=FUNCTION_BUILTIN)) &&    !val->u.object->prog)    val = &dested;       if((tmp=low_mapping_lookup(data->encoded, val)))    {    entry_id = *tmp; /* It's always a small integer. */ -  if (entry_id.u.integer < 0) entry_id.u.integer = -entry_id.u.integer; -  if (force_encode && tmp->u.integer < 0) { +  if (entry_id.u.integer < COUNTER_START) +  entry_id.u.integer = CONVERT_ENTRY_ID (entry_id.u.integer); +  if (force_encode && tmp->u.integer < COUNTER_START) {    EDB(1,    fprintf(stderr, "%*sEncoding delayed thing to <%d>: ",    data->depth, "", entry_id.u.integer);    if(data->debug == 1)    {    fprintf(stderr,"TAG%d",val->type);    }else{    print_svalue(stderr, val);       }
pike.git/src/encode.c:1142:       /* Portable encoding (4 and 5). */       if (!force_encode) {    /* Encode later (5). */    EDB(1, fprintf(stderr, "%*sencode: delayed encoding of program\n",    data->depth, ""));    code_entry (TAG_PROGRAM, 5, data);    data->delayed = append_array (data->delayed, val);    tmp = low_mapping_lookup (data->encoded, val); -  tmp->u.integer = -tmp->u.integer; +  tmp->u.integer = CONVERT_ENTRY_ID (tmp->u.integer);    goto encode_done;    }       EDB(1, fprintf(stderr, "%*sencode: encoding program in new style\n",    data->depth, ""));    code_entry(TAG_PROGRAM, 4, data);       /* Byte-order. */    code_number(PIKE_BYTEORDER, data);