Changeset 4718
- Timestamp:
- Aug 5, 2005, 9:57:06 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/libohana/src/ohana_allocate.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libohana/src/ohana_allocate.c
r4498 r4718 11 11 if (X == NULL) { \ 12 12 fprintf(stderr,"failed malloc at %d in %s\n", __LINE__, __FILE__);\ 13 exit (10); }13 abort(); } 14 14 # define OHANA_REALLOCATE(X,T,S) \ 15 15 X = (T *) realloc(X,(unsigned)(MAX(((S)*((int)sizeof(T))),1))); \ 16 16 if (X == NULL) { \ 17 17 fprintf(stderr,"failed realloc at %d in %s\n", __LINE__, __FILE__);\ 18 exit (10); }18 abort(); } 19 19 # define OHANA_CHECK_REALLOCATE(X,T,S,N,D) \ 20 20 if ((N) >= (S)) { \ … … 23 23 if (X == NULL) { \ 24 24 fprintf(stderr,"failed realloc increment at %d in %s\n", __LINE__, __FILE__);\ 25 exit (10); } }25 abort(); } } 26 26 # define OHANA_FREE(X) free(X) 27 27 … … 42 42 int Nmemlist = 0; 43 43 int NMEMLIST = 0; 44 int NMEMBYTE = 0; 44 45 45 46 void ohana_meminit () { … … 47 48 NMEMLIST = 1000; 48 49 OHANA_ALLOCATE (memlist, Memlist, NMEMLIST); 50 NMEMBYTE = sizeof(size_t); 49 51 } 50 52 … … 55 57 vfprintf (stderr, format, argp); 56 58 va_end (argp); 57 exit (5);59 abort(); 58 60 } 59 61 … … 62 64 void *ptr, *new; 63 65 int size; 64 int *marker;66 size_t *marker; 65 67 66 68 if (memlist == NULL) ohana_meminit (); … … 69 71 size = Nelem * esize; 70 72 71 new = malloc (size + 8); /* 8 extrato save endposts */73 new = malloc (size + 2*NMEMBYTE); /* 2 extra locations to save endposts */ 72 74 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; 76 78 *marker = 0xdeadbeef; 77 marker = ( int *)(new + size + 4);79 marker = (size_t *)(new + size + NMEMBYTE); 78 80 *marker = 0xdeadbeef; 79 81 … … 96 98 int i, size; 97 99 void *ptr, *ref, *new; 98 int *marker;100 size_t *marker; 99 101 100 102 if (memlist == NULL) ohana_memabort ("REALLOCATE before ALLOCATE"); … … 103 105 size = Nelem * esize; 104 106 105 ref = in - 4;107 ref = in - NMEMBYTE; 106 108 107 109 /* find old entry, update ptr, file, line */ … … 113 115 114 116 /* ask for new memory */ 115 new = realloc (ref, size + 8); /* 8 extrato save endposts */117 new = realloc (ref, size + 2*NMEMBYTE); /* 2 extra slots to save endposts */ 116 118 if (new == NULL) ohana_memabort ("failed to reallocate memory (%s, %d)\n", file, line); 117 ptr = new + 4;119 ptr = new + NMEMBYTE; 118 120 119 121 /* set the marker */ 120 marker = ( int *) new;122 marker = (size_t *) new; 121 123 *marker = 0xdeadbeef; 122 marker = ( int *)(ptr + size);124 marker = (size_t *)(ptr + size); 123 125 *marker = 0xdeadbeef; 124 126 … … 188 190 189 191 int i, header; 190 int *marker;192 size_t *marker; 191 193 char top, bottom; 192 194 … … 203 205 204 206 top = bottom = 'Y'; 205 marker = ( int *)(memlist[i].ptr - 4);207 marker = (size_t *)(memlist[i].ptr - NMEMBYTE); 206 208 if (*marker == 0xdeadbeef) bottom = 'N'; 207 marker = ( int *)(memlist[i].ptr + memlist[i].size);209 marker = (size_t *)(memlist[i].ptr + memlist[i].size); 208 210 if (*marker == 0xdeadbeef) top = 'N'; 209 211 … … 242 244 if ((allmemory == 0) && (memlist[i].state == STATE_FREE)) continue; 243 245 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, 246 248 S[N], memlist[i].file, memlist[i].line); 247 249 } 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), 251 253 S[N], memlist[i].file, memlist[i].line); 252 254 }
Note:
See TracChangeset
for help on using the changeset viewer.
