Index: /branches/jch-memory/psLib/src/sys/psMemory.c
===================================================================
--- /branches/jch-memory/psLib/src/sys/psMemory.c	(revision 10905)
+++ /branches/jch-memory/psLib/src/sys/psMemory.c	(revision 10906)
@@ -9,6 +9,6 @@
 *  @author Joshua Hoblitt, University of Hawaii
 *
-*  @version $Revision: 1.88.2.13 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2007-01-04 22:34:06 $
+*  @version $Revision: 1.88.2.14 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2007-01-05 01:15:33 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -72,11 +72,11 @@
 fprintf(stderr, "\n");
 
-#define HANDLE_BAD_BLOCK(memBlock) \
-if (badMemBlock(stderr, memBlock)) { \
+#define HANDLE_BAD_BLOCK(memBlock, file, lineo, func) \
+if (badMemBlock(stderr, memBlock, file, lineo, func)) { \
     psMemBlockPrint(stderr, memBlock); \
     PS_MEM_ABORT(__func__, "Unsafe to Continue"); \
 }
 
-static bool badMemBlock(FILE *output, const psMemBlock *memBlock);
+static bool badMemBlock(FILE *output, const psMemBlock *memBlock, const char *file, unsigned int lineo, const char *func);
 
 // pointer to the last mem block that was allocated
@@ -149,5 +149,5 @@
  * N.b. If the block wasn't allocated by psAlloc, it will appear corrupted
  */
-static bool badMemBlock(FILE *output, const psMemBlock *memBlock)
+static bool badMemBlock(FILE *output, const psMemBlock *memBlock, const char *file, unsigned int lineno, const char *func)
 {
     // n.b. since this is called by psMemCheckCorruption while the memblock
@@ -158,5 +158,5 @@
     // as they make be changed out from underneath us by new memory allocation
     if (memBlock == NULL) {
-        fprintf(output, _("NULL memory block found."));
+        fprintf(output, _("NULL memory block. Caught in %s at (%s:%d.)."), func, file, lineno);
         return true;
     }
@@ -164,15 +164,15 @@
     if (memBlock->refCounter == 0) {
         // using an unreferenced block of memory, are you?
-        fprintf(output, _("Memory block was freed but still being used."));
+        fprintf(output, _("Memory block was freed but still being used.  Caught in %s at (%s:%d)."), func, file, lineno);
         return true;
     }
 
     if (memBlock->startblock != P_PS_MEMMAGIC || memBlock->endblock != P_PS_MEMMAGIC) {
-        fprintf(output, _("Memory block is corrupted; buffer underflow detected."));
+        fprintf(output, _("Memory block is corrupted; buffer underflow detected.Caught in %s at (%s:%d)."), func, file, lineno);
         return true;
     }
     if (*(psPtr *)((int8_t *) (memBlock + 1) + memBlock->userMemorySize) != P_PS_MEMMAGIC) {
         fprintf(output,
-                _("Memory block is corrupted; buffer overflow detected."));
+                _("Memory block is corrupted; buffer overflow detected. Caught in %s at (%s:%d)."), func, file, lineno);
         return true;
     }
@@ -321,5 +321,5 @@
     psS32 nbad = 0;               // number of bad blocks
     for (psMemBlock *memBlock = lastMemBlockAllocated; memBlock != NULL; memBlock = memBlock->nextBlock) {
-        if (badMemBlock(output, memBlock)) {
+        if (badMemBlock(output, memBlock, __FILE__, __LINE__, __func__)) {
             nbad++;
 
@@ -443,5 +443,5 @@
     psMemBlock *memBlock = ((psMemBlock *)ptr) - 1;
 
-    HANDLE_BAD_BLOCK(memBlock);
+    HANDLE_BAD_BLOCK(memBlock, file, lineno, func);
 
     if (size == memBlock->userMemorySize) {
@@ -555,5 +555,8 @@
 
 // return refCounter
-psReferenceCount psMemGetRefCounter(const psPtr ptr)
+psReferenceCount p_psMemGetRefCounter(const psPtr ptr,
+                                      const char *file,
+                                      unsigned int lineno,
+                                      const char *func)
 {
     if (ptr == NULL) {
@@ -563,5 +566,5 @@
     psMemBlock *memBlock = ((psMemBlock *) ptr) - 1;
 
-    HANDLE_BAD_BLOCK(memBlock);
+    HANDLE_BAD_BLOCK(memBlock, file, lineno, func);
 
     return memBlock->refCounter;
@@ -571,5 +574,6 @@
 psPtr p_psMemIncrRefCounter(const psPtr ptr,
                             const char *file,
-                            psS32 lineno)
+                            unsigned int lineno,
+                            const char *func)
 {
     if (ptr == NULL) {
@@ -579,5 +583,5 @@
     psMemBlock* memBlock = ((psMemBlock *) ptr) - 1;
 
-    HANDLE_BAD_BLOCK(memBlock);
+    HANDLE_BAD_BLOCK(memBlock, file, lineno, func);
 
     memBlock->refCounter++;
@@ -629,5 +633,6 @@
 psPtr p_psMemDecrRefCounter(psPtr ptr,
                             const char *file,
-                            psS32 lineno)
+                            unsigned int lineno,
+                            const char *func)
 {
     if (ptr == NULL) {
@@ -637,15 +642,5 @@
     psMemBlock *memBlock = ((psMemBlock *) ptr) - 1;
 
-    HANDLE_BAD_BLOCK(memBlock);
-
-    if (memBlock->refCounter < 1) {
-        PS_MEM_ABORT(__func__,_("Block %lu, allocated at %s (%s:%d), freed multiple times at %s:%d."),
-                     (unsigned long)memBlock->id,
-                     memBlock->func,
-                     memBlock->file,
-                     memBlock->lineno,
-                     file,
-                     lineno);
-    }
+    HANDLE_BAD_BLOCK(memBlock, file, lineno, func);
 
     // if we have multiple references, just decrement the count and return.
@@ -693,6 +688,9 @@
 }
 
-void psMemSetDeallocator(psPtr ptr,
-                         psFreeFunc freeFunc)
+void p_psMemSetDeallocator(psPtr ptr,
+                           psFreeFunc freeFunc,
+                           const char *file,
+                           unsigned int lineno,
+                           const char *func)
 {
     if (ptr == NULL) {
@@ -702,10 +700,13 @@
     psMemBlock* memBlock = ((psMemBlock *)ptr) - 1;
 
-    HANDLE_BAD_BLOCK(memBlock);
+    HANDLE_BAD_BLOCK(memBlock, file, lineno, func);
 
     memBlock->freeFunc = freeFunc;
 }
 
-psFreeFunc psMemGetDeallocator(const psPtr ptr)
+psFreeFunc p_psMemGetDeallocator(const psPtr ptr,
+                                 const char *file,
+                                 unsigned int lineno,
+                                 const char *func)
 {
     if (ptr == NULL) {
@@ -715,5 +716,5 @@
     psMemBlock* memBlock = ((psMemBlock *)ptr) - 1;
 
-    HANDLE_BAD_BLOCK(memBlock);
+    HANDLE_BAD_BLOCK(memBlock, file, lineno, func);
 
     return memBlock->freeFunc;
@@ -983,5 +984,8 @@
 }
 
-bool p_psMemGetPersistent(psPtr ptr)
+bool p_psMemGetPersistent(psPtr ptr,
+                          const char *file,
+                          unsigned int lineno,
+                          const char *func)
 {
     if (ptr == NULL) {
@@ -991,5 +995,5 @@
     psMemBlock* memBlock = ((psMemBlock *) ptr) - 1;
 
-    HANDLE_BAD_BLOCK(memBlock);
+    HANDLE_BAD_BLOCK(memBlock, file, lineno, func);
 
     return memBlock->persistent;
@@ -997,5 +1001,8 @@
 
 void p_psMemSetPersistent(psPtr ptr,
-                          bool value)
+                          bool value,
+                          const char *file,
+                          unsigned int lineno,
+                          const char *func)
 {
     if (ptr == NULL) {
@@ -1005,5 +1012,5 @@
     psMemBlock* memBlock = ((psMemBlock *) ptr) - 1;
 
-    HANDLE_BAD_BLOCK(memBlock);
+    HANDLE_BAD_BLOCK(memBlock, file, lineno, func);
 
     memBlock->persistent = value;
Index: /branches/jch-memory/psLib/src/sys/psMemory.h
===================================================================
--- /branches/jch-memory/psLib/src/sys/psMemory.h	(revision 10905)
+++ /branches/jch-memory/psLib/src/sys/psMemory.h	(revision 10906)
@@ -12,6 +12,6 @@
  *  @ingroup MemoryManagement
  *
- *  @version $Revision: 1.61.2.5 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-01-04 21:55:39 $
+ *  @version $Revision: 1.61.2.6 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-01-05 01:15:33 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -109,5 +109,5 @@
 typedef void (*psMemProblemCallback) (
     psMemBlock* ptr,                   ///< the pointer to the problematic memory block.
-    const char *filename,                    ///< the file in which the problem originated
+    const char *file,                  ///< the file in which the problem originated
     unsigned int lineno                ///< the line number in which the problem originated
 );
@@ -139,5 +139,5 @@
 psPtr p_psAlloc(
     size_t size,                       ///< Size required
-    const char *filename,              ///< File of caller
+    const char *file,                  ///< File of caller
     unsigned int lineno,               ///< Line number of caller
     const char *func                   ///< Function name of caller
@@ -152,4 +152,5 @@
 #endif // ! DOXYGEN
 
+
 /** Set the deallocator routine
  *
@@ -159,8 +160,28 @@
  *
  */
+#ifdef DOXYGEN
+
 void psMemSetDeallocator(
     psPtr ptr,                         ///< the memory block to operate on
     psFreeFunc freeFunc                ///< the function to be executed at deallocation
 );
+
+#else // ifdef DOXYGEN
+
+void p_psMemSetDeallocator(
+    psPtr ptr,                          ///< the memory block to operate on
+    psFreeFunc freeFunc,                ///< the function to be executed at deallocation
+    const char *file,                   ///< File of caller
+    unsigned int lineno,                ///< Line number of caller
+    const char *func                    ///< Function name of caller
+);
+
+#ifndef SWIG
+#define psMemSetDeallocator(ptr, freeFunc) \
+p_psMemSetDeallocator(ptr, freeFunc, __FILE__, __LINE__, __func__);
+#endif // ! SWIG
+
+#endif // ifdef DOXYGEN
+
 
 /** Get the deallocator routine
@@ -173,7 +194,26 @@
  *  @return psFreeFunc    the routine to be called at deallocation.
  */
+#ifdef DOXYGEN
+
 psFreeFunc psMemGetDeallocator(
-    const psPtr ptr                    ///< the memory block
-);
+    const psPtr ptr                     ///< the memory block
+);
+
+#else // ifdef DOXYGEN
+
+psFreeFunc p_psMemGetDeallocator(
+    const psPtr ptr,                    ///< the memory block
+    const char *file,                   ///< File of caller
+    unsigned int lineno,                ///< Line number of caller
+    const char *func                    ///< Function name of caller
+);
+
+#ifndef SWIG
+#define psMemGetDeallocator(ptr) \
+p_psMemGetDeallocator(ptr, __FILE__, __LINE__, __func__)
+#endif // ! SWIG
+
+#endif // ifdef DOXYGEN
+
 
 /** Checks the deallocator to see if the pointer matches the desired datatype.
@@ -207,4 +247,5 @@
 bool psMemGetThreadSafety(void);
 
+
 /** Set the memory as persistent so that it is ignored when detecting memory leaks.
  *
@@ -217,8 +258,28 @@
  *
  */
+#ifdef DOXYGEN
+
+void psMemSetPersistent(
+    psPtr ptr,                         ///< the memory block to operate on
+    bool value,                        ///< true if memory is persistent, otherwise false
+);
+
+#else // #ifdef DOXYGEN
+
 void p_psMemSetPersistent(
     psPtr ptr,                         ///< the memory block to operate on
-    bool value                         ///< true if memory is persistent, otherwise false
-);
+    bool value,                        ///< true if memory is persistent, otherwise false
+    const char *file,                  ///< File of caller
+    unsigned int lineno,               ///< Line number of caller
+    const char *func                   ///< Function name of caller
+);
+
+#ifndef SWIG
+#define psMemSetPersistent(ptr, value) \
+p_psMemSetPersistent(ptr, value, __FILE__, __LINE__, __func__);
+#endif // ! SWIG
+
+#endif // DOXYGEN
+
 
 /** Set whether allocated memory is persistent
@@ -229,4 +290,5 @@
  */
 bool p_psMemAllocatePersistent(bool is_persistent); ///< Should all memory allocated be persistent?
+
 
 /** Get the memory's persistent flag.
@@ -239,7 +301,24 @@
  *  @return bool    true if memory is marked persistent, otherwise false.
  */
+#ifdef DOXYGEN
+
+bool psMemGetPersistent(
+    psPtr ptr,                         ///< the memory block to check.
+);
+#else // ifdef DOXYGEN
+
 bool p_psMemGetPersistent(
-    psPtr ptr                          ///< the memory block to check.
-);
+    psPtr ptr,                         ///< the memory block to check.
+    const char *file,                  ///< File of caller
+    unsigned int lineno,               ///< Line number of caller
+    const char *func                   ///< Function name of caller
+);
+
+#ifndef SWIG
+#define psMemGetPersistent(ptr) \
+p_MemGetPersistent(ptr, __FILE__, __LINE__, __func__);
+#endif // ! SWIG
+
+#endif // DOXYGEN
 
 
@@ -260,5 +339,5 @@
     psPtr ptr,                         ///< Pointer to re-allocate
     size_t size,                       ///< Size required
-    const char *filename,              ///< File of caller
+    const char *file,                  ///< File of caller
     unsigned int lineno,               ///< Line number of caller
     const char *func                   ///< Function name of caller
@@ -273,4 +352,5 @@
 #endif // ! DOXYGEN
 
+
 /** Free memory.  This operates much like free().
  *
@@ -285,9 +365,10 @@
 /// Free memory.  psFree sends file and line number to p_psFree.
 #ifndef SWIG
-//#define psFree(ptr) { p_psMemDecrRefCounter((psPtr)ptr, __FILE__, __LINE__); *(void**)&(ptr) = NULL; }
-#define psFree(ptr) { p_psMemDecrRefCounter((psPtr)ptr, __FILE__, __LINE__); }
+#define            psFree(ptr) \
+p_psMemDecrRefCounter((psPtr *)ptr, __FILE__, __LINE__, __func__);
 #endif // ! SWIG
 
 #endif // ! DOXYGEN
+
 
 /** Check for memory leaks.  This scans for allocated memory buffers not freed with an ID not less than id0.
@@ -330,8 +411,27 @@
  *  @ingroup memRefCount
  */
+#ifdef DOXYGEN
+
 psReferenceCount psMemGetRefCounter(
     const psPtr ptr                    ///< Pointer to get refCounter for
 );
 
+#else // ifdef DOXYGEN
+
+psReferenceCount p_psMemGetRefCounter(
+    const psPtr ptr,                   ///< Pointer to get refCounter for
+    const char *file,                  ///< File of call
+    unsigned int lineno,               ///< Line number of call
+    const char *func                   ///< Function name of caller
+);
+
+#ifndef SWIG
+#define psMemGetRefCounter(ptr) \
+p_psMemGetRefCounter(ptr, __FILE__, __LINE__, __func__)
+#endif // !SWIG
+
+#endif // !DOXYGEN
+
+
 /** Increment reference counter and return the pointer
  *
@@ -341,19 +441,24 @@
  */
 #ifdef DOXYGEN
+
 psPtr psMemIncrRefCounter(
     const psPtr ptr                    ///< Pointer to increment refCounter, and return
 );
-#else
+#else // ifdef DOXYGEN
+
 psPtr p_psMemIncrRefCounter(
-    const psPtr vptr,                  ///< Pointer to increment refCounter, and return
+    const psPtr ptr,                  ///< Pointer to increment refCounter, and return
     const char *file,                  ///< File of call
-    psS32 lineno                       ///< Line number of call
-);
-
-#ifndef SWIG
-#define psMemIncrRefCounter(vptr) p_psMemIncrRefCounter(vptr, __FILE__, __LINE__)
+    unsigned int lineno,               ///< Line number of call
+    const char *func                   ///< Function name of caller
+);
+
+#ifndef SWIG
+#define psMemIncrRefCounter(ptr) \
+p_psMemIncrRefCounter(ptr, __FILE__, __LINE__, __func__)
 #endif // !SWIG
 
 #endif // !DOXYGEN
+
 
 /** Decrement reference counter and return the pointer
@@ -365,16 +470,21 @@
  */
 #ifdef DOXYGEN
+
 psPtr psMemDecrRefCounter(
     psPtr ptr                         ///< Pointer to decrement refCounter, and return
 );
+
 #else // DOXYGEN
+
 psPtr p_psMemDecrRefCounter(
-    psPtr vptr,                        ///< Pointer to decrement refCounter, and return
+    psPtr ptr,                        ///< Pointer to decrement refCounter, and return
     const char *file,                  ///< File of call
-    psS32 lineno                       ///< Line number of call
-);
-
-#ifndef SWIG
-#define psMemDecrRefCounter(vptr) p_psMemDecrRefCounter(vptr, __FILE__, __LINE__)
+    unsigned int lineno,               ///< Line number of call
+    const char *func                   ///< Function name of caller
+);
+
+#ifndef SWIG
+#define psMemDecrRefCounter(ptr) \
+p_psMemDecrRefCounter(ptr, __FILE__, __LINE__, __func__)
 #endif // !SWIG
 
@@ -408,18 +518,4 @@
 #endif // !DOXYGEN
 #endif // psMemSetRefCounter
-
-/** Set callback for problems.
- *
- *  At various occasions, the memory manager can check the state of the memory
- *  stack. If any of these checks discover that the memory stack is corrupted,
- *  the psMemProblemCallback is called.
- 
- *  @ingroup memCallback
- *
- *  @return psMemProblemCallback       old psMemProblemCallback function
- */
-psMemProblemCallback psMemProblemCallbackSet(
-    psMemProblemCallback func          ///< Function to run at memory problem detection
-);
 
 /** Set callback for out-of-memory.
