IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 6, 2004, 2:06:06 PM (22 years ago)
Author:
desonia
Message:

another attempt to get astyle to get it right.

Location:
trunk/psLib/src/sysUtils
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sysUtils/psAbort.c

    r1406 r1407  
     1
    12/** @file  psAbort.c
    23 *
     
    910 *  @author Eric Van Alst, MHPCC
    1011 *   
    11  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-08-06 22:34:05 $
     12 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-08-07 00:06:06 $
    1314 *
    1415 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1617
    1718/******************************************************************************/
     19
    1820/*  INCLUDE FILES                                                             */
     21
    1922/******************************************************************************/
    2023#include <stdarg.h>
     
    2427
    2528/******************************************************************************/
     29
    2630/*  DEFINE STATEMENTS                                                         */
     31
    2732/******************************************************************************/
    2833
     
    3035
    3136/******************************************************************************/
     37
    3238/*  TYPE DEFINITIONS                                                          */
     39
    3340/******************************************************************************/
    3441
     
    3643
    3744/*****************************************************************************/
     45
    3846/*  GLOBAL VARIABLES                                                         */
     47
    3948/*****************************************************************************/
    4049
     
    4251
    4352/*****************************************************************************/
     53
    4454/*  FILE STATIC VARIABLES                                                    */
     55
    4556/*****************************************************************************/
    4657
     
    4859
    4960/*****************************************************************************/
     61
    5062/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
     63
    5164/*****************************************************************************/
    5265
     
    5467
    5568/*****************************************************************************/
     69
    5670/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
     71
    5772/*****************************************************************************/
    5873
    59 void psAbort(const char *name, const char *fmt,... )
     74void psAbort(const char *name, const char *fmt, ...)
    6075{
    61     va_list    argPtr;     // variable list arguement pointer
     76    va_list argPtr;             // variable list arguement pointer
    6277
    6378    // Get the variable list parameters to pass to logging function
     
    7388    abort();
    7489}
    75 
  • trunk/psLib/src/sysUtils/psAbort.h

    r974 r1407  
     1
    12/** @file  psAbort.h
    23 *
     
    1112 *  @author Eric Van Alst, MHPCC
    1213 *
    13  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-06-10 01:58:06 $
     14 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2004-08-07 00:06:06 $
    1516 *
    1617 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1819
    1920#ifndef PS_ABORT_H
    20 #define PS_ABORT_H
    21 
     21#    define PS_ABORT_H
    2222
    2323// Doxygen grouping tags
     24
    2425/** @addtogroup ErrorHandling
    2526 *  @{
     
    3637 *
    3738 */
    38 void psAbort(
    39     const char* name,                   ///< Source of abort such as file or function detected
    40     const char* fmt,                    ///< A printf style formatting statement defining msg
    41     ...
    42 );
     39void psAbort(const char *name,  // /< Source of abort such as file or function detected
     40             const char *fmt,   // /< A printf style formatting statement defining msg
     41             ...
     42            );
    4343
    44 /* @} */  // Doxygen - End of SystemGroup Functions
     44/* @} */// Doxygen - End of SystemGroup Functions
    4545
    4646#endif
    47 
  • trunk/psLib/src/sysUtils/psError.c

    r1406 r1407  
     1
    12/** @file  psError.c
    23 *
     
    1011 *  @author Eric Van Alst, MHPCC
    1112 *   
    12  *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-08-06 22:34:05 $
     13 *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-08-07 00:06:06 $
    1415 *
    1516 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1718
    1819/******************************************************************************/
     20
    1921/*  INCLUDE FILES                                                             */
     22
    2023/******************************************************************************/
    2124#include <stdarg.h>
     
    2427
    2528/******************************************************************************/
     29
    2630/*  DEFINE STATEMENTS                                                         */
     31
    2732/******************************************************************************/
    2833
     
    3035
    3136/******************************************************************************/
     37
    3238/*  TYPE DEFINITIONS                                                          */
     39
    3340/******************************************************************************/
    3441
     
    3643
    3744/*****************************************************************************/
     45
    3846/*  GLOBAL VARIABLES                                                         */
     47
    3948/*****************************************************************************/
    4049
     
    4251
    4352/*****************************************************************************/
     53
    4454/*  FILE STATIC VARIABLES                                                    */
     55
    4556/*****************************************************************************/
    4657
     
    4859
    4960/*****************************************************************************/
     61
    5062/*  FUNCTION IMPLEMENTATIONS - LOCAL                                         */
     63
    5164/*****************************************************************************/
    5265
     
    5467
    5568/*****************************************************************************/
     69
    5670/* FUNCTION IMPLEMENTATIONS - PUBLIC                                         */
     71
    5772/*****************************************************************************/
    5873
    59 void psError(const char *name,const char *fmt, ...)
     74void psError(const char *name, const char *fmt, ...)
    6075{
    61     va_list    argPtr;        // variable list arguement pointer
     76    va_list argPtr;             // variable list arguement pointer
    6277
    63     // Get the variable list parameters  to pass to logging function
     78    // Get the variable list parameters to pass to logging function
    6479    va_start(argPtr, fmt);
    6580
     
    7085    va_end(argPtr);
    7186}
    72 
  • trunk/psLib/src/sysUtils/psError.h

    r974 r1407  
     1
    12/** @file  psError.h
    23 *
     
    1213 *  @author Eric Van Alst, MHPCC
    1314 *
    14  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2004-06-10 01:58:06 $
     15 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     16 *  @date $Date: 2004-08-07 00:06:06 $
    1617 *
    1718 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1920
    2021#ifndef PS_ERROR_H
    21 #define PS_ERROR_H
     22#    define PS_ERROR_H
    2223
    2324/** @addtogroup ErrorHandling
     
    3435 *
    3536 */
    36 void psError(
    37     const char *name,                   ///< Source of error such as file or function detected
    38     const char *fmt,                    ///< A printf style formatting statement defining msg
    39     ...
    40 );
     37void psError(const char *name,  // /< Source of error such as file or function detected
     38             const char *fmt,   // /< A printf style formatting statement defining msg
     39             ...
     40            );
    4141
    42 /* @} */  // End of SysUtils Functions
     42/* @} */// End of SysUtils Functions
    4343
    4444#endif
    45 
  • trunk/psLib/src/sysUtils/psHash.c

    r1406 r1407  
     1
    12/** @file  psHash.c
    23*
     
    1011*  @author George Gusciora, MHPCC
    1112*
    12 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2004-08-06 22:34:05 $
     13*  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     14*  @date $Date: 2004-08-07 00:06:06 $
    1415*
    1516*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2526#include "psAbort.h"
    2627
    27 static psHashBucket *hashBucketAlloc( const char *key, void *data, psHashBucket *next );
    28 static void hashBucketFree( psHashBucket *bucket );
    29 static void *doHashWork( psHash* table, const char* key, void* data, bool remove
    30                            )
    31     ;
    32 static void hashFree( psHash *table );
     28static psHashBucket *hashBucketAlloc(const char *key, void *data, psHashBucket * next);
     29static void hashBucketFree(psHashBucket * bucket);
     30static void *doHashWork(psHash * table, const char *key, void *data, bool remove
     31                           );
     32static void hashFree(psHash * table);
    3333
    3434/******************************************************************************
     
    4040    The linked list
    4141 *****************************************************************************/
    42 psList *psHashKeyList( psHash *table )
    43 {
    44     int i = 0;                          // Loop index variable
     42psList *psHashKeyList(psHash * table)
     43{
     44    int i = 0;                  // Loop index variable
    4545    psList *myLinkList = NULL;  // The output data structure
    46     psHashBucket *ptr = NULL;           // Used to step thru linked list.
    47 
    48     if ( table == NULL ) {
     46    psHashBucket *ptr = NULL;   // Used to step thru linked list.
     47
     48    if (table == NULL) {
    4949        return NULL;
    5050    }
    51 
    5251    // Create the linked list
    53     myLinkList = psListAlloc( NULL );
     52    myLinkList = psListAlloc(NULL);
    5453
    5554    // Loop through every bucket in the hash table.  If that bucket is not
    5655    // NULL, then add the bucket's key to the linked list.
    57     for ( i = 0;i < table->nbucket;i++ ) {
    58         if ( table->buckets[ i ] != NULL ) {
     56    for (i = 0; i < table->nbucket; i++) {
     57        if (table->buckets[i] != NULL) {
    5958            // Since a bucket contains a linked list of keys/data, we must
    6059            // step trough each key in that linked list:
    6160
    62             ptr = table->buckets[ i ];
    63             while ( ptr != NULL ) {
    64                 psListAdd( myLinkList, ptr->key, PS_LIST_HEAD );
     61            ptr = table->buckets[i];
     62            while (ptr != NULL) {
     63                psListAdd(myLinkList, ptr->key, PS_LIST_HEAD);
    6564                ptr = ptr->next;
    6665            }
     
    6968
    7069    // Return the linked list
    71     return ( myLinkList );
    72 }
    73 
    74 
     70    return (myLinkList);
     71}
    7572
    7673/******************************************************************************
     
    8481    the new hash bucket.
    8582 *****************************************************************************/
    86 static psHashBucket *hashBucketAlloc( const char *key,
    87                                       void *data,
    88                                       psHashBucket *next )
    89 {
    90     if ( key == NULL ) {
    91         psAbort( __func__, "psHashBucket() called with NULL key." );
    92     }
    93 
     83static psHashBucket *hashBucketAlloc(const char *key, void *data, psHashBucket * next)
     84{
     85    if (key == NULL) {
     86        psAbort(__func__, "psHashBucket() called with NULL key.");
     87    }
    9488    // Allocate memory for the new hash bucket.
    95     psHashBucket *bucket = psAlloc( sizeof( psHashBucket ) );
    96     p_psMemSetDeallocator( bucket, ( psFreeFcn ) hashBucketFree );
     89    psHashBucket *bucket = psAlloc(sizeof(psHashBucket));
     90
     91    p_psMemSetDeallocator(bucket, (psFreeFcn) hashBucketFree);
    9792
    9893    // Initialize the bucket.
    99     bucket->key = psStringCopy( key );
    100 
    101     if ( data == NULL ) {
     94    bucket->key = psStringCopy(key);
     95
     96    if (data == NULL) {
    10297        // NOTE: Should we flag a warning message?
    10398        bucket->data = NULL;
    10499    } else {
    105         bucket->data = psMemIncrRefCounter( data );
     100        bucket->data = psMemIncrRefCounter(data);
    106101    }
    107102
     
    110105    return bucket;
    111106}
    112 
    113107
    114108/******************************************************************************
     
    120114    NONE
    121115 *****************************************************************************/
    122 static void hashBucketFree( psHashBucket *bucket )
    123 {
    124     if ( bucket == NULL ) {
    125         return ;
    126     }
    127 
     116static void hashBucketFree(psHashBucket * bucket)
     117{
     118    if (bucket == NULL) {
     119        return;
     120    }
    128121    // A bucket is actually a linked list of buckets.  We recursively step
    129122    // through that linked list, free each bucket.
    130     psFree( bucket->next );
    131 
    132     psFree( bucket->key );
    133 
    134     psFree( bucket->data );
    135 }
    136 
     123    psFree(bucket->next);
     124
     125    psFree(bucket->key);
     126
     127    psFree(bucket->data);
     128}
    137129
    138130/******************************************************************************
     
    144136    The new hash table.
    145137 *****************************************************************************/
    146 psHash *psHashAlloc( int nbucket )   // initial number of buckets
    147 {
    148     int i = 0;   // loop index variable
     138psHash *psHashAlloc(int nbucket)        // initial number of buckets
     139{
     140    int i = 0;                  // loop index variable
     141
    149142    // Create the new hash table.
    150     psHash *table = psAlloc( sizeof( psHash ) );
    151     p_psMemSetDeallocator( table, ( psFreeFcn ) hashFree );
     143    psHash *table = psAlloc(sizeof(psHash));
     144
     145    p_psMemSetDeallocator(table, (psFreeFcn) hashFree);
    152146
    153147    // Allocate memory for the buckets.
    154     table->buckets = psAlloc( nbucket * sizeof( psHashBucket * ) );
     148    table->buckets = psAlloc(nbucket * sizeof(psHashBucket *));
    155149    table->nbucket = nbucket;
    156150
    157     psTrace( "utils.hash", 1, "Creating %d-element hash table\n", nbucket );
     151    psTrace("utils.hash", 1, "Creating %d-element hash table\n", nbucket);
    158152
    159153    // Initialize all buckets to NULL.
    160     for ( i = 0; i < nbucket; i++ )
     154    for (i = 0; i < nbucket; i++)
    161155    {
    162         table->buckets[ i ] = NULL;
     156        table->buckets[i] = NULL;
    163157    }
    164158
     
    166160    return table;
    167161}
    168 
    169 
    170162
    171163/******************************************************************************
     
    179171    NONE
    180172 *****************************************************************************/
    181 static void hashFree( psHash *table )
    182 {
    183     int i = 0;                          // Loop index variable.
    184 
    185     if ( table == NULL ) {
    186         return ;
    187     }
    188 
     173static void hashFree(psHash * table)
     174{
     175    int i = 0;                  // Loop index variable.
     176
     177    if (table == NULL) {
     178        return;
     179    }
    189180    // Loop through each bucket in the hash table.  If that bucket is not
    190181    // NULL, then free the bucket via a function call to hashBucketFree();
    191     for ( i = 0; i < table->nbucket; i++ ) {
     182    for (i = 0; i < table->nbucket; i++) {
    192183
    193184        // A bucket is composed of a linked list of buckets.
    194         if ( table->buckets[ i ] != NULL ) {
    195             psFree( table->buckets[ i ] );
     185        if (table->buckets[i] != NULL) {
     186            psFree(table->buckets[i]);
    196187        }
    197188    }
    198189
    199190    // Free the bucket structure, then the hash table.
    200     psFree( table->buckets );
     191    psFree(table->buckets);
    201192}
    202193
     
    220211there is little common code between those functions.
    221212  *****************************************************************************/
    222 static void *doHashWork( psHash *table, const char *key, void *data, bool remove
     213static void *doHashWork(psHash * table, const char *key, void *data, bool remove
    223214                           )
    224215{
    225     long int hash = 1;                  // This will contain an integer value
     216    long int hash = 1;          // This will contain an integer value
     217
    226218    // "hashed" from the key.
    227     char *tmpchar = NULL;               // Used in computing the hash function.
    228     psHashBucket *ptr = NULL;           // Used to retrieve the hash bucket.
    229     psHashBucket *optr = NULL;          // "original pointer": used to step
     219    char *tmpchar = NULL;       // Used in computing the hash function.
     220    psHashBucket *ptr = NULL;   // Used to retrieve the hash bucket.
     221    psHashBucket *optr = NULL;  // "original pointer": used to step
     222
    230223    // thru the linked list for a bucket.
    231224
     
    233226    // function, but I'm checking it anyway since future coders might change
    234227    // the way this procedure is called.
    235     if ( ( table == NULL ) || ( key == NULL ) ) {
    236 
    237         psAbort( __func__, "psHashRemove() called with NULL key or table." );
    238     }
    239 
     228    if ((table == NULL) || (key == NULL)) {
     229
     230        psAbort(__func__, "psHashRemove() called with NULL key or table.");
     231    }
    240232    // NOTE: This is the originally supplied hash function.
    241     //    for (int i = 0, len = strlen(key); i < len; i++) {
    242     //        hash = (hash << 1) ^ key[i];
    243     //    }
    244     //    hash &= (table->nbucket - 1);
     233    // for (int i = 0, len = strlen(key); i < len; i++) {
     234    // hash = (hash << 1) ^ key[i];
     235    // }
     236    // hash &= (table->nbucket - 1);
    245237
    246238    // This hash algorithm is from Sedgewick.  NOTE: must reread to ensure that
    247239    // the size of the hash table is not required to be a prime number.
    248     tmpchar = ( char * ) key;
    249     for ( hash = 0; *tmpchar != '\0'; tmpchar++ ) {
    250         hash = ( 64 * hash + *tmpchar ) % ( table->nbucket );
     240    tmpchar = (char *)key;
     241    for (hash = 0; *tmpchar != '\0'; tmpchar++) {
     242        hash = (64 * hash + *tmpchar) % (table->nbucket);
    251243    }
    252244
    253245    // NOTE: This should not be necessary, but for now, I'm checking bounds
    254246    // anyway.
    255     if ( ( hash < 0 ) || ( hash >= table->nbucket ) ) {
    256         psAbort( __func__, "Internal hash function out of range (%d)", hash );
    257     }
    258 
     247    if ((hash < 0) || (hash >= table->nbucket)) {
     248        psAbort(__func__, "Internal hash function out of range (%d)", hash);
     249    }
    259250    // ptr will have the correct hash bucket.
    260     ptr = table->buckets[ hash ];
     251    ptr = table->buckets[hash];
    261252
    262253    // We know the correct hash bucket, now we need to know what to do.
     
    264255    // or a remove operation on the hash table.
    265256
    266     if ( data == NULL ) {
    267         if ( remove
    268                ) {
    269                 // We search through the linked list for this bucket in
    270                 // the hash table and look for an entry for this key.
    271 
     257    if (data == NULL) {
     258        if (remove
     259           ) {
     260            // We search through the linked list for this bucket in
     261            // the hash table and look for an entry for this key.
     262
     263            optr = ptr;
     264            while (ptr != NULL) {
     265                // Dtermine if this entry holds the correct key.
     266                if (strcmp(key, ptr->key) == 0) {
     267                    // The following lines of code are fairly standard ways
     268                    // of removing an item from a single-linked list.
     269
     270                    void *data = ptr->data;
     271
     272                    optr->next = ptr->next;
     273                    if (ptr == table->buckets[hash]) {
     274                        table->buckets[hash] = ptr->next;
     275                    }
     276
     277                    psFree(ptr);
     278
     279                    // By definition, the data associated with that key
     280                    // must be returned, not freed.
     281                    return data;
     282                }
    272283                optr = ptr;
    273                 while ( ptr != NULL ) {
    274                     // Dtermine if this entry holds the correct key.
    275                     if ( strcmp( key, ptr->key ) == 0 ) {
    276                         // The following lines of code are fairly standard ways
    277                         // of removing an item from a single-linked list.
    278 
    279                         void * data = ptr->data;
    280                         optr->next = ptr->next;
    281                         if ( ptr == table->buckets[ hash ] ) {
    282                             table->buckets[ hash ] = ptr->next;
    283                         }
    284 
    285                         psFree( ptr );
    286 
    287                         // By definition, the data associated with that key
    288                         // must be returned, not freed.
    289                         return data;
    290                     }
    291                     optr = ptr;
    292                     ptr = ptr->next;
    293                 }
    294                 return NULL;   // not in hash
     284                ptr = ptr->next;
    295285            }
     286            return NULL;                   // not in hash
     287        }
    296288        else {
    297289            // If we get here, then a retrieve operation is requested.  So,
    298290            // we step trough the linked list at this bucket, and return the
    299291            // data once we find it, or return NULL if we don't.
    300             while ( ptr != NULL ) {
    301                 if ( strcmp( key, ptr->key ) == 0 ) {
     292            while (ptr != NULL) {
     293                if (strcmp(key, ptr->key) == 0) {
    302294                    return ptr->data;
    303295                }
    304296                ptr = ptr->next;
    305297            }
    306             return NULL;   // not in hash
     298            return NULL;                   // not in hash
    307299        }
    308300    } else {
     
    312304        // the hash table and look for a duplicate entry for this key.
    313305
    314         while ( ptr != NULL ) {
    315             if ( strcmp( key, ptr->key ) == 0 ) {
     306        while (ptr != NULL) {
     307            if (strcmp(key, ptr->key) == 0) {
    316308                // We have found this key in the hash table.
    317309
    318                 psTrace( "utils.hash.insert", 3, "Replacing data for %s\n",
    319                          key );
     310                psTrace("utils.hash.insert", 3, "Replacing data for %s\n", key);
    320311
    321312                // NOTE: I have changed this behavior from the originally
     
    323314                // the new data was not inserted into the hash table.
    324315
    325                 psFree( ptr->data );
    326 
    327                 ptr->data = psMemIncrRefCounter( data );
     316                psFree(ptr->data);
     317
     318                ptr->data = psMemIncrRefCounter(data);
    328319                return data;
    329320            }
     
    333324        // table.  So, we insert this data at the head of that linked list.
    334325
    335         table->buckets[ hash ] = hashBucketAlloc( key,
    336                                  data,
    337                                  table->buckets[ hash ] );
     326        table->buckets[hash] = hashBucketAlloc(key, data, table->buckets[hash]);
    338327        return data;
    339328    }
     
    351340    boolean value defining success or failure
    352341 *****************************************************************************/
    353 bool psHashAdd( psHash *table, const char *key, void *data )
    354 {
    355     if ( table == NULL ) {
    356         psAbort( __func__, "psHashInsert() called with NULL hash table." );
    357     }
    358     if ( key == NULL ) {
    359         psAbort( __func__, "psHashInsert() called with NULL key." );
    360     }
    361     if ( data == NULL ) {
    362         psAbort( __func__, "psHashLookup() called with NULL data." );
    363     }
    364 
    365     return ( doHashWork( table, key, data, 0 ) != NULL );
     342bool psHashAdd(psHash * table, const char *key, void *data)
     343{
     344    if (table == NULL) {
     345        psAbort(__func__, "psHashInsert() called with NULL hash table.");
     346    }
     347    if (key == NULL) {
     348        psAbort(__func__, "psHashInsert() called with NULL key.");
     349    }
     350    if (data == NULL) {
     351        psAbort(__func__, "psHashLookup() called with NULL data.");
     352    }
     353
     354    return (doHashWork(table, key, data, 0) != NULL);
    366355}
    367356
     
    377366    The data associated with that key.
    378367 *****************************************************************************/
    379 void *psHashLookup( psHash *table,     // table to lookup key in
    380                     const char *key )   // key to lookup
    381 {
    382     if ( table == NULL ) {
    383         psAbort( __func__, "psHashLookup() called with NULL hash table." );
    384     }
    385     if ( key == NULL ) {
    386         psAbort( __func__, "psHashLookup() called with NULL key." );
    387     }
    388 
    389 
    390     return doHashWork( table, key, NULL, 0 );
     368void *psHashLookup(psHash * table,      // table to lookup key in
     369                   const char *key)     // key to lookup
     370{
     371    if (table == NULL) {
     372        psAbort(__func__, "psHashLookup() called with NULL hash table.");
     373    }
     374    if (key == NULL) {
     375        psAbort(__func__, "psHashLookup() called with NULL key.");
     376    }
     377
     378    return doHashWork(table, key, NULL, 0);
    391379}
    392380
     
    401389    boolean value defining success or failure
    402390 *****************************************************************************/
    403 bool psHashRemove( psHash *table, const char *key )
    404 {
    405     void * data = NULL;
     391bool psHashRemove(psHash * table, const char *key)
     392{
     393    void *data = NULL;
    406394    bool retVal = false;
    407395
    408     if ( table == NULL ) {
    409         psAbort( __func__, "psHashRemove() called with NULL hash table." );
    410     }
    411     if ( key == NULL ) {
    412         psAbort( __func__, "psHashRemove() called with NULL key." );
    413     }
    414 
    415     data = doHashWork( table, key, NULL, 1 );
    416     if ( data != NULL ) {
    417         psFree( data );
     396    if (table == NULL) {
     397        psAbort(__func__, "psHashRemove() called with NULL hash table.");
     398    }
     399    if (key == NULL) {
     400        psAbort(__func__, "psHashRemove() called with NULL key.");
     401    }
     402
     403    data = doHashWork(table, key, NULL, 1);
     404    if (data != NULL) {
     405        psFree(data);
    418406        retVal = true;
    419407    } else {
  • trunk/psLib/src/sysUtils/psHash.h

    r1406 r1407  
     1
    12/** @file  psHash.h
    23 *  @brief Contains support for basic hashing functions.
     
    1011 *  @author George Gusciora, MHPCC
    1112 *   
    12  *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-08-06 22:34:05 $
     13 *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-08-07 00:06:06 $
    1415 *
    1516 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1617 */
    1718#if !defined(PS_HASH_H)
    18 #define PS_HASH_H
     19#    define PS_HASH_H
    1920
    2021/** \addtogroup HashTable
    2122 *  \{
    2223 */
    23 #include<stdbool.h>
     24#    include<stdbool.h>
    2425
    25 #include "psList.h"
     26#    include "psList.h"
    2627
    2728/** A bucket that holds an item of data. */
    2829typedef struct psHashBucket
    2930{
    30     char *key;                          ///< key for this item of data
    31     void *data;                         ///< the data itself
    32     struct psHashBucket *next;          ///< list of other possible keys
     31    char *key;                  // /< key for this item of data
     32    void *data;                 // /< the data itself
     33    struct psHashBucket *next;  // /< list of other possible keys
    3334}
    3435psHashBucket;
    3536
    3637//typedef struct HashTable psHash; ///< Opaque type for a hash table
     38
    3739/** The hash-table itself. */
    3840typedef struct psHash
    3941{
    40     int nbucket;                        ///< Number of buckets in hash table.
    41     psHashBucket **buckets;             ///< The bucket data.
     42    int nbucket;                // /< Number of buckets in hash table.
     43    psHashBucket **buckets;     // /< The bucket data.
    4244}
    4345psHash;
    4446
    4547/// Allocate hash buckets in table.
    46 psHash *psHashAlloc(int nbucket       ///< The number of buckets to allocate.
     48psHash *psHashAlloc(int nbucket // /< The number of buckets to allocate.
    4749                   );
    4850
    4951/// Insert entry into table.
    50 bool psHashAdd(psHash *table,               ///< table to insert in
    51                const char *key,             ///< key to use
    52                void *data                   ///< data to insert
     52bool psHashAdd(psHash * table,  // /< table to insert in
     53               const char *key, // /< key to use
     54               void *data       // /< data to insert
    5355              );
    5456
    5557/// Lookup key in table.
    56 void *psHashLookup(psHash *table,      ///< table to lookup key in
    57                    const char *key     ///< key to lookup
     58void *psHashLookup(psHash * table,      // /< table to lookup key in
     59                   const char *key      // /< key to lookup
    5860                  );
    5961
    6062/// Remove key from table.
    61 bool psHashRemove(psHash *table,      ///< table to lookup key in
    62                   const char *key     ///< key to lookup
     63bool psHashRemove(psHash * table,       // /< table to lookup key in
     64                  const char *key       // /< key to lookup
    6365                 );
    6466
    6567/// List all keys in table.
    66 psList *psHashKeyList(psHash *table  ///< table to list keys from.
     68psList *psHashKeyList(psHash * table    // /< table to list keys from.
    6769                     );
    6870
    69 /* \} */ // End of DataGroup Functions
     71/* \} */// End of DataGroup Functions
    7072
    7173#endif
  • trunk/psLib/src/sysUtils/psLogMsg.c

    r1406 r1407  
     1
    12/** @file  psLogMsg.c
    23 *  @brief Procedures for logging messages.
     
    1112 *  @author George Gusciora, MHPCC
    1213 *
    13  *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-08-06 22:34:05 $
     14 *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2004-08-07 00:06:06 $
    1516 *
    1617 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4445
    4546#define MAX_LOG_LINE_LENGTH 128
    46 static FILE* logDest = (FILE*)1;       // flag to initialize to stderr before using.
    47 static int globalLogLevel = PS_LOG_INFO; // log all messages at this or above
    48 static bool logTime = true;            // Flag to include time info
    49 static bool logHost = true;            // Flag to include host info
    50 static bool logLevel = true;           // Flag to include level info
    51 static bool logName = true;            // Flag to include name info
    52 static bool logMsg = true;             // Flag to include message info
     47static FILE *logDest = (FILE *) 1;      // flag to initialize to stderr before using.
     48static int globalLogLevel = PS_LOG_INFO;        // log all messages at this or above
     49static bool logTime = true;     // Flag to include time info
     50static bool logHost = true;     // Flag to include host info
     51static bool logLevel = true;    // Flag to include level info
     52static bool logName = true;     // Flag to include name info
     53static bool logMsg = true;      // Flag to include message info
    5354
    5455/*****************************************************************************
     
    6768
    6869    if ((level < MIN_LOG_LEVEL) || (level > MAX_LOG_LEVEL)) {
    69         psLogMsg("logmsg", PS_LOG_WARN,
    70                  "Attempt to set invalid logMsg level: %d", level);
     70        psLogMsg("logmsg", PS_LOG_WARN, "Attempt to set invalid logMsg level: %d", level);
    7171        level = (level < MIN_LOG_LEVEL) ? MIN_LOG_LEVEL : MAX_LOG_LEVEL;
    7272    }
    73 
    7473    // Set new global log level
    7574    globalLogLevel = level;
     
    7877    return oldLevel;
    7978}
    80 
    8179
    8280/*****************************************************************************
     
    9189 An integer specifying the old log destination.
    9290 *****************************************************************************/
    93 int psLogSetDestination(const char* dest)
     91int psLogSetDestination(const char *dest)
    9492{
    9593    char protocol[5];
     
    9795
    9896    // if logDest has not been initialized, do so before using it
    99     if (logDest==(FILE*)1) {
     97    if (logDest == (FILE *) 1) {
    10098        logDest = stderr;
    10199    }
    102100
    103     if (dest == NULL || strcmp(dest,"none")==0) {
     101    if (dest == NULL || strcmp(dest, "none") == 0) {
    104102        if (logDest != NULL && logDest != stderr && logDest != stdout) {
    105103            fclose(logDest);
     
    109107    }
    110108
    111     if (sscanf(dest,"%4s:%256s",protocol,location) < 2) {
    112         psError(__func__,"The specified destination, %s, is malformed.", dest);
     109    if (sscanf(dest, "%4s:%256s", protocol, location) < 2) {
     110        psError(__func__, "The specified destination, %s, is malformed.", dest);
    113111        return 1;
    114112    }
    115113
    116     if (strcmp(protocol,"dest") == 0) {
    117         if (strcmp(location,"stderr") == 0) {
     114    if (strcmp(protocol, "dest") == 0) {
     115        if (strcmp(location, "stderr") == 0) {
    118116            if (logDest != NULL && logDest != stderr && logDest != stdout) {
    119117                fclose(logDest);
     
    122120            return 0;
    123121        }
    124         if (strcmp(location,"stdout") == 0) {
     122        if (strcmp(location, "stdout") == 0) {
    125123            if (logDest != NULL && logDest != stderr && logDest != stdout) {
    126124                fclose(logDest);
     
    129127            return 0;
    130128        }
    131         psError(__func__,"The location, %s, for protocol 'dest' is invalid.",location);
     129        psError(__func__, "The location, %s, for protocol 'dest' is invalid.", location);
    132130        return 1;
    133     } else
    134         if (strcmp(protocol,"file") == 0) {
    135             FILE* file = fopen(location,"w");
    136             if (file == NULL) {
    137                 psError(__func__,"Could not open file '%s' for output.",location);
    138                 return 1;
    139             }
    140             if (logDest != NULL && logDest != stderr && logDest != stdout) {
    141                 fclose(logDest);
    142             }
    143             logDest = file;
    144             return 0;
    145         }
    146 
    147     psError(__func__,"Do not know how to handle the protocol '%s'.",protocol);
     131    } else if (strcmp(protocol, "file") == 0) {
     132        FILE *file = fopen(location, "w");
     133
     134        if (file == NULL) {
     135            psError(__func__, "Could not open file '%s' for output.", location);
     136            return 1;
     137        }
     138        if (logDest != NULL && logDest != stderr && logDest != stdout) {
     139            fclose(logDest);
     140        }
     141        logDest = file;
     142        return 0;
     143    }
     144
     145    psError(__func__, "Do not know how to handle the protocol '%s'.", protocol);
    148146    return 1;
    149147}
     
    181179        fmt = "THLNM";
    182180    }
    183 
    184181    // Step through each character in the format string.  For each letter
    185182    // in that string, set/unset the appropriate logging.
     
    214211
    215212    if (!logMsg) {
    216         psTrace("utils.logMsg", 1,
    217                 "You must at least log error messages (You chose \"%s\")",
    218                 fmt);
    219     }
    220 }
    221 
    222 
    223 
    224 #if !defined(HOST_NAME_MAX)  // should be in limits.h
    225 #  define HOST_NAME_MAX 256
     213        psTrace("utils.logMsg", 1, "You must at least log error messages (You chose \"%s\")", fmt);
     214    }
     215}
     216
     217#if !defined(HOST_NAME_MAX)                // should be in limits.h
     218#    define HOST_NAME_MAX 256
    226219#endif
     220
    227221/*****************************************************************************
    228222    psVLogMsg(): This routine sends the message, which is a printf style
     
    239233 NULL.
    240234 *****************************************************************************/
    241 void psLogMsgV(const char *name,
    242                int level,
    243                const char *fmt,
    244                va_list ap)
    245 {
    246     static int first = 1;               // Flag for calling gethostname()
     235void psLogMsgV(const char *name, int level, const char *fmt, va_list ap)
     236{
     237    static int first = 1;       // Flag for calling gethostname()
    247238    static char hostname[HOST_NAME_MAX + 1];
     239
    248240    // Buffer for hostname.
    249     char clevel=0;                      // letter-name for level
    250     char head[MAX_LOG_LINE_LENGTH+2];  // the added two are for the ending | and \0
    251     char *head_ptr = head;              // where we've got to in head
     241    char clevel = 0;            // letter-name for level
     242    char head[MAX_LOG_LINE_LENGTH + 2]; // the added two are for the ending | and \0
     243    char *head_ptr = head;      // where we've got to in head
    252244    int maxLength = MAX_LOG_LINE_LENGTH;
    253     time_t clock = time(NULL);          // The current time.
     245    time_t clock = time(NULL);  // The current time.
    254246    struct tm *utc = gmtime(&clock);    // The current gm time.
    255247
    256248    // if logDest has not been initialized, do so before using it
    257     if (logDest==(FILE*)1) {
     249    if (logDest == (FILE *) 1) {
    258250        logDest = stderr;
    259251    }
    260 
    261252    // If logging is off, or if the level is too high, return immediately.
    262253    if ((level > globalLogLevel) || (logDest == NULL)) {
    263254        return;
    264255    }
    265 
    266256    // If I have not been here yet, determine my hostname and save it.
    267257    if (first) {
     
    297287
    298288    default:
    299         psTrace("utils.logMsg", 2, "Invalid logMsg level: %d (%s)\n",
    300                 level, fmt);
     289        psTrace("utils.logMsg", 2, "Invalid logMsg level: %d (%s)\n", level, fmt);
    301290        level = (level < 0) ? 0 : 9;
    302291        break;
     
    307296        maxLength -= snprintf(head_ptr, maxLength, "%4d:%02d:%02d %02d:%02d:%02dZ",
    308297                              utc->tm_year + 1900, utc->tm_mon + 1, utc->tm_mday,
    309                               utc->tm_hour, utc->tm_min, utc->tm_sec)-1;
     298                              utc->tm_hour, utc->tm_min, utc->tm_sec) - 1;
    310299        head_ptr += strlen(head_ptr);
    311300    }
     
    336325    if (head_ptr > head) {
    337326        *head_ptr++ = '|';
    338     } else
    339         if (!logMsg) { // no output desired
    340             return;
    341         }
     327    } else if (!logMsg) {                  // no output desired
     328        return;
     329    }
    342330    *head_ptr = '\0';
    343331
     
    352340    }
    353341}
    354 
    355342
    356343/*****************************************************************************
     
    369356 NULL
    370357 *****************************************************************************/
    371 void psLogMsg(const char *name,
    372               int level,
    373               const char *fmt,
    374               ...)
     358void psLogMsg(const char *name, int level, const char *fmt, ...)
    375359{
    376360    va_list ap;
  • trunk/psLib/src/sysUtils/psLogMsg.h

    r1406 r1407  
     1
    12/** @file  psLogMsg.h
    23 *  @brief Procedures for logging messages.
     
    1112 *  @author George Gusciora, MHPCC
    1213 *
    13  *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-08-06 22:34:05 $
     14 *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2004-08-07 00:06:06 $
    1516 *
    1617 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1718 */
    1819#if !defined(PS_LOG_MSG_H)
    19 #define PS_LOG_MSG_H
    20 #include <stdarg.h>
     20#    define PS_LOG_MSG_H
     21#    include <stdarg.h>
    2122
    2223/** @addtogroup LogTrace
     
    2930/// In future versions, this procedure will take a character string as an
    3031/// argument which can specify more general log destinations.
    31 int psLogSetDestination(const char* dest   ///< Specifies where to send messages.
     32int psLogSetDestination(const char *dest        // /< Specifies where to send messages.
    3233                       );
    33 
    3434
    3535/// This procedure sets the message level for future log messages.  Subsequent
     
    3838/// Ie. higher values set by this procedure will cause more log messages to
    3939/// be displayed.
    40 int psLogSetLevel(int level          ///< Specifies the system log level
     40int psLogSetLevel(int level     // /< Specifies the system log level
    4141                 );
    42 
    4342
    4443/// This procedure sets the log format for future log messages.  The argument
     
    4746/// Deleting a letter from the string will cause the associated information
    4847/// to not be logged.
    49 void psLogSetFormat(const char *fmt ///< Specifies the system log format
     48void psLogSetFormat(const char *fmt     // /< Specifies the system log format
    5049                   );
    51 
    5250
    5351/// This procedure logs a message to the destination set by a prior
     
    5553/// specified by a prior call to psLogSetLevel().  The message is specified
    5654/// with a printf-stype string an arguments.
    57 void psLogMsg(const char *name,     ///< name of the log source
    58               int myLevel,          ///< severity level of this log message
    59               const char *fmt, ...  ///< printf-style format command
     55void psLogMsg(const char *name, // /< name of the log source
     56              int myLevel,      // /< severity level of this log message
     57              const char *fmt, ...      // /< printf-style format command
    6058             );
    61 
    6259
    6360/// This procedure is functionally equivalent to psLogMsg(), except that
    6461/// it takes a va_list as the message parameter, not a printf-style string.
    65 void psLogMsgV(const char *name, ///< name of the log source
    66                int myLevel,      ///< severity level of this log message
    67                const char *fmt,  ///< printf-style format command
    68                va_list ap        ///< varargs argument list
     62void psLogMsgV(const char *name,        // /< name of the log source
     63               int myLevel,     // /< severity level of this log message
     64               const char *fmt, // /< printf-style format command
     65               va_list ap       // /< varargs argument list
    6966              );
    7067
     
    7471    PS_LOG_ERROR,
    7572    PS_LOG_WARN,
    76     PS_LOG_INFO };
     73    PS_LOG_INFO
     74};
    7775
    7876///< Destinations for log messages
     
    8078    PS_LOG_NONE,
    8179    PS_LOG_TO_STDERR,
    82     PS_LOG_TO_STDOUT };
     80    PS_LOG_TO_STDOUT
     81};
    8382
    8483/// @}
  • trunk/psLib/src/sysUtils/psMemory.c

    r1406 r1407  
     1
    12/** @file  psMemory.c
    23*
     
    89*  @author Robert Lupton, Princeton University
    910*
    10 *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
    11 *  @date $Date: 2004-08-06 22:34:05 $
     11*  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2004-08-07 00:06:06 $
    1213*
    1314*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1415*/
    1516
    16 #define PS_ALLOW_MALLOC                 // we're allowed to call malloc()
     17#define PS_ALLOW_MALLOC                    // we're allowed to call malloc()
    1718
    1819#include <stdlib.h>
     
    2627#include "psLogMsg.h"
    2728
    28 #define P_PS_MEMMAGIC (void *)0xdeadbeef // Magic number in psMemBlock header
    29 
    30 #define P_PS_LARGE_BLOCK_SIZE 65536    // size where under, we try to recycle
    31 
    32 static int checkMemBlock( const psMemBlock *m, const char* funcName );
     29#define P_PS_MEMMAGIC (void *)0xdeadbeef   // Magic number in psMemBlock header
     30
     31#define P_PS_LARGE_BLOCK_SIZE 65536        // size where under, we try to recycle
     32
     33static int checkMemBlock(const psMemBlock * m, const char *funcName);
    3334static psMemBlock *lastMemBlockAllocated = NULL;
    3435static pthread_mutex_t memBlockListMutex = PTHREAD_MUTEX_INITIALIZER;
     
    3839
    3940static int recycleBins = 13;
    40 static int recycleBinSize[ 14 ] =
    41     {
    42         8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, P_PS_LARGE_BLOCK_SIZE
    43     };
     41static int recycleBinSize[14] = {
     42                                    8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, P_PS_LARGE_BLOCK_SIZE
     43                                };
     44
    4445// N.B. recycleBinSize should be terminated by P_PS_LARGE_BLOCK_SIZE (simplifies search loops)
    45 static psMemBlock* recycleMemBlockList[ 13 ] =
    46     {
    47         NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
    48     };
     46static psMemBlock *recycleMemBlockList[13] = {
     47            NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
     48        };
    4949
    5050#ifdef PS_MEM_DEBUG
    51 static psMemBlock* deadBlockList;    // a place to put dead memBlocks in debug mode.
     51static psMemBlock *deadBlockList;       // a place to put dead memBlocks in debug mode.
    5252#endif
     53
    5354/**
    5455 * Unique ID for allocated blocks
     
    5960 *  Default memExhausted callback.
    6061 */
    61 static void *memExhaustedCallbackDefault( size_t size )
    62 {
    63     void * ptr = NULL;
    64 
    65     pthread_mutex_lock( &recycleMemBlockListMutex );
     62static void *memExhaustedCallbackDefault(size_t size)
     63{
     64    void *ptr = NULL;
     65
     66    pthread_mutex_lock(&recycleMemBlockListMutex);
    6667    int level = recycleBins - 1;
    67     while ( level >= 0 && ptr == NULL ) {
    68         while ( recycleMemBlockList[ level ] != NULL && ptr == NULL ) {
    69             psMemBlock * old = recycleMemBlockList[ level ];
    70             recycleMemBlockList[ level ] = recycleMemBlockList[ level ] ->nextBlock;
    71             free( old );
    72             ptr = malloc( size );
     68
     69    while (level >= 0 && ptr == NULL) {
     70        while (recycleMemBlockList[level] != NULL && ptr == NULL) {
     71            psMemBlock *old = recycleMemBlockList[level];
     72
     73            recycleMemBlockList[level] = recycleMemBlockList[level]->nextBlock;
     74            free(old);
     75            ptr = malloc(size);
    7376        }
    7477        level--;
    7578    }
    76     pthread_mutex_unlock( &recycleMemBlockListMutex );
     79    pthread_mutex_unlock(&recycleMemBlockListMutex);
    7780
    7881    return ptr;
     
    8184static psMemExhaustedCallback memExhaustedCallback = memExhaustedCallbackDefault;
    8285
    83 psMemExhaustedCallback psMemExhaustedCallbackSet( psMemExhaustedCallback func )
     86psMemExhaustedCallback psMemExhaustedCallbackSet(psMemExhaustedCallback func)
    8487{
    8588    psMemExhaustedCallback old = memExhaustedCallback;
    8689
    87     if ( func != NULL ) {
     90    if (func != NULL) {
    8891        memExhaustedCallback = func;
    8992    } else {
     
    9497}
    9598
    96 static void memProblemCallbackDefault( const psMemBlock *ptr,
    97                                        const char *file, int lineno )
    98 {
    99     if ( ptr->refCounter < 1 ) {
    100         psError( __func__,
    101                  "Block %ld allocated at %s:%d freed more than once at %s:%d\n",
    102                  ptr->id, ptr->file, ptr->lineno, file, lineno );
    103     }
    104 
    105     if ( lineno > 0 ) {
    106         psAbort( __func__, "Detected a problem in the memory system at %s:%d", file, lineno );
     99static void memProblemCallbackDefault(const psMemBlock * ptr, const char *file, int lineno)
     100{
     101    if (ptr->refCounter < 1) {
     102        psError(__func__,
     103                "Block %ld allocated at %s:%d freed more than once at %s:%d\n",
     104                ptr->id, ptr->file, ptr->lineno, file, lineno);
     105    }
     106
     107    if (lineno > 0) {
     108        psAbort(__func__, "Detected a problem in the memory system at %s:%d", file, lineno);
    107109    }
    108110}
    109111static psMemProblemCallback memProblemCallback = memProblemCallbackDefault;
    110112
    111 psMemProblemCallback psMemProblemCallbackSet( psMemProblemCallback func )
     113psMemProblemCallback psMemProblemCallbackSet(psMemProblemCallback func)
    112114{
    113115    psMemProblemCallback old = memProblemCallback;
    114116
    115     if ( func != NULL ) {
     117    if (func != NULL) {
    116118        memProblemCallback = func;
    117119    } else {
     
    121123    return old;
    122124}
     125
    123126/*
    124127 * And now the I-want-to-be-informed callbacks
     
    126129 * Call the callbacks when these IDs are allocated/freed
    127130 */
    128 psMemoryId p_psMemAllocateID = 0;  // notify user this block is allocated
     131psMemoryId p_psMemAllocateID = 0;       // notify user this block is allocated
    129132psMemoryId p_psMemFreeID = 0;   // notify user this block is freed
    130133
    131 psMemoryId psMemAllocateCallbackSetID( psMemoryId id )
     134psMemoryId psMemAllocateCallbackSetID(psMemoryId id)
    132135{
    133136    psMemoryId old = p_psMemAllocateID;
     137
    134138    p_psMemAllocateID = id;
    135139
     
    137141}
    138142
    139 psMemoryId psMemFreeCallbackSetID( psMemoryId id )
     143psMemoryId psMemFreeCallbackSetID(psMemoryId id)
    140144{
    141145    psMemoryId old = p_psMemFreeID;
     146
    142147    p_psMemFreeID = id;
    143148
     
    151156 * isn't resignalled)
    152157 */
    153 static psMemoryId memAllocateCallbackDefault( const psMemBlock *ptr )
    154 {
    155     static psMemoryId incr = 0;  // "p_psMemAllocateID += incr"
     158static psMemoryId memAllocateCallbackDefault(const psMemBlock * ptr)
     159{
     160    static psMemoryId incr = 0; // "p_psMemAllocateID += incr"
    156161
    157162    return incr;
    158163}
    159164
    160 static psMemoryId memFreeCallbackDefault( const psMemBlock *ptr )
    161 {
    162     static psMemoryId incr = 0;  // "p_psMemFreeID += incr"
     165static psMemoryId memFreeCallbackDefault(const psMemBlock * ptr)
     166{
     167    static psMemoryId incr = 0; // "p_psMemFreeID += incr"
    163168
    164169    return incr;
     
    171176static psMemFreeCallback memFreeCallback = memFreeCallbackDefault;
    172177
    173 psMemAllocateCallback psMemAllocateCallbackSet( psMemAllocateCallback func )
     178psMemAllocateCallback psMemAllocateCallbackSet(psMemAllocateCallback func)
    174179{
    175180    psMemFreeCallback old = memAllocateCallback;
    176181
    177     if ( func != NULL ) {
     182    if (func != NULL) {
    178183        memAllocateCallback = func;
    179184    } else {
     
    184189}
    185190
    186 psMemFreeCallback psMemFreeCallbackSet( psMemFreeCallback func )
     191psMemFreeCallback psMemFreeCallbackSet(psMemFreeCallback func)
    187192{
    188193    psMemFreeCallback old = memFreeCallback;
    189194
    190     if ( func != NULL ) {
     195    if (func != NULL) {
    191196        memFreeCallback = func;
    192197    } else {
     
    200205 * Return memory ID counter for next block to be allocated
    201206 */
    202 psMemoryId psMemGetId( void )
     207psMemoryId psMemGetId(void)
    203208{
    204209    psMemoryId id;
    205     pthread_mutex_lock( &memIdMutex );
     210
     211    pthread_mutex_lock(&memIdMutex);
    206212    id = memid + 1;
    207     pthread_mutex_unlock( &memIdMutex );
     213    pthread_mutex_unlock(&memIdMutex);
    208214
    209215    return id;
     
    216222 */
    217223
    218 static int checkMemBlock( const psMemBlock *m, const char* funcName )
     224static int checkMemBlock(const psMemBlock * m, const char *funcName)
    219225{
    220226    // n.b. since this is called by psMemCheckCorruption while the memblock list is mutex locked,
    221227    // we shouldn't call such things as p_psAlloc/p_psFree here.
    222228
    223     if ( m == NULL ) {
    224         psError( funcName, "Memory Corruption: NULL memory block found." );
     229    if (m == NULL) {
     230        psError(funcName, "Memory Corruption: NULL memory block found.");
    225231        return 1;
    226232    }
    227233
    228     if ( m->refCounter == 0 ) {
     234    if (m->refCounter == 0) {
    229235        // using an unreferenced block of memory, are you?
    230         psError( __func__, "Memory Corruption: memory block %ld was freed but still used.",
    231                  m->id );
     236        psError(__func__, "Memory Corruption: memory block %ld was freed but still used.", m->id);
    232237        return 1;
    233238    }
    234239
    235     if ( m->startblock != P_PS_MEMMAGIC || m->endblock != P_PS_MEMMAGIC ) {
    236         psError( funcName, "Memory Corruption: memory block %ld is corrupted (buffer underflow)",
    237                  m->id );
     240    if (m->startblock != P_PS_MEMMAGIC || m->endblock != P_PS_MEMMAGIC) {
     241        psError(funcName, "Memory Corruption: memory block %ld is corrupted (buffer underflow)", m->id);
    238242        return 1;
    239243    }
    240     if ( *( void** ) ( ( int8_t* ) ( m + 1 ) + m->userMemorySize ) != P_PS_MEMMAGIC ) {
    241         psError( funcName, "Memory Corruption: memory block %ld is corrupted (buffer overflow)",
    242                  m->id );
     244    if (*(void **)((int8_t *) (m + 1) + m->userMemorySize) != P_PS_MEMMAGIC) {
     245        psError(funcName, "Memory Corruption: memory block %ld is corrupted (buffer overflow)", m->id);
    243246        return 1;
    244247    }
     
    247250}
    248251
    249 int psMemCheckCorruption( bool abort_on_error )
    250 {
    251     int nbad = 0;                       // number of bad blocks
     252int psMemCheckCorruption(bool abort_on_error)
     253{
     254    int nbad = 0;               // number of bad blocks
    252255
    253256    // get exclusive access to the memBlock list to avoid it changing on us while we use it.
    254     pthread_mutex_lock( &memBlockListMutex );
    255 
    256     for ( psMemBlock * iter = lastMemBlockAllocated; iter != NULL; iter = iter->nextBlock ) {
    257         if ( checkMemBlock( iter, __func__ ) ) {
     257    pthread_mutex_lock(&memBlockListMutex);
     258
     259    for (psMemBlock * iter = lastMemBlockAllocated; iter != NULL; iter = iter->nextBlock) {
     260        if (checkMemBlock(iter, __func__)) {
    258261            nbad++;
    259262
    260             memProblemCallback( iter, __func__, __LINE__ );
    261 
    262             if ( abort_on_error ) {
     263            memProblemCallback(iter, __func__, __LINE__);
     264
     265            if (abort_on_error) {
    263266                // release the lock on the memblock list
    264                 pthread_mutex_unlock( &memBlockListMutex );
    265                 psAbort( __func__, "Detected memory corruption" );
     267                pthread_mutex_unlock(&memBlockListMutex);
     268                psAbort(__func__, "Detected memory corruption");
    266269                return nbad;
    267270            }
     
    270273
    271274    // release the lock on the memblock list
    272     pthread_mutex_unlock( &memBlockListMutex );
     275    pthread_mutex_unlock(&memBlockListMutex);
    273276    return nbad;
    274277}
    275278
    276 void *p_psAlloc( size_t size, const char *file, int lineno )
    277 {
    278 
    279     psMemBlock * ptr = NULL;
     279void *p_psAlloc(size_t size, const char *file, int lineno)
     280{
     281
     282    psMemBlock *ptr = NULL;
    280283
    281284    // memory is of the size I want to bother recycling?
    282     if ( size < P_PS_LARGE_BLOCK_SIZE ) {
     285    if (size < P_PS_LARGE_BLOCK_SIZE) {
    283286        // find the bin we need.
    284287        int level = 0;
    285         while ( size > recycleBinSize[ level ] ) {
     288
     289        while (size > recycleBinSize[level]) {
    286290            level++;
    287291        }
    288292        // Are we in one of the bins
    289         if ( level < recycleBins ) {
    290 
    291             size = recycleBinSize[ level ];  // round-up size to next sized bin.
    292 
    293             pthread_mutex_lock( &recycleMemBlockListMutex );
    294 
    295             if ( recycleMemBlockList[ level ] != NULL ) {
    296                 ptr = recycleMemBlockList[ level ];
    297                 recycleMemBlockList[ level ] = ptr->nextBlock;
    298                 if ( recycleMemBlockList[ level ] != NULL ) {
    299                     recycleMemBlockList[ level ] ->previousBlock = NULL;
     293        if (level < recycleBins) {
     294
     295            size = recycleBinSize[level];  // round-up size to next sized bin.
     296
     297            pthread_mutex_lock(&recycleMemBlockListMutex);
     298
     299            if (recycleMemBlockList[level] != NULL) {
     300                ptr = recycleMemBlockList[level];
     301                recycleMemBlockList[level] = ptr->nextBlock;
     302                if (recycleMemBlockList[level] != NULL) {
     303                    recycleMemBlockList[level]->previousBlock = NULL;
    300304                }
    301305                size = ptr->userMemorySize;
    302306            }
    303307
    304             pthread_mutex_unlock( &recycleMemBlockListMutex );
    305         }
    306     }
    307 
    308     if ( ptr == NULL ) {
    309         ptr = malloc( sizeof( psMemBlock ) + size + sizeof( void* ) );
    310 
    311         if ( ptr == NULL ) {
    312             ptr = memExhaustedCallback( size );
    313             if ( ptr == NULL ) {
    314                 psAbort( __func__, "Failed to allocate %u bytes at %s:%d",
    315                          size, file, lineno );
     308            pthread_mutex_unlock(&recycleMemBlockListMutex);
     309        }
     310    }
     311
     312    if (ptr == NULL) {
     313        ptr = malloc(sizeof(psMemBlock) + size + sizeof(void *));
     314
     315        if (ptr == NULL) {
     316            ptr = memExhaustedCallback(size);
     317            if (ptr == NULL) {
     318                psAbort(__func__, "Failed to allocate %u bytes at %s:%d", size, file, lineno);
    316319            }
    317320        }
     
    320323        ptr->endblock = P_PS_MEMMAGIC;
    321324        ptr->userMemorySize = size;
    322         pthread_mutex_init( &ptr->refCounterMutex, NULL );
    323     }
    324 
     325        pthread_mutex_init(&ptr->refCounterMutex, NULL);
     326    }
    325327    // increment the memory id safely.
    326     pthread_mutex_lock( &memBlockListMutex );
    327     *( psMemoryId* ) & ptr->id = ++memid;
    328     pthread_mutex_unlock( &memBlockListMutex );
     328    pthread_mutex_lock(&memBlockListMutex);
     329    *(psMemoryId *) & ptr->id = ++memid;
     330    pthread_mutex_unlock(&memBlockListMutex);
    329331
    330332    ptr->file = file;
    331333    ptr->freeFcn = NULL;
    332     *( unsigned int* ) & ptr->lineno = lineno;
    333     *( void** ) ( ( int8_t* ) ( ptr + 1 ) + size ) = P_PS_MEMMAGIC;
     334    *(unsigned int *)&ptr->lineno = lineno;
     335    *(void **)((int8_t *) (ptr + 1) + size) = P_PS_MEMMAGIC;
    334336    ptr->previousBlock = NULL;
    335337
    336     ptr->refCounter = 1;                // one user so far
     338    ptr->refCounter = 1;                   // one user so far
    337339
    338340    // need exclusive access of the memory block list now...
    339     pthread_mutex_lock( &memBlockListMutex );
     341    pthread_mutex_lock(&memBlockListMutex);
    340342
    341343    // insert the new block to the front of the memBlock linked-list
    342344    ptr->nextBlock = lastMemBlockAllocated;
    343     if ( ptr->nextBlock != NULL ) {
     345    if (ptr->nextBlock != NULL) {
    344346        ptr->nextBlock->previousBlock = ptr;
    345347    }
    346348    lastMemBlockAllocated = ptr;
    347349
    348     pthread_mutex_unlock( &memBlockListMutex );
    349 
    350     //  Did the user ask to be informed about this allocation?
    351     if ( ptr->id == p_psMemAllocateID ) {
    352         p_psMemAllocateID += memAllocateCallback( ptr );
    353     }
    354 
     350    pthread_mutex_unlock(&memBlockListMutex);
     351
     352    // Did the user ask to be informed about this allocation?
     353    if (ptr->id == p_psMemAllocateID) {
     354        p_psMemAllocateID += memAllocateCallback(ptr);
     355    }
    355356    // And return the user the memory that they allocated
    356     return ptr + 1;   // user memory
    357 }
    358 
    359 void *p_psRealloc( void *vptr, size_t size, const char *file, int lineno )
    360 {
    361     if ( vptr == NULL ) {
    362         return p_psAlloc( size, file, lineno );
     357    return ptr + 1;                        // user memory
     358}
     359
     360void *p_psRealloc(void *vptr, size_t size, const char *file, int lineno)
     361{
     362    if (vptr == NULL) {
     363        return p_psAlloc(size, file, lineno);
    363364    } else {
    364         psMemBlock *ptr = ( ( psMemBlock * ) vptr ) - 1;
     365        psMemBlock *ptr = ((psMemBlock *) vptr) - 1;
    365366        bool isBlockLast = false;
    366367
    367         if ( checkMemBlock( ptr, __func__ ) != 0 ) {
    368             memProblemCallback( ptr, file, lineno );
    369             psAbort( file, "Realloc detected a memory corruption (id %ld @ %s:%d).",
    370                      ptr->id, ptr->file, ptr->lineno );
    371         }
    372 
    373         pthread_mutex_lock( &memBlockListMutex );
    374 
    375         isBlockLast = ( ptr == lastMemBlockAllocated );
    376 
    377         ptr = ( psMemBlock* ) realloc( ptr, sizeof( psMemBlock ) + size + sizeof( void* ) );
    378 
    379         if ( ptr == NULL ) {
    380             psAbort( __func__, "Failed to reallocate %ld bytes at %s:%d",
    381                      size, file, lineno );
     368        if (checkMemBlock(ptr, __func__) != 0) {
     369            memProblemCallback(ptr, file, lineno);
     370            psAbort(file, "Realloc detected a memory corruption (id %ld @ %s:%d).",
     371                    ptr->id, ptr->file, ptr->lineno);
     372        }
     373
     374        pthread_mutex_lock(&memBlockListMutex);
     375
     376        isBlockLast = (ptr == lastMemBlockAllocated);
     377
     378        ptr = (psMemBlock *) realloc(ptr, sizeof(psMemBlock) + size + sizeof(void *));
     379
     380        if (ptr == NULL) {
     381            psAbort(__func__, "Failed to reallocate %ld bytes at %s:%d", size, file, lineno);
    382382        }
    383383
    384384        ptr->userMemorySize = size;
    385         *( void** ) ( ( int8_t* ) ( ptr + 1 ) + size ) = P_PS_MEMMAGIC;
    386 
    387         if ( isBlockLast ) {
     385        *(void **)((int8_t *) (ptr + 1) + size) = P_PS_MEMMAGIC;
     386
     387        if (isBlockLast) {
    388388            lastMemBlockAllocated = ptr;
    389389        }
    390 
    391390        // the block location may have changed, so fix the linked list addresses.
    392         if ( ptr->nextBlock != NULL ) {
     391        if (ptr->nextBlock != NULL) {
    393392            ptr->nextBlock->previousBlock = ptr;
    394393        }
    395         if ( ptr->previousBlock != NULL ) {
     394        if (ptr->previousBlock != NULL) {
    396395            ptr->previousBlock->nextBlock = ptr;
    397396        }
    398397
    399         pthread_mutex_unlock( &memBlockListMutex );
    400 
    401         //  Did the user ask to be informed about this allocation?
    402         if ( ptr->id == p_psMemAllocateID ) {
    403             p_psMemAllocateID += memAllocateCallback( ptr );
    404         }
    405 
    406         return ptr + 1;   // usr memory
    407     }
    408 }
    409 
    410 void p_psFree( void *vptr, const char *file, int lineno )
    411 {
    412     ( void ) p_psMemDecrRefCounter( vptr, file, lineno );   // this handles the free, if required.
     398        pthread_mutex_unlock(&memBlockListMutex);
     399
     400        // Did the user ask to be informed about this allocation?
     401        if (ptr->id == p_psMemAllocateID) {
     402            p_psMemAllocateID += memAllocateCallback(ptr);
     403        }
     404
     405        return ptr + 1;                    // usr memory
     406    }
     407}
     408
     409void p_psFree(void *vptr, const char *file, int lineno)
     410{
     411    (void)p_psMemDecrRefCounter(vptr, file, lineno);    // this handles the free, if required.
    413412}
    414413
     
    416415 * Check for memory leaks.
    417416 */
    418 int psMemCheckLeaks( psMemoryId id0, psMemBlock ***arr, FILE *fd )
     417int psMemCheckLeaks(psMemoryId id0, psMemBlock *** arr, FILE * fd)
    419418{
    420419    int nleak = 0;
    421420    int j = 0;
    422     psMemBlock* topBlock = lastMemBlockAllocated;
    423 
    424     pthread_mutex_lock( &memBlockListMutex );
    425 
    426     for ( psMemBlock * iter = topBlock; iter != NULL; iter = iter->nextBlock ) {
    427         if ( ( psMemGetRefCounter( iter + 1 ) > 0 ) && ( iter->id >= id0 ) ) {
     421    psMemBlock *topBlock = lastMemBlockAllocated;
     422
     423    pthread_mutex_lock(&memBlockListMutex);
     424
     425    for (psMemBlock * iter = topBlock; iter != NULL; iter = iter->nextBlock) {
     426        if ((psMemGetRefCounter(iter + 1) > 0) && (iter->id >= id0)) {
    428427            nleak++;
    429428
    430             if ( fd != NULL ) {
    431                 if ( nleak == 1 ) {
    432                     fprintf( fd, "   %20s:line ID\n", "file" );
     429            if (fd != NULL) {
     430                if (nleak == 1) {
     431                    fprintf(fd, "   %20s:line ID\n", "file");
    433432                }
    434433
    435                 fprintf( fd, "   %20s:%-4d %ld\n", iter->file, iter->lineno, iter->id );
    436             }
    437         }
    438     }
    439 
    440     pthread_mutex_unlock( &memBlockListMutex );
    441 
    442     if ( nleak == 0 || arr == NULL ) {
     434                fprintf(fd, "   %20s:%-4d %ld\n", iter->file, iter->lineno, iter->id);
     435            }
     436        }
     437    }
     438
     439    pthread_mutex_unlock(&memBlockListMutex);
     440
     441    if (nleak == 0 || arr == NULL) {
    443442        return nleak;
    444443    }
    445444
    446     *arr = p_psAlloc( nleak * sizeof( psMemBlock ), __FILE__, __LINE__ );
    447     pthread_mutex_lock( &memBlockListMutex );
    448 
    449     for ( psMemBlock * iter = topBlock; iter != NULL; iter = iter->nextBlock ) {
    450         if ( ( psMemGetRefCounter( iter + 1 ) > 0 ) && ( iter->id >= id0 ) ) {
    451             ( *arr ) [ j++ ] = iter;
    452             if ( j == nleak ) { // found them all
     445    *arr = p_psAlloc(nleak * sizeof(psMemBlock), __FILE__, __LINE__);
     446    pthread_mutex_lock(&memBlockListMutex);
     447
     448    for (psMemBlock * iter = topBlock; iter != NULL; iter = iter->nextBlock) {
     449        if ((psMemGetRefCounter(iter + 1) > 0) && (iter->id >= id0)) {
     450            (*arr)[j++] = iter;
     451            if (j == nleak) {              // found them all
    453452                break;
    454453            }
     
    456455    }
    457456
    458     pthread_mutex_unlock( &memBlockListMutex );
     457    pthread_mutex_unlock(&memBlockListMutex);
    459458
    460459    return nleak;
     
    465464 */
    466465// return refCounter
    467 psReferenceCount psMemGetRefCounter( void *vptr )
    468 {
    469     psMemBlock * ptr;
     466psReferenceCount psMemGetRefCounter(void *vptr)
     467{
     468    psMemBlock *ptr;
    470469    unsigned int refCount;
    471470
    472     if ( vptr == NULL ) {
     471    if (vptr == NULL) {
    473472        return 0;
    474473    }
    475474
    476     ptr = ( ( psMemBlock * ) vptr ) - 1;
    477 
    478     if ( checkMemBlock( ptr, __func__ ) != 0 ) {
    479         memProblemCallback( ptr, __func__, __LINE__ );
    480     }
    481 
    482     pthread_mutex_lock( &ptr->refCounterMutex );
     475    ptr = ((psMemBlock *) vptr) - 1;
     476
     477    if (checkMemBlock(ptr, __func__) != 0) {
     478        memProblemCallback(ptr, __func__, __LINE__);
     479    }
     480
     481    pthread_mutex_lock(&ptr->refCounterMutex);
    483482    refCount = ptr->refCounter;
    484     pthread_mutex_unlock( &ptr->refCounterMutex );
     483    pthread_mutex_unlock(&ptr->refCounterMutex);
    485484
    486485    return refCount;
    487486}
     487
    488488// increment and return refCounter
    489 void* p_psMemIncrRefCounter( void *vptr, const char *file, int lineno )
    490 {
    491     psMemBlock * ptr;
    492 
    493     if ( vptr == NULL ) {
     489void *p_psMemIncrRefCounter(void *vptr, const char *file, int lineno)
     490{
     491    psMemBlock *ptr;
     492
     493    if (vptr == NULL) {
    494494        return vptr;
    495495    }
    496496
    497     ptr = ( ( psMemBlock * ) vptr ) - 1;
    498 
    499     if ( checkMemBlock( ptr, __func__ ) ) {
    500         memProblemCallback( ptr, file, lineno );
    501     }
    502 
    503     pthread_mutex_lock( &ptr->refCounterMutex );
     497    ptr = ((psMemBlock *) vptr) - 1;
     498
     499    if (checkMemBlock(ptr, __func__)) {
     500        memProblemCallback(ptr, file, lineno);
     501    }
     502
     503    pthread_mutex_lock(&ptr->refCounterMutex);
    504504    ptr->refCounter++;
    505     pthread_mutex_unlock( &ptr->refCounterMutex );
     505    pthread_mutex_unlock(&ptr->refCounterMutex);
    506506
    507507    return vptr;
     
    509509
    510510// decrement and return refCounter
    511 void* p_psMemDecrRefCounter( void *vptr, const char *file, int lineno )
    512 {
    513     if ( vptr == NULL ) {
     511void *p_psMemDecrRefCounter(void *vptr, const char *file, int lineno)
     512{
     513    if (vptr == NULL) {
    514514        return NULL;
    515515    }
    516516
    517     psMemBlock *ptr = ( ( psMemBlock * ) vptr ) - 1;
    518 
    519     if ( checkMemBlock( ptr, __func__ ) != 0 ) {
    520         memProblemCallback( ptr, file, lineno );
     517    psMemBlock *ptr = ((psMemBlock *) vptr) - 1;
     518
     519    if (checkMemBlock(ptr, __func__) != 0) {
     520        memProblemCallback(ptr, file, lineno);
    521521        return NULL;
    522522    }
    523523
    524     pthread_mutex_lock( &ptr->refCounterMutex );
    525 
    526     if ( ptr->refCounter > 1 ) {
    527         /// XXX - Probably should have another mutex here.
    528         ptr->refCounter--;          // multiple references, just decrement the count.
    529         pthread_mutex_unlock( &ptr->refCounterMutex );
     524    pthread_mutex_lock(&ptr->refCounterMutex);
     525
     526    if (ptr->refCounter > 1) {
     527        // / XXX - Probably should have another mutex here.
     528        ptr->refCounter--;                 // multiple references, just decrement the count.
     529        pthread_mutex_unlock(&ptr->refCounterMutex);
    530530
    531531    } else {
    532         pthread_mutex_unlock( &ptr->refCounterMutex );
     532        pthread_mutex_unlock(&ptr->refCounterMutex);
    533533
    534534        // Did the user ask to be informed about this deallocation?
    535         if ( ptr->id == p_psMemFreeID ) {
    536             p_psMemFreeID += memFreeCallback( ptr );
    537         }
    538 
    539         if ( ptr->freeFcn != NULL ) {
    540             ptr->freeFcn( vptr );
    541         }
    542 
    543         pthread_mutex_lock( &memBlockListMutex );
     535        if (ptr->id == p_psMemFreeID) {
     536            p_psMemFreeID += memFreeCallback(ptr);
     537        }
     538
     539        if (ptr->freeFcn != NULL) {
     540            ptr->freeFcn(vptr);
     541        }
     542
     543        pthread_mutex_lock(&memBlockListMutex);
    544544
    545545        // cut the memBlock out of the memBlock list
    546         if ( ptr->nextBlock != NULL ) {
     546        if (ptr->nextBlock != NULL) {
    547547            ptr->nextBlock->previousBlock = ptr->previousBlock;
    548548        }
    549         if ( ptr->previousBlock != NULL ) {
     549        if (ptr->previousBlock != NULL) {
    550550            ptr->previousBlock->nextBlock = ptr->nextBlock;
    551551        }
    552         if ( lastMemBlockAllocated == ptr ) {
     552        if (lastMemBlockAllocated == ptr) {
    553553            lastMemBlockAllocated = ptr->nextBlock;
    554554        }
    555555
    556         pthread_mutex_unlock( &memBlockListMutex );
    557 
     556        pthread_mutex_unlock(&memBlockListMutex);
    558557
    559558        // do we need to recycle?
    560         if ( ptr->userMemorySize < P_PS_LARGE_BLOCK_SIZE ) {
     559        if (ptr->userMemorySize < P_PS_LARGE_BLOCK_SIZE) {
    561560
    562561            int level = 1;
    563             while ( ptr->userMemorySize >= recycleBinSize[ level ] ) {
     562
     563            while (ptr->userMemorySize >= recycleBinSize[level]) {
    564564                level++;
    565565            }
     
    569569            ptr->previousBlock = NULL;
    570570
    571             pthread_mutex_lock( &recycleMemBlockListMutex );
    572             ptr->nextBlock = recycleMemBlockList[ level ];
    573             if ( recycleMemBlockList[ level ] != NULL ) {
    574                 recycleMemBlockList[ level ] ->previousBlock = ptr;
    575             }
    576             recycleMemBlockList[ level ] = ptr;
    577             pthread_mutex_unlock( &recycleMemBlockListMutex );
     571            pthread_mutex_lock(&recycleMemBlockListMutex);
     572            ptr->nextBlock = recycleMemBlockList[level];
     573            if (recycleMemBlockList[level] != NULL) {
     574                recycleMemBlockList[level]->previousBlock = ptr;
     575            }
     576            recycleMemBlockList[level] = ptr;
     577            pthread_mutex_unlock(&recycleMemBlockListMutex);
    578578
    579579        } else {
    580580            // memory is larger than I want to recycle.
    581581            #ifdef PS_MEM_DEBUG
    582             ( void ) p_psRealloc( vptr, 0, file, lineno );
     582            (void)p_psRealloc(vptr, 0, file, lineno);
    583583            ptr->previousBlock = NULL;
    584584            ptr->nextBlock = deadBlockList;
    585             if ( deadBlockList != NULL ) {
     585            if (deadBlockList != NULL) {
    586586                deadBlockList->previous = ptr;
    587587            }
     
    589589            #else
    590590
    591             pthread_mutex_destroy( &ptr->refCounterMutex );
    592             free( ptr );
     591            pthread_mutex_destroy(&ptr->refCounterMutex);
     592            free(ptr);
    593593            #endif
    594594
    595595        }
    596596
    597         vptr = NULL;    // since we freed it, make sure we return NULL.
     597        vptr = NULL;                       // since we freed it, make sure we return NULL.
    598598    }
    599599
     
    601601}
    602602
    603 void p_psMemSetDeallocator( void* vptr, psFreeFcn freeFcn )
    604 {
    605     if ( vptr == NULL ) {
    606         return ;
    607     }
    608 
    609     psMemBlock *ptr = ( ( psMemBlock * ) vptr ) - 1;
    610 
    611     if ( checkMemBlock( ptr, __func__ ) != 0 ) {
    612         memProblemCallback( ptr, __func__, __LINE__ );
     603void p_psMemSetDeallocator(void *vptr, psFreeFcn freeFcn)
     604{
     605    if (vptr == NULL) {
     606        return;
     607    }
     608
     609    psMemBlock *ptr = ((psMemBlock *) vptr) - 1;
     610
     611    if (checkMemBlock(ptr, __func__) != 0) {
     612        memProblemCallback(ptr, __func__, __LINE__);
    613613    }
    614614
     
    616616
    617617}
    618 psFreeFcn p_psMemGetDeallocator( void* vptr )
    619 {
    620     if ( vptr == NULL ) {
     618psFreeFcn p_psMemGetDeallocator(void *vptr)
     619{
     620    if (vptr == NULL) {
    621621        return NULL;
    622622    }
    623623
    624     psMemBlock *ptr = ( ( psMemBlock * ) vptr ) - 1;
    625 
    626     if ( checkMemBlock( ptr, __func__ ) != 0 ) {
    627         memProblemCallback( ptr, __func__, __LINE__ );
     624    psMemBlock *ptr = ((psMemBlock *) vptr) - 1;
     625
     626    if (checkMemBlock(ptr, __func__) != 0) {
     627        memProblemCallback(ptr, __func__, __LINE__);
    628628    }
    629629
  • trunk/psLib/src/sysUtils/psMemory.h

    r1406 r1407  
    11#if !defined(PS_MEMORY_H)
    2 #define PS_MEMORY_H
     2#    define PS_MEMORY_H
     3
    34/** @file  psMemory.h
    45 *
     
    1415 *  @ingroup MemoryManagement
    1516 *
    16  *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
    17  *  @date $Date: 2004-08-06 22:34:05 $
     17 *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
     18 *  @date $Date: 2004-08-07 00:06:06 $
    1819 *
    1920 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    2021 */
    2122
    22 #include <stdio.h>                      // needed for FILE
    23 #include <stdbool.h>
    24 #include <pthread.h>                    // we need a mutex to make this stuff thread safe.
     23#    include <stdio.h>                     // needed for FILE
     24#    include <stdbool.h>
     25#    include <pthread.h>                   // we need a mutex to make this stuff thread safe.
    2526
    2627/** @addtogroup MemoryManagement
     
    5354
    5455/// typedef for deallocator.
    55 typedef void (*psFreeFcn)(void* ptr);
     56typedef void (*psFreeFcn) (void *ptr);
    5657
    5758/** Book-keeping data for storage allocator.
     
    6263typedef struct psMemBlock
    6364{
    64     const void* startblock;            ///< initialised to p_psMEMMAGIC
    65     struct psMemBlock* previousBlock;  ///< previous block in allocation list
    66     struct psMemBlock* nextBlock;      ///< next block allocation list
    67     psFreeFcn freeFcn;                 ///< deallocator.  If NULL, use generic deallocation.
    68     size_t  userMemorySize;            ///< the size of the user-portion of the memory block
    69     const psMemoryId id;               ///< a unique ID for this allocation
    70     const char* file;                  ///< set from __FILE__ in e.g. p_psAlloc
    71     const int lineno;                  ///< set from __LINE__ in e.g. p_psAlloc
    72     pthread_mutex_t   refCounterMutex; ///< mutex to ensure exclusive access to reference counter
    73     psReferenceCount refCounter;       ///< how many times pointer is referenced
    74     const void* endblock;              ///< initialised to p_psMEMMAGIC
     65    const void *startblock;     // /< initialised to p_psMEMMAGIC
     66    struct psMemBlock *previousBlock;   // /< previous block in allocation list
     67    struct psMemBlock *nextBlock;       // /< next block allocation list
     68    psFreeFcn freeFcn;          // /< deallocator.  If NULL, use generic deallocation.
     69    size_t userMemorySize;      // /< the size of the user-portion of the memory block
     70    const psMemoryId id;        // /< a unique ID for this allocation
     71    const char *file;           // /< set from __FILE__ in e.g. p_psAlloc
     72    const int lineno;           // /< set from __LINE__ in e.g. p_psAlloc
     73    pthread_mutex_t refCounterMutex;    // /< mutex to ensure exclusive access to reference counter
     74    psReferenceCount refCounter;        // /< how many times pointer is referenced
     75    const void *endblock;       // /< initialised to p_psMEMMAGIC
    7576}
    7677psMemBlock;
     
    8182 *  @ingroup memCallback
    8283 */
    83 typedef psMemoryId (*psMemAllocateCallback)(
    84     const psMemBlock *ptr           ///< the psMemBlock just allocated
    85 );
     84typedef psMemoryId(*psMemAllocateCallback) (const psMemBlock * ptr      // /< the psMemBlock just allocated
     85                                           );
    8686
    8787/** prototype of memory free callback used by memory functions
     
    9090 *  @ingroup memCallback
    9191 */
    92 typedef psMemoryId (*psMemFreeCallback)(
    93     const psMemBlock *ptr           ///< the psMemBlock being freed
    94 );
     92typedef psMemoryId(*psMemFreeCallback) (const psMemBlock * ptr  // /< the psMemBlock being freed
     93                                       );
    9594
    9695/** prototype of a callback used in error conditions
     
    101100 *  @ingroup memCallback
    102101 */
    103 typedef void (*psMemProblemCallback)(
    104     const psMemBlock *ptr,          ///< the pointer to the problematic memory block.
    105     const char *file,               ///< the file in which the problem originated
    106     int lineno                      ///< the line number in which the problem originated
    107 );
     102typedef void (*psMemProblemCallback) (const psMemBlock * ptr,   // /< the pointer to the problematic memory
     103                                      // block.
     104                                      const char *file, // /< the file in which the problem originated
     105                                      int lineno        // /< the line number in which the problem originated
     106                                     );
    108107
    109108/** prototype of a callback function used when memory runs out
     
    115114 *  @ingroup memCallback
    116115 */
    117 typedef void *(*psMemExhaustedCallback)(
    118     size_t size                     //< the size of buffer required
    119 );
     116typedef void *(*psMemExhaustedCallback) (size_t size    // < the size of buffer required
     117                                        );
    120118
    121119/** Memory allocation.  This operates much like malloc(), but is guaranteed to return a non-NULL value.
     
    124122 *  @see psFree
    125123 */
    126 #ifdef DOXYGEN
    127 void* psAlloc(
    128     size_t size                     ///< Size required
    129 );
    130 #else
    131 void* p_psAlloc(
    132     size_t size,                    ///< Size required
    133     const char *file,               ///< File of call
    134     int lineno                      ///< Line number of call
    135 );
    136 
    137 void p_psMemSetDeallocator(void* ptr, psFreeFcn freeFcn);
    138 psFreeFcn p_psMemGetDeallocator(void* ptr);
     124#    ifdef DOXYGEN
     125void *psAlloc(size_t size       // /< Size required
     126             );
     127#    else
     128    void *p_psAlloc(size_t size,    // /< Size required
     129                    const char *file,       // /< File of call
     130                    int lineno      // /< Line number of call
     131                   );
     132
     133void p_psMemSetDeallocator(void *ptr, psFreeFcn freeFcn);
     134psFreeFcn p_psMemGetDeallocator(void *ptr);
    139135
    140136/// Memory allocation. psAlloc sends file and line number to p_psAlloc.
    141 #define psAlloc(size) p_psAlloc(size, __FILE__, __LINE__)
    142 #endif
    143 
     137#        define psAlloc(size) p_psAlloc(size, __FILE__, __LINE__)
     138#    endif
    144139
    145140/** Memory re-allocation.  This operates much like realloc(), but is guaranteed to return a non-NULL value.
     
    148143 *  @see psAlloc, psFree
    149144 */
    150 #ifdef DOXYGEN
    151 void* psRealloc(void *ptr               ///< Pointer to re-allocate
    152                 size_t size,            ///< Size required
     145#    ifdef DOXYGEN
     146void *psRealloc(void *ptr       // /< Pointer to re-allocate
     147                size_t size,    // /< Size required
    153148               );
    154 #else
    155 void* p_psRealloc(void *ptr,            ///< Pointer to re-allocate
    156                   size_t size,          ///< Size required
    157                   const char *file,     ///< File of call
    158                   int lineno            ///< Line number of call
     149#    else
     150    void *p_psRealloc(void *ptr,    // /< Pointer to re-allocate
     151                      size_t size,  // /< Size required
     152                      const char *file,     // /< File of call
     153                      int lineno    // /< Line number of call
     154                     );
     155
     156/// Memory re-allocation.  psRealloc sends file and line number to p_psRealloc.
     157#        define psRealloc(ptr, size) p_psRealloc(ptr, size, __FILE__, __LINE__)
     158
     159#    endif
     160
     161/** Free memory.  This operates much like free().
     162 *
     163 *  @see psAlloc, psRealloc
     164 */
     165#    ifdef DOXYGEN
     166void psFree(void *ptr,          // /< Pointer to free, if NULL, function returns immediately.
     167           );
     168#    else
     169    void p_psFree(void *ptr,        // /< Pointer to free
     170                  const char *file, // /< File of call
     171                  int lineno        // /< Line number of call
    159172                 );
    160173
    161 /// Memory re-allocation.  psRealloc sends file and line number to p_psRealloc.
    162 #define psRealloc(ptr, size) p_psRealloc(ptr, size, __FILE__, __LINE__)
    163 
    164 #endif
    165 
    166 
    167 /** Free memory.  This operates much like free().
    168  *
    169  *  @see psAlloc, psRealloc
    170  */
    171 #ifdef DOXYGEN
    172 void psFree(void *ptr,                  ///< Pointer to free, if NULL, function returns immediately.
    173            );
    174 #else
    175 void p_psFree(void *ptr,                ///< Pointer to free
    176               const char *file,         ///< File of call
    177               int lineno                ///< Line number of call
    178              );
    179 
    180174/// Free memory.  psFree sends file and line number to p_psFree.
    181 #define psFree(size) p_psFree(size, __FILE__, __LINE__)
    182 
    183 #endif
     175#        define psFree(size) p_psFree(size, __FILE__, __LINE__)
     176
     177#    endif
    184178
    185179/** Check for memory leaks.  This scans for allocated memory buffers not freed with an ID not less than id0.
     
    197191 *  @ingroup memTracing
    198192 */
    199 int psMemCheckLeaks(
    200     psMemoryId id0,              ///< don't list blocks with id < id0
    201     psMemBlock ***arr,              ///< pointer to array of pointers to leaked blocks, or NULL
    202     FILE *fd                        ///< print list of leaks to fd (or NULL)
    203 );
     193int psMemCheckLeaks(psMemoryId id0,     // /< don't list blocks with id < id0
     194                    psMemBlock *** arr, // /< pointer to array of pointers to leaked blocks, or NULL
     195                    FILE * fd   // /< print list of leaks to fd (or NULL)
     196                   );
    204197
    205198/** Check for memory corruption.  Scans all currently allocated memory buffers and checks for corruptions,
     
    208201 *  @ingroup memTracing
    209202 */
    210 int psMemCheckCorruption(
    211     bool abort_on_error              ///< Abort on detecting corruption?
    212 );
     203int psMemCheckCorruption(bool abort_on_error    // /< Abort on detecting corruption?
     204                        );
    213205
    214206/** Return reference counter
     
    216208 *  @ingroup memRefCount
    217209 */
    218 psReferenceCount psMemGetRefCounter(
    219     void *vptr                      ///< Pointer to get refCounter for
    220 );
     210psReferenceCount psMemGetRefCounter(void *vptr  // /< Pointer to get refCounter for
     211                                   );
    221212
    222213/** Increment reference counter and return the pointer
     
    224215 *  @ingroup memRefCount
    225216 */
    226 #ifdef DOXYGEN
    227 void* psMemIncrRefCounter(
    228     void *vptr                         ///< Pointer to increment refCounter, and return
    229 );
    230 #else
    231 void* p_psMemIncrRefCounter(
    232     void *vptr,                        ///< Pointer to increment refCounter, and return
    233     const char *file,                  ///< File of call
    234     int lineno                         ///< Line number of call
    235 );
    236 #define psMemIncrRefCounter(vptr) p_psMemIncrRefCounter(vptr, __FILE__, __LINE__)
    237 #endif
     217#    ifdef DOXYGEN
     218void *psMemIncrRefCounter(void *vptr    // /< Pointer to increment refCounter, and return
     219                         );
     220#    else
     221    void *p_psMemIncrRefCounter(void *vptr, // /< Pointer to increment refCounter, and return
     222                                const char *file,   // /< File of call
     223                                int lineno  // /< Line number of call
     224                               );
     225
     226#        define psMemIncrRefCounter(vptr) p_psMemIncrRefCounter(vptr, __FILE__, __LINE__)
     227#    endif
    238228
    239229/** Decrement reference counter and return the pointer
     
    241231 *  @ingroup memRefCount
    242232 */
    243 #ifdef DOXYGEN
    244 void* psMemDecrRefCounter(
    245     void *vptr                         ///< Pointer to decrement refCounter, and return
    246 );
    247 #else
    248 void* p_psMemDecrRefCounter(
    249     void *vptr,                        ///< Pointer to decrement refCounter, and return
    250     const char *file,                  ///< File of call
    251     int lineno                         ///< Line number of call
    252 );
    253 #define psMemDecrRefCounter(vptr) p_psMemDecrRefCounter(vptr, __FILE__, __LINE__)
    254 #endif
     233#    ifdef DOXYGEN
     234void *psMemDecrRefCounter(void *vptr    // /< Pointer to decrement refCounter, and return
     235                         );
     236#    else
     237    void *p_psMemDecrRefCounter(void *vptr, // /< Pointer to decrement refCounter, and return
     238                                const char *file,   // /< File of call
     239                                int lineno  // /< Line number of call
     240                               );
     241
     242#        define psMemDecrRefCounter(vptr) p_psMemDecrRefCounter(vptr, __FILE__, __LINE__)
     243#    endif
    255244
    256245/** Set callback for problems
    257246 *  @ingroup memCallback
    258247 */
    259 psMemProblemCallback psMemProblemCallbackSet(
    260     psMemProblemCallback func       ///< Function to run
    261 );
     248psMemProblemCallback psMemProblemCallbackSet(psMemProblemCallback func  // /< Function to run
     249                                            );
    262250
    263251/** Set callback for out-of-memory
     
    265253 *  @ingroup memCallback
    266254 */
    267 psMemExhaustedCallback psMemExhaustedCallbackSet(
    268     psMemExhaustedCallback func     ///< Function to run
    269 );
     255psMemExhaustedCallback psMemExhaustedCallbackSet(psMemExhaustedCallback func    // /< Function to run
     256                                                );
    270257
    271258/** Set call back for when a particular memory block is allocated
     
    273260 *  @ingroup memCallback
    274261 */
    275 psMemAllocateCallback psMemAllocateCallbackSet(
    276     psMemAllocateCallback func          ///< Function to run
    277 );
     262psMemAllocateCallback psMemAllocateCallbackSet(psMemAllocateCallback func       // /< Function to run
     263                                              );
    278264
    279265/** Set call back for when a particular memory block is freed
     
    281267 *  @ingroup memCallback
    282268 */
    283 psMemFreeCallback psMemFreeCallbackSet(
    284     psMemFreeCallback func              ///< Function to run
    285 );
     269psMemFreeCallback psMemFreeCallbackSet(psMemFreeCallback func   // /< Function to run
     270                                      );
    286271
    287272/** get next memory ID
     
    295280 *  @ingroup memCallback
    296281 */
    297 psMemoryId psMemAllocateCallbackSetID(
    298     psMemoryId id                       ///< ID to set
    299 );
     282psMemoryId psMemAllocateCallbackSetID(psMemoryId id     // /< ID to set
     283                                     );
    300284
    301285/** set p_psMemFreeID to id
     
    303287 *  @ingroup memCallback
    304288 */
    305 psMemoryId psMemFreeCallbackSetID(
    306     psMemoryId id                       ///< ID to set
    307 );
     289psMemoryId psMemFreeCallbackSetID(psMemoryId id // /< ID to set
     290                                 );
    308291
    309292//@} End of Memory Management Functions
    310293
    311 #ifndef DOXYGEN
     294#    ifndef DOXYGEN
    312295
    313296/*
    314297 * Ensure that any program using malloc/realloc/free will fail to compile
    315298 */
    316 #ifndef PS_ALLOW_MALLOC
    317 #ifdef __GNUC__
    318 #pragma GCC poison malloc realloc calloc free
    319 #else
    320 #define malloc(S)       _Pragma("error Use of malloc is not allowed.  Use psAlloc instead.")
    321 #define realloc(P,S)    _Pragma("error Use of realloc is not allowed.  Use psRealloc instead.")
    322 #define calloc(S)       _Pragma("error Use of calloc is not allowed.  Use psAlloc instead.")
    323 #define free(P)         _Pragma("error Use of free is not allowed.  Use psFree instead.")
    324 #endif
    325 #endif
    326 
    327 #endif // doxygen skip
    328 
    329 #endif // end of header file
     299#        ifndef PS_ALLOW_MALLOC
     300#            ifdef __GNUC__
     301#                pragma GCC poison malloc realloc calloc free
     302#            else
     303    #                define malloc(S)       _Pragma("error Use of malloc is not allowed.  Use psAlloc instead.")
     304    #                define realloc(P,S)    _Pragma("error Use of realloc is not allowed.  Use psRealloc instead.")
     305    #                define calloc(S)       _Pragma("error Use of calloc is not allowed.  Use psAlloc instead.")
     306    #                define free(P)         _Pragma("error Use of free is not allowed.  Use psFree instead.")
     307    #            endif
     308    #        endif
     309
     310    #    endif
     311    // doxygen skip
     312
     313    #endif // end of header file
  • trunk/psLib/src/sysUtils/psString.c

    r1406 r1407  
     1
    12/** @file  psString.c
    23 *
     
    89 *  @author Eric Van Alst, MHPCC
    910 *   
    10  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2004-08-06 22:34:05 $
     11 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-08-07 00:06:06 $
    1213 *
    1314 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1516
    1617/******************************************************************************/
     18
    1719/*  INCLUDE FILES                                                             */
     20
    1821/******************************************************************************/
    1922#include <stdlib.h>
     
    2427
    2528/******************************************************************************/
     29
    2630/*  DEFINE STATEMENTS                                                         */
     31
    2732/******************************************************************************/
    2833
     
    3035
    3136/******************************************************************************/
     37
    3238/*  TYPE DEFINITIONS                                                          */
     39
    3340/******************************************************************************/
    3441
     
    3643
    3744/*****************************************************************************/
     45
    3846/*  GLOBAL VARIABLES                                                         */
     47
    3948/*****************************************************************************/
    4049
     
    4251
    4352/*****************************************************************************/
     53
    4454/*  FILE STATIC VARIABLES                                                    */
     55
    4556/*****************************************************************************/
    4657
     
    4859
    4960/*****************************************************************************/
     61
    5062/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
     63
    5164/*****************************************************************************/
    5265
     
    5467
    5568/*****************************************************************************/
     69
    5670/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
     71
    5772/*****************************************************************************/
    5873
    59 char *psStringCopy(
    60     const char*  str
    61 )
     74char *psStringCopy(const char *str)
    6275{
    6376    // Allocate memory using psAlloc function
     
    6780}
    6881
    69 char *psStringNCopy(
    70     const char*  str,
    71     int          nChar
    72 )
     82char *psStringNCopy(const char *str, int nChar)
    7383{
    7484    char *returnValue = NULL;
    7585
    7686    // Check the number of characters to copy is non-negative
    77     if ( nChar < 0 ) {
     87    if (nChar < 0) {
    7888        // Log error message and return NULL
    79         psError(__FILE__,"psStringNCopy with negative count specified %d",
    80                 nChar);
     89        psError(__FILE__, "psStringNCopy with negative count specified %d", nChar);
    8190        return NULL;
    8291    }
     
    8493    // Copy input string to memory allocated up to nChar characters
    8594    // Return the copy
    86     returnValue = strncpy(psAlloc((size_t)nChar + 1), str, (size_t)nChar);
     95    returnValue = strncpy(psAlloc((size_t) nChar + 1), str, (size_t) nChar);
    8796
    8897    // Ensure the last byte is NULL character
    89     if ( nChar > 0 ) {
    90         returnValue[nChar-1] = '\0';
     98    if (nChar > 0) {
     99        returnValue[nChar - 1] = '\0';
    91100    }
    92 
    93101    // Return the string pointer
    94102    return returnValue;
    95103}
    96 
    97 
  • trunk/psLib/src/sysUtils/psString.h

    r974 r1407  
     1
    12/** @file  psString.h
    23 *
     
    1011 *  @author Eric Van Alst, MHPCC
    1112 *
    12  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-06-10 01:58:06 $
     13 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-08-07 00:06:06 $
    1415 *
    1516 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1718
    1819#ifndef PS_STRING_H
    19 #define PS_STRING_H
     20#    define PS_STRING_H
    2021
    2122/******************************************************************************/
     23
    2224/*  DEFINE STATEMENTS                                                         */
     25
    2326/******************************************************************************/
    2427
    2528/** This macro will convert the arguement to a quoted string */
    26 #define PS_STRING(S)  #S
     29#    define PS_STRING(S)  #S
    2730
    2831/******************************************************************************/
     32
    2933/*  TYPE DEFINITIONS                                                          */
     34
    3035/******************************************************************************/
    3136
     
    3338
    3439/*****************************************************************************/
     40
    3541/* FUNCTION PROTOTYPES                                                       */
     42
    3643/*****************************************************************************/
    3744
    3845// Doxygen group tags
     46
    3947/** @addtogroup SysUtils
    4048 *  @{
     
    4957 *
    5058 */
    51 char *psStringCopy(
    52     const char *str      /**< Input string of characters to copy */
    53 );
    5459
     60char *psStringCopy(const char *str
     61                   /**< Input string of characters to copy */
     62                  );
    5563
    5664/** Copies the input string up to the specified number of characters
     
    6775 *
    6876 */
     77
    6978/*@null@*/
    70 char *psStringNCopy(
    71     const char *str,    /**< Input string of characters to copy */
    72     int        nChar    /**< Number of bytes to allocate for string copy */
    73 );
    7479
    75 /* @} */  // Doxygen - End of SystemGroup Functions
     80char *psStringNCopy(const char *str,
     81                    /**< Input string of characters to copy */
     82
     83                    int nChar
     84                    /**< Number of bytes to allocate for string copy */
     85                   );
     86
     87/* @} */// Doxygen - End of SystemGroup Functions
    7688
    7789#endif
    78 
  • trunk/psLib/src/sysUtils/psTrace.c

    r1406 r1407  
     1
    12/** @file psTrace.c
    23 *  \brief basic run-time trace facilities
     
    910 *  @author George Gusciora, MHPCC
    1011 *
    11  *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-08-06 22:34:05 $
     12 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-08-07 00:06:06 $
    1314 *
    1415 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1516 */
     17
    1618/*****************************************************************************
    1719    NOTES:
     
    3436#ifndef PS_NO_TRACE
    3537
    36 #include <stdlib.h>
    37 #include <stdio.h>
    38 #include <string.h>
    39 #include <stdarg.h>
    40 #include "psMemory.h"
    41 #include "psTrace.h"
    42 #include "psString.h"
    43 #include "psError.h"
    44 
    45 static p_psComponent *p_psCroot = NULL;       // The root of the trace component
    46 static FILE *p_psTraceFP = NULL;          // File destination for messages.
    47 
    48 static void componentFree(p_psComponent *comp);
    49 static p_psComponent *componentAlloc(const char *name,int level);
     38#    include <stdlib.h>
     39#    include <stdio.h>
     40#    include <string.h>
     41#    include <stdarg.h>
     42#    include "psMemory.h"
     43#    include "psTrace.h"
     44#    include "psString.h"
     45#    include "psError.h"
     46
     47static p_psComponent *p_psCroot = NULL; // The root of the trace component
     48static FILE *p_psTraceFP = NULL;        // File destination for messages.
     49
     50static void componentFree(p_psComponent * comp);
     51static p_psComponent *componentAlloc(const char *name, int level);
    5052
    5153/*****************************************************************************
    5254componentAlloc(): allocate memory for a new node, and initialize members.
    5355 *****************************************************************************/
    54 static p_psComponent *componentAlloc(const char *name,
    55                                      int level)
     56static p_psComponent *componentAlloc(const char *name, int level)
    5657{
    5758    p_psComponent *comp = psAlloc(sizeof(p_psComponent));
    58     p_psMemSetDeallocator(comp,(psFreeFcn)componentFree);
     59
     60    p_psMemSetDeallocator(comp, (psFreeFcn) componentFree);
    5961    comp->name = psStringCopy(name);
    6062    comp->level = level;
     
    6466}
    6567
    66 
    6768/*****************************************************************************
    6869componentFree(): free the current node in the root tree, and all children
    6970nodes as well.
    7071 *****************************************************************************/
    71 static void componentFree(p_psComponent *comp)
     72static void componentFree(p_psComponent * comp)
    7273{
    7374    if (comp == NULL) {
     
    8586}
    8687
    87 
    8888/*****************************************************************************
    8989initTrace(): simply initialize the component root tree.
     
    9696}
    9797
    98 
    9998/*****************************************************************************
    10099Set all trace levels to zero.
    101100 *****************************************************************************/
    102 void p_psTraceReset(p_psComponent *currentNode)
     101void p_psTraceReset(p_psComponent * currentNode)
    103102{
    104103    int i = 0;
     
    109108
    110109    currentNode->level = 0;
    111     for (i=0;i<currentNode->n;i++) {
     110    for (i = 0; i < currentNode->n; i++) {
    112111        if (NULL == currentNode->subcomp[i]) {
    113112            psError(__func__,
    114                     "Sub-component %d of node %s in the trace tree is NULL.\n",
    115                     i, currentNode->name);
     113                    "Sub-component %d of node %s in the trace tree is NULL.\n", i, currentNode->name);
    116114        } else {
    117115            p_psTraceReset(currentNode->subcomp[i]);
     
    129127}
    130128
    131 
    132129/*****************************************************************************
    133130Free all nodes in the component tree.
     
    137134    psFree(p_psCroot);
    138135}
    139 
    140136
    141137/*****************************************************************************
     
    145141to ANSI-C.
    146142 *****************************************************************************/
    147 static void componentAdd(const char *addNodeName,
    148                          int         level)
    149 {
    150     int        i = 0;                         // Loop index variable.
    151     char       name[strlen(addNodeName) + 1]; // buffer for writeable copy.
    152     char      *pname=name;
    153     char      *firstComponent = NULL;       // first component of name
     143static void componentAdd(const char *addNodeName, int level)
     144{
     145    int i = 0;                  // Loop index variable.
     146    char name[strlen(addNodeName) + 1]; // buffer for writeable copy.
     147    char *pname = name;
     148    char *firstComponent = NULL;        // first component of name
    154149    p_psComponent *currentNode = p_psCroot;
    155     int        nodeExists = 0;
    156 
    157     // Is this the root node?  If so, simply set level and return.
     150    int nodeExists = 0;
     151
     152    // Is this the root node? If so, simply set level and return.
    158153    if (strcmp(".", addNodeName) == 0) {
    159154        p_psCroot->level = level;
     
    162157
    163158    if (addNodeName[0] != '.') {
    164         printf("ERROR: failed to add %s to the root component tree.\n",
    165                addNodeName);
     159        printf("ERROR: failed to add %s to the root component tree.\n", addNodeName);
    166160        exit(1);
    167161    }
     
    188182        if (nodeExists == 0) {
    189183            currentNode->subcomp = psRealloc(currentNode->subcomp,
    190                                              (currentNode->n + 1) * sizeof(p_psComponent*));
    191             currentNode->n = (currentNode->n)+1;
    192 
    193             currentNode->subcomp[(currentNode->n)-1] =
    194                 componentAlloc(firstComponent, level);
    195         }
    196     }
    197 }
    198 
     184                                             (currentNode->n + 1) * sizeof(p_psComponent *));
     185            currentNode->n = (currentNode->n) + 1;
     186
     187            currentNode->subcomp[(currentNode->n) - 1] = componentAlloc(firstComponent, level);
     188        }
     189    }
     190}
    199191
    200192/*****************************************************************************
     
    210202*****************************************************************************/
    211203int psTraceSetLevel(const char *comp,   // component of interest
    212                     int level)          // desired trace level
     204                    int level)  // desired trace level
    213205{
    214206    // If the root component tree does not exist, then initialize it.
     
    216208        initTrace();
    217209    }
    218 
    219210    // Add the new component to the component tree.
    220211    componentAdd(comp, level);
     
    223214    return 0;
    224215}
    225 
    226216
    227217/*****************************************************************************
     
    241231static int doGetTraceLevel(const char *aname)
    242232{
    243     char       name[strlen(aname) + 1]; // need a writeable copy: for strsep()
    244     char      *pname=name;
    245     char      *firstComponent = NULL;   // first component of name
     233    char name[strlen(aname) + 1];      // need a writeable copy: for strsep()
     234    char *pname = name;
     235    char *firstComponent = NULL;        // first component of name
    246236    p_psComponent *currentNode = p_psCroot;
    247     int        i = 0;
     237    int i = 0;
    248238
    249239    if (NULL == currentNode) {
    250         return(PS_UNKNOWN_TRACE_LEVEL);
     240        return (PS_UNKNOWN_TRACE_LEVEL);
    251241    }
    252242
    253243    if (strcmp(".", aname) == 0) {
    254         return(p_psCroot->level);
     244        return (p_psCroot->level);
    255245    }
    256246
    257247    if (aname[0] != '.') {
    258         return(PS_UNKNOWN_TRACE_LEVEL);
     248        return (PS_UNKNOWN_TRACE_LEVEL);
    259249    }
    260250
     
    266256            if (NULL == currentNode->subcomp[i]) {
    267257                psError(__func__,
    268                         "Sub-component %d of node %s in trace tree is NULL.\n",
    269                         i, currentNode->name);
     258                        "Sub-component %d of node %s in trace tree is NULL.\n", i, currentNode->name);
    270259            }
    271260
     
    273262                currentNode = currentNode->subcomp[i];
    274263                if (pname == NULL) {
    275                     return(currentNode->level);
     264                    return (currentNode->level);
    276265                }
    277266            }
    278267        }
    279268    }
    280     return(PS_UNKNOWN_TRACE_LEVEL);
    281 }
    282 
     269    return (PS_UNKNOWN_TRACE_LEVEL);
     270}
    283271
    284272/*****************************************************************************
     
    297285{
    298286    if (p_psCroot == NULL) {
    299         return(PS_UNKNOWN_TRACE_LEVEL);
    300     }
    301 
     287        return (PS_UNKNOWN_TRACE_LEVEL);
     288    }
    302289    // Search the component root tree, determine the trace level.
    303     return(doGetTraceLevel(name));
    304 }
    305 
     290    return (doGetTraceLevel(name));
     291}
    306292
    307293/*****************************************************************************
     
    317303 null
    318304 *****************************************************************************/
    319 static void doPrintTraceLevels(const p_psComponent *comp,
    320                                int depth)
     305static void doPrintTraceLevels(const p_psComponent * comp, int depth)
    321306{
    322307    int i = 0;
     
    327312    } else {
    328313        if (comp->level == PS_UNKNOWN_TRACE_LEVEL) {
    329             printf("%*s%-*s %s\n", depth, "", 20 - depth,
    330                    comp->name, ".");
     314            printf("%*s%-*s %s\n", depth, "", 20 - depth, comp->name, ".");
    331315        } else {
    332             printf("%*s%-*s %d\n", depth, "", 20 - depth,
    333                    comp->name, comp->level);
     316            printf("%*s%-*s %d\n", depth, "", 20 - depth, comp->name, comp->level);
    334317        }
    335318    }
    336319
    337320    for (i = 0; i < comp->n; i++) {
    338         doPrintTraceLevels(comp->subcomp[i], depth+1);
    339     }
    340 }
    341 
     321        doPrintTraceLevels(comp->subcomp[i], depth + 1);
     322    }
     323}
    342324
    343325/*****************************************************************************
     
    359341    doPrintTraceLevels(p_psCroot, 0);
    360342}
    361 
    362343
    363344/*****************************************************************************
     
    376357 *****************************************************************************/
    377358void p_psTrace(const char *comp,        // component being traced
    378                int level,               // desired trace level
    379                ...)                     // arguments
     359               int level,       // desired trace level
     360               ...)             // arguments
    380361{
    381362    char *fmt = NULL;
     
    384365
    385366    if (NULL == comp) {
    386         psError(__func__,
    387                 "p_psTrace() called on a NULL trace level tree\n");
    388     }
    389 
     367        psError(__func__, "p_psTrace() called on a NULL trace level tree\n");
     368    }
    390369    // Only display this message if it's trace level is less than the level
    391370    // of it's associatedcomponent.
     
    413392        va_end(ap);
    414393    }
    415 
    416     // NOTE: should we free *fmt as well?  Read the man page.
    417 }
    418 
    419 void psTraceSetDestination(FILE *fp)
     394    // NOTE: should we free *fmt as well? Read the man page.
     395}
     396
     397void psTraceSetDestination(FILE * fp)
    420398{
    421399    p_psTraceFP = fp;
  • trunk/psLib/src/sysUtils/psTrace.h

    r1393 r1407  
     1
    12/** @file psTrace.h
    23 *  \brief basic run-time trace facilities
     
    910 *  @author George Gusciora, MHPCC
    1011 *
    11  *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-08-05 19:38:52 $
     12 *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-08-07 00:06:06 $
    1314 *
    1415 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1516 */
    1617#if !defined(PS_TRACE_H)
    17 #define PS_TRACE_H 1
     18#    define PS_TRACE_H 1
    1819
    19 #define PS_UNKNOWN_TRACE_LEVEL -9999         // we don't know this name's level
    20 #define PS_DEFAULT_TRACE_LEVEL 0
    21 
     20#    define PS_UNKNOWN_TRACE_LEVEL -9999   // we don't know this name's level
     21#    define PS_DEFAULT_TRACE_LEVEL 0
    2222
    2323/** \addtogroup LogTrace
     
    2929//#define PS_NO_TRACE 1   ///< to turn off all tracing
    3030
    31 #if defined(PS_NO_TRACE)
    32 #define psTrace(facil, level, ...) (void)0 /* do nothing */
    33 #define p_psTrace(facil, level, ...)  (void)0 /* do nothing */
    34 #define psTraceSetLevel(facil,level) 0
    35 #define psTraceGetLevel(facil) 0
    36 #define psTraceReset() (void)0 /* do nothing */
    37 #define psTraceFree() (void)0 /* do nothing */
    38 #define psTracePrintLevels() (void)0 /* do nothing */
    39 #define psTraceSetDestination(fp) (void)0 /* do nothing */
    40 #else
     31#    if defined(PS_NO_TRACE)
     32    #        define psTrace(facil, level, ...) (void)0
     33    /* do nothing */
     34    #        define p_psTrace(facil, level, ...)  (void)0
     35    /* do nothing */
     36    #        define psTraceSetLevel(facil,level) 0
     37    #        define psTraceGetLevel(facil) 0
     38    #        define psTraceReset() (void)0     /* do nothing */
     39    #        define psTraceFree() (void)0      /* do nothing */
     40    #        define psTracePrintLevels() (void)0
     41    /* do nothing */
     42    #        define psTraceSetDestination(fp) (void)0
     43    /* do nothing */
     44    #    else
    4145
    42 /** Basic structure for the component tree.  A component is a string of the
    43     form aaa.bbb.ccc, and may itself contain further subcomponents.  The
    44     Component structure doesn't in fact contain it's full name, but only the
    45     last part. */
    46 typedef struct p_psComponent
    47 {
    48     const char *name;                     // last part of name of component
    49     int level;                            // trace level for this component
    50     int n;                                // number of subcomponents
    51     struct p_psComponent **subcomp;           // next level of subcomponents
    52 }
     46        /** Basic structure for the component tree.  A component is a string of the
     47            form aaa.bbb.ccc, and may itself contain further subcomponents.  The
     48            Component structure doesn't in fact contain it's full name, but only the
     49            last part. */
     50        typedef struct p_psComponent
     51        {
     52            const char *name;           // last part of name of component
     53            int level;                  // trace level for this component
     54            int n;                      // number of subcomponents
     55            struct p_psComponent **subcomp;     // next level of subcomponents
     56        }
    5357p_psComponent;
    5458
    55 #ifndef DOXYGEN
     59#        ifndef DOXYGEN
    5660/// Send a trace message
    57 void p_psTrace(const char *facil,  ///< facilty of interest
    58                int myLevel,  ///< desired trace level
    59                ...)   ///< trace message arguments
     61void p_psTrace(const char *facil,       // /< facilty of interest
     62               int myLevel,     // /< desired trace level
     63               ...)             // /< trace message arguments
    6064;
    61 #endif
     65#        endif
    6266
    6367/// Set trace level
    64 int psTraceSetLevel(const char *facil, ///< facilty of interest
    65                     int level)  ///< desired trace level
     68int psTraceSetLevel(const char *facil,     // /< facilty of interest
     69                    int level)     // /< desired trace level
    6670;
    6771
    6872/// Get the trace level
    69 int psTraceGetLevel(const char *facil) ///< facilty of interest
     73int psTraceGetLevel(const char *facil)     // /< facilty of interest
    7074;
    7175
    7276/// Set all trace levels to zero (do not free nodes in the component tree).
    73 void psTraceReset()
    74 ;
     77void psTraceReset();
    7578
    7679/// Free all nodes in the component tree.
    77 void psTraceFree()
    78 ;
     80void psTraceFree();
    7981
    8082/// print trace levels
    81 void psTracePrintLevels(void)
    82 ;
     83void psTracePrintLevels(void);
    8384
    8485/// Set the destination of future trace messages.
    85 void psTraceSetDestination(FILE *fp);
     86void psTraceSetDestination(FILE * fp);
    8687
     88/* \} */// End of SystemGroup Functions
    8789
    88 /* \} */ // End of SystemGroup Functions
    89 
    90 #define psTrace(facil, level, ...) p_psTrace(facil, level, __VA_ARGS__)
    91 #endif
     90#        define psTrace(facil, level, ...) p_psTrace(facil, level, __VA_ARGS__)
     91#    endif
    9292
    9393#endif
    94 
  • trunk/psLib/src/sysUtils/psType.h

    r1385 r1407  
     1
    12/** @file  psType.h
    23*
     
    1011*  @author Ross Harman, MHPCC
    1112*
    12 *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2004-08-04 23:37:39 $
     13*  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
     14*  @date $Date: 2004-08-07 00:06:06 $
    1415*
    1516*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1718
    1819#ifndef PS_TYPE_H
    19 #define PS_TYPE_H
     20#    define PS_TYPE_H
    2021
    21 #include <complex.h>
    22 #include <stdint.h>
    23 #include <float.h>
     22#    include <complex.h>
     23#    include <stdint.h>
     24#    include <float.h>
    2425
    2526/// @addtogroup DataContainer
     
    2728
    2829/******************************************************************************/
     30
    2931/*  TYPE DEFINITIONS                                                          */
     32
    3033/******************************************************************************/
    3134
     
    3740 */
    3841
    39 typedef uint8_t psU8;           ///< 8-bit unsigned int
    40 typedef uint16_t psU16;          ///< 16-bit unsigned int
    41 typedef uint32_t psU32;          ///< 32-bit unsigned int
    42 typedef uint64_t psU64;          ///< 64-bit unsigned int
    43 typedef int8_t psS8;           ///< 8-bit signed int
    44 typedef int16_t psS16;          ///< 16-bit signed int
    45 typedef int32_t psS32;          ///< 32-bit signed int
    46 typedef int64_t psS64;          ///< 64-bit signed int
    47 typedef float psF32;          ///< 32-bit floating point
    48 typedef double psF64;          ///< 64-bit floating point
    49 typedef complex float psC32;          ///< complex with 32-bit floating point Real and Imagary numbers
    50 typedef complex double psC64;          ///< complex with 64-bit floating point Real and Imagary numbers
    51 typedef void* psPTR;           ///< void pointer
    52 
     42typedef uint8_t psU8;           // /< 8-bit unsigned int
     43typedef uint16_t psU16;         // /< 16-bit unsigned int
     44typedef uint32_t psU32;         // /< 32-bit unsigned int
     45typedef uint64_t psU64;         // /< 64-bit unsigned int
     46typedef int8_t psS8;            // /< 8-bit signed int
     47typedef int16_t psS16;          // /< 16-bit signed int
     48typedef int32_t psS32;          // /< 32-bit signed int
     49typedef int64_t psS64;          // /< 64-bit signed int
     50typedef float psF32;            // /< 32-bit floating point
     51typedef double psF64;           // /< 64-bit floating point
     52typedef complex float psC32;    // /< complex with 32-bit floating point Real and Imagary numbers
     53typedef complex double psC64;   // /< complex with 64-bit floating point Real and Imagary numbers
     54typedef void *psPTR;            // /< void pointer
    5355
    5456typedef enum {
    55     PS_TYPE_S8 = 0x0101,   ///< Character.
    56     PS_TYPE_S16 = 0x0102,   ///< Short integer.
    57     PS_TYPE_S32 = 0x0104,   ///< Integer.
    58     PS_TYPE_S64 = 0x0108,   ///< Long integer.
    59     PS_TYPE_U8 = 0x0301,   ///< Unsigned character.
    60     PS_TYPE_U16 = 0x0302,   ///< Unsigned short integer.
    61     PS_TYPE_U32 = 0x0304,   ///< Unsigned integer.
    62     PS_TYPE_U64 = 0x0308,   ///< Unsigned long integer.
    63     PS_TYPE_F32 = 0x0404,   ///< Single-precision Floating point.
    64     PS_TYPE_F64 = 0x0408,   ///< Double-precision floating point.
    65     PS_TYPE_C32 = 0x0808,   ///< Complex numbers consisting of single-precision floating point.
    66     PS_TYPE_C64 = 0x0810,   ///< Complex numbers consisting of double-precision floating point.
    67     PS_TYPE_PTR = 0x0000   ///< Something else that's not supported for arithmetic.
     57    PS_TYPE_S8 = 0x0101,        // /< Character.
     58    PS_TYPE_S16 = 0x0102,                  // /< Short integer.
     59    PS_TYPE_S32 = 0x0104,                  // /< Integer.
     60    PS_TYPE_S64 = 0x0108,                  // /< Long integer.
     61    PS_TYPE_U8 = 0x0301,                   // /< Unsigned character.
     62    PS_TYPE_U16 = 0x0302,                  // /< Unsigned short integer.
     63    PS_TYPE_U32 = 0x0304,                  // /< Unsigned integer.
     64    PS_TYPE_U64 = 0x0308,                  // /< Unsigned long integer.
     65    PS_TYPE_F32 = 0x0404,                  // /< Single-precision Floating point.
     66    PS_TYPE_F64 = 0x0408,                  // /< Double-precision floating point.
     67    PS_TYPE_C32 = 0x0808,                  // /< Complex numbers consisting of single-precision floating
     68    // point.
     69    PS_TYPE_C64 = 0x0810,                  // /< Complex numbers consisting of double-precision floating
     70    // point.
     71    PS_TYPE_PTR = 0x0000                   // /< Something else that's not supported for arithmetic.
    6872} psElemType;
    6973
    70 #define PS_TYPE_MASK PS_TYPE_U8         ///< the psElemType to use for mask image
    71 #define PS_TYPE_MASK_DATA U8            ///< the data member to use for mask image
    72 #define PS_TYPE_MASK_NAME "psU8"
    73 typedef psU8 psMaskType;                ///< the C datatype for a mask image
     74#    define PS_TYPE_MASK PS_TYPE_U8        // /< the psElemType to use for mask image
     75#    define PS_TYPE_MASK_DATA U8           // /< the data member to use for mask image
     76#    define PS_TYPE_MASK_NAME "psU8"
     77typedef psU8 psMaskType;        // /< the C datatype for a mask image
    7478
    75 #define PS_MIN_S8        INT8_MIN
    76 #define PS_MIN_S16       INT16_MIN
    77 #define PS_MIN_S32       INT32_MIN
    78 #define PS_MIN_S64       INT64_MIN
    79 #define PS_MIN_U8        0
    80 #define PS_MIN_U16       0
    81 #define PS_MIN_U32       0
    82 #define PS_MIN_U64       0
    83 #define PS_MIN_F32       -FLT_MAX
    84 #define PS_MIN_F64       -DBL_MAX
    85 #define PS_MIN_C32       -FLT_MAX
    86 #define PS_MIN_C64       -DBL_MAX
     79#    define PS_MIN_S8        INT8_MIN
     80#    define PS_MIN_S16       INT16_MIN
     81#    define PS_MIN_S32       INT32_MIN
     82#    define PS_MIN_S64       INT64_MIN
     83#    define PS_MIN_U8        0
     84#    define PS_MIN_U16       0
     85#    define PS_MIN_U32       0
     86#    define PS_MIN_U64       0
     87#    define PS_MIN_F32       -FLT_MAX
     88#    define PS_MIN_F64       -DBL_MAX
     89#    define PS_MIN_C32       -FLT_MAX
     90#    define PS_MIN_C64       -DBL_MAX
    8791
    88 #define PS_MAX_S8        INT8_MAX
    89 #define PS_MAX_S16       INT16_MAX
    90 #define PS_MAX_S32       INT32_MAX
    91 #define PS_MAX_S64       INT64_MAX
    92 #define PS_MAX_U8        UINT8_MAX
    93 #define PS_MAX_U16       UINT16_MAX
    94 #define PS_MAX_U32       UINT32_MAX
    95 #define PS_MAX_U64       UINT64_MAX
    96 #define PS_MAX_F32       FLT_MAX
    97 #define PS_MAX_F64       DBL_MAX
    98 #define PS_MAX_C32       FLT_MAX
    99 #define PS_MAX_C64       DBL_MAX
     92#    define PS_MAX_S8        INT8_MAX
     93#    define PS_MAX_S16       INT16_MAX
     94#    define PS_MAX_S32       INT32_MAX
     95#    define PS_MAX_S64       INT64_MAX
     96#    define PS_MAX_U8        UINT8_MAX
     97#    define PS_MAX_U16       UINT16_MAX
     98#    define PS_MAX_U32       UINT32_MAX
     99#    define PS_MAX_U64       UINT64_MAX
     100#    define PS_MAX_F32       FLT_MAX
     101#    define PS_MAX_F64       DBL_MAX
     102#    define PS_MAX_C32       FLT_MAX
     103#    define PS_MAX_C64       DBL_MAX
    100104
    101105/// Macro to get the bad pixel reason code (stored as part of mask value)
    102 #define PS_BADPIXEL_BITMASK 0x0f
    103 #define PS_GET_BADPIXEL(maskValue) (maskValue & PS_BADPIXEL_BITMASK)
     106#    define PS_BADPIXEL_BITMASK 0x0f
     107#    define PS_GET_BADPIXEL(maskValue) (maskValue & PS_BADPIXEL_BITMASK)
    104108
    105 #define PS_IS_BADPIXEL(maskValue) (PS_GET_BADPIXEL(maskValue) != 0)
     109#    define PS_IS_BADPIXEL(maskValue) (PS_GET_BADPIXEL(maskValue) != 0)
    106110
    107111/// Macro to apply a bad pixel reason code to mask image
    108 #define PS_SET_BADPIXEL(maskValue, reasonCode) \
     112#    define PS_SET_BADPIXEL(maskValue, reasonCode) \
    109113{ \
    110114    maskValue = (psMaskType)((reasonCode & PS_BADPIXEL_BITMASK) | (maskValue & ~PS_BADPIXEL_BITMASK)); \
     
    112116
    113117/// Macro to determine if the psElemType is an integer.
    114 #define PS_IS_PSELEMTYPE_INT(x) ((x & 0x100) == 0x100)
     118#    define PS_IS_PSELEMTYPE_INT(x) ((x & 0x100) == 0x100)
    115119/// Macro to determine if the psElemType is unsigned.
    116 #define PS_IS_PSELEMTYPE_UNSIGNED(x) ((x & 0x200) == 0x200)
     120#    define PS_IS_PSELEMTYPE_UNSIGNED(x) ((x & 0x200) == 0x200)
    117121/// Macro to determine if the psElemType is a real (non-complex) floating-point type.
    118 #define PS_IS_PSELEMTYPE_REAL(x) ((x & 0x400) == 0x400)
     122#    define PS_IS_PSELEMTYPE_REAL(x) ((x & 0x400) == 0x400)
    119123/// Macro to determine if the psElemType is complex number type.
    120 #define PS_IS_PSELEMTYPE_COMPLEX(x) ((x & 0x800) == 0x800)
     124#    define PS_IS_PSELEMTYPE_COMPLEX(x) ((x & 0x800) == 0x800)
    121125/// Macro to determine the storage size, in bytes, of the psElemType.
    122 #define PSELEMTYPE_SIZEOF(x) ( (x==PS_TYPE_PTR) ? sizeof(void*) :(x & 0xFF) )
     126#    define PSELEMTYPE_SIZEOF(x) ( (x==PS_TYPE_PTR) ? sizeof(void*) :(x & 0xFF) )
    123127
    124128/** Dimensions of a data type.
     
    128132 */
    129133typedef enum {
    130     PS_DIMEN_SCALAR,     ///< Scalar.
    131     PS_DIMEN_VECTOR,     ///< Vector.
    132     PS_DIMEN_TRANSV,     ///< Transposed vector.
    133     PS_DIMEN_IMAGE,      ///< Image.
    134     PS_DIMEN_OTHER      ///< Something else that's not supported for arithmetic.
     134    PS_DIMEN_SCALAR,            // /< Scalar.
     135    PS_DIMEN_VECTOR,            // /< Vector.
     136    PS_DIMEN_TRANSV,            // /< Transposed vector.
     137    PS_DIMEN_IMAGE,             // /< Image.
     138    PS_DIMEN_OTHER              // /< Something else that's not supported for arithmetic.
    135139} psDimen;
    136140
     
    143147typedef struct
    144148{
    145     psElemType type;    ///< Primitive type.
    146     psDimen dimen;      ///< Dimensionality.
     149    psElemType type;            // /< Primitive type.
     150    psDimen dimen;              // /< Dimensionality.
    147151}
    148152psType;
Note: See TracChangeset for help on using the changeset viewer.