IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4718


Ignore:
Timestamp:
Aug 5, 2005, 9:57:06 AM (21 years ago)
Author:
eugene
Message:

fixed marker ptr type (32 vs 64 bit machines)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libohana/src/ohana_allocate.c

    r4498 r4718  
    1111  if (X == NULL) { \
    1212    fprintf(stderr,"failed malloc at %d in %s\n", __LINE__, __FILE__);\
    13     exit (10); }
     13    abort(); }
    1414# define OHANA_REALLOCATE(X,T,S) \
    1515  X = (T *) realloc(X,(unsigned)(MAX(((S)*((int)sizeof(T))),1))); \
    1616  if (X == NULL) { \
    1717    fprintf(stderr,"failed realloc at %d in %s\n", __LINE__, __FILE__);\
    18     exit (10); }
     18    abort(); }
    1919# define OHANA_CHECK_REALLOCATE(X,T,S,N,D) \
    2020  if ((N) >= (S)) { \
     
    2323    if (X == NULL) { \
    2424      fprintf(stderr,"failed realloc increment at %d in %s\n", __LINE__, __FILE__);\
    25       exit (10); } }
     25      abort(); } }
    2626# define OHANA_FREE(X) free(X)
    2727
     
    4242int Nmemlist = 0;
    4343int NMEMLIST = 0;
     44int NMEMBYTE = 0;
    4445
    4546void ohana_meminit () {
     
    4748  NMEMLIST = 1000;
    4849  OHANA_ALLOCATE (memlist, Memlist, NMEMLIST);
     50  NMEMBYTE = sizeof(size_t);
    4951}
    5052
     
    5557  vfprintf (stderr, format, argp);
    5658  va_end (argp);
    57   exit (5);
     59  abort();
    5860}
    5961
     
    6264  void *ptr, *new;
    6365  int size;
    64   int *marker;
     66  size_t *marker;
    6567
    6668  if (memlist == NULL) ohana_meminit ();
     
    6971  size = Nelem * esize;
    7072
    71   new = malloc (size + 8); /* 8 extra to save endposts */
     73  new = malloc (size + 2*NMEMBYTE); /* 2 extra locations to save endposts */
    7274  if (new == NULL) ohana_memabort ("failed to allocate memory (%s, %d)\n", file, line);
    73   ptr = new + 4;
    74 
    75   marker = (int *) new;
     75  ptr = new + NMEMBYTE;
     76
     77  marker = (size_t *) new;
    7678  *marker = 0xdeadbeef;
    77   marker = (int *)(new + size + 4);
     79  marker = (size_t *)(new + size + NMEMBYTE);
    7880  *marker = 0xdeadbeef;
    7981
     
    9698  int i, size;
    9799  void *ptr, *ref, *new;
    98   int *marker;
     100  size_t *marker;
    99101
    100102  if (memlist == NULL) ohana_memabort ("REALLOCATE before ALLOCATE");
     
    103105  size = Nelem * esize;
    104106
    105   ref = in - 4;
     107  ref = in - NMEMBYTE;
    106108
    107109  /* find old entry, update ptr, file, line */
     
    113115
    114116      /* ask for new memory */
    115       new = realloc (ref, size + 8); /* 8 extra to save endposts */
     117      new = realloc (ref, size + 2*NMEMBYTE); /* 2 extra slots to save endposts */
    116118      if (new == NULL) ohana_memabort ("failed to reallocate memory (%s, %d)\n", file, line);
    117       ptr = new + 4;
     119      ptr = new + NMEMBYTE;
    118120     
    119121      /* set the marker */
    120       marker = (int *) new;
     122      marker = (size_t *) new;
    121123      *marker = 0xdeadbeef;
    122       marker = (int *)(ptr + size);
     124      marker = (size_t *)(ptr + size);
    123125      *marker = 0xdeadbeef;
    124126
     
    188190
    189191  int i, header;
    190   int *marker;
     192  size_t *marker;
    191193  char top, bottom;
    192194
     
    203205
    204206    top = bottom = 'Y';
    205     marker = (int *)(memlist[i].ptr - 4);
     207    marker = (size_t *)(memlist[i].ptr - NMEMBYTE);
    206208    if (*marker == 0xdeadbeef) bottom = 'N';
    207     marker = (int *)(memlist[i].ptr + memlist[i].size);
     209    marker = (size_t *)(memlist[i].ptr + memlist[i].size);
    208210    if (*marker == 0xdeadbeef) top = 'N';
    209211   
     
    242244    if ((allmemory == 0) && (memlist[i].state == STATE_FREE)) continue;
    243245    if (memlist[i].state == STATE_EXTERNAL) {
    244       fprintf (stderr, "%3d %4d %x : %x - external (external external) %c %s %d\n",
    245                Ns[N], i, memlist[i].ptr, memlist[i].ptr,
     246      fprintf (stderr, "%3d %4d %lx : %lx - extern (extern     extern) %c %s %d\n",
     247               Ns[N], i, (long)memlist[i].ptr, (long)memlist[i].ptr,
    246248               S[N], memlist[i].file, memlist[i].line);
    247249    } else {
    248       fprintf (stderr, "%3d %4d %x : %x - %x (%x %x) %c %s %d\n",
    249                Ns[N], i, memlist[i].ptr, (memlist[i].ptr - 4), (memlist[i].ptr + memlist[i].size + 4),
    250                *(long *)(memlist[i].ptr - 4), *(long *)(memlist[i].ptr + memlist[i].size),
     250      fprintf (stderr, "%3d %4d %lx : %lx - %lx (%lx %lx) %c %s %d\n",
     251               Ns[N], i, (long)memlist[i].ptr, (long)(memlist[i].ptr - NMEMBYTE), (long)(memlist[i].ptr + memlist[i].size + NMEMBYTE),
     252               *(long *)(memlist[i].ptr - NMEMBYTE), *(long *)(memlist[i].ptr + memlist[i].size),
    251253               S[N], memlist[i].file, memlist[i].line);
    252254    }
Note: See TracChangeset for help on using the changeset viewer.