Changeset 446 for trunk/archive/pslib/src/Utils
- Timestamp:
- Apr 19, 2004, 9:41:51 AM (22 years ago)
- Location:
- trunk/archive/pslib/src/Utils
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/pslib/src/Utils/Makefile
r384 r446 1 1 CC = cc -std=c99 2 CFLAGS = -Wall -g -I$(PSLIB_DIR)/include 2 CFLAGS = -Wall -g -I$(PSLIB_DIR)/include -I$(FFTW_DIR)/include 3 3 4 4 PSLIB_DIR = ../.. … … 6 6 OBJS = array.o dlist.o error.o hash.o logmsg.o memory.o misc.o trace.o 7 7 8 libUtils.a : $(OBJS)9 ar r libUtils.a $?10 ranlib libUtils.a8 $(PSLIB_DIR)/lib/libUtils.a : $(OBJS) 9 ar r $(PSLIB_DIR)/lib/libUtils.a $? 10 ranlib $(PSLIB_DIR)/lib/libUtils.a 11 11 # 12 12 # Error codes … … 25 25 $$p; \ 26 26 done 27 tst_array : libUtils.a tst_array.o28 $(CC) -o tst_array tst_array.olibUtils.a29 tst_dlist : libUtils.a tst_dlist.o30 $(CC) -o tst_dlist tst_dlist.olibUtils.a31 tst_error : libUtils.a tst_error.o32 $(CC) -o tst_error tst_error.olibUtils.a33 tst_hash : libUtils.a tst_hash.o34 $(CC) -o tst_hash tst_hash.olibUtils.a35 tst_logmsg : libUtils.a tst_logmsg.o36 $(CC) -o tst_logmsg tst_logmsg.olibUtils.a37 tst_memory : libUtils.a tst_memory.o38 $(CC) -o tst_memory tst_memory.olibUtils.a39 tst_trace : libUtils.a tst_trace.o40 $(CC) -o tst_trace tst_trace.olibUtils.a27 tst_array : $(PSLIB_DIR)/lib/libUtils.a tst_array.o 28 $(CC) $(CFLAGS) -o tst_array tst_array.o $(PSLIB_DIR)/lib/libUtils.a 29 tst_dlist : $(PSLIB_DIR)/lib/libUtils.a tst_dlist.o 30 $(CC) $(CFLAGS) -o tst_dlist tst_dlist.o $(PSLIB_DIR)/lib/libUtils.a 31 tst_error : $(PSLIB_DIR)/lib/libUtils.a tst_error.o 32 $(CC) $(CFLAGS) -o tst_error tst_error.o $(PSLIB_DIR)/lib/libUtils.a 33 tst_hash : $(PSLIB_DIR)/lib/libUtils.a tst_hash.o 34 $(CC) $(CFLAGS) -o tst_hash tst_hash.o $(PSLIB_DIR)/lib/libUtils.a 35 tst_logmsg : $(PSLIB_DIR)/lib/libUtils.a tst_logmsg.o 36 $(CC) $(CFLAGS) -o tst_logmsg tst_logmsg.o $(PSLIB_DIR)/lib/libUtils.a 37 tst_memory : $(PSLIB_DIR)/lib/libUtils.a tst_memory.o 38 $(CC) $(CFLAGS) -o tst_memory tst_memory.o $(PSLIB_DIR)/lib/libUtils.a 39 tst_trace : $(PSLIB_DIR)/lib/libUtils.a tst_trace.o 40 $(CC) $(CFLAGS) -o tst_trace tst_trace.o $(PSLIB_DIR)/lib/libUtils.a 41 41 # 42 42 # -
trunk/archive/pslib/src/Utils/array.c
r385 r446 11 11 P_PS_CREATE_ARRAY_TYPE(static, my_, psVoidPtr); 12 12 13 psVoidPtrArray *psVoidPtrArrayAlloc(int n , int s)13 psVoidPtrArray *psVoidPtrArrayAlloc(int n) 14 14 { 15 return my_psVoidPtrArrayAlloc(n , s);15 return my_psVoidPtrArrayAlloc(n); 16 16 } 17 17 -
trunk/archive/pslib/src/Utils/dlist.c
r390 r446 313 313 } 314 314 315 psVoidPtrArray *restrict arr = psVoidPtrArrayAlloc(dlist->n , dlist->n);315 psVoidPtrArray *restrict arr = psVoidPtrArrayAlloc(dlist->n); 316 316 317 317 psDlistElem *ptr = dlist->head; -
trunk/archive/pslib/src/Utils/hash.c
r267 r446 67 67 * Con/Destruct psHash tables 68 68 */ 69 psHash *psHashAlloc(int nbucket) // initial number of buckets 70 { 69 psHash *psHashAlloc(void) 70 { 71 int nbucket = 128; // XXX initial number of buckets 71 72 psHash *table = psAlloc(sizeof(psHash)); 72 73 table->buckets = psAlloc(nbucket*sizeof(HashBucket *)); -
trunk/archive/pslib/src/Utils/memory.c
r329 r446 52 52 return NULL; 53 53 } 54 static psMemExhaustedC allbackmemExhaustedCB = memExhaustedCB0;55 56 psMemExhaustedC allback psMemExhaustedSetCB(psMemExhaustedCallbackfunc)57 { 58 psMemExhaustedC allbackold = memExhaustedCB;54 static psMemExhaustedCB memExhaustedCB = memExhaustedCB0; 55 56 psMemExhaustedCB psMemExhaustedSetCB(psMemExhaustedCB func) 57 { 58 psMemExhaustedCB old = memExhaustedCB; 59 59 60 60 memExhaustedCB = (func != NULL) ? func : memExhaustedCB0; … … 89 89 } 90 90 } 91 static psMemProblemC allbackmemProblemCB = memProblemCB0;92 93 psMemProblemC allback psMemProblemSetCB(psMemProblemCallbackfunc)94 { 95 psMemProblemC allbackold = memProblemCB;91 static psMemProblemCB memProblemCB = memProblemCB0; 92 93 psMemProblemCB psMemProblemSetCB(psMemProblemCB func) 94 { 95 psMemProblemCB old = memProblemCB; 96 96 97 97 memProblemCB = (func != NULL) ? func : memProblemCB0; … … 129 129 * isn't resignalled) 130 130 */ 131 static intmemAllocateCB0(const psMemBlock *ptr)131 static long memAllocateCB0(const psMemBlock *ptr) 132 132 { 133 133 static int incr = 0; // "p_psMemAllocateID += incr" … … 138 138 } 139 139 140 static intmemFreeCB0(const psMemBlock *ptr)140 static long memFreeCB0(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 psMem CallbackmemAllocateCB = memAllocateCB0;153 static psMem CallbackmemFreeCB = memFreeCB0;154 155 psMem Callback psMemAllocateSetCB(psMemCallbackfunc)156 { 157 psMem Callbackold = memAllocateCB;152 static psMemAllocateCB memAllocateCB = memAllocateCB0; 153 static psMemFreeCB memFreeCB = memFreeCB0; 154 155 psMemAllocateCB psMemAllocateSetCB(psMemAllocateCB func) 156 { 157 psMemAllocateCB old = memAllocateCB; 158 158 159 159 memAllocateCB = (func != NULL) ? func : memAllocateCB0; … … 162 162 } 163 163 164 psMem Callback psMemFreeSetCB(psMemCallbackfunc)165 { 166 psMem Callbackold = memFreeCB;164 psMemFreeCB psMemFreeSetCB(psMemFreeCB func) 165 { 166 psMemFreeCB old = memFreeCB; 167 167 168 168 memFreeCB = (func != NULL) ? func : memFreeCB0; … … 208 208 } 209 209 210 if (m-> magic0 != P_PS_MEMMAGIC || m->magic!= P_PS_MEMMAGIC) {210 if (m->startblock != P_PS_MEMMAGIC || m->endblock != P_PS_MEMMAGIC) { 211 211 if (!quiet) { 212 212 psError(__func__, PS_ERR_MEMORY_CORRUPTION, PS_NEW_ERROR, … … 261 261 ptr->file = file; 262 262 *(int *)&ptr->lineno = lineno; 263 *(void **)&ptr->magic0 = *(void **)&ptr->magic = P_PS_MEMMAGIC; 263 *(void **)&ptr->startblock = *(void **)&ptr->endblock = P_PS_MEMMAGIC; 264 ptr->endpost = &ptr->endblock; // should point just beyond allocated memory XXX 264 265 265 266 ptr->refCounter = 1; // one user so far -
trunk/archive/pslib/src/Utils/psArray.h
r388 r446 2 2 #define PS_ARRAY_H 3 3 4 //#include <stdlib.h>5 4 /** 6 5 * Declare TYPEArray … … 8 7 #define PS_DECLARE_ARRAY_TYPE(TYPE) \ 9 8 typedef struct { \ 10 int size; /* number of allocated elements */\11 int n ; /* number of elements in use */\12 \9 psType type; /* Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT */\ 10 int nalloc; /* Total number of elements available */\ 11 int n; /* Number of elements in use */\ 13 12 TYPE *arr; /* the actual data */ \ 14 13 } PS_CONCAT(TYPE, Array); \ 15 14 \ 16 PS_CONCAT(TYPE, Array) *PS_CONCAT3(TYPE,Array,Alloc)(int n , int s); \15 PS_CONCAT(TYPE, Array) *PS_CONCAT3(TYPE,Array,Alloc)(int n); \ 17 16 PS_CONCAT(TYPE, Array) *PS_CONCAT3(TYPE,Array,Realloc)(PS_CONCAT(TYPE, Array) *arr, int n); \ 18 17 void PS_CONCAT3(TYPE,Array,Free)(PS_CONCAT(TYPE, Array) *arr) … … 27 26 #define P_PS_CREATE_ARRAY_TYPE(QUAL,PREFIX,TYPE) \ 28 27 \ 29 QUAL PS_CONCAT(TYPE, Array) *PS_CONCAT4(PREFIX,TYPE,Array,Alloc)(int n, /* initial dimension */\ 30 int s) /* initial number of elements */ \ 28 QUAL PS_CONCAT(TYPE, Array) *PS_CONCAT4(PREFIX,TYPE,Array,Alloc)(int n) /* initial dimension */ \ 31 29 { \ 32 30 PS_CONCAT(TYPE, Array) *arr = psAlloc(sizeof(PS_CONCAT(TYPE, Array))); \ 33 31 \ 34 if (n > s) { \ 35 psLogMsg(PS_STRING(TYPE) "ArrayAlloc", PS_LOG_ERROR, "Too few elements requested in array (%d < %d)\n", s, n); \ 36 s = n; \ 37 } \ 32 arr->nalloc = arr->n = n; \ 38 33 \ 39 arr->size = s; \ 40 arr->n = n; \ 41 \ 42 if (s == 0) { \ 34 if (n == 0) { \ 43 35 arr->arr = NULL; \ 44 36 } else { \ 45 arr->arr = psAlloc( s*sizeof(TYPE)); \37 arr->arr = psAlloc(n*sizeof(TYPE)); \ 46 38 } \ 47 39 \ … … 52 44 { \ 53 45 if (arr == NULL) { \ 54 return PS_CONCAT4(PREFIX,TYPE,Array,Alloc)(n , n); \46 return PS_CONCAT4(PREFIX,TYPE,Array,Alloc)(n); \ 55 47 } \ 56 48 \ 57 if (n <= arr-> size) { \49 if (n <= arr->nalloc) { \ 58 50 if (arr->n < n) { \ 59 51 arr->n = n; \ … … 61 53 } else { \ 62 54 arr->arr = psRealloc(arr->arr, n*sizeof(TYPE)); \ 63 arr-> size= n; \55 arr->nalloc = n; \ 64 56 } \ 65 57 \ … … 91 83 P_PS_CREATE_ARRAY_TYPE(static, my_, P_PS_CONCAT(TYPE, Ptr)) \ 92 84 \ 93 PS_CONCAT(TYPE, PtrArray) *PS_CONCAT3(TYPE,PtrArray,Alloc)(int n , int s) \85 PS_CONCAT(TYPE, PtrArray) *PS_CONCAT3(TYPE,PtrArray,Alloc)(int n) \ 94 86 { \ 95 PS_CONCAT(TYPE, PtrArray) *arr = PS_CONCAT4(my_,TYPE,PtrArray,Alloc)(n , s); \87 PS_CONCAT(TYPE, PtrArray) *arr = PS_CONCAT4(my_,TYPE,PtrArray,Alloc)(n); \ 96 88 for (int i = 0; i < arr->n; i++) { \ 97 89 arr->arr[i] = psMemIncrRefCounter(PS_CONCAT(TYPE, Alloc)());\ … … 113 105 { \ 114 106 if (arr == NULL) { return; } \ 115 for (int i = 0; i < arr-> size; i++) { \107 for (int i = 0; i < arr->nalloc; i++) { \ 116 108 PS_CONCAT(TYPE, Free)(psMemDecrRefCounter(arr->arr[i])); \ 117 109 } \ -
trunk/archive/pslib/src/Utils/tst_array.c
r267 r446 1 1 #include "psLib.h" 2 #include "psArray.h" 2 3 3 4 typedef struct { … … 23 24 int main(void) 24 25 { 25 psXYArray *t = psXYArrayAlloc(10 , 15);26 psXYPtrArray *pt = psXYPtrArrayAlloc(10 , 10);26 psXYArray *t = psXYArrayAlloc(10); 27 psXYPtrArray *pt = psXYPtrArrayAlloc(10); 27 28 28 29 for (int i = 0; i < t->n; i++) { -
trunk/archive/pslib/src/Utils/tst_hash.c
r267 r446 32 32 long memId0 = psMemGetId(); 33 33 34 psHash *hash = psHashAlloc( 16);34 psHash *hash = psHashAlloc(); 35 35 36 36 psHashInsert(hash, "Lynda", IdAlloc("Lee"), (void (*)(void *))IdFree); -
trunk/archive/pslib/src/Utils/tst_memory.c
r390 r446 30 30 } 31 31 32 static psMemProblemC allbackdefault_MemProblemCB = NULL;32 static psMemProblemCB default_MemProblemCB = NULL; 33 33 34 34 static void my_MemProblemCB(const psMemBlock *ptr,
Note:
See TracChangeset
for help on using the changeset viewer.
