IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 4, 2007, 3:15:33 PM (19 years ago)
Author:
jhoblitt
Message:

change badMemBlock() to accept file, lineno, & func
rename psMemGetRefCounter() -> p_psMemGetRefCounter()
rename psMemGetDeallocator() -> p_psMemGetDeallocator()
rename psMemSetDeallocator() -> p_psMemSetDeallocator()
add psMemGetRefCounter, psMemGetDeallocator, & psMemSetDeallocator wrapper macros
rename some function params to be more consistent with each other
remove psMemProblemCallbackSet() prototype
add file, lineno, & func to most public functions
remove redundant double free check from p_psMemDecrRefCounter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/jch-memory/psLib/src/sys/psMemory.c

    r10903 r10906  
    99*  @author Joshua Hoblitt, University of Hawaii
    1010*
    11 *  @version $Revision: 1.88.2.13 $ $Name: not supported by cvs2svn $
    12 *  @date $Date: 2007-01-04 22:34:06 $
     11*  @version $Revision: 1.88.2.14 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2007-01-05 01:15:33 $
    1313*
    1414*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    7272fprintf(stderr, "\n");
    7373
    74 #define HANDLE_BAD_BLOCK(memBlock) \
    75 if (badMemBlock(stderr, memBlock)) { \
     74#define HANDLE_BAD_BLOCK(memBlock, file, lineo, func) \
     75if (badMemBlock(stderr, memBlock, file, lineo, func)) { \
    7676    psMemBlockPrint(stderr, memBlock); \
    7777    PS_MEM_ABORT(__func__, "Unsafe to Continue"); \
    7878}
    7979
    80 static bool badMemBlock(FILE *output, const psMemBlock *memBlock);
     80static bool badMemBlock(FILE *output, const psMemBlock *memBlock, const char *file, unsigned int lineo, const char *func);
    8181
    8282// pointer to the last mem block that was allocated
     
    149149 * N.b. If the block wasn't allocated by psAlloc, it will appear corrupted
    150150 */
    151 static bool badMemBlock(FILE *output, const psMemBlock *memBlock)
     151static bool badMemBlock(FILE *output, const psMemBlock *memBlock, const char *file, unsigned int lineno, const char *func)
    152152{
    153153    // n.b. since this is called by psMemCheckCorruption while the memblock
     
    158158    // as they make be changed out from underneath us by new memory allocation
    159159    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);
    161161        return true;
    162162    }
     
    164164    if (memBlock->refCounter == 0) {
    165165        // 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);
    167167        return true;
    168168    }
    169169
    170170    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);
    172172        return true;
    173173    }
    174174    if (*(psPtr *)((int8_t *) (memBlock + 1) + memBlock->userMemorySize) != P_PS_MEMMAGIC) {
    175175        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);
    177177        return true;
    178178    }
     
    321321    psS32 nbad = 0;               // number of bad blocks
    322322    for (psMemBlock *memBlock = lastMemBlockAllocated; memBlock != NULL; memBlock = memBlock->nextBlock) {
    323         if (badMemBlock(output, memBlock)) {
     323        if (badMemBlock(output, memBlock, __FILE__, __LINE__, __func__)) {
    324324            nbad++;
    325325
     
    443443    psMemBlock *memBlock = ((psMemBlock *)ptr) - 1;
    444444
    445     HANDLE_BAD_BLOCK(memBlock);
     445    HANDLE_BAD_BLOCK(memBlock, file, lineno, func);
    446446
    447447    if (size == memBlock->userMemorySize) {
     
    555555
    556556// return refCounter
    557 psReferenceCount psMemGetRefCounter(const psPtr ptr)
     557psReferenceCount p_psMemGetRefCounter(const psPtr ptr,
     558                                      const char *file,
     559                                      unsigned int lineno,
     560                                      const char *func)
    558561{
    559562    if (ptr == NULL) {
     
    563566    psMemBlock *memBlock = ((psMemBlock *) ptr) - 1;
    564567
    565     HANDLE_BAD_BLOCK(memBlock);
     568    HANDLE_BAD_BLOCK(memBlock, file, lineno, func);
    566569
    567570    return memBlock->refCounter;
     
    571574psPtr p_psMemIncrRefCounter(const psPtr ptr,
    572575                            const char *file,
    573                             psS32 lineno)
     576                            unsigned int lineno,
     577                            const char *func)
    574578{
    575579    if (ptr == NULL) {
     
    579583    psMemBlock* memBlock = ((psMemBlock *) ptr) - 1;
    580584
    581     HANDLE_BAD_BLOCK(memBlock);
     585    HANDLE_BAD_BLOCK(memBlock, file, lineno, func);
    582586
    583587    memBlock->refCounter++;
     
    629633psPtr p_psMemDecrRefCounter(psPtr ptr,
    630634                            const char *file,
    631                             psS32 lineno)
     635                            unsigned int lineno,
     636                            const char *func)
    632637{
    633638    if (ptr == NULL) {
     
    637642    psMemBlock *memBlock = ((psMemBlock *) ptr) - 1;
    638643
    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);
    650645
    651646    // if we have multiple references, just decrement the count and return.
     
    693688}
    694689
    695 void psMemSetDeallocator(psPtr ptr,
    696                          psFreeFunc freeFunc)
     690void p_psMemSetDeallocator(psPtr ptr,
     691                           psFreeFunc freeFunc,
     692                           const char *file,
     693                           unsigned int lineno,
     694                           const char *func)
    697695{
    698696    if (ptr == NULL) {
     
    702700    psMemBlock* memBlock = ((psMemBlock *)ptr) - 1;
    703701
    704     HANDLE_BAD_BLOCK(memBlock);
     702    HANDLE_BAD_BLOCK(memBlock, file, lineno, func);
    705703
    706704    memBlock->freeFunc = freeFunc;
    707705}
    708706
    709 psFreeFunc psMemGetDeallocator(const psPtr ptr)
     707psFreeFunc p_psMemGetDeallocator(const psPtr ptr,
     708                                 const char *file,
     709                                 unsigned int lineno,
     710                                 const char *func)
    710711{
    711712    if (ptr == NULL) {
     
    715716    psMemBlock* memBlock = ((psMemBlock *)ptr) - 1;
    716717
    717     HANDLE_BAD_BLOCK(memBlock);
     718    HANDLE_BAD_BLOCK(memBlock, file, lineno, func);
    718719
    719720    return memBlock->freeFunc;
     
    983984}
    984985
    985 bool p_psMemGetPersistent(psPtr ptr)
     986bool p_psMemGetPersistent(psPtr ptr,
     987                          const char *file,
     988                          unsigned int lineno,
     989                          const char *func)
    986990{
    987991    if (ptr == NULL) {
     
    991995    psMemBlock* memBlock = ((psMemBlock *) ptr) - 1;
    992996
    993     HANDLE_BAD_BLOCK(memBlock);
     997    HANDLE_BAD_BLOCK(memBlock, file, lineno, func);
    994998
    995999    return memBlock->persistent;
     
    9971001
    9981002void p_psMemSetPersistent(psPtr ptr,
    999                           bool value)
     1003                          bool value,
     1004                          const char *file,
     1005                          unsigned int lineno,
     1006                          const char *func)
    10001007{
    10011008    if (ptr == NULL) {
     
    10051012    psMemBlock* memBlock = ((psMemBlock *) ptr) - 1;
    10061013
    1007     HANDLE_BAD_BLOCK(memBlock);
     1014    HANDLE_BAD_BLOCK(memBlock, file, lineno, func);
    10081015
    10091016    memBlock->persistent = value;
Note: See TracChangeset for help on using the changeset viewer.