Changeset 8800 for trunk/psLib/src/sys/psError.c
- Timestamp:
- Sep 12, 2006, 11:10:22 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sys/psError.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psError.c
r8792 r8800 11 11 * @author Eric Van Alst, MHPCC 12 12 * 13 * @version $Revision: 1.3 5$ $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 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 35 35 static pthread_key_t errorStack_key; 36 36 37 typedef struct38 {39 int n;40 psErr **stack;41 }42 psErrorStack;43 44 static psErrorStack *psErrorStackAlloc(void);45 static void psErrorStackFree(psErrorStack *errorStack);46 37 static void psFreeWrapper(void *ptr); 47 38 static void psErrorStackPush(psErr* err); 48 static ps ErrorStack*psErrorStackGet(void);39 static psArray *psErrorStackGet(void); 49 40 static 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 }70 41 71 42 // needed for pthread_key_create() because p_psFree() does not match free()'s … … 79 50 static void psErrorStackPush(psErr* err) 80 51 { 81 ps ErrorStack*errorStack = psErrorStackGet();52 psArray *errorStack = psErrorStackGet(); 82 53 83 54 // 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 87 57 p_psMemSetPersistent(err, true); 88 58 p_psMemSetPersistent(err->msg, true); 89 59 p_psMemSetPersistent(err->name, true); 60 61 psArrayAdd(errorStack, 0, err); 90 62 } else { 91 63 psAbort(__func__, "attempt to exceed maximum error stack depth of %d", … … 94 66 } 95 67 96 static ps ErrorStack*psErrorStackGet(void)68 static psArray *psErrorStackGet(void) 97 69 { 98 70 // check to see if the error stack key has been initialized … … 109 81 110 82 // check to see if the error stack for this thread has been allocated 111 ps ErrorStack*errorStack = NULL;83 psArray *errorStack = NULL; 112 84 if ((errorStack = pthread_getspecific(errorStack_key)) == NULL) { 113 85 // allocate the error stack 114 errorStack = ps ErrorStackAlloc();86 errorStack = psArrayAlloc(MAX_ERROR_STACK_SIZE); 115 87 p_psMemSetPersistent(errorStack, true); 116 p_psMemSetPersistent(errorStack-> stack, true);88 p_psMemSetPersistent(errorStack->data, true); 117 89 // store this threads error stack 118 90 // note that pthread_setspecifc() does not take a pointer as the first … … 141 113 err->code = code; 142 114 143 psMemSetDeallocator(err, (psFreeFunc)psErrFree);115 psMemSetDeallocator(err, (psFreeFunc)psErrFree); 144 116 145 117 return err; … … 218 190 } 219 191 220 psErr* psErrorGet( intwhich)192 psErr* psErrorGet(long which) 221 193 { 222 194 psErr* result; 223 195 224 ps ErrorStack*errorStack = psErrorStackGet();196 psArray *errorStack = psErrorStackGet(); 225 197 226 198 // Check for negative reference and if found return PS_ERR_NONE … … 228 200 result = psErrAlloc("", PS_ERR_NONE, ""); 229 201 } 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,""); 234 207 } else { 235 result = psMemIncrRefCounter(errorStack->stack[which]); // a new reference passed back 208 // a new reference passed back 209 result = psMemIncrRefCounter(errorStack->data[which]); 236 210 } 237 211 } … … 240 214 } 241 215 242 intpsErrorGetStackSize()243 { 244 ps ErrorStack*errorStack = psErrorStackGet();245 246 return errorStack->n;216 long psErrorGetStackSize() 217 { 218 psArray *errorStack = psErrorStackGet(); 219 220 return psArrayLength(errorStack); 247 221 } 248 222 … … 263 237 void psErrorClear(void) 264 238 { 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); 275 250 } 276 251 … … 289 264 void psErrorStackPrintV(FILE *fd, const char *format, va_list va) 290 265 { 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) { 298 274 fprintf(fd," -> %s: %s\n %s\n", 299 err orStack->stack[i]->name,300 psErrorCodeString(err orStack->stack[i]->code),301 err orStack->stack[i]->msg);275 err->name, 276 psErrorCodeString(err->code), 277 err->msg); 302 278 } else { 303 279 fprintf(fd," -> %s: %s\n %s\n", 304 err orStack->stack[i]->name,305 strerror(err orStack->stack[i]->code),306 err orStack->stack[i]->msg);280 err->name, 281 strerror(err->code), 282 err->msg); 307 283 } 308 284 }
Note:
See TracChangeset
for help on using the changeset viewer.
