comparison src/gmalloc.c @ 251:677f6a0ee643 r20-5b24

Import from CVS: tag r20-5b24
author cvs
date Mon, 13 Aug 2007 10:19:59 +0200
parents 51092a27c943
children 084402c475ba
comparison
equal deleted inserted replaced
250:f385a461c9aa 251:677f6a0ee643
400 #define _MALLOC_INTERNAL 400 #define _MALLOC_INTERNAL
401 #include <malloc.h> 401 #include <malloc.h>
402 #endif 402 #endif
403 403
404 /* How to really get more memory. */ 404 /* How to really get more memory. */
405 #ifdef HEAP_IN_DATA
406 /* once dumped, free() & realloc() on static heap space will fail */
407 #define PURE_DATA(x) \
408 ((static_heap_dumped && (char*)x >= static_heap_base \
409 && (char*)x <= (static_heap_base + static_heap_size) ) ? 1 : 0)
410 extern int initialized;
411 extern int purify_flag;
412 extern char* static_heap_base;
413 extern char* static_heap_ptr;
414 extern char* static_heap_dumped;
415 extern unsigned long static_heap_size;
416 extern __ptr_t more_static_core __P ((ptrdiff_t __size));
417 __ptr_t (*__morecore) __P ((ptrdiff_t __size)) = more_static_core;
418 #else
405 __ptr_t (*__morecore) __P ((ptrdiff_t __size)) = __default_morecore; 419 __ptr_t (*__morecore) __P ((ptrdiff_t __size)) = __default_morecore;
420 #define PURE_DATA(x) 0
421 #endif
406 422
407 /* Debugging hook for `malloc'. */ 423 /* Debugging hook for `malloc'. */
408 __ptr_t (*__malloc_hook) __P ((__malloc_size_t __size)); 424 __ptr_t (*__malloc_hook) __P ((__malloc_size_t __size));
409 425
410 /* Pointer to the base of the first block. */ 426 /* Pointer to the base of the first block. */
463 /* Set everything up and remember that we have. */ 479 /* Set everything up and remember that we have. */
464 static int initialize __P ((void)); 480 static int initialize __P ((void));
465 static int 481 static int
466 initialize () 482 initialize ()
467 { 483 {
484 #ifdef HEAP_IN_DATA
485 if (static_heap_dumped && __morecore == more_static_core)
486 {
487 __morecore = __default_morecore;
488 }
489 #endif
468 heapsize = HEAP / BLOCKSIZE; 490 heapsize = HEAP / BLOCKSIZE;
469 _heapinfo = (malloc_info *) align (heapsize * sizeof (malloc_info)); 491 _heapinfo = (malloc_info *) align (heapsize * sizeof (malloc_info));
470 if (_heapinfo == NULL) 492 if (_heapinfo == NULL)
471 return 0; 493 return 0;
472 memset (_heapinfo, 0, heapsize * sizeof (malloc_info)); 494 memset (_heapinfo, 0, heapsize * sizeof (malloc_info));
495 memset (_fraghead, 0, BLOCKLOG * sizeof (struct list));
473 _heapinfo[0].free.size = 0; 496 _heapinfo[0].free.size = 0;
474 _heapinfo[0].free.next = _heapinfo[0].free.prev = 0; 497 _heapinfo[0].free.next = _heapinfo[0].free.prev = 0;
475 _heapindex = 0; 498 _heapindex = 0;
499 _heaplimit = 0;
476 _heapbase = (char *) _heapinfo; 500 _heapbase = (char *) _heapinfo;
477 501
478 /* Account for the _heapinfo block itself in the statistics. */ 502 /* Account for the _heapinfo block itself in the statistics. */
479 _bytes_used = heapsize * sizeof (malloc_info); 503 _bytes_used = heapsize * sizeof (malloc_info);
480 _chunks_used = 1; 504 _chunks_used = 1;
505 _chunks_free=0;
506 _bytes_free=0;
507 _aligned_blocks=0;
481 508
482 __malloc_initialized = 1; 509 __malloc_initialized = 1;
483 return 1; 510 return 1;
484 } 511 }
485 512
934 struct alignlist *l; 961 struct alignlist *l;
935 962
936 if (ptr == NULL) 963 if (ptr == NULL)
937 return; 964 return;
938 965
966 if (PURE_DATA(ptr))
967 {
968 return;
969 }
970
939 for (l = _aligned_blocks; l != NULL; l = l->next) 971 for (l = _aligned_blocks; l != NULL; l = l->next)
940 if (l->aligned == ptr) 972 if (l->aligned == ptr)
941 { 973 {
942 l->aligned = NULL; /* Mark the slot in the list as free. */ 974 l->aligned = NULL; /* Mark the slot in the list as free. */
943 ptr = l->exact; 975 ptr = l->exact;
1110 { 1142 {
1111 __ptr_t result; 1143 __ptr_t result;
1112 int type; 1144 int type;
1113 __malloc_size_t block, blocks, oldlimit; 1145 __malloc_size_t block, blocks, oldlimit;
1114 1146
1115 if (size == 0) 1147 if (PURE_DATA(ptr))
1148 {
1149 result = malloc (size);
1150 memcpy(result, ptr, size);
1151 return result;
1152 }
1153
1154 else if (size == 0)
1116 { 1155 {
1117 free (ptr); 1156 free (ptr);
1118 return malloc (0); 1157 return malloc (0);
1119 } 1158 }
1120 else if (ptr == NULL) 1159 else if (ptr == NULL)