Index: /branches/jch-memory/psLib/src/sys/psMemory.c
===================================================================
--- /branches/jch-memory/psLib/src/sys/psMemory.c	(revision 10902)
+++ /branches/jch-memory/psLib/src/sys/psMemory.c	(revision 10903)
@@ -9,6 +9,6 @@
 *  @author Joshua Hoblitt, University of Hawaii
 *
-*  @version $Revision: 1.88.2.12 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2007-01-04 21:55:39 $
+*  @version $Revision: 1.88.2.13 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2007-01-04 22:34:06 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -72,13 +72,11 @@
 fprintf(stderr, "\n");
 
-#define PS_MEM_ABORT_CORRUPT(ptr) \
-PS_MEM_ABORT(file, "Memory corruption detected in block %lu, allocated at %s (%s:%d) by thread id %lu", \
-             (unsigned long)ptr->id, \
-             ptr->func, \
-             ptr->file, \
-             ptr->lineno,\
-             ptr->tid);
-
-static bool badMemBlock(const psMemBlock *memBlock);
+#define HANDLE_BAD_BLOCK(memBlock) \
+if (badMemBlock(stderr, memBlock)) { \
+    psMemBlockPrint(stderr, memBlock); \
+    PS_MEM_ABORT(__func__, "Unsafe to Continue"); \
+}
+
+static bool badMemBlock(FILE *output, const psMemBlock *memBlock);
 
 // pointer to the last mem block that was allocated
@@ -151,5 +149,5 @@
  * N.b. If the block wasn't allocated by psAlloc, it will appear corrupted
  */
-static bool badMemBlock(const psMemBlock *memBlock)
+static bool badMemBlock(FILE *output, const psMemBlock *memBlock)
 {
     // n.b. since this is called by psMemCheckCorruption while the memblock
@@ -160,6 +158,5 @@
     // as they make be changed out from underneath us by new memory allocation
     if (memBlock == NULL) {
-        PS_MEM_ERROR(PS_ERR_MEMORY_CORRUPTION, true,
-                     _("NULL memory block found."));
+        fprintf(output, _("NULL memory block found."));
         return true;
     }
@@ -167,20 +164,15 @@
     if (memBlock->refCounter == 0) {
         // using an unreferenced block of memory, are you?
-        PS_MEM_ERROR(PS_ERR_MEMORY_CORRUPTION, true,
-                     _("Memory block %lu was freed but still being used."),
-                     (unsigned long)memBlock->id);
+        fprintf(output, _("Memory block was freed but still being used."));
         return true;
     }
 
     if (memBlock->startblock != P_PS_MEMMAGIC || memBlock->endblock != P_PS_MEMMAGIC) {
-        PS_MEM_ERROR(PS_ERR_MEMORY_CORRUPTION, true,
-                     _("Memory block %lu is corrupted; buffer underflow detected."),
-                     (unsigned long)memBlock->id);
+        fprintf(output, _("Memory block is corrupted; buffer underflow detected."));
         return true;
     }
     if (*(psPtr *)((int8_t *) (memBlock + 1) + memBlock->userMemorySize) != P_PS_MEMMAGIC) {
-        PS_MEM_ERROR(PS_ERR_MEMORY_CORRUPTION, true,
-                     _("Memory block %lu is corrupted; buffer overflow detected."),
-                     (unsigned long)memBlock->id);
+        fprintf(output,
+                _("Memory block is corrupted; buffer overflow detected."));
         return true;
     }
@@ -197,7 +189,6 @@
 {
     static psMemId incr = 10; // "p_psMemAllocID += incr"
-    bool abort_on_error = false;
-
-    if (psMemCheckCorruption(stderr, abort_on_error) > 0) {
+
+    if (psMemCheckCorruption(stderr, false) > 0) {
         fprintf(stderr, "Detected memory corruption\n"); // somewhere to set a breakpoint
     }
@@ -324,23 +315,14 @@
 int psMemCheckCorruption(FILE *output, bool abort_on_error)
 {
-    psS32 nbad = 0;               // number of bad blocks
-
     // get exclusive access to the memBlock list to avoid it changing on us
     // while we use it.
     MUTEX_LOCK(&memBlockListMutex);
 
+    psS32 nbad = 0;               // number of bad blocks
     for (psMemBlock *memBlock = lastMemBlockAllocated; memBlock != NULL; memBlock = memBlock->nextBlock) {
-        if (badMemBlock(memBlock)) {
+        if (badMemBlock(output, memBlock)) {
             nbad++;
 
-            fprintf(output,
-                    "Memory corruption detected in memBlock %lu\n"
-                    "\tSize %zd\n"
-                    "\tPosts: %p %p %p\n"
-                    "\tAllocated at %s (%s:%d) by thread %lu\n",
-                    memBlock->id,
-                    memBlock->userMemorySize,
-                    memBlock->startblock, memBlock->endblock, (memBlock + 1 + memBlock->userMemorySize),
-                    memBlock->func, memBlock->file, memBlock->lineno, memBlock->tid);
+            psMemBlockPrint(output, memBlock);
 
             if (abort_on_error) {
@@ -461,12 +443,5 @@
     psMemBlock *memBlock = ((psMemBlock *)ptr) - 1;
 
-    if (badMemBlock(memBlock)) {
-        PS_MEM_ABORT(file, "Memory corruption detected in block %lu, allocated at %s (%s:%d) by thread id %lu",
-                     (unsigned long)memBlock->id,
-                     memBlock->func,
-                     memBlock->file,
-                     memBlock->lineno,
-                     memBlock->tid);
-    }
+    HANDLE_BAD_BLOCK(memBlock);
 
     if (size == memBlock->userMemorySize) {
@@ -483,5 +458,7 @@
         if (memBlock == NULL) {
             MUTEX_UNLOCK(&memBlockListMutex);
-            PS_MEM_ABORT(__func__, "Failed to reallocate %zd bytes at %s (%s:%d)", size, func, file, lineno);
+            fprintf(stderr, "Problem reallocating block\n");
+            psMemBlockPrint(stderr,  ((psMemBlock *)ptr) - 1);
+            PS_MEM_ABORT(__func__, "Failed to reallocate to %zd bytes at %s (%s:%d)", size, func, file, lineno);
         }
     }
@@ -586,7 +563,5 @@
     psMemBlock *memBlock = ((psMemBlock *) ptr) - 1;
 
-    if (badMemBlock(memBlock)) {
-        PS_MEM_ABORT_CORRUPT(memBlock);
-    }
+    HANDLE_BAD_BLOCK(memBlock);
 
     return memBlock->refCounter;
@@ -604,7 +579,5 @@
     psMemBlock* memBlock = ((psMemBlock *) ptr) - 1;
 
-    if (badMemBlock(memBlock)) {
-        PS_MEM_ABORT_CORRUPT(memBlock);
-    }
+    HANDLE_BAD_BLOCK(memBlock);
 
     memBlock->refCounter++;
@@ -664,8 +637,5 @@
     psMemBlock *memBlock = ((psMemBlock *) ptr) - 1;
 
-    if (badMemBlock(memBlock)) {
-        PS_MEM_ABORT_CORRUPT(memBlock);
-        return NULL;
-    }
+    HANDLE_BAD_BLOCK(memBlock);
 
     if (memBlock->refCounter < 1) {
@@ -732,7 +702,5 @@
     psMemBlock* memBlock = ((psMemBlock *)ptr) - 1;
 
-    if (badMemBlock(memBlock)) {
-        PS_MEM_ABORT_CORRUPT(memBlock);
-    }
+    HANDLE_BAD_BLOCK(memBlock);
 
     memBlock->freeFunc = freeFunc;
@@ -747,7 +715,5 @@
     psMemBlock* memBlock = ((psMemBlock *)ptr) - 1;
 
-    if (badMemBlock(memBlock)) {
-        PS_MEM_ABORT_CORRUPT(memBlock);
-    }
+    HANDLE_BAD_BLOCK(memBlock);
 
     return memBlock->freeFunc;
@@ -1025,7 +991,5 @@
     psMemBlock* memBlock = ((psMemBlock *) ptr) - 1;
 
-    if (badMemBlock(memBlock)) {
-        PS_MEM_ABORT_CORRUPT(memBlock);
-    }
+    HANDLE_BAD_BLOCK(memBlock);
 
     return memBlock->persistent;
@@ -1041,7 +1005,5 @@
     psMemBlock* memBlock = ((psMemBlock *) ptr) - 1;
 
-    if (badMemBlock(memBlock)) {
-        PS_MEM_ABORT_CORRUPT(memBlock);
-    }
+    HANDLE_BAD_BLOCK(memBlock);
 
     memBlock->persistent = value;
@@ -1110,7 +1072,8 @@
                    "\tPrevious Block: %p Next Block: %p\n"
                    "\tFree function: %p\n"
-                   "\tSize: %zd Reference count: %lu\n Persistent: %s\n"
+                   "\tSize: %zd Reference count: %lu Persistent: %s\n"
                    "\tPosts: %p %p %p\n"
-                   "\tAllocated at %s (%s:%d) by thread %lu\n",
+                   "\tAllocated in %s at (%s:%d)\n"
+                   "\t\tby Thread ID %lu\n",
                    memBlock->id,
                    memBlock->previousBlock, memBlock->nextBlock,
Index: /trunk/psLib/test/sys/tap_psMemory.c
===================================================================
--- /trunk/psLib/test/sys/tap_psMemory.c	(revision 10902)
+++ /trunk/psLib/test/sys/tap_psMemory.c	(revision 10903)
@@ -6,6 +6,6 @@
 *  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-12-18 19:18:46 $
+*  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2007-01-04 22:34:06 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -61,6 +61,10 @@
     TPcheckLeaks();
 
+    // psMemProblemCallbackSet() has been removed -JH
+    #if 0
+
     void TPmemCorruption( void );
     TPmemCorruption();
+    #endif
 
     void TPmultipleFree( void );
@@ -225,5 +229,5 @@
     }
 
-    psMemCheckCorruption( 1 );
+    psMemCheckCorruption(stderr, false);
 
     // realloc to 2x
@@ -242,5 +246,5 @@
     ok(error==0, "Realloc preserve the contents with expanding buffer");
 
-    psMemCheckCorruption( 1 );
+    psMemCheckCorruption(stderr, false);
 
     // realloc to 1/2 initial value.
@@ -403,4 +407,5 @@
 
 
+#if 0
 void TPmemCorruption( void )
 {
@@ -443,4 +448,5 @@
     skip_end();
 }
+#endif
 
 
