|
|
| version 1.1.2.5.2.9, 2003/04/01 13:48:32 | version 1.4, 2004/02/03 16:45:25 |
|---|---|
| Line 5 | Line 5 |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| */ | */ |
| static const char* IDENT_MEMORY_C="$Date$"; | static const char * const IDENT_MEMORY_C="$Date$"; |
| #include "pa_sapi.h" | #include "pa_sapi.h" |
| #include "pa_common.h" | #include "pa_common.h" |
| void *pa_fail_alloc(const char* what, size_t size) { | void *pa_fail_alloc(const char* what, size_t size) { |
| #ifdef PA_DEBUG_DISABLE_GC | #ifdef PA_DEBUG_DISABLE_GC |
| SAPI::abort("xx"); | SAPI::die("out of memory (in pa_fail_alloc)"); |
| #else | #else |
| SAPI::abort("out of memory: failed to %s %u bytes. " | SAPI::die("out of memory: failed to %s %u bytes. " |
| "heap_used=%lu, heap_free=%lu, bytes_since_gc=%lu, total_bytes=%lu", | "heap_used=%u, heap_free=%u, bytes_since_gc=%u, total_bytes=%u", |
| what, size, | what, size, |
| GC_get_heap_size(), | GC_get_heap_size(), |
| GC_get_free_bytes(), | GC_get_free_bytes(), |
| Line 30 void *pa_fail_alloc(const char* what, si | Line 30 void *pa_fail_alloc(const char* what, si |
| #ifdef PA_DEBUG_GC_MEMORY | #ifdef PA_DEBUG_GC_MEMORY |
| void bug() {} | |
| const size_t HEADTAIL_SIZE=4; | const size_t HEADTAIL_SIZE=4; |
| static size_t debug_size(size_t user_size) { | static size_t debug_size(size_t user_size) { |
| Line 52 static void* fill_return_user(void* aptr | Line 50 static void* fill_return_user(void* aptr |
| for(size_t i=pure_size; i<raw_size; i++) | for(size_t i=pure_size; i<raw_size; i++) |
| ptr[i]=PAD_MARK; | ptr[i]=PAD_MARK; |
| //if(ptr>=(char*)0x01c357e40 && ptr<=((char*)0x01c357e4+100)) | |
| //printf("valid:0x%p\n", ptr); | |
| return ptr+HEADTAIL_SIZE; | return ptr+HEADTAIL_SIZE; |
| } | } |
| static void* check_return_debug(void* auser_ptr) { | static void* check_return_debug(void* auser_ptr) { |
| Line 59 static void* check_return_debug(void* au | Line 60 static void* check_return_debug(void* au |
| char* ptr=user_ptr-HEADTAIL_SIZE; | char* ptr=user_ptr-HEADTAIL_SIZE; |
| size_t raw_size=GC_size(ptr); | size_t raw_size=GC_size(ptr); |
| if(raw_size==0) | assert(raw_size!=0); |
| bug(); | |
| size_t pure_size=raw_size; | size_t pure_size=raw_size; |
| while(ptr[pure_size-1]==PAD_MARK) | while(ptr[pure_size-1]==PAD_MARK) |
| pure_size--; | pure_size--; |
| if(memcmp(ptr, &BEFORE_MARK, HEADTAIL_SIZE)!=0) | assert(memcmp(ptr, &BEFORE_MARK, HEADTAIL_SIZE)==0); |
| bug(); | assert(memcmp(ptr+pure_size-HEADTAIL_SIZE, &AFTER_MARK, HEADTAIL_SIZE)==0); |
| if(memcmp(ptr+pure_size-HEADTAIL_SIZE, &AFTER_MARK, HEADTAIL_SIZE)!=0) | |
| bug(); | |
| return ptr; | return ptr; |
| } | } |
| Line 86 void* pa_gc_malloc_atomic(size_t size) { | Line 84 void* pa_gc_malloc_atomic(size_t size) { |
| } | } |
| void* pa_gc_realloc(void* user_ptr, size_t size) { | void* pa_gc_realloc(void* user_ptr, size_t size) { |
| if(!GC_is_visible(user_ptr)) | GC_is_visible(user_ptr); |
| bug(); | |
| //printf("realloc: 0x%p -> %u\n", ptr, size); | //printf("realloc: 0x%p -> %u\n", ptr, size); |
| size=debug_size(size); | size=debug_size(size); |
| return fill_return_user( | return fill_return_user( |