Changeset 753 for trunk/archive/pslib/src/Utils
- Timestamp:
- May 20, 2004, 6:12:37 PM (22 years ago)
- Location:
- trunk/archive/pslib/src/Utils
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/pslib/src/Utils/Makefile
r707 r753 2 2 CFLAGS = -Wall -g -I$(PSLIB_DIR)/include -I$(FFTW_DIR)/include 3 3 DYLIB = dylib 4 DYLIB_LDFLAGS = "-undefined suppress -flat_namespace -dynamiclib";4 DYLIB_LDFLAGS = -undefined suppress -flat_namespace -dynamiclib -shared 5 5 6 6 PSLIB_DIR = ../.. -
trunk/archive/pslib/src/Utils/dlist.c
r707 r753 317 317 psDlistElem *ptr = dlist->head; 318 318 for (int i = 0, n = dlist->n; i < n; i++) { 319 arr->arr.arr_v[i] = ptr->data; 320 319 arr->data.V[i] = ptr->data; 321 320 ptr->data = NULL; 322 321 ptr = ptr->next; … … 339 338 for (int i = 0, n = arr->n; i < n; i++) { 340 339 psDlistAppend(list, 341 psMemDecrRefCounter(arr-> arr.arr_v[i])); // it\'s already Incr342 arr-> arr.arr_v[i] = NULL;340 psMemDecrRefCounter(arr->data.V[i])); // it\'s already Incr 341 arr->data.V[i] = NULL; 343 342 } 344 343 -
trunk/archive/pslib/src/Utils/error.c
r707 r753 76 76 int psError(const char *name, // category of code that caused the error 77 77 psErrorCode code, // code of error (equivalent to errno) 78 psErrorStatus status,// is this a new error?78 int new, // is this a new error? 79 79 const char *fmt, ...) // format and possible extra arguments 80 80 { 81 if (code == PS_ERR_NONE || status == PS_NEW_ERROR) { // free old error stack81 if (code == PS_ERR_NONE || new) { // free old error stack 82 82 errStack *eptr = errorStack; 83 83 … … 99 99 100 100 va_start(ap, fmt); 101 p _psLogVMsg(name, PS_LOG_ERROR, fmt, ap);101 psLogMsgV(name, PS_LOG_ERROR, fmt, ap); 102 102 va_end(ap); 103 103 } … … 210 210 } 211 211 212 psError VStackPrint(fd, fmt, ap);212 psErrorStackPrintV(fd, fmt, ap); 213 213 214 214 if (fmt != NULL) { … … 217 217 } 218 218 219 void psError VStackPrint(FILE *fd, // write to this file descriptor219 void psErrorStackPrintV(FILE *fd, // write to this file descriptor 220 220 const char *fmt,// format for any header information; may be NULL 221 221 va_list ap) // arguments for format -
trunk/archive/pslib/src/Utils/logmsg.c
r707 r753 110 110 #endif 111 111 112 void p _psLogVMsg(const char *name, int level, const char *fmt, va_list ap)112 void psLogMsgV(const char *name, int level, const char *fmt, va_list ap) 113 113 { 114 114 static int first = 1; … … 224 224 va_start(ap, fmt); 225 225 226 p _psLogVMsg(name, level, fmt, ap);226 psLogVMsg(name, level, fmt, ap); 227 227 va_end(ap); 228 228 } -
trunk/archive/pslib/src/Utils/memory.c
r687 r753 48 48 * First the I-can't-get-the-memory callback 49 49 */ 50 static void *memExhaustedC B0(size_t size)50 static void *memExhaustedCallback0(size_t size) 51 51 { 52 52 return NULL; 53 53 } 54 static psMemExhaustedC B memExhaustedCB = memExhaustedCB0;55 56 psMemExhaustedC B psMemExhaustedCBSet(psMemExhaustedCBfunc)57 { 58 psMemExhaustedC B old = memExhaustedCB;59 60 memExhaustedC B = (func != NULL) ? func : memExhaustedCB0;54 static psMemExhaustedCallback memExhaustedCallback = memExhaustedCallback0; 55 56 psMemExhaustedCallback psMemExhaustedCallbackSet(psMemExhaustedCallback func) 57 { 58 psMemExhaustedCallback old = memExhaustedCallback; 59 60 memExhaustedCallback = (func != NULL) ? func : memExhaustedCallback0; 61 61 62 62 return old; … … 65 65 * then the I-have-detected-a-problem callback 66 66 */ 67 static void memProblemC B0(const psMemBlock *ptr,67 static void memProblemCallback0(const psMemBlock *ptr, 68 68 const char *file, int lineno) 69 69 { … … 76 76 fprintf(stderr, "\n"); 77 77 } else if (ptr->refCounter <= 0) { 78 psError(__func__, PS_ERR_BADFREE, PS_NEW_ERROR,78 psError(__func__, PS_ERR_BADFREE, 1, 79 79 "Block %ld allocated at %s:%d freed more than once at %s:%d\n", 80 80 ptr->id, ptr->file, ptr->lineno, file, lineno); 81 81 } else if (ptr->refCounter > 1) { 82 psError(__func__, PS_ERR_BADFREE, PS_NEW_ERROR,82 psError(__func__, PS_ERR_BADFREE, 1, 83 83 "Block %ld allocated at %s:%d freed while still referenced at %s:%d\n", 84 84 ptr->id, ptr->file, ptr->lineno, file, lineno); … … 89 89 } 90 90 } 91 static psMemProblemC B memProblemCB = memProblemCB0;92 93 psMemProblemC B psMemProblemCBSet(psMemProblemCBfunc)94 { 95 psMemProblemC B old = memProblemCB;96 97 memProblemC B = (func != NULL) ? func : memProblemCB0;91 static psMemProblemCallback memProblemCallback = memProblemCallback0; 92 93 psMemProblemCallback psMemProblemCallbackSet(psMemProblemCallback func) 94 { 95 psMemProblemCallback old = memProblemCallback; 96 97 memProblemCallback = (func != NULL) ? func : memProblemCallback0; 98 98 99 99 return old; … … 129 129 * isn't resignalled) 130 130 */ 131 static long memAllocateC B0(const psMemBlock *ptr)131 static long memAllocateCallback0(const psMemBlock *ptr) 132 132 { 133 133 static int incr = 0; // "p_psMemAllocateID += incr" … … 138 138 } 139 139 140 static long memFreeC B0(const psMemBlock *ptr)140 static long memFreeCallback0(const psMemBlock *ptr) 141 141 { 142 142 static int incr = 0; // "p_psMemFreeID += incr" … … 150 150 * The default callbacks, and the routines to change them 151 151 */ 152 static psMemAllocateC B memAllocateCB = memAllocateCB0;153 static psMemFreeC B memFreeCB = memFreeCB0;154 155 psMemAllocateC B psMemAllocateCBSet(psMemAllocateCBfunc)156 { 157 psMemAllocateC B old = memAllocateCB;158 159 memAllocateC B = (func != NULL) ? func : memAllocateCB0;160 161 return old; 162 } 163 164 psMemFreeC B psMemFreeCBSet(psMemFreeCBfunc)165 { 166 psMemFreeC B old = memFreeCB;167 168 memFreeC B = (func != NULL) ? func : memFreeCB0;152 static psMemAllocateCallback memAllocateCallback = memAllocateCallback0; 153 static psMemFreeCallback memFreeCallback = memFreeCallback0; 154 155 psMemAllocateCallback psMemAllocateCallbackSet(psMemAllocateCallback func) 156 { 157 psMemAllocateCallback old = memAllocateCallback; 158 159 memAllocateCallback = (func != NULL) ? func : memAllocateCallback0; 160 161 return old; 162 } 163 164 psMemFreeCallback psMemFreeCallbackSet(psMemFreeCallback func) 165 { 166 psMemFreeCallback old = memFreeCallback; 167 168 memFreeCallback = (func != NULL) ? func : memFreeCallback0; 169 169 170 170 return old; … … 194 194 if (m == NULL) { 195 195 if (!quiet) { 196 psError(__func__, PS_ERR_MEMORY_CORRUPTION, PS_NEW_ERROR,196 psError(__func__, PS_ERR_MEMORY_CORRUPTION, 1, 197 197 "psMemCheckCorruption: NULL memory block\n"); 198 198 } … … 202 202 if (!ALIGNED(m)) { 203 203 if (!quiet) { 204 psError(__func__, PS_ERR_MEMORY_CORRUPTION, PS_NEW_ERROR,204 psError(__func__, PS_ERR_MEMORY_CORRUPTION, 1, 205 205 "psMemCheckCorruption: non-aligned memory block\n"); 206 206 } … … 210 210 if (m->startblock != P_PS_MEMMAGIC || m->endblock != P_PS_MEMMAGIC) { 211 211 if (!quiet) { 212 psError(__func__, PS_ERR_MEMORY_CORRUPTION, PS_NEW_ERROR,212 psError(__func__, PS_ERR_MEMORY_CORRUPTION, 1, 213 213 "psMemCheckCorruption: memory block %ld is corrupted\n", m->id); 214 214 } … … 232 232 nbad++; 233 233 234 memProblemC B(memBlocks[i], "(psMemCheckCorruption)", 0);234 memProblemCallback(memBlocks[i], "(psMemCheckCorruption)", 0); 235 235 236 236 if (abort_on_error) { … … 251 251 252 252 if (ptr == NULL) { 253 ptr = memExhaustedC B(size);253 ptr = memExhaustedCallback(size); 254 254 if (ptr == NULL) { 255 255 psAbort(__func__, "Failed to allocate %ld bytes at %s:%d", … … 270 270 271 271 if (ptr->id == p_psMemAllocateID && p_psMemAllocateID > 0) { 272 p_psMemAllocateID += memAllocateC B(ptr);272 p_psMemAllocateID += memAllocateCallback(ptr); 273 273 } 274 274 /* … … 310 310 */ 311 311 if (ptr->id == p_psMemFreeID && p_psMemFreeID > 0) { 312 p_psMemFreeID += memFreeC B(ptr);312 p_psMemFreeID += memFreeCallback(ptr); 313 313 } 314 314 315 315 if (bad_memblock(ptr, 0)) { 316 memProblemC B(ptr, file, lineno); // we may not own this block; don't free it316 memProblemCallback(ptr, file, lineno); // we may not own this block; don't free it 317 317 } else { 318 318 if (ptr->refCounter != 1) { 319 memProblemC B(ptr, file, lineno);319 memProblemCallback(ptr, file, lineno); 320 320 } 321 321 ptr->refCounter--; … … 396 396 397 397 if (bad_memblock(ptr, 0)) { 398 memProblemC B(ptr, "(psMemGetRefCounter)", -1);398 memProblemCallback(ptr, "(psMemGetRefCounter)", -1); 399 399 } 400 400 … … 411 411 412 412 if (bad_memblock(ptr, 0)) { 413 memProblemC B(ptr, "(psMemIncrRefCounter)", -1);413 memProblemCallback(ptr, "(psMemIncrRefCounter)", -1); 414 414 } 415 415 … … 428 428 429 429 if (bad_memblock(ptr, 0)) { 430 memProblemC B(ptr, "(psMemDecrRefCounter)", -1);430 memProblemCallback(ptr, "(psMemDecrRefCounter)", -1); 431 431 } 432 432 -
trunk/archive/pslib/src/Utils/misc.c
r707 r753 29 29 30 30 va_start(ap, fmt); 31 p _psLogVMsg(name, PS_LOG_ABORT, fmt, ap);31 psLogMsgV(name, PS_LOG_ABORT, fmt, ap); 32 32 va_end(ap); 33 33 -
trunk/archive/pslib/src/Utils/vector.c
r709 r753 16 16 17 17 *(int *)&vec->n = *(int *)&vec->nalloc = nalloc; 18 vec-> arr.arr_v= psAlloc(nalloc*sizeof(void **));18 vec->data.V = psAlloc(nalloc*sizeof(void **)); 19 19 20 20 return vec; … … 34 34 35 35 if (elemFree != NULL && vec->nalloc > 0) { 36 assert (vec-> arr.arr!= NULL); /* choose any member of the union */36 assert (vec->data.V != NULL); /* choose any member of the union */ 37 37 const int n = vec->nalloc; 38 38 for (int i = 0; i < n; i++) { 39 elemFree(vec-> arr.arr_v[i]);39 elemFree(vec->data.V[i]); 40 40 } 41 41 } 42 42 43 psFree(vec-> arr.arr_v);43 psFree(vec->data.V); 44 44 psFree(vec); 45 45 }
Note:
See TracChangeset
for help on using the changeset viewer.
