Changeset 10906 for branches/jch-memory/psLib/src/sys/psMemory.c
- Timestamp:
- Jan 4, 2007, 3:15:33 PM (19 years ago)
- File:
-
- 1 edited
-
branches/jch-memory/psLib/src/sys/psMemory.c (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/jch-memory/psLib/src/sys/psMemory.c
r10903 r10906 9 9 * @author Joshua Hoblitt, University of Hawaii 10 10 * 11 * @version $Revision: 1.88.2.1 3$ $Name: not supported by cvs2svn $12 * @date $Date: 2007-01-0 4 22:34:06$11 * @version $Revision: 1.88.2.14 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2007-01-05 01:15:33 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 72 72 fprintf(stderr, "\n"); 73 73 74 #define HANDLE_BAD_BLOCK(memBlock ) \75 if (badMemBlock(stderr, memBlock )) { \74 #define HANDLE_BAD_BLOCK(memBlock, file, lineo, func) \ 75 if (badMemBlock(stderr, memBlock, file, lineo, func)) { \ 76 76 psMemBlockPrint(stderr, memBlock); \ 77 77 PS_MEM_ABORT(__func__, "Unsafe to Continue"); \ 78 78 } 79 79 80 static bool badMemBlock(FILE *output, const psMemBlock *memBlock );80 static bool badMemBlock(FILE *output, const psMemBlock *memBlock, const char *file, unsigned int lineo, const char *func); 81 81 82 82 // pointer to the last mem block that was allocated … … 149 149 * N.b. If the block wasn't allocated by psAlloc, it will appear corrupted 150 150 */ 151 static bool badMemBlock(FILE *output, const psMemBlock *memBlock )151 static bool badMemBlock(FILE *output, const psMemBlock *memBlock, const char *file, unsigned int lineno, const char *func) 152 152 { 153 153 // n.b. since this is called by psMemCheckCorruption while the memblock … … 158 158 // as they make be changed out from underneath us by new memory allocation 159 159 if (memBlock == NULL) { 160 fprintf(output, _("NULL memory block found."));160 fprintf(output, _("NULL memory block. Caught in %s at (%s:%d.)."), func, file, lineno); 161 161 return true; 162 162 } … … 164 164 if (memBlock->refCounter == 0) { 165 165 // using an unreferenced block of memory, are you? 166 fprintf(output, _("Memory block was freed but still being used. "));166 fprintf(output, _("Memory block was freed but still being used. Caught in %s at (%s:%d)."), func, file, lineno); 167 167 return true; 168 168 } 169 169 170 170 if (memBlock->startblock != P_PS_MEMMAGIC || memBlock->endblock != P_PS_MEMMAGIC) { 171 fprintf(output, _("Memory block is corrupted; buffer underflow detected. "));171 fprintf(output, _("Memory block is corrupted; buffer underflow detected.Caught in %s at (%s:%d)."), func, file, lineno); 172 172 return true; 173 173 } 174 174 if (*(psPtr *)((int8_t *) (memBlock + 1) + memBlock->userMemorySize) != P_PS_MEMMAGIC) { 175 175 fprintf(output, 176 _("Memory block is corrupted; buffer overflow detected. "));176 _("Memory block is corrupted; buffer overflow detected. Caught in %s at (%s:%d)."), func, file, lineno); 177 177 return true; 178 178 } … … 321 321 psS32 nbad = 0; // number of bad blocks 322 322 for (psMemBlock *memBlock = lastMemBlockAllocated; memBlock != NULL; memBlock = memBlock->nextBlock) { 323 if (badMemBlock(output, memBlock )) {323 if (badMemBlock(output, memBlock, __FILE__, __LINE__, __func__)) { 324 324 nbad++; 325 325 … … 443 443 psMemBlock *memBlock = ((psMemBlock *)ptr) - 1; 444 444 445 HANDLE_BAD_BLOCK(memBlock );445 HANDLE_BAD_BLOCK(memBlock, file, lineno, func); 446 446 447 447 if (size == memBlock->userMemorySize) { … … 555 555 556 556 // return refCounter 557 psReferenceCount psMemGetRefCounter(const psPtr ptr) 557 psReferenceCount p_psMemGetRefCounter(const psPtr ptr, 558 const char *file, 559 unsigned int lineno, 560 const char *func) 558 561 { 559 562 if (ptr == NULL) { … … 563 566 psMemBlock *memBlock = ((psMemBlock *) ptr) - 1; 564 567 565 HANDLE_BAD_BLOCK(memBlock );568 HANDLE_BAD_BLOCK(memBlock, file, lineno, func); 566 569 567 570 return memBlock->refCounter; … … 571 574 psPtr p_psMemIncrRefCounter(const psPtr ptr, 572 575 const char *file, 573 psS32 lineno) 576 unsigned int lineno, 577 const char *func) 574 578 { 575 579 if (ptr == NULL) { … … 579 583 psMemBlock* memBlock = ((psMemBlock *) ptr) - 1; 580 584 581 HANDLE_BAD_BLOCK(memBlock );585 HANDLE_BAD_BLOCK(memBlock, file, lineno, func); 582 586 583 587 memBlock->refCounter++; … … 629 633 psPtr p_psMemDecrRefCounter(psPtr ptr, 630 634 const char *file, 631 psS32 lineno) 635 unsigned int lineno, 636 const char *func) 632 637 { 633 638 if (ptr == NULL) { … … 637 642 psMemBlock *memBlock = ((psMemBlock *) ptr) - 1; 638 643 639 HANDLE_BAD_BLOCK(memBlock); 640 641 if (memBlock->refCounter < 1) { 642 PS_MEM_ABORT(__func__,_("Block %lu, allocated at %s (%s:%d), freed multiple times at %s:%d."), 643 (unsigned long)memBlock->id, 644 memBlock->func, 645 memBlock->file, 646 memBlock->lineno, 647 file, 648 lineno); 649 } 644 HANDLE_BAD_BLOCK(memBlock, file, lineno, func); 650 645 651 646 // if we have multiple references, just decrement the count and return. … … 693 688 } 694 689 695 void psMemSetDeallocator(psPtr ptr, 696 psFreeFunc freeFunc) 690 void p_psMemSetDeallocator(psPtr ptr, 691 psFreeFunc freeFunc, 692 const char *file, 693 unsigned int lineno, 694 const char *func) 697 695 { 698 696 if (ptr == NULL) { … … 702 700 psMemBlock* memBlock = ((psMemBlock *)ptr) - 1; 703 701 704 HANDLE_BAD_BLOCK(memBlock );702 HANDLE_BAD_BLOCK(memBlock, file, lineno, func); 705 703 706 704 memBlock->freeFunc = freeFunc; 707 705 } 708 706 709 psFreeFunc psMemGetDeallocator(const psPtr ptr) 707 psFreeFunc p_psMemGetDeallocator(const psPtr ptr, 708 const char *file, 709 unsigned int lineno, 710 const char *func) 710 711 { 711 712 if (ptr == NULL) { … … 715 716 psMemBlock* memBlock = ((psMemBlock *)ptr) - 1; 716 717 717 HANDLE_BAD_BLOCK(memBlock );718 HANDLE_BAD_BLOCK(memBlock, file, lineno, func); 718 719 719 720 return memBlock->freeFunc; … … 983 984 } 984 985 985 bool p_psMemGetPersistent(psPtr ptr) 986 bool p_psMemGetPersistent(psPtr ptr, 987 const char *file, 988 unsigned int lineno, 989 const char *func) 986 990 { 987 991 if (ptr == NULL) { … … 991 995 psMemBlock* memBlock = ((psMemBlock *) ptr) - 1; 992 996 993 HANDLE_BAD_BLOCK(memBlock );997 HANDLE_BAD_BLOCK(memBlock, file, lineno, func); 994 998 995 999 return memBlock->persistent; … … 997 1001 998 1002 void p_psMemSetPersistent(psPtr ptr, 999 bool value) 1003 bool value, 1004 const char *file, 1005 unsigned int lineno, 1006 const char *func) 1000 1007 { 1001 1008 if (ptr == NULL) { … … 1005 1012 psMemBlock* memBlock = ((psMemBlock *) ptr) - 1; 1006 1013 1007 HANDLE_BAD_BLOCK(memBlock );1014 HANDLE_BAD_BLOCK(memBlock, file, lineno, func); 1008 1015 1009 1016 memBlock->persistent = value;
Note:
See TracChangeset
for help on using the changeset viewer.
