IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8800


Ignore:
Timestamp:
Sep 12, 2006, 11:10:22 AM (20 years ago)
Author:
jhoblitt
Message:

replace psErrorStack struct with a psArray to simplify the implementation
change psErrorGetStackSize() to return long (same type as psArray->n)
change psErrorGet()'s which param to be long (same type as psArray->n)

Location:
trunk/psLib/src/sys
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psError.c

    r8792 r8800  
    1111 *  @author Eric Van Alst, MHPCC
    1212 *
    13  *  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2006-09-12 03:16:51 $
     13 *  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2006-09-12 21:10:22 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3535static pthread_key_t errorStack_key;
    3636
    37 typedef struct
    38 {
    39     int n;
    40     psErr **stack;
    41 }
    42 psErrorStack;
    43 
    44 static psErrorStack *psErrorStackAlloc(void);
    45 static void psErrorStackFree(psErrorStack *errorStack);
    4637static void psFreeWrapper(void *ptr);
    4738static void psErrorStackPush(psErr* err);
    48 static psErrorStack *psErrorStackGet(void);
     39static psArray *psErrorStackGet(void);
    4940static void psErrFree(psErr* err);
    50 
    51 static psErrorStack *psErrorStackAlloc(void)
    52 {
    53     psErrorStack *errorStack = psAlloc(sizeof(psErrorStack));
    54     errorStack->n = 0;
    55     errorStack->stack = psAlloc(sizeof(psErr*) * MAX_ERROR_STACK_SIZE);
    56 
    57     psMemSetDeallocator(errorStack, (psFreeFunc)psErrorStackFree);
    58 
    59     return errorStack;
    60 }
    61 
    62 static void psErrorStackFree(psErrorStack *errorStack)
    63 {
    64     if (!errorStack) {
    65         return;
    66     }
    67 
    68     psFree(errorStack->stack);
    69 }
    7041
    7142// needed for pthread_key_create() because p_psFree() does not match free()'s
     
    7950static void psErrorStackPush(psErr* err)
    8051{
    81     psErrorStack *errorStack = psErrorStackGet();
     52    psArray *errorStack = psErrorStackGet();
    8253
    8354    // push the item onto the stack and increment the error count
    84     if (errorStack->n < MAX_ERROR_STACK_SIZE) {
    85         errorStack->stack[errorStack->n] = psMemIncrRefCounter(err);
    86         (errorStack->n)++;
     55    if (psArrayLength(errorStack) < MAX_ERROR_STACK_SIZE) {
     56        // make the psErr persistent
    8757        p_psMemSetPersistent(err, true);
    8858        p_psMemSetPersistent(err->msg, true);
    8959        p_psMemSetPersistent(err->name, true);
     60
     61        psArrayAdd(errorStack, 0, err);
    9062    } else {
    9163        psAbort(__func__, "attempt to exceed maximum error stack depth of %d",
     
    9466}
    9567
    96 static psErrorStack *psErrorStackGet(void)
     68static psArray *psErrorStackGet(void)
    9769{
    9870    // check to see if the error stack key has been initialized
     
    10981
    11082    // check to see if the error stack for this thread has been allocated
    111     psErrorStack *errorStack = NULL;
     83    psArray *errorStack = NULL;
    11284    if ((errorStack = pthread_getspecific(errorStack_key)) == NULL) {
    11385        // allocate the error stack
    114         errorStack = psErrorStackAlloc();
     86        errorStack = psArrayAlloc(MAX_ERROR_STACK_SIZE);
    11587        p_psMemSetPersistent(errorStack, true);
    116         p_psMemSetPersistent(errorStack->stack, true);
     88        p_psMemSetPersistent(errorStack->data, true);
    11789        // store this threads error stack
    11890        // note that pthread_setspecifc() does not take a pointer as the first
     
    141113    err->code = code;
    142114
    143     psMemSetDeallocator(err,(psFreeFunc)psErrFree);
     115    psMemSetDeallocator(err, (psFreeFunc)psErrFree);
    144116
    145117    return err;
     
    218190}
    219191
    220 psErr* psErrorGet(int which)
     192psErr* psErrorGet(long which)
    221193{
    222194    psErr* result;
    223195
    224     psErrorStack *errorStack = psErrorStackGet();
     196    psArray *errorStack = psErrorStackGet();
    225197
    226198    // Check for negative reference and if found return PS_ERR_NONE
     
    228200        result = psErrAlloc("", PS_ERR_NONE, "");
    229201    } else {
    230 
    231         which = errorStack->n - 1 - which;     // the which input is from the end of errorStack
    232         if (which < 0 || which >= errorStack->n) {
    233             result = psErrAlloc("",PS_ERR_NONE,"");    // no error at the given location
     202        // the which input is from the end of errorStack
     203        which = psArrayLength(errorStack) - 1 - which;
     204        if (which < 0 || which >= psArrayLength(errorStack)) {
     205            // no error at the given location
     206            result = psErrAlloc("",PS_ERR_NONE,"");
    234207        } else {
    235             result = psMemIncrRefCounter(errorStack->stack[which]); // a new reference passed back
     208            // a new reference passed back
     209            result = psMemIncrRefCounter(errorStack->data[which]);
    236210        }
    237211    }
     
    240214}
    241215
    242 int psErrorGetStackSize()
    243 {
    244     psErrorStack *errorStack = psErrorStackGet();
    245 
    246     return errorStack->n;
     216long psErrorGetStackSize()
     217{
     218    psArray *errorStack = psErrorStackGet();
     219
     220    return psArrayLength(errorStack);
    247221}
    248222
     
    263237void psErrorClear(void)
    264238{
    265     psErrorStack *errorStack = psErrorStackGet();
    266 
    267     for (int i = 0; i < errorStack->n; i++) {
    268         p_psMemSetPersistent(errorStack->stack[i], false);
    269         p_psMemSetPersistent((errorStack->stack[i])->msg, false);
    270         p_psMemSetPersistent((errorStack->stack[i])->name, false);
    271         psFree(errorStack->stack[i]);
    272     }
    273 
    274     errorStack->n = 0;
     239    psArray *errorStack = psErrorStackGet();
     240
     241    for (long i = 0; i < psArrayLength(errorStack); i++) {
     242        psErr *err = errorStack->data[i];
     243
     244        p_psMemSetPersistent(err, false);
     245        p_psMemSetPersistent(err->msg, false);
     246        p_psMemSetPersistent(err->name, false);
     247    }
     248
     249    psArrayElementsFree(errorStack);
    275250}
    276251
     
    289264void psErrorStackPrintV(FILE *fd, const char *format, va_list va)
    290265{
    291     psErrorStack *errorStack = psErrorStackGet();
    292 
    293     if (errorStack->n > 0) {
    294         vfprintf(fd,format,va);
    295 
    296         for (int i = 0; i < errorStack->n; i++) {
    297             if(errorStack->stack[i]->code >= PS_ERR_BASE) {
     266    psArray *errorStack = psErrorStackGet();
     267
     268    if (psArrayLength(errorStack) > 0) {
     269        vfprintf(fd, format, va);
     270
     271        for (long i = 0; i < psArrayLength(errorStack); i++) {
     272            psErr *err = errorStack->data[i];
     273            if(err->code >= PS_ERR_BASE) {
    298274                fprintf(fd," -> %s: %s\n     %s\n",
    299                         errorStack->stack[i]->name,
    300                         psErrorCodeString(errorStack->stack[i]->code),
    301                         errorStack->stack[i]->msg);
     275                        err->name,
     276                        psErrorCodeString(err->code),
     277                        err->msg);
    302278            } else {
    303279                fprintf(fd," -> %s: %s\n     %s\n",
    304                         errorStack->stack[i]->name,
    305                         strerror(errorStack->stack[i]->code),
    306                         errorStack->stack[i]->msg);
     280                        err->name,
     281                        strerror(err->code),
     282                        err->msg);
    307283            }
    308284        }
  • trunk/psLib/src/sys/psError.h

    r8792 r8800  
    1212 *  @author Eric Van Alst, MHPCC
    1313 *
    14  *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2006-09-12 03:16:51 $
     14 *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2006-09-12 21:10:22 $
    1616 *
    1717 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5353 */
    5454psErr* psErrorGet(
    55     int which                          ///< position in the error stack. 0 is last error on stack.
     55    long which                          ///< position in the error stack. 0 is last error on stack.
    5656);
    5757
     
    8282 *  @return int The number of items on the error stack
    8383 */
    84 int psErrorGetStackSize();
     84long psErrorGetStackSize();
    8585
    8686/** Prints error stack to specified open file descriptor
Note: See TracChangeset for help on using the changeset viewer.