Index: trunk/psLib/src/sys/psError.c
===================================================================
--- trunk/psLib/src/sys/psError.c	(revision 8792)
+++ trunk/psLib/src/sys/psError.c	(revision 8800)
@@ -11,6 +11,6 @@
  *  @author Eric Van Alst, MHPCC
  *
- *  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-09-12 03:16:51 $
+ *  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-09-12 21:10:22 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -35,37 +35,8 @@
 static pthread_key_t errorStack_key;
 
-typedef struct
-{
-    int n;
-    psErr **stack;
-}
-psErrorStack;
-
-static psErrorStack *psErrorStackAlloc(void);
-static void psErrorStackFree(psErrorStack *errorStack);
 static void psFreeWrapper(void *ptr);
 static void psErrorStackPush(psErr* err);
-static psErrorStack *psErrorStackGet(void);
+static psArray *psErrorStackGet(void);
 static void psErrFree(psErr* err);
-
-static psErrorStack *psErrorStackAlloc(void)
-{
-    psErrorStack *errorStack = psAlloc(sizeof(psErrorStack));
-    errorStack->n = 0;
-    errorStack->stack = psAlloc(sizeof(psErr*) * MAX_ERROR_STACK_SIZE);
-
-    psMemSetDeallocator(errorStack, (psFreeFunc)psErrorStackFree);
-
-    return errorStack;
-}
-
-static void psErrorStackFree(psErrorStack *errorStack)
-{
-    if (!errorStack) {
-        return;
-    }
-
-    psFree(errorStack->stack);
-}
 
 // needed for pthread_key_create() because p_psFree() does not match free()'s
@@ -79,13 +50,14 @@
 static void psErrorStackPush(psErr* err)
 {
-    psErrorStack *errorStack = psErrorStackGet();
+    psArray *errorStack = psErrorStackGet();
 
     // push the item onto the stack and increment the error count
-    if (errorStack->n < MAX_ERROR_STACK_SIZE) {
-        errorStack->stack[errorStack->n] = psMemIncrRefCounter(err);
-        (errorStack->n)++;
+    if (psArrayLength(errorStack) < MAX_ERROR_STACK_SIZE) {
+        // make the psErr persistent
         p_psMemSetPersistent(err, true);
         p_psMemSetPersistent(err->msg, true);
         p_psMemSetPersistent(err->name, true);
+
+        psArrayAdd(errorStack, 0, err);
     } else {
         psAbort(__func__, "attempt to exceed maximum error stack depth of %d",
@@ -94,5 +66,5 @@
 }
 
-static psErrorStack *psErrorStackGet(void)
+static psArray *psErrorStackGet(void)
 {
     // check to see if the error stack key has been initialized
@@ -109,10 +81,10 @@
 
     // check to see if the error stack for this thread has been allocated
-    psErrorStack *errorStack = NULL;
+    psArray *errorStack = NULL;
     if ((errorStack = pthread_getspecific(errorStack_key)) == NULL) {
         // allocate the error stack
-        errorStack = psErrorStackAlloc();
+        errorStack = psArrayAlloc(MAX_ERROR_STACK_SIZE);
         p_psMemSetPersistent(errorStack, true);
-        p_psMemSetPersistent(errorStack->stack, true);
+        p_psMemSetPersistent(errorStack->data, true);
         // store this threads error stack
         // note that pthread_setspecifc() does not take a pointer as the first
@@ -141,5 +113,5 @@
     err->code = code;
 
-    psMemSetDeallocator(err,(psFreeFunc)psErrFree);
+    psMemSetDeallocator(err, (psFreeFunc)psErrFree);
 
     return err;
@@ -218,9 +190,9 @@
 }
 
-psErr* psErrorGet(int which)
+psErr* psErrorGet(long which)
 {
     psErr* result;
 
-    psErrorStack *errorStack = psErrorStackGet();
+    psArray *errorStack = psErrorStackGet();
 
     // Check for negative reference and if found return PS_ERR_NONE
@@ -228,10 +200,12 @@
         result = psErrAlloc("", PS_ERR_NONE, "");
     } else {
-
-        which = errorStack->n - 1 - which;     // the which input is from the end of errorStack
-        if (which < 0 || which >= errorStack->n) {
-            result = psErrAlloc("",PS_ERR_NONE,"");    // no error at the given location
+        // the which input is from the end of errorStack
+        which = psArrayLength(errorStack) - 1 - which;
+        if (which < 0 || which >= psArrayLength(errorStack)) {
+            // no error at the given location
+            result = psErrAlloc("",PS_ERR_NONE,"");
         } else {
-            result = psMemIncrRefCounter(errorStack->stack[which]); // a new reference passed back
+            // a new reference passed back
+            result = psMemIncrRefCounter(errorStack->data[which]);
         }
     }
@@ -240,9 +214,9 @@
 }
 
-int psErrorGetStackSize()
-{
-    psErrorStack *errorStack = psErrorStackGet();
-
-    return errorStack->n;
+long psErrorGetStackSize()
+{
+    psArray *errorStack = psErrorStackGet();
+
+    return psArrayLength(errorStack);
 }
 
@@ -263,14 +237,15 @@
 void psErrorClear(void)
 {
-    psErrorStack *errorStack = psErrorStackGet();
-
-    for (int i = 0; i < errorStack->n; i++) {
-        p_psMemSetPersistent(errorStack->stack[i], false);
-        p_psMemSetPersistent((errorStack->stack[i])->msg, false);
-        p_psMemSetPersistent((errorStack->stack[i])->name, false);
-        psFree(errorStack->stack[i]);
-    }
-
-    errorStack->n = 0;
+    psArray *errorStack = psErrorStackGet();
+
+    for (long i = 0; i < psArrayLength(errorStack); i++) {
+        psErr *err = errorStack->data[i];
+
+        p_psMemSetPersistent(err, false);
+        p_psMemSetPersistent(err->msg, false);
+        p_psMemSetPersistent(err->name, false);
+    }
+
+    psArrayElementsFree(errorStack);
 }
 
@@ -289,20 +264,21 @@
 void psErrorStackPrintV(FILE *fd, const char *format, va_list va)
 {
-    psErrorStack *errorStack = psErrorStackGet();
-
-    if (errorStack->n > 0) {
-        vfprintf(fd,format,va);
-
-        for (int i = 0; i < errorStack->n; i++) {
-            if(errorStack->stack[i]->code >= PS_ERR_BASE) {
+    psArray *errorStack = psErrorStackGet();
+
+    if (psArrayLength(errorStack) > 0) {
+        vfprintf(fd, format, va);
+
+        for (long i = 0; i < psArrayLength(errorStack); i++) {
+            psErr *err = errorStack->data[i];
+            if(err->code >= PS_ERR_BASE) {
                 fprintf(fd," -> %s: %s\n     %s\n",
-                        errorStack->stack[i]->name,
-                        psErrorCodeString(errorStack->stack[i]->code),
-                        errorStack->stack[i]->msg);
+                        err->name,
+                        psErrorCodeString(err->code),
+                        err->msg);
             } else {
                 fprintf(fd," -> %s: %s\n     %s\n",
-                        errorStack->stack[i]->name,
-                        strerror(errorStack->stack[i]->code),
-                        errorStack->stack[i]->msg);
+                        err->name,
+                        strerror(err->code),
+                        err->msg);
             }
         }
