IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 19, 2004, 9:41:51 AM (22 years ago)
Author:
rhl
Message:

Fixed up code for changes in organisation and APIs

Location:
trunk/archive/pslib/src/Utils
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/archive/pslib/src/Utils/Makefile

    r384 r446  
    11CC = cc -std=c99
    2 CFLAGS = -Wall -g -I$(PSLIB_DIR)/include
     2CFLAGS = -Wall -g -I$(PSLIB_DIR)/include -I$(FFTW_DIR)/include
    33
    44PSLIB_DIR = ../..
     
    66OBJS = array.o dlist.o error.o hash.o logmsg.o memory.o misc.o trace.o
    77
    8 libUtils.a : $(OBJS)
    9         ar r libUtils.a $?
    10         ranlib libUtils.a
     8$(PSLIB_DIR)/lib/libUtils.a : $(OBJS)
     9        ar r $(PSLIB_DIR)/lib/libUtils.a $?
     10        ranlib $(PSLIB_DIR)/lib/libUtils.a
    1111#
    1212# Error codes
     
    2525                $$p; \
    2626        done
    27 tst_array : libUtils.a tst_array.o
    28         $(CC) -o tst_array tst_array.o libUtils.a
    29 tst_dlist : libUtils.a tst_dlist.o
    30         $(CC) -o tst_dlist tst_dlist.o libUtils.a
    31 tst_error : libUtils.a tst_error.o
    32         $(CC) -o tst_error tst_error.o libUtils.a
    33 tst_hash : libUtils.a tst_hash.o
    34         $(CC) -o tst_hash tst_hash.o libUtils.a
    35 tst_logmsg : libUtils.a tst_logmsg.o
    36         $(CC) -o tst_logmsg tst_logmsg.o libUtils.a
    37 tst_memory : libUtils.a tst_memory.o
    38         $(CC) -o tst_memory tst_memory.o libUtils.a
    39 tst_trace : libUtils.a tst_trace.o
    40         $(CC) -o tst_trace tst_trace.o libUtils.a
     27tst_array : $(PSLIB_DIR)/lib/libUtils.a tst_array.o
     28        $(CC) $(CFLAGS) -o tst_array tst_array.o $(PSLIB_DIR)/lib/libUtils.a
     29tst_dlist : $(PSLIB_DIR)/lib/libUtils.a tst_dlist.o
     30        $(CC) $(CFLAGS) -o tst_dlist tst_dlist.o $(PSLIB_DIR)/lib/libUtils.a
     31tst_error : $(PSLIB_DIR)/lib/libUtils.a tst_error.o
     32        $(CC) $(CFLAGS) -o tst_error tst_error.o $(PSLIB_DIR)/lib/libUtils.a
     33tst_hash : $(PSLIB_DIR)/lib/libUtils.a tst_hash.o
     34        $(CC) $(CFLAGS) -o tst_hash tst_hash.o $(PSLIB_DIR)/lib/libUtils.a
     35tst_logmsg : $(PSLIB_DIR)/lib/libUtils.a tst_logmsg.o
     36        $(CC) $(CFLAGS) -o tst_logmsg tst_logmsg.o $(PSLIB_DIR)/lib/libUtils.a
     37tst_memory : $(PSLIB_DIR)/lib/libUtils.a tst_memory.o
     38        $(CC) $(CFLAGS) -o tst_memory tst_memory.o $(PSLIB_DIR)/lib/libUtils.a
     39tst_trace : $(PSLIB_DIR)/lib/libUtils.a tst_trace.o
     40        $(CC) $(CFLAGS) -o tst_trace tst_trace.o $(PSLIB_DIR)/lib/libUtils.a
    4141#
    4242#
  • trunk/archive/pslib/src/Utils/array.c

    r385 r446  
    1111P_PS_CREATE_ARRAY_TYPE(static, my_, psVoidPtr);
    1212
    13 psVoidPtrArray *psVoidPtrArrayAlloc(int n, int s)
     13psVoidPtrArray *psVoidPtrArrayAlloc(int n)
    1414{
    15     return my_psVoidPtrArrayAlloc(n, s);
     15    return my_psVoidPtrArrayAlloc(n);
    1616}
    1717
  • trunk/archive/pslib/src/Utils/dlist.c

    r390 r446  
    313313    }
    314314   
    315     psVoidPtrArray *restrict arr = psVoidPtrArrayAlloc(dlist->n, dlist->n);
     315    psVoidPtrArray *restrict arr = psVoidPtrArrayAlloc(dlist->n);
    316316
    317317    psDlistElem *ptr = dlist->head;
  • trunk/archive/pslib/src/Utils/hash.c

    r267 r446  
    6767 * Con/Destruct psHash tables
    6868 */
    69 psHash *psHashAlloc(int nbucket)        // initial number of buckets
    70 {
     69psHash *psHashAlloc(void)
     70{
     71    int nbucket = 128;                  // XXX initial number of buckets
    7172    psHash *table = psAlloc(sizeof(psHash));
    7273    table->buckets = psAlloc(nbucket*sizeof(HashBucket *));
  • trunk/archive/pslib/src/Utils/memory.c

    r329 r446  
    5252    return NULL;
    5353}
    54 static psMemExhaustedCallback memExhaustedCB = memExhaustedCB0;
    55 
    56 psMemExhaustedCallback psMemExhaustedSetCB(psMemExhaustedCallback func)
    57 {
    58     psMemExhaustedCallback old = memExhaustedCB;
     54static psMemExhaustedCB memExhaustedCB = memExhaustedCB0;
     55
     56psMemExhaustedCB psMemExhaustedSetCB(psMemExhaustedCB func)
     57{
     58    psMemExhaustedCB old = memExhaustedCB;
    5959
    6060    memExhaustedCB = (func != NULL) ? func : memExhaustedCB0;
     
    8989    }
    9090}
    91 static psMemProblemCallback memProblemCB = memProblemCB0;
    92 
    93 psMemProblemCallback psMemProblemSetCB(psMemProblemCallback func)
    94 {
    95     psMemProblemCallback old = memProblemCB;
     91static psMemProblemCB memProblemCB = memProblemCB0;
     92
     93psMemProblemCB psMemProblemSetCB(psMemProblemCB func)
     94{
     95    psMemProblemCB old = memProblemCB;
    9696
    9797    memProblemCB = (func != NULL) ? func : memProblemCB0;
     
    129129 * isn't resignalled)
    130130 */
    131 static int memAllocateCB0(const psMemBlock *ptr)
     131static long memAllocateCB0(const psMemBlock *ptr)
    132132{
    133133    static int incr = 0;                // "p_psMemAllocateID += incr"
     
    138138}
    139139
    140 static int memFreeCB0(const psMemBlock *ptr)
     140static long memFreeCB0(const psMemBlock *ptr)
    141141{
    142142    static int incr = 0;                // "p_psMemFreeID += incr"
     
    150150 * The default callbacks, and the routines to change them
    151151 */
    152 static psMemCallback memAllocateCB = memAllocateCB0;
    153 static psMemCallback memFreeCB = memFreeCB0;
    154 
    155 psMemCallback psMemAllocateSetCB(psMemCallback func)
    156 {
    157     psMemCallback old = memAllocateCB;
     152static psMemAllocateCB memAllocateCB = memAllocateCB0;
     153static psMemFreeCB memFreeCB = memFreeCB0;
     154
     155psMemAllocateCB psMemAllocateSetCB(psMemAllocateCB func)
     156{
     157    psMemAllocateCB old = memAllocateCB;
    158158
    159159    memAllocateCB = (func != NULL) ? func : memAllocateCB0;
     
    162162}
    163163
    164 psMemCallback psMemFreeSetCB(psMemCallback func)
    165 {
    166     psMemCallback old = memFreeCB;
     164psMemFreeCB psMemFreeSetCB(psMemFreeCB func)
     165{
     166    psMemFreeCB old = memFreeCB;
    167167
    168168    memFreeCB = (func != NULL) ? func : memFreeCB0;
     
    208208    }
    209209   
    210     if (m->magic0 != P_PS_MEMMAGIC || m->magic != P_PS_MEMMAGIC) {
     210    if (m->startblock != P_PS_MEMMAGIC || m->endblock != P_PS_MEMMAGIC) {
    211211        if (!quiet) {
    212212            psError(__func__, PS_ERR_MEMORY_CORRUPTION, PS_NEW_ERROR,
     
    261261    ptr->file = file;
    262262    *(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
    264265
    265266    ptr->refCounter = 1;                // one user so far
  • trunk/archive/pslib/src/Utils/psArray.h

    r388 r446  
    22#define PS_ARRAY_H
    33
    4 //#include <stdlib.h>
    54/**
    65 * Declare TYPEArray
     
    87#define PS_DECLARE_ARRAY_TYPE(TYPE) \
    98    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 */\
    1312        TYPE *arr;                      /* the actual data */ \
    1413    } PS_CONCAT(TYPE, Array); \
    1514    \
    16 PS_CONCAT(TYPE, Array) *PS_CONCAT3(TYPE,Array,Alloc)(int n, int s); \
     15PS_CONCAT(TYPE, Array) *PS_CONCAT3(TYPE,Array,Alloc)(int n); \
    1716PS_CONCAT(TYPE, Array) *PS_CONCAT3(TYPE,Array,Realloc)(PS_CONCAT(TYPE, Array) *arr, int n); \
    1817void PS_CONCAT3(TYPE,Array,Free)(PS_CONCAT(TYPE, Array) *arr)
     
    2726#define P_PS_CREATE_ARRAY_TYPE(QUAL,PREFIX,TYPE) \
    2827\
    29 QUAL PS_CONCAT(TYPE, Array) *PS_CONCAT4(PREFIX,TYPE,Array,Alloc)(int n, /* initial dimension */\
    30                                                    int s) /* initial number of elements */ \
     28QUAL PS_CONCAT(TYPE, Array) *PS_CONCAT4(PREFIX,TYPE,Array,Alloc)(int n) /* initial dimension */ \
    3129{ \
    3230    PS_CONCAT(TYPE, Array) *arr = psAlloc(sizeof(PS_CONCAT(TYPE, Array))); \
    3331    \
    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; \
    3833    \
    39     arr->size = s; \
    40     arr->n = n; \
    41     \
    42     if (s == 0) { \
     34    if (n == 0) { \
    4335        arr->arr = NULL; \
    4436    } else { \
    45         arr->arr = psAlloc(s*sizeof(TYPE)); \
     37        arr->arr = psAlloc(n*sizeof(TYPE)); \
    4638    } \
    4739    \
     
    5244{ \
    5345    if (arr == NULL) { \
    54         return PS_CONCAT4(PREFIX,TYPE,Array,Alloc)(n, n); \
     46        return PS_CONCAT4(PREFIX,TYPE,Array,Alloc)(n); \
    5547    } \
    5648    \
    57     if (n <= arr->size) { \
     49    if (n <= arr->nalloc) { \
    5850        if (arr->n < n) { \
    5951            arr->n = n; \
     
    6153    } else { \
    6254        arr->arr = psRealloc(arr->arr, n*sizeof(TYPE)); \
    63         arr->size = n; \
     55        arr->nalloc = n; \
    6456    } \
    6557    \
     
    9183    P_PS_CREATE_ARRAY_TYPE(static, my_, P_PS_CONCAT(TYPE, Ptr)) \
    9284    \
    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) \
    9486    { \
    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); \
    9688        for (int i = 0; i < arr->n; i++) { \
    9789            arr->arr[i] = psMemIncrRefCounter(PS_CONCAT(TYPE, Alloc)());\
     
    113105    { \
    114106        if (arr == NULL) { return; } \
    115         for (int i = 0; i < arr->size; i++) { \
     107        for (int i = 0; i < arr->nalloc; i++) { \
    116108            PS_CONCAT(TYPE, Free)(psMemDecrRefCounter(arr->arr[i])); \
    117109        } \
  • trunk/archive/pslib/src/Utils/tst_array.c

    r267 r446  
    11#include "psLib.h"
     2#include "psArray.h"
    23
    34typedef struct {
     
    2324int main(void)
    2425{
    25     psXYArray *t = psXYArrayAlloc(10, 15);
    26     psXYPtrArray *pt = psXYPtrArrayAlloc(10, 10);
     26    psXYArray *t = psXYArrayAlloc(10);
     27    psXYPtrArray *pt = psXYPtrArrayAlloc(10);
    2728
    2829    for (int i = 0; i < t->n; i++) {
  • trunk/archive/pslib/src/Utils/tst_hash.c

    r267 r446  
    3232    long memId0 = psMemGetId();
    3333
    34     psHash *hash = psHashAlloc(16);
     34    psHash *hash = psHashAlloc();
    3535
    3636    psHashInsert(hash, "Lynda", IdAlloc("Lee"), (void (*)(void *))IdFree);
  • trunk/archive/pslib/src/Utils/tst_memory.c

    r390 r446  
    3030}
    3131
    32 static psMemProblemCallback default_MemProblemCB = NULL;
     32static psMemProblemCB default_MemProblemCB = NULL;
    3333
    3434static void my_MemProblemCB(const psMemBlock *ptr,
Note: See TracChangeset for help on using the changeset viewer.