Branch: Tag:

2003-06-30

2003-06-30 17:11:20 by Martin Stjernholm <mast@lysator.liu.se>

Cleaned up some pointer handling.

Rev: src/apply_low.h:1.19
Rev: src/backend.cmod:1.43
Rev: src/block_alloc.h:1.68
Rev: src/builtin_functions.c:1.497
Rev: src/cyclic.c:1.11
Rev: src/encode.c:1.190
Rev: src/fdlib.c:1.63
Rev: src/fsort_template.h:1.16
Rev: src/gc.c:1.220
Rev: src/interpret.c:1.307
Rev: src/interpret.h:1.142
Rev: src/interpret_functions.h:1.151
Rev: src/las.c:1.336
Rev: src/main.c:1.177
Rev: src/mapping.c:1.168
Rev: src/mapping.h:1.50
Rev: src/modules/Oracle/oracle.c:1.78
Rev: src/modules/_Charset/misc.c:1.14
Rev: src/multiset.c:1.74
Rev: src/object.c:1.238
Rev: src/object.h:1.79
Rev: src/pike_macros.h:1.37
Rev: src/pike_memory.c:1.146
Rev: src/pike_search.c:1.16
Rev: src/pike_search_engine2.c:1.9
Rev: src/pike_threadlib.h:1.47
Rev: src/pike_types.c:1.218
Rev: src/port.c:1.72
Rev: src/port.h:1.51
Rev: src/signal_handler.c:1.274
Rev: src/svalue.c:1.168
Rev: src/threads.c:1.219

2:   || 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: pike_types.c,v 1.217 2003/06/12 18:57:16 nilsson Exp $ + || $Id: pike_types.c,v 1.218 2003/06/30 17:06:10 mast Exp $   */      #include "global.h" - RCSID("$Id: pike_types.c,v 1.217 2003/06/12 18:57:16 nilsson Exp $"); + RCSID("$Id: pike_types.c,v 1.218 2003/06/30 17:06:10 mast Exp $");   #include <ctype.h>   #include "svalue.h"   #include "pike_types.h"
321:   {    unsigned INT32 hash = DO_NOT_WARN((unsigned INT32)    ((ptrdiff_t)type*0x10204081)^ -  (0x8003*(((char *)car)-(char *)0))^ -  ~(0x10001*(((char *)cdr)-(char *)0))); +  (0x8003*PTR_TO_INT(car))^ +  ~(0x10001*PTR_TO_INT(cdr)));    unsigned INT32 index = hash % pike_type_hash_size;    struct pike_type *t;   
812:    if (type->type == T_ASSIGN) {    /* Strip assign */   #if 0 -  fprintf(stderr, "Assign to marker %d.\n", -  ((char *)type->car)-(char *)0); +  fprintf(stderr, "Assign to marker %d.\n", CAR_TO_INT(type);   #endif /* 0 */    type = type->cdr;    goto recurse;
1415: Inside #if defined(PIKE_DEBUG)
   break;       case T_SCOPE: -  fprintf(stderr, "scope(%ld, ", -  (long)(((char *)s->car)-(char *)0)); +  fprintf(stderr, "scope(%"PRINTSIZET"d, ", CAR_TO_INT(s));    simple_describe_type(s->cdr);    fprintf(stderr, ")");    break;
1428: Inside #if defined(PIKE_DEBUG)
   fprintf(stderr, ")");    break;    case T_ASSIGN: -  fprintf(stderr, "%ld = ", -  (long)(((char *)s->car)-(char *)0)); +  fprintf(stderr, "%"PRINTSIZET"d = ", CAR_TO_INT(s));    simple_describe_type(s->cdr);    break;    case T_INT:    { -  INT32 min = ((char *)s->car)-(char *)0; -  INT32 max = ((char *)s->cdr)-(char *)0; +  INT32 min = CAR_TO_INT(s); +  INT32 max = CDR_TO_INT(s);    fprintf(stderr, "int");    if(min!=MIN_INT32 || max!=MAX_INT32)    fprintf(stderr, "(%ld..%ld)",(long)min,(long)max);
1454: Inside #if defined(PIKE_DEBUG)
   fprintf(stderr, ")");    break;    case T_OBJECT: -  fprintf(stderr, "object(%s %ld)", +  fprintf(stderr, "object(%s %"PRINTSIZET"d)",    s->car?"is":"implements", -  (long)(((char *)s->cdr)-(char *)0)); +  CDR_TO_INT(s));    break;    case T_FUNCTION:    case T_MANY:
1567:       case T_ASSIGN:    my_putchar('('); -  my_putchar('0' + (((char *)t->car)-(char *)0)); +  my_putchar('0' + CAR_TO_INT(t));    my_putchar('=');    my_describe_type(t->cdr);    my_putchar(')');
1575:       case T_SCOPE:    my_putchar('{'); -  my_putchar(((char *)t->car)-(char *)0); +  my_putchar(CAR_TO_INT(t));    my_putchar(',');    my_describe_type(t->cdr);    my_putchar('}');
1595:    case PIKE_T_UNKNOWN: my_strcat("unknown"); break;    case T_INT:    { -  INT32 min=((char *)t->car)-(char *)0; -  INT32 max=((char *)t->cdr)-(char *)0; +  INT32 min=CAR_TO_INT(t); +  INT32 max=CDR_TO_INT(t);    my_strcat("int");       if(min!=MIN_INT32 || max!=MAX_INT32)
1622:    if (t->cdr)    {    char buffer[100]; -  sprintf(buffer,"object(%s %ld)", +  sprintf(buffer,"object(%s %"PRINTSIZET"d)",    t->car?"is":"implements", -  (long)(((char *)t->cdr)-(char *)0)); +  CDR_TO_INT(t));    my_strcat(buffer);    }else{    my_strcat("object");
1917:    }    else if(t1->type == T_INT && t2->type == T_INT)    { -  INT32 min1 = ((char *)t1->car)-(char *)0; -  INT32 max1 = ((char *)t1->cdr)-(char *)0; -  INT32 min2 = ((char *)t2->car)-(char *)0; -  INT32 max2 = ((char *)t2->cdr)-(char *)0; +  INT32 min1 = CAR_TO_INT(t1); +  INT32 max1 = CDR_TO_INT(t1); +  INT32 min2 = CAR_TO_INT(t2); +  INT32 max2 = CDR_TO_INT(t2);       if ((max1 + 1 < min2) || (max2 + 1 < min1)) {    /* No overlap. */
1940:    if (t2->type == T_SCOPE) {    low_or_pike_types(t1->cdr, t2->cdr, zero_implied);    if (t1->car > t2->car) -  push_scope_type(((char *)t1->car)-(char *)0); +  push_scope_type(CAR_TO_INT(t1));    else -  push_scope_type(((char *)t2->car)-(char *)0); +  push_scope_type(CAR_TO_INT(t2));    } else {    low_or_pike_types(t1->cdr, t2, zero_implied); -  push_scope_type(((char *)t1->car)-(char *)0); +  push_scope_type(CAR_TO_INT(t1));    }    }    else if (t2->type == T_SCOPE)    {    low_or_pike_types(t1, t2->cdr, zero_implied); -  push_scope_type(((char *)t2->car)-(char *)0); +  push_scope_type(CAR_TO_INT(t2));    push_type(T_SCOPE);    }    else
1997:    if (t1->type == T_INT) {    INT32 i1, i2;    INT32 upper_bound, lower_bound; -  i1 = ((char *)t1->cdr)-(char *)0; -  i2 = ((char *)t2->cdr)-(char *)0; +  i1 = CDR_TO_INT(t1); +  i2 = CDR_TO_INT(t2);    upper_bound = MINIMUM(i1,i2);    -  i1 = ((char *)t1->car)-(char *)0; -  i2 = ((char *)t2->car)-(char *)0; +  i1 = CAR_TO_INT(t1); +  i2 = CAR_TO_INT(t2);    lower_bound = MAXIMUM(i1,i2);       if (upper_bound >= lower_bound) {
2098:    {    INT32 i1,i2;    INT32 upper_bound, lower_bound; -  i1 = ((char *)t1->cdr)-(char *)0; -  i2 = ((char *)t2->cdr)-(char *)0; +  i1 = CDR_TO_INT(t1); +  i2 = CDR_TO_INT(t2);    upper_bound = MINIMUM(i1,i2);    -  i1 = ((char *)t1->car)-(char *)0; -  i2 = ((char *)t2->car)-(char *)0; +  i1 = CAR_TO_INT(t1); +  i2 = CAR_TO_INT(t2);    lower_bound = MAXIMUM(i1,i2);       if (upper_bound >= lower_bound) {
2119:    if (t2->type == T_SCOPE) {    low_and_pike_types(t1->cdr, t2->cdr);    if (t1->car > t2->car) -  push_scope_type(((char *)t1->car)-(char *)0); +  push_scope_type(CAR_TO_INT(t1));    else -  push_scope_type(((char *)t2->car)-(char *)0); +  push_scope_type(CAR_TO_INT(t2));    } else {    low_and_pike_types(t1->cdr, t2); -  push_scope_type(((char *)t1->car)-(char *)0); +  push_scope_type(CAR_TO_INT(t1));    }    }    else if (t2->type == T_SCOPE)    {    low_and_pike_types(t1, t2->cdr); -  push_scope_type(((char *)t2->car)-(char *)0); +  push_scope_type(CAR_TO_INT(t2));    }    else if((t1->type == t2->type) &&    ((t1->type == T_STRING) ||
2176:   {    struct program *p;    int i; -  p = id_to_program(((char *)t->cdr)-(char *)0); +  p = id_to_program(CDR_TO_INT(t));    if(!p) return 0;    i=FIND_LFUN(p, lfun);    if(i==-1) return 0;
2312:    ret = low_match_types(a->cdr, b, flags);    if(ret && (b->type != T_VOID))    { -  int m = ((char *)a->car)-(char *)0; +  int m = CAR_TO_INT(a);    struct pike_type *tmp;      #ifdef PIKE_DEBUG
2347:    }   #endif   #ifdef PIKE_DEBUG -  if((((char *)a_markers[m]->type)-(char *)0) == m+'0') +  if(PTR_TO_INT(a_markers[m]->type) == m+'0')    Pike_fatal("Cyclic type!\n");   #endif    }
2406:    ret = low_match_types(a, b->cdr, flags);    if(ret && (a->type != T_VOID))    { -  int m = ((char *)b->car)-(char *)0; +  int m = CAR_TO_INT(b);    struct pike_type *tmp;    type_stack_mark();    push_finished_type_with_markers(a, a_markers);
2433:    }   #endif   #ifdef PIKE_DEBUG -  if((((char *)b_markers[m]->type)-(char *)0) == m+'0') +  if(PTR_TO_INT(b_markers[m]->type) == m+'0')    Pike_fatal("Cyclic type!\n");   #endif    }
2549:    }    case TWOT(T_INT, T_ZERO):    { -  if (((((char *)a->car)-(char *)0) > 0) || -  ((((char *)a->cdr)-(char *)0) < 0)) { +  if ((CAR_TO_INT(a) > 0) || (CDR_TO_INT(a) < 0)) {    return 0;    }    return a;    }    case TWOT(T_ZERO, T_INT):    { -  if (((((char *)b->car)-(char *)0) > 0) || -  ((((char *)b->cdr)-(char *)0) < 0)) { +  if ((CAR_TO_INT(b) > 0) || (CDR_TO_INT(b) < 0)) {    return 0;    }    return a;
2659: Inside #if 0
   * (got "Prototype doesn't match for function foo" even though    * there was no other prototype for that function). /mast */    struct program *ap,*bp; -  ap = id_to_program(((char *)a->cdr)-(char *)0); -  bp = id_to_program(((char *)b->cdr)-(char *)0); +  ap = id_to_program(CDR_TO_INT(a)); +  bp = id_to_program(CDR_TO_INT(b));    if (!is_compatible(ap, bp)) return 0;   #endif    break;
2669:       {    struct program *ap,*bp; -  ap = id_to_program(((char *)a->cdr)-(char *)0); -  bp = id_to_program(((char *)b->cdr)-(char *)0); +  ap = id_to_program(CDR_TO_INT(a)); +  bp = id_to_program(CDR_TO_INT(b));       if(!ap || !bp) break;   
2696:       case T_INT:    { -  INT32 amin = ((char *)a->car)-(char *)0; -  INT32 amax = ((char *)a->cdr)-(char *)0; +  INT32 amin = CAR_TO_INT(a); +  INT32 amax = CDR_TO_INT(a);    -  INT32 bmin = ((char *)b->car)-(char *)0; -  INT32 bmax = ((char *)b->cdr)-(char *)0; +  INT32 bmin = CAR_TO_INT(b); +  INT32 bmax = CDR_TO_INT(b);       if(amin > bmax || bmin > amax) return 0;    break;
2863:    ret = low_pike_types_le(a->cdr, b, array_cnt, flags);    if(ret && (b->type != T_VOID))    { -  int m = ((char *)a->car)-(char *)0; +  int m = CAR_TO_INT(a);    struct pike_type *tmp;    int i;    type_stack_mark();
2947:    ret = low_pike_types_le(a, b->cdr, array_cnt, flags);    if(ret && (a->type != T_VOID))    { -  int m = ((char *)b->car)-(char *)0; +  int m = CAR_TO_INT(b);    struct pike_type *tmp;    int i;    type_stack_mark();
3216:    }       { -  struct program *ap = id_to_program(((char *)a->cdr)-(char *)0); -  struct program *bp = id_to_program(((char *)b->cdr)-(char *)0); +  struct program *ap = id_to_program(CDR_TO_INT(a)); +  struct program *bp = id_to_program(CDR_TO_INT(b));       if (!ap || !bp) {    /* Shouldn't happen... */
3232:       case T_INT:    { -  INT32 amin = ((char *)a->car)-(char *)0; -  INT32 amax = ((char *)a->cdr)-(char *)0; +  INT32 amin = CAR_TO_INT(a); +  INT32 amax = CDR_TO_INT(a);    -  INT32 bmin = ((char *)b->car)-(char *)0; -  INT32 bmax = ((char *)b->cdr)-(char *)0; +  INT32 bmin = CAR_TO_INT(b); +  INT32 bmax = CDR_TO_INT(b);       if(amin < bmin || amax > bmax) return 0;    break;
3436:    {    case T_OBJECT:    { -  p = id_to_program(((char *)t->cdr)-(char *)0); +  p = id_to_program(CDR_TO_INT(t));       comefrom_int_index:    if(p && n)
3615:    {    case T_OBJECT:    { -  p = id_to_program(((char *)t->cdr)-(char *)0); +  p = id_to_program(CDR_TO_INT(t));       if(p)    {
3797:    {    case T_OBJECT:    { -  struct program *p = id_to_program(((char *)t->cdr)-(char *)0); +  struct program *p = id_to_program(CDR_TO_INT(t));    if(p && n)    {    if(n->token == F_ARROW)
3906:       case T_OBJECT:    { -  struct program *p = id_to_program(((char *)type->cdr)-(char *)0); +  struct program *p = id_to_program(CDR_TO_INT(type));    if(p)    {    if(n->token == F_ARROW)
4383:    }    sval.type = T_PROGRAM;    if ((obj_t->type != T_OBJECT) || -  (!(id = ((char *)obj_t->cdr)-(char *)0)) || +  (!(id = CDR_TO_INT(obj_t))) ||    (!(sval.u.program = id_to_program(id))) ||    (!(sub = get_type_of_svalue(&sval)))) {    if (res) {
4446:       case T_OBJECT:    { -  struct program *p = id_to_program(((char *)type->cdr)-(char *)0); +  struct program *p = id_to_program(CDR_TO_INT(type));    if(!p) return 1;    return FIND_LFUN(p, lfun)!=-1;    }
4789:    {    INT32 i;    my_putchar(T_OBJECT); -  i = (INT32)(((char *)t->car)-(char *)0); +  i = (INT32)CAR_TO_INT(t);    my_putchar( i ); -  i = (INT32)(((char *)t->cdr)-(char *)0); +  i = (INT32)CDR_TO_INT(t);       if( i > 65535 ) i = 0; /* Not constant between recompilations */   
4806:    {    INT32 i;    my_putchar(T_INT); -  i = (INT32)(((char *)t->car)-(char *)0); +  i = (INT32)CAR_TO_INT(t);    my_putchar((i >> 24) & 0xff);    my_putchar((i >> 16) & 0xff);    my_putchar((i >> 8) & 0xff);    my_putchar(i & 0xff); -  i = (INT32)(((char *)t->cdr)-(char *)0); +  i = (INT32)CDR_TO_INT(t);    my_putchar((i >> 24) & 0xff);    my_putchar((i >> 16) & 0xff);    my_putchar((i >> 8) & 0xff);
4834:    case T_SCOPE:    case T_ASSIGN:    my_putchar(t->type); -  my_putchar('0' + (((char *)t->car)-(char *)0)); +  my_putchar('0' + CAR_TO_INT(t));    t = t->cdr;    goto recurse;