IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 11674


Ignore:
Timestamp:
Feb 6, 2007, 3:15:50 PM (19 years ago)
Author:
jhoblitt
Message:

change psFree() macro to *NOT* cast all pointers to (void *)
change psFree() macro to not append a ';' to the line
change all psMemory functions to pass file, lineno, func as the first 3 params

Location:
trunk/psLib/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/astro/psEarthOrientation.c

    r11618 r11674  
    88 *  @author Robert Daniel DeSonia, MHPCC
    99 *
    10  *  @version $Revision: 1.44 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2007-02-03 06:01:42 $
     10 *  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2007-02-07 01:15:49 $
    1212 *
    1313 *  Copyright 2005 Maui High Performance Computing Center, University of Hawaii
     
    333333        psFree(directionVector);
    334334        psFree(actualVector);
    335         psFree(apparent)
     335        psFree(apparent);
    336336        return NULL;
    337337    } else {
  • trunk/psLib/src/math/psHistogram.c

    r10999 r11674  
    55 *  @author GLG (MHPCC), EAM (IfA)
    66 *
    7  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2007-01-09 22:38:53 $
     7 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2007-02-07 01:15:49 $
    99 *
    1010 *  Copyright 2006 IfA, University of Hawaii
     
    127127static void histogramFree(psHistogram* myHist)
    128128{
    129     psFree(myHist->bounds);
     129    psFree((void *)myHist->bounds);
    130130    psFree(myHist->nums);
    131131}
  • trunk/psLib/src/math/psMinimizePolyFit.c

    r10999 r11674  
    1010 *  @author EAM, IfA
    1111 *
    12  *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2007-01-09 22:38:53 $
     12 *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2007-02-07 01:15:49 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    12211221        if (!psVectorFitPolynomial2D(poly, mask, maskValue, f, fErr, x, y)) {
    12221222            psError(PS_ERR_UNKNOWN, false, "Could not fit a polynomial to the data.  Returning false.\n");
    1223             psFree(resid)
     1223            psFree(resid);
    12241224            return false;
    12251225        }
     
    12281228        if (fit == NULL) {
    12291229            psError(PS_ERR_UNKNOWN, false, "Could not call psPolynomial3DEvalVector().  Returning NULL.\n");
    1230             psFree(resid)
     1230            psFree(resid);
    12311231            return false;
    12321232        }
     
    12531253        if (!psVectorStats(stats, resid, NULL, mask, maskValue)) {
    12541254            psError(PS_ERR_UNKNOWN, false, "Could not compute statistics on the resid vector.  Returning NULL.\n");
    1255             psFree(resid)
    1256             psFree(fit)
     1255            psFree(resid);
     1256            psFree(fit);
    12571257            return false;
    12581258        }
     
    16701670        if (!psVectorFitPolynomial3D(poly, mask, maskValue, f, fErr, x, y, z)) {
    16711671            psError(PS_ERR_UNKNOWN, false, "Could not fit a polynomial to the data.  Returning NULL.\n");
    1672             psFree(resid)
     1672            psFree(resid);
    16731673            return false;
    16741674        }
     
    16761676        if (fit == NULL) {
    16771677            psError(PS_ERR_UNKNOWN, false, "Could not call psPolynomial3DEvalVector().  Returning NULL.\n");
    1678             psFree(resid)
     1678            psFree(resid);
    16791679            return false;
    16801680        }
     
    17001700        if (!psVectorStats(stats, resid, NULL, mask, maskValue)) {
    17011701            psError(PS_ERR_UNKNOWN, false, "Could not compute statistics on the resid vector.  Returning NULL.\n");
    1702             psFree(resid)
    1703             psFree(fit)
     1702            psFree(resid);
     1703            psFree(fit);
    17041704            return false;
    17051705        }
     
    21442144        if (!psVectorFitPolynomial4D (poly, mask, maskValue, f, fErr, x, y, z, t)) {
    21452145            psError(PS_ERR_UNKNOWN, false, "Could not fit a polynomial to the data.  Returning NULL.\n");
    2146             psFree(resid)
     2146            psFree(resid);
    21472147            return false;
    21482148        }
     
    21512151        if (fit == NULL) {
    21522152            psError(PS_ERR_UNKNOWN, false, "Could not call psPolynomial4DEvalVector().  Returning NULL.\n");
    2153             psFree(resid)
     2153            psFree(resid);
    21542154            return false;
    21552155        }
     
    21752175        if (!psVectorStats (stats, resid, NULL, mask, maskValue)) {
    21762176            psError(PS_ERR_UNKNOWN, false, "Could not compute statistics on the resid vector.  Returning NULL.\n");
    2177             psFree(resid)
    2178             psFree(fit)
     2177            psFree(resid);
     2178            psFree(fit);
    21792179            return false;
    21802180        }
  • trunk/psLib/src/math/psPolynomialUtils.c

    r10999 r11674  
    8888        if (fit == NULL) {
    8989            psError(PS_ERR_UNKNOWN, false, "Could not call psPolynomial4DEvalVector().  Returning NULL.\n");
    90             psFree(resid)
     90            psFree(resid);
    9191            return false;
    9292        }
  • trunk/psLib/src/sys/psError.c

    r11617 r11674  
    1111 *  @author Eric Van Alst, MHPCC
    1212 *
    13  *  @version $Revision: 1.43 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2007-02-03 05:54:08 $
     13 *  @version $Revision: 1.44 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2007-02-07 01:15:49 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    249249psErrorCode psErrorCodeLast(void)
    250250{
    251     const psErr *err = psErrorGet(0);
     251    psErr *err = psErrorGet(0);
    252252    psErrorCode code = err->code;
    253253    psFree(err);
  • trunk/psLib/src/sys/psError.h

    r11668 r11674  
    1111 *  @author Eric Van Alst, MHPCC
    1212 *
    13  *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2007-02-06 21:36:09 $
     13 *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2007-02-07 01:15:49 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    4040psErr;
    4141
     42
    4243/** Get a error from the error stack
    4344 *
  • trunk/psLib/src/sys/psMemory.c

    r11672 r11674  
    1010*  @author Joshua Hoblitt, University of Hawaii
    1111*
    12 *  @version $Revision: 1.93 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2007-02-07 00:36:02 $
     12*  @version $Revision: 1.94 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2007-02-07 01:15:49 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    355355}
    356356
    357 int p_psMemCheckCorruption(FILE *output,
    358                            bool abort_on_error,
    359                            const char *file,
     357int p_psMemCheckCorruption(const char *file,
    360358                           unsigned int lineno,
    361                            const char *func)
     359                           const char *func,
     360                           FILE *output,
     361                           bool abort_on_error)
    362362{
    363363    // get exclusive access to the memBlock list to avoid it changing on us
     
    385385}
    386386
     387
    387388/*
    388389 * Set whether allocated memory is persistent
     
    400401}
    401402
     403
    402404/*
    403405 * Actually allocate memory
    404406 */
    405 void *p_psAlloc(size_t size,
    406                 const char *file,
     407void *p_psAlloc(const char *file,
    407408                unsigned int lineno,
    408                 const char *func)
     409                const char *func,
     410                size_t size)
    409411{
    410412
     
    490492}
    491493
    492 void *p_psRealloc(void *ptr,
    493                   size_t size,
    494                   const char *file,
     494
     495void *p_psRealloc(const char *file,
    495496                  unsigned int lineno,
    496                   const char *func)
     497                  const char *func,
     498                  void *ptr,
     499                  size_t size)
    497500{
    498501    if (ptr == NULL) {
    499         return p_psAlloc(size, file, lineno, func);
     502        return p_psAlloc(file, lineno, func, size);
    500503    }
    501504
     
    565568 * Check for memory leaks.
    566569 */
    567 int p_psMemCheckLeaks(psMemId id0,
     570int p_psMemCheckLeaks(const char *file,
     571                      unsigned int lineno,
     572                      const char *func,
     573                      psMemId id0,
    568574                      psMemBlock ***array,
    569575                      FILE * fd,
    570                       bool persistence,
    571                       const char *file,
    572                       unsigned int lineno,
    573                       const char *func)
     576                      bool persistence)
    574577{
    575578    psS32 nleak = 0;
     
    579582    // make sure that the memblock list is free of corruption before we crawl
    580583    // the list
    581     p_psMemCheckCorruption(fd, true, file, lineno, func);
     584    p_psMemCheckCorruption(file, lineno, func, fd, true);
    582585
    583586    MUTEX_LOCK(&memBlockListMutex);
     
    675678}
    676679
     680
    677681/*
    678682 * Reference counting APIs
    679683 */
    680 
    681 // return refCounter
    682 psReferenceCount p_psMemGetRefCounter(void *ptr,
    683                                       const char *file,
     684psReferenceCount p_psMemGetRefCounter(const char *file,
    684685                                      unsigned int lineno,
    685                                       const char *func)
     686                                      const char *func,
     687                                      void *ptr)
    686688{
    687689    if (ptr == NULL) {
     
    696698}
    697699
     700
    698701// increment and return refCounter
    699 void *p_psMemIncrRefCounter(void *ptr,
    700                             const char *file,
     702void *p_psMemIncrRefCounter(const char *file,
    701703                            unsigned int lineno,
    702                             const char *func)
     704                            const char *func,
     705                            void *ptr)
    703706{
    704707    if (ptr == NULL) {
     
    721724    return ptr;
    722725}
     726
    723727
    724728#if 0
     
    755759#endif
    756760
     761
    757762// decrement and return refCounter
    758 void *p_psMemDecrRefCounter(void * ptr,
    759                             const char *file,
     763void *p_psMemDecrRefCounter(const char *file,
    760764                            unsigned int lineno,
    761                             const char *func)
     765                            const char *func,
     766                            void * ptr)
    762767{
    763768    if (ptr == NULL) {
     
    823828}
    824829
    825 void p_psMemSetDeallocator(void *ptr,
    826                            psFreeFunc freeFunc,
    827                            const char *file,
     830
     831void p_psMemSetDeallocator(const char *file,
    828832                           unsigned int lineno,
    829                            const char *func)
     833                           const char *func,
     834                           void *ptr,
     835                           psFreeFunc freeFunc)
    830836{
    831837    if (ptr == NULL) {
     
    840846}
    841847
    842 psFreeFunc p_psMemGetDeallocator(void *ptr,
    843                                  const char *file,
     848
     849psFreeFunc p_psMemGetDeallocator(const char *file,
    844850                                 unsigned int lineno,
    845                                  const char *func)
     851                                 const char *func,
     852                                 void *ptr)
    846853{
    847854    if (ptr == NULL) {
     
    856863}
    857864
     865
    858866bool psMemSetThreadSafety(bool safe)
    859867{
     
    868876}
    869877
     878
    870879bool psMemGetThreadSafety(void)
    871880{
     
    879888}
    880889
    881 bool p_psMemGetPersistent(void *ptr,
    882                           const char *file,
     890
     891bool p_psMemGetPersistent(const char *file,
    883892                          unsigned int lineno,
    884                           const char *func)
     893                          const char *func,
     894                          void *ptr)
    885895{
    886896    if (ptr == NULL) {
     
    895905}
    896906
    897 void p_psMemSetPersistent(void *ptr,
    898                           bool value,
    899                           const char *file,
     907
     908void p_psMemSetPersistent(const char *file,
    900909                          unsigned int lineno,
    901                           const char *func)
     910                          const char *func,
     911                          void *ptr,
     912                          bool value)
    902913{
    903914    if (ptr == NULL) {
     
    912923}
    913924
    914 /************************************************************************************************************/
    915 /*
    916  * Return the total amount of memory owned by psLib; if non-NULL also provide a breakdown
    917  * into recyclable, allocated, and allocated-and-persistent
     925
     926/******************************************************************************/
     927/*
     928 * Return the total amount of memory owned by psLib; if non-NULL also provide a
     929 * breakdown into recyclable, allocated, and allocated-and-persistent
    918930 *
    919  * It would be simple enough to fix this code to return an array of structs to describe
    920  * the insides of the allocator rather than the printf used here.
     931 * It would be simple enough to fix this code to return an array of structs to
     932 * describe the insides of the allocator rather than the printf used here.
    921933 */
    922934size_t psMemStats(const bool print, // print details as they're found?
  • trunk/psLib/src/sys/psMemory.h

    r11672 r11674  
    1515 *  @ingroup MemoryManagement
    1616 *
    17  *  @version $Revision: 1.66 $ $Name: not supported by cvs2svn $
    18  *  @date $Date: 2007-02-07 00:36:02 $
     17 *  @version $Revision: 1.67 $ $Name: not supported by cvs2svn $
     18 *  @date $Date: 2007-02-07 01:15:49 $
    1919 *
    2020 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2828
    2929#include <stdio.h>                      // needed for FILE
    30 #include <pthread.h>                    // we need a mutex to make this stuff thread safe.
     30#include <pthread.h>                    // mutexes
    3131#include <stdint.h>                     // for uint32_t
    3232#include <stdbool.h>
     
    5858typedef struct psMemBlock
    5959{
    60     const uint32_t startblock;            ///< initialised to p_psMEMMAGIC
    61     struct psMemBlock* previousBlock;  ///< previous block in allocation list
    62     struct psMemBlock* nextBlock;      ///< next block allocation list
    63     psFreeFunc freeFunc;               ///< deallocator.  If NULL, use generic deallocation.
    64     size_t userMemorySize;             ///< the size of the user-portion of the memory block
    65     const psMemId id;                  ///< a unique ID for this allocation
    66     const pthread_t tid;               ///< set from pthread_self();
    67     const char *file;                  ///< set from __FILE__ in e.g. p_psAlloc
    68     const unsigned int lineno;         ///< set from __LINE__ in e.g. p_psAlloc
    69     const char *func;                  ///< set from __func__
     60    const uint32_t startblock;          ///< initialised to p_psMEMMAGIC
     61    struct psMemBlock *previousBlock;   ///< previous block in allocation list
     62    struct psMemBlock *nextBlock;       ///< next block allocation list
     63    psFreeFunc freeFunc;                ///< deallocator.  If NULL, use generic deallocation.
     64    size_t userMemorySize;              ///< the size of the user-portion of the memory block
     65    const psMemId id;                   ///< a unique ID for this allocation
     66    const pthread_t tid;                ///< set from pthread_self();
     67    const char *file;                   ///< set from __FILE__ in e.g. p_psAlloc
     68    const unsigned int lineno;          ///< set from __LINE__ in e.g. p_psAlloc
     69    const char *func;                   ///< set from __func__
     70
    7071    #ifdef HAVE_BACKTRACE
    7172
    72     const void **backtrace;                  ///< set from backtrace()
    73     const size_t backtraceSize;              ///< set from bracktrace()
     73    const void **backtrace;             ///< set from backtrace()
     74    const size_t backtraceSize;         ///< set from bracktrace()
    7475    #endif // ifdef HAVE_BACKTRACE
    7576
    76     psReferenceCount refCounter;       ///< how many times pointer is referenced
    77     bool persistent;                   ///< marks if this non-user persistent data like error stack, etc.
    78     const uint32_t endblock;              ///< initialised to p_psMEMMAGIC
     77    psReferenceCount refCounter;        ///< how many times pointer is referenced
     78    bool persistent;                    ///< marks if this non-user persistent data like error stack, etc.
     79    const uint32_t endblock;            ///< initialised to p_psMEMMAGIC
    7980}
    8081psMemBlock;
     
    8586 */
    8687typedef psMemId(*psMemAllocCallback) (
    87     const psMemBlock* ptr              ///< the psMemBlock just allocated
     88    const psMemBlock *ptr              ///< the psMemBlock just allocated
    8889);
    8990
     
    9394 */
    9495typedef psMemId(*psMemFreeCallback) (
    95     const psMemBlock* ptr              ///< the psMemBlock being freed
     96    const psMemBlock *ptr              ///< the psMemBlock being freed
    9697);
    9798
     
    103104 */
    104105typedef void (*psMemProblemCallback) (
    105     psMemBlock* ptr,                   ///< the pointer to the problematic memory block.
    106     const char *file,                  ///< the file in which the problem originated
    107     unsigned int lineno                ///< the line number in which the problem originated
     106    const char *file,                   ///< File of caller
     107    unsigned int lineno,                ///< Line number of caller
     108    const char *func,                   ///< Function name of caller
     109    psMemBlock *ptr                     ///< the pointer to the problematic memory block.
    108110);
    109111
    110112/** prototype of a callback function used when memory runs out
    111113 *
    112  *  @return void * pointer to requested buffer of the size size_t, or NULL if memory could not
    113  *          be found.
     114 *  @return void * pointer to requested buffer of the size size_t, or NULL if
     115 *  memory could not be found.
    114116 *
    115117 *  @see psMemExhaustedCallbackSet
    116118 */
    117119typedef void *(*psMemExhaustedCallback) (
    118     size_t size                        ///< the size of buffer required
     120    size_t size                         ///< the size of buffer required
    119121);
    120122
    121 /** Memory allocation.  This operates much like malloc(), but is guaranteed to return a non-NULL value.
     123/** Memory allocation.  This operates much like malloc(), but is guaranteed to
     124 * return a non-NULL value.
    122125 *
    123126 *  @return void * pointer to the allocated buffer. This will not be NULL.
     
    125128 */
    126129#ifdef DOXYGEN
    127 
    128130void *psAlloc(
    129131    size_t size                        ///< Size required
    130132);
    131 
    132133#else // #ifdef DOXYGEN
    133 
    134 #ifdef __GNUC__
    135134void *p_psAlloc(
    136     size_t size,                       ///< Size required
    137135    const char *file,                  ///< File of caller
    138136    unsigned int lineno,               ///< Line number of caller
    139     const char *func                   ///< Function name of caller
     137    const char *func,                  ///< Function name of caller
     138    size_t size                        ///< Size required
     139    #ifdef __GNUC__
    140140) __attribute__((malloc));
    141141# else // __GNUC__
    142     void *p_psAlloc(
    143         size_t size,                       ///< Size required
    144         const char *file,                  ///< File of caller
    145         unsigned int lineno,               ///< Line number of caller
    146         const char *func                   ///< Function name of caller
    147     );
    148 #endif // __GNUC__
    149 
    150 /// Memory allocation. psAlloc sends file and line number to p_psAlloc.
    151 #ifndef SWIG
    152 #define psAlloc(size) \
    153 p_psAlloc(size, __FILE__, __LINE__, __func__)
    154 #endif // ! SWIG
    155 
    156 #endif // ! DOXYGEN
    157 
    158 
    159 /** Set the deallocator routine
    160  *
    161  *  A deallocator routine can optionally be assigned to a memory block to
    162  *  ensure that associated memory blocks also get freed, e.g., memory buffers
    163  *  referenced within a struct.
    164  *
    165  */
    166 #ifdef DOXYGEN
    167 
    168 void psMemSetDeallocator(
    169     void *ptr,                         ///< the memory block to operate on
    170     psFreeFunc freeFunc                ///< the function to be executed at deallocation
    171 );
    172 
    173 #else // ifdef DOXYGEN
    174 
    175 void p_psMemSetDeallocator(
    176     void *ptr,                          ///< the memory block to operate on
    177     psFreeFunc freeFunc,                ///< the function to be executed at deallocation
    178     const char *file,                   ///< File of caller
    179     unsigned int lineno,                ///< Line number of caller
    180     const char *func                    ///< Function name of caller
    181 );
    182 
    183 #ifndef SWIG
    184 #define psMemSetDeallocator(ptr, freeFunc) \
    185 p_psMemSetDeallocator(ptr, freeFunc, __FILE__, __LINE__, __func__);
    186 #endif // ! SWIG
    187 
    188 #endif // ifdef DOXYGEN
    189 
    190 
    191 /** Get the deallocator routine
    192  *
    193  *  This function returns the deallocator for a memory block.  A deallocator
    194  *  routine can optionally be assigned to a memory block to ensure that
    195  *  associated memory blocks also get freed, e.g., memory buffers referenced
    196  *  within a struct.
    197  *
    198  *  @return psFreeFunc    the routine to be called at deallocation.
    199  */
    200 #ifdef DOXYGEN
    201 
    202 psFreeFunc psMemGetDeallocator(
    203     void *ptr                     ///< the memory block
    204 );
    205 
    206 #else // ifdef DOXYGEN
    207 
    208 psFreeFunc p_psMemGetDeallocator(
    209     void *ptr,                    ///< the memory block
    210     const char *file,                   ///< File of caller
    211     unsigned int lineno,                ///< Line number of caller
    212     const char *func                    ///< Function name of caller
    213 );
    214 
    215 #ifndef SWIG
    216 #define psMemGetDeallocator(ptr) \
    217 p_psMemGetDeallocator(ptr, __FILE__, __LINE__, __func__)
    218 #endif // ! SWIG
    219 
    220 #endif // ifdef DOXYGEN
    221 
    222 
    223 /** Activate or Deactivate thread safety and mutex locking in the memory management.
    224  *
    225  *  psMemThreadSafety shall turn on thread safety in the memory management functions if
    226  *  safe is true, and deactivate all mutex locking in the memory management functions if
    227  *  safe is false.  The function shall return the previous value of the thread safety.
    228  *  Note that the default behaviour of the library shall be for the locking to be performed.
    229  *
    230  *  @return bool:       The previous value of the thread safety.
    231  */
    232 bool psMemSetThreadSafety(
    233     bool safe                          ///< boolean for turning on/off thread safety
    234 );
    235 
    236 /** Get the current state of thread safety and mutex locking in the memory management.
    237  *
    238  * psMemGetThreadSafety shall return the current state of thread safety in the memory management system.
    239  *
    240  *  @return bool:       The current state of thread safety.
    241  */
    242 bool psMemGetThreadSafety(void);
    243 
    244 
    245 /** Set the memory as persistent so that it is ignored when detecting memory leaks.
    246  *
    247  *  Used to mark a memory block as persistent data within the library,
    248  *  i.e., non user-level data used to hold psLib's state or cache data.  Such
    249  *  examples of this class of memory is psTrace's trace-levels and dynamic
    250  *  error codes.
    251  *
    252  *  Memory marked as persistent is excluded from memory leak checks.
    253  *
    254  */
    255 #ifdef DOXYGEN
    256 
    257 void psMemSetPersistent(
    258     void *ptr,                          ///< the memory block to operate on
    259     bool value,                         ///< true if memory is persistent, otherwise false
    260 );
    261 
    262 #else // #ifdef DOXYGEN
    263 
    264 void p_psMemSetPersistent(
    265     void *ptr,                          ///< the memory block to operate on
    266     bool value,                         ///< true if memory is persistent, otherwise false
    267     const char *file,                   ///< File of caller
    268     unsigned int lineno,                ///< Line number of caller
    269     const char *func                    ///< Function name of caller
    270 );
    271 
    272 #ifndef SWIG
    273 #define psMemSetPersistent(ptr, value) \
    274 p_psMemSetPersistent(ptr, value, __FILE__, __LINE__, __func__);
    275 #endif // ! SWIG
    276 
    277 #endif // DOXYGEN
    278 
    279 
    280 /** Set whether allocated memory is persistent
    281  *
    282  *  Set whether allocated memory is persistent. The defeault is false.
    283  *
    284  *  @return bool:       The previous value of whether all allocated memory is persistent
    285  */
    286 bool p_psMemAllocatePersistent(bool is_persistent); ///< Should all memory allocated be persistent?
    287 
    288 
    289 /** Get the memory's persistent flag.
    290  *
    291  *  Checks if a memory block has been marked as persistent by
    292  *  p_psMemSetPresistent.
    293  *
    294  *  Memory marked as persistent is excluded from memory leak checks.
    295  *
    296  *  @return bool    true if memory is marked persistent, otherwise false.
    297  */
    298 #ifdef DOXYGEN
    299 
    300 bool psMemGetPersistent(
    301     void *ptr,                          ///< the memory block to check.
    302 );
    303 #else // ifdef DOXYGEN
    304 
    305 bool p_psMemGetPersistent(
    306     void *ptr,                          ///< the memory block to check.
    307     const char *file,                   ///< File of caller
    308     unsigned int lineno,                ///< Line number of caller
    309     const char *func                    ///< Function name of caller
    310 );
    311 
    312 #ifndef SWIG
    313 #define psMemGetPersistent(ptr) \
    314 p_MemGetPersistent(ptr, __FILE__, __LINE__, __func__);
    315 #endif // ! SWIG
    316 
    317 #endif // DOXYGEN
    318 
    319 
    320 /** Memory re-allocation.  This operates much like realloc(), but is guaranteed to return a non-NULL value.
    321  *
    322  *  @return void * pointer to resized buffer. This will not be NULL.
    323  *  @see psAlloc, psFree
    324  */
    325 #ifdef DOXYGEN
    326 
    327 void *psRealloc(
    328     void *ptr,                          ///< Pointer to re-allocate
    329     size_t size                         ///< Size required
    330 );
    331 #else // #ifdef DOXYGEN
    332 #ifdef __GNUC__
    333 void *p_psRealloc(
    334     void *ptr,                          ///< Pointer to re-allocate
    335     size_t size,                        ///< Size required
    336     const char *file,                   ///< File of caller
    337     unsigned int lineno,                ///< Line number of caller
    338     const char *func                    ///< Function name of caller
    339 ) __attribute__((malloc));
    340 # else // __GNUC__
    341     void *p_psRealloc(
    342         void *ptr,                          ///< Pointer to re-allocate
    343         size_t size,                        ///< Size required
     142    );
     143    #endif // __GNUC__
     144
     145    /// Memory allocation. psAlloc sends file and line number to p_psAlloc.
     146    #ifndef SWIG
     147    #define psAlloc(size) \
     148    p_psAlloc(__FILE__, __LINE__, __func__, size)
     149    #endif // ! SWIG
     150    #endif // ! DOXYGEN
     151
     152
     153    /** Set the deallocator routine
     154     *
     155     *  A deallocator routine can optionally be assigned to a memory block to
     156     *  ensure that associated memory blocks also get freed, e.g., memory buffers
     157     *  referenced within a struct.
     158     *
     159     */
     160    #ifdef DOXYGEN
     161    void psMemSetDeallocator(
     162        void *ptr,                         ///< the memory block to operate on
     163        psFreeFunc freeFunc                ///< the function to be executed at deallocation
     164    );
     165    #else // ifdef DOXYGEN
     166    void p_psMemSetDeallocator(
    344167        const char *file,                   ///< File of caller
    345168        unsigned int lineno,                ///< Line number of caller
    346         const char *func                    ///< Function name of caller
    347     );
    348 #endif // __GNUC__
    349 
    350 /// Memory re-allocation.  psRealloc sends file and line number to p_psRealloc.
    351 #ifndef SWIG
    352 #define psRealloc(ptr, size) \
    353 p_psRealloc(ptr, size, __FILE__, __LINE__, __func__)
    354 #endif // ! SWIG
    355 
    356 #endif // ! DOXYGEN
    357 
    358 
    359 /** Free memory.  This operates much like free().
    360  *
    361  *  @see psAlloc, psRealloc
    362  */
    363 #ifdef DOXYGEN
    364 void psFree(
    365     void *ptr                           ///< Pointer to free, if NULL, function returns immediately.
    366 );
    367 #else // #ifdef DOXYGEN
    368 
    369 /// Free memory.  psFree sends file and line number to p_psFree.
    370 #ifndef SWIG
    371 #define            psFree(ptr) \
    372 p_psMemDecrRefCounter((void **)ptr, __FILE__, __LINE__, __func__);
    373 #endif // ! SWIG
    374 
    375 #endif // ! DOXYGEN
    376 
    377 
    378 /** Check for memory leaks.  This scans for allocated memory buffers not freed with an ID not less than id0.
    379  *  This is used to check for memory leaks by:
    380  *      -# before a block of code to be checked, store the current ID count via psGetMemId
    381  *      -# after the block of code to be checked, call this function using the ID stored above.  If all
    382  *         memory in the block that was allocated has been freed, this call should output nothing and
    383  *         return 0.
    384  *
    385  *  If memory leaks are found, the Memory Problem callback will be called as well.
    386  *
    387  *  @return int  number of memory blocks found as 'leaks', i.e., the number of currently allocated memory
    388  *              blocks above id0 that have not been freed.
    389  *  @see psAlloc, psFree, psgetMemId, psMemProblemCallbackSet
    390  */
    391 #ifdef DOXYGEN
    392 int psMemCheckLeaks(
    393     psMemId id0,                       ///< don't list blocks with id < id0
    394     psMemBlock ***array,               ///< pointer to array of pointers to leaked blocks, or NULL
    395     FILE * fd,                         ///< print list of leaks to fd (or NULL)
    396     bool persistence                   ///< make check across all object even persistent ones
    397 );
    398 #else // ifdef DOXYGEN
    399 int p_psMemCheckLeaks(
    400     psMemId id0,                       ///< don't list blocks with id < id0
    401     psMemBlock ***array,               ///< pointer to array of pointers to leaked blocks, or NULL
    402     FILE * fd,                         ///< print list of leaks to fd (or NULL)
    403     bool persistence,                  ///< make check across all object even persistent ones
    404     const char *file,                   ///< File of caller
    405     unsigned int lineno,                ///< Line number of caller
    406     const char *func                    ///< Function name of caller
    407 );
    408 #ifndef SWIG
    409 #define psMemCheckLeaks(id0, array, fd, persistence) \
    410 p_psMemCheckLeaks(id0, array, fd, persistence, __FILE__, __LINE__, __func__)
    411 #endif // ifndef SWIG
    412 #endif // ifdef DOXYGEN
    413 
    414 
    415 /** Check for memory corruption.  Scans all currently allocated memory buffers and checks for corruptions,
    416  *  i.e., invalid markers that signify a buffer under/overflow.
    417  *
    418  *  @return int
    419  *
    420  */
    421 #ifdef DOXYGEN
    422 int psMemCheckCorruption(
    423     FILE *output,                       ///< FILE to write corrupted blocks too
    424     bool abort_on_error                 ///< Abort on detecting corruption?
    425 );
    426 #else // ifdef DOXYGEN
    427 int p_psMemCheckCorruption(
    428     FILE *output,                       ///< FILE to write corrupted blocks too
    429     bool abort_on_error,                ///< Abort on detecting corruption?
    430     const char *file,                   ///< File of caller
    431     unsigned int lineno,                ///< Line number of caller
    432     const char *func                    ///< Function name of caller
    433 );
    434 #ifndef SWIG
    435 #define psMemCheckCorruption(output, abort_on_error) \
    436 p_psMemCheckCorruption(output, abort_on_error, __FILE__, __LINE__, __func__)
    437 #endif // ifndef SWIG
    438 #endif // ifdef DOXYGEN
    439 
    440 
    441 /** Return reference counter
    442  *
    443  *  @return psReferenceCount
    444  *
    445  */
    446 #ifdef DOXYGEN
    447 
    448 psReferenceCount psMemGetRefCounter(
    449     void *ptr                     ///< Pointer to get refCounter for
    450 );
    451 
    452 #else // ifdef DOXYGEN
    453 
    454 psReferenceCount p_psMemGetRefCounter(
    455     void *ptr,                    ///< Pointer to get refCounter for
    456     const char *file,                   ///< File of call
    457     unsigned int lineno,                ///< Line number of call
    458     const char *func                    ///< Function name of caller
    459 );
    460 
    461 #ifndef SWIG
    462 #define psMemGetRefCounter(ptr) \
    463 p_psMemGetRefCounter(ptr, __FILE__, __LINE__, __func__)
    464 #endif // !SWIG
    465 
    466 #endif // !DOXYGEN
    467 
    468 
    469 /** Increment reference counter and return the pointer
    470  *
    471  *  @return void *
    472  *
    473  */
    474 #ifdef DOXYGEN
    475 
    476 void *psMemIncrRefCounter(
    477     void *ptr                           ///< Pointer to increment refCounter, and return
    478 );
    479 #else // ifdef DOXYGEN
    480 
    481 void *p_psMemIncrRefCounter(
    482     void *ptr,                          ///< Pointer to increment refCounter, and return
    483     const char *file,                   ///< File of call
    484     unsigned int lineno,                ///< Line number of call
    485     const char *func                    ///< Function name of caller
    486 );
    487 
    488 #ifndef SWIG
    489 #define psMemIncrRefCounter(ptr) \
    490 p_psMemIncrRefCounter(ptr, __FILE__, __LINE__, __func__)
    491 #endif // !SWIG
    492 
    493 #endif // !DOXYGEN
    494 
    495 
    496 /** Decrement reference counter and return the pointer
    497  *
    498  *
    499  *  @return void *    the pointer deremented in refCount, or NULL if pointer is
    500  *                   fully dereferenced.
    501  */
    502 #ifdef DOXYGEN
    503 
    504 void *psMemDecrRefCounter(
    505     void *ptr                           ///< Pointer to decrement refCounter, and return
    506 );
    507 
    508 #else // DOXYGEN
    509 
    510 void *p_psMemDecrRefCounter(
    511     void *ptr,                          ///< Pointer to decrement refCounter, and return
    512     const char *file,                   ///< File of call
    513     unsigned int lineno,                ///< Line number of call
    514     const char *func                    ///< Function name of caller
    515 );
    516 
    517 #ifndef SWIG
    518 #define psMemDecrRefCounter(ptr) \
    519 p_psMemDecrRefCounter(ptr, __FILE__, __LINE__, __func__)
    520 #endif // !SWIG
    521 
    522 #endif // !DOXYGEN
    523 
    524 #if 0 // psMemSetRefCounter
    525 /** Set reference counter and return the pointer
    526  *
    527  *  @return void *    the pointer with refCount set, or NULL if pointer is
    528  *                   fully dereferenced.
    529  */
    530 #ifdef DOXYGEN
    531 void * psMemSetRefCounter(
    532     void * ptr,                        ///< Pointer to decrement refCounter, and return
    533     psReferenceCount count            ///< New reference count
    534 );
    535 #else // DOXYGEN
    536 void * p_psMemSetRefCounter(
    537     void * vptr,                        ///< Pointer to decrement refCounter, and return
    538     psReferenceCount count,            ///< New reference count
    539     const char *file,                  ///< File of call
    540     psS32 lineno                       ///< Line number of call
    541 );
    542 
    543 #ifndef SWIG
    544 #define psMemSetRefCounter(vptr, count) p_psMemSetRefCounter(vptr, count, __FILE__, __LINE__)
    545 #endif // !SWIG
    546 
    547 #endif // !DOXYGEN
    548 #endif // psMemSetRefCounter
    549 
    550 /** Set callback for out-of-memory.
    551  *
    552  *  If not enough memory is available to satisfy a request by psAlloc or
    553  *  psRealloc, these functions attempt to find an alternative solution by
    554  *  calling the psMemExhaustedCallback, a function which may be set by the
    555  *  programmer in appropriate circumstances, rather than immediately fail.
    556  *  The typical use of such a feature may be when a program needs a large
    557  *  chunk of memory to do an operation, but the exact size is not critical.
    558  *  This feature gives the programmer the opportunity to make a smaller
    559  *  request and try again, limiting the size of the operating buffer.
    560  *
    561  *  @return psMemExhaustedCallback     old psMemExhaustedCallback function
    562  */
    563 psMemExhaustedCallback psMemExhaustedCallbackSet(
    564     psMemExhaustedCallback func        ///< Function to run at memory exhaustion
    565 );
    566 
    567 /** Set call back for when a particular memory block is allocated
    568  *
    569  *  A private variable, p_psMemAllocID, can be used to trace the allocation
    570  *  and freeing of specific memory blocks. If p_psMemAllocID is set and a
    571  *  memory block with that ID is allocated, psMemAllocCallback is called
    572  *  just before memory is returned to the calling function.
    573  *
    574  *  @return psMemAllocCallback      old psMemAllocCallback function
    575  */
    576 psMemAllocCallback psMemAllocCallbackSet(
    577     psMemAllocCallback func            ///< Function to run at memory allocation of specific mem block
    578 );
    579 
    580 /** Set call back for when a particular memory block is freed
    581  *
    582  *  A private variable, p_psMemFreeID, can be used to trace the freeing of
    583  *  specific memory blocks. If p_psMemFreeID is set and the memory block with
    584  *  the ID is about to be freed, the psMemFreeCallback callback is called just
    585  *  before the memory block is freed.
    586  *
    587  *  @return psMemFreeCallback          old psMemFreeCallback function
    588  */
    589 psMemFreeCallback psMemFreeCallbackSet(
    590     psMemFreeCallback func             ///< Function to run at memory free of specific mem block
    591 );
    592 
    593 /** get next memory ID
    594  *
    595  *  @return psMemId                 the next memory ID to be used
    596  */
    597 psMemId psMemGetId(void);
    598 
    599 /** get the last memory ID used
    600  *
    601  *  @return psMemId                 the last memory ID used
    602  */
    603 psMemId psMemGetLastId(void);
    604 
    605 /** set p_psMemAllocID to specific id
    606  *
    607  *  A private variable, p_psMemAllocID, can be used to trace the allocation
    608  *  and freeing of specific memory blocks. If p_psMemAllocID is set and a
    609  *  memory block with that ID is allocated, psMemAllocCallback is called
    610  *  just before memory is returned to the calling function.
    611  *
    612  *  @return psMemId
    613  *
    614  *  @see psMemAllocCallbackSet
    615  */
    616 psMemId psMemAllocCallbackSetID(
    617     psMemId id                         ///< ID to set
    618 );
    619 
    620 /** set p_psMemFreeID to id
    621  *
    622  *  A private variable, p_psMemFreeID, can be used to trace the freeing of
    623  *  specific memory blocks. If p_psMemFreeID is set and the memory block with
    624  *  the ID is about to be freed, the psMemFreeCallback callback is called just
    625  *  before the memory block is freed.
    626  *
    627  *  @return psMemId                 the old p_psMemFreeID
    628  *
    629  *  @see psMemFreeCallbackSet
    630  */
    631 psMemId psMemFreeCallbackSetID(
    632     psMemId id                         ///< ID to set
    633 );
    634 
    635 
    636 /** return statistics on memory usage
    637  *
    638  * @return the total amount of memory owned by psLib; if non-NULL also provide
    639  * a breakdown into allocated and allocated-and-persistent
    640  */
    641 size_t psMemStats(const bool print, ///< print details as they're found?
    642                   size_t *allocated, ///< memory that's currently allocated (but not persistent)
    643                   size_t *persistent); ///< persistent memory that's currently allocated
    644 
    645 /** print detailed information about a psMemBlock
    646  *
    647  * This function prints a detailed description of a psMemBlock to output.
    648  *
    649  * @return the return status of fprintf()
    650  */
    651 int psMemBlockPrint(
    652     FILE *output,                       ///< FILE to write information too
    653     const psMemBlock *memBlock          ///< psMemBlock to be examined
    654 );
    655 
    656 
    657 /// @} end of SysUtils
    658 
    659 #ifndef DOXYGEN
    660 
    661 /*
    662  * Ensure that any program using malloc/realloc/free will fail to compile
    663  */
    664 #ifndef PS_ALLOW_MALLOC
    665 #ifdef __GNUC__
    666 #pragma GCC poison malloc realloc calloc free
    667 #else // __GNUC__
    668 #define malloc(S)       _Pragma("error Use of malloc is not allowed.  Use psAlloc instead.")
    669 #define realloc(P,S)    _Pragma("error Use of realloc is not allowed.  Use psRealloc instead.")
    670 #define calloc(S)       _Pragma("error Use of calloc is not allowed.  Use psAlloc instead.")
    671 #define free(P)         _Pragma("error Use of free is not allowed.  Use psFree instead.")
    672 #endif // ! __GNUC__
    673 #endif // #ifndef PS_ALLOW_MALLOC
    674 
    675 #endif // #ifndef DOXYGEN
    676 #endif // #ifndef PS_MEMORY_H
     169        const char *func,                   ///< Function name of caller
     170        void *ptr,                          ///< the memory block to operate on
     171        psFreeFunc freeFunc                 ///< the function to be executed at deallocation
     172    );
     173    #ifndef SWIG
     174    #define psMemSetDeallocator(ptr, freeFunc) \
     175    p_psMemSetDeallocator(__FILE__, __LINE__, __func__, ptr, freeFunc)
     176    #endif // ! SWIG
     177    #endif // ifdef DOXYGEN
     178
     179
     180    /** Get the deallocator routine
     181     *
     182     *  This function returns the deallocator for a memory block.  A deallocator
     183     *  routine can optionally be assigned to a memory block to ensure that
     184     *  associated memory blocks also get freed, e.g., memory buffers referenced
     185     *  within a struct.
     186     *
     187     *  @return psFreeFunc    the routine to be called at deallocation.
     188     */
     189    #ifdef DOXYGEN
     190    psFreeFunc psMemGetDeallocator(
     191        void *ptr                           ///< the memory block
     192    );
     193    #else // ifdef DOXYGEN
     194    psFreeFunc p_psMemGetDeallocator(
     195        const char *file,                   ///< File of caller
     196        unsigned int lineno,                ///< Line number of caller
     197        const char *func,                   ///< Function name of caller
     198        void *ptr                           ///< the memory block
     199    );
     200    #ifndef SWIG
     201    #define psMemGetDeallocator(ptr) \
     202    p_psMemGetDeallocator(__FILE__, __LINE__, __func__, ptr)
     203    #endif // ! SWIG
     204    #endif // ifdef DOXYGEN
     205
     206
     207    /** Activate or Deactivate thread safety and mutex locking in the memory
     208     * management.
     209     *
     210     *  psMemThreadSafety shall turn on thread safety in the memory management
     211     *  functions if safe is true, and deactivate all mutex locking in the memory
     212     *  management functions if safe is false.  The function shall return the
     213     *  previous value of the thread safety.  Note that the default behaviour of
     214     *  the library shall be for the locking to be performed.
     215     *
     216     *  @return bool:       The previous value of the thread safety.
     217     */
     218    bool psMemSetThreadSafety(
     219        bool safe                          ///< boolean for turning on/off thread safety
     220    );
     221
     222    /** Get the current state of thread safety and mutex locking in the memory
     223     * management.
     224     *
     225     * psMemGetThreadSafety shall return the current state of thread safety in the
     226     * memory management system.
     227     *
     228     *  @return bool:       The current state of thread safety.
     229     */
     230    bool psMemGetThreadSafety(void);
     231
     232
     233    /** Set the memory as persistent so that it is ignored when detecting memory
     234     * leaks.
     235     *
     236     *  Used to mark a memory block as persistent data within the library,
     237     *  i.e., non user-level data used to hold psLib's state or cache data.  Such
     238     *  examples of this class of memory is psTrace's trace-levels and dynamic
     239     *  error codes.
     240     *
     241     *  Memory marked as persistent is excluded from memory leak checks.
     242     *
     243     */
     244    #ifdef DOXYGEN
     245    void psMemSetPersistent(
     246        void *ptr,                          ///< the memory block to operate on
     247        bool value,                         ///< true if memory is persistent, otherwise false
     248    );
     249    #else // #ifdef DOXYGEN
     250    void p_psMemSetPersistent(
     251        const char *file,                   ///< File of caller
     252        unsigned int lineno,                ///< Line number of caller
     253        const char *func,                   ///< Function name of caller
     254        void *ptr,                          ///< the memory block to operate on
     255        bool value                          ///< true if memory is persistent, otherwise false
     256    );
     257    #ifndef SWIG
     258    #define psMemSetPersistent(ptr, value) \
     259    p_psMemSetPersistent(__FILE__, __LINE__, __func__, ptr, value)
     260    #endif // ! SWIG
     261    #endif // DOXYGEN
     262
     263
     264    /** Set whether allocated memory is persistent
     265     *
     266     *  Set whether allocated memory is persistent. The defeault is false.
     267     *
     268     *  @return bool:       The previous value of whether all allocated memory is
     269     *  persistent
     270     */
     271    bool p_psMemAllocatePersistent(bool is_persistent); ///< Should all memory allocated be persistent?
     272
     273
     274    /** Get the memory's persistent flag.
     275     *
     276     *  Checks if a memory block has been marked as persistent by
     277     *  p_psMemSetPresistent.
     278     *
     279     *  Memory marked as persistent is excluded from memory leak checks.
     280     *
     281     *  @return bool    true if memory is marked persistent, otherwise false.
     282     */
     283    #ifdef DOXYGEN
     284    bool psMemGetPersistent(
     285        void *ptr,                          ///< the memory block to check.
     286    );
     287    #else // ifdef DOXYGEN
     288    bool p_psMemGetPersistent(
     289        const char *file,                   ///< File of caller
     290        unsigned int lineno,                ///< Line number of caller
     291        const char *func,                   ///< Function name of caller
     292        void *ptr                           ///< the memory block to check.
     293    );
     294    #ifndef SWIG
     295    #define psMemGetPersistent(ptr) \
     296    p_psMemGetPersistent(__FILE__, __LINE__, __func__, ptr)
     297    #endif // ! SWIG
     298    #endif // DOXYGEN
     299
     300
     301    /** Memory re-allocation.  This operates much like realloc(), but is guaranteed
     302     * to return a non-NULL value.
     303     *
     304     *  @return void * pointer to resized buffer. This will not be NULL.
     305     *  @see psAlloc, psFree
     306     */
     307    #ifdef DOXYGEN
     308    void *psRealloc(
     309        void *ptr,                          ///< Pointer to re-allocate
     310        size_t size                         ///< Size required
     311    );
     312    #else // #ifdef DOXYGEN
     313    void *p_psRealloc(
     314        const char *file,                   ///< File of caller
     315        unsigned int lineno,                ///< Line number of caller
     316        const char *func,                   ///< Function name of caller
     317        void *ptr,                          ///< Pointer to re-allocate
     318        size_t size                         ///< Size required
     319        #ifdef __GNUC__
     320    ) __attribute__((malloc));
     321    # else // __GNUC__
     322        );
     323        #endif // __GNUC__
     324        #ifndef SWIG
     325        #define psRealloc(ptr, size) \
     326        p_psRealloc(__FILE__, __LINE__, __func__, ptr, size)
     327        #endif // ! SWIG
     328        #endif // ! DOXYGEN
     329
     330
     331        /** Free memory.  This operates much like free().
     332         *
     333         *  @see psAlloc, psRealloc
     334         */
     335        #ifdef DOXYGEN
     336        void psFree(
     337            void *ptr                           ///< Pointer to free, if NULL, function returns immediately.
     338        );
     339        #else // #ifdef DOXYGEN
     340        /// Free memory.  psFree sends file and line number to p_psFree.
     341        #ifndef SWIG
     342        #define psFree(ptr) \
     343        psMemDecrRefCounter(ptr)
     344        #endif // ! SWIG
     345        #endif // ! DOXYGEN
     346
     347
     348        /** Check for memory leaks.  This scans for allocated memory buffers not freed
     349         * with an ID not less than id0.  This is used to check for memory leaks by: -#
     350         * before a block of code to be checked, store the current ID count via
     351         * psGetMemId -# after the block of code to be checked, call this function
     352         * using the ID stored above.  If all memory in the block that was allocated
     353         * has been freed, this call should output nothing and return 0.
     354         *
     355         *  If memory leaks are found, the Memory Problem callback will be called as
     356         *  well.
     357         *
     358         *  @return int  number of memory blocks found as 'leaks', i.e., the number of
     359         *  currently allocated memory blocks above id0 that have not been freed.  @see
     360         *  psAlloc, psFree, psgetMemId, psMemProblemCallbackSet
     361         */
     362        #ifdef DOXYGEN
     363        int psMemCheckLeaks(
     364            psMemId id0,                       ///< don't list blocks with id < id0
     365            psMemBlock ***array,               ///< pointer to array of pointers to leaked blocks, or NULL
     366            FILE * fd,                         ///< print list of leaks to fd (or NULL)
     367            bool persistence                   ///< make check across all object even persistent ones
     368        );
     369        #else // ifdef DOXYGEN
     370        int p_psMemCheckLeaks(
     371            const char *file,                   ///< File of caller
     372            unsigned int lineno,                ///< Line number of caller
     373            const char *func,                   ///< Function name of caller
     374            psMemId id0,                        ///< don't list blocks with id < id0
     375            psMemBlock ***array,                ///< pointer to array of pointers to leaked blocks, or NULL
     376            FILE * fd,                          ///< print list of leaks to fd (or NULL)
     377            bool persistence                    ///< make check across all object even persistent ones
     378        );
     379        #ifndef SWIG
     380        #define psMemCheckLeaks(id0, array, fd, persistence) \
     381        p_psMemCheckLeaks(__FILE__, __LINE__, __func__, id0, array, fd, persistence)
     382        #endif // ifndef SWIG
     383        #endif // ifdef DOXYGEN
     384
     385
     386        /** Check for memory corruption.  Scans all currently allocated memory buffers
     387         * and checks for corruptions, i.e., invalid markers that signify a buffer
     388         * under/overflow.
     389         *
     390         *  @return int
     391         *
     392         */
     393        #ifdef DOXYGEN
     394        int psMemCheckCorruption(
     395            FILE *output,                       ///< FILE to write corrupted blocks too
     396            bool abort_on_error                 ///< Abort on detecting corruption?
     397        );
     398        #else // ifdef DOXYGEN
     399        int p_psMemCheckCorruption(
     400            const char *file,                   ///< File of caller
     401            unsigned int lineno,                ///< Line number of caller
     402            const char *func,                   ///< Function name of caller
     403            FILE *output,                       ///< FILE to write corrupted blocks too
     404            bool abort_on_error                 ///< Abort on detecting corruption?
     405        );
     406        #ifndef SWIG
     407        #define psMemCheckCorruption(output, abort_on_error) \
     408        p_psMemCheckCorruption(__FILE__, __LINE__, __func__, output, abort_on_error)
     409        #endif // ifndef SWIG
     410        #endif // ifdef DOXYGEN
     411
     412
     413        /** Return reference counter
     414         *
     415         *  @return psReferenceCount
     416         *
     417         */
     418        #ifdef DOXYGEN
     419        psReferenceCount psMemGetRefCounter(
     420            void *ptr                     ///< Pointer to get refCounter for
     421        );
     422
     423        #else // ifdef DOXYGEN
     424        psReferenceCount p_psMemGetRefCounter(
     425            const char *file,                   ///< File of call
     426            unsigned int lineno,                ///< Line number of call
     427            const char *func,                   ///< Function name of caller
     428            void *ptr                           ///< Pointer to get refCounter for
     429        );
     430        #ifndef SWIG
     431        #define psMemGetRefCounter(ptr) \
     432        p_psMemGetRefCounter(__FILE__, __LINE__, __func__, ptr)
     433        #endif // !SWIG
     434        #endif // !DOXYGEN
     435
     436
     437        /** Increment reference counter and return the pointer
     438         *
     439         *  @return void *
     440         *
     441         */
     442        #ifdef DOXYGEN
     443        void *psMemIncrRefCounter(
     444            void *ptr                           ///< Pointer to increment refCounter, and return
     445        );
     446        #else // ifdef DOXYGEN
     447        void *p_psMemIncrRefCounter(
     448            const char *file,                   ///< File of call
     449            unsigned int lineno,                ///< Line number of call
     450            const char *func,                   ///< Function name of caller
     451            void *ptr                           ///< Pointer to increment refCounter, and return
     452        );
     453        #ifndef SWIG
     454        #define psMemIncrRefCounter(ptr) \
     455        p_psMemIncrRefCounter(__FILE__, __LINE__, __func__, ptr)
     456        #endif // !SWIG
     457        #endif // !DOXYGEN
     458
     459
     460        /** Decrement reference counter and return the pointer
     461         *
     462         *
     463         *  @return void *    the pointer deremented in refCount, or NULL if pointer is
     464         *                   fully dereferenced.
     465         */
     466        #ifdef DOXYGEN
     467        void *psMemDecrRefCounter(
     468            void *ptr                           ///< Pointer to decrement refCounter, and return
     469        );
     470        #else // DOXYGEN
     471        void *p_psMemDecrRefCounter(
     472            const char *file,                   ///< File of call
     473            unsigned int lineno,                ///< Line number of call
     474            const char *func,                   ///< Function name of caller
     475            void *ptr                           ///< Pointer to decrement refCounter, and return
     476        );
     477        #ifndef SWIG
     478        #define psMemDecrRefCounter(ptr) \
     479        p_psMemDecrRefCounter(__FILE__, __LINE__, __func__, ptr)
     480        #endif // !SWIG
     481        #endif // !DOXYGEN
     482
     483
     484        #if 0 // psMemSetRefCounter
     485        /** Set reference counter and return the pointer
     486         *
     487         *  @return void *    the pointer with refCount set, or NULL if pointer is
     488         *                   fully dereferenced.
     489         */
     490        #ifdef DOXYGEN
     491        void * psMemSetRefCounter(
     492            void * ptr,                        ///< Pointer to decrement refCounter, and return
     493            psReferenceCount count            ///< New reference count
     494        );
     495        #else // DOXYGEN
     496        void * p_psMemSetRefCounter(
     497            void * vptr,                        ///< Pointer to decrement refCounter, and return
     498            psReferenceCount count,            ///< New reference count
     499            const char *file,                  ///< File of call
     500            psS32 lineno                       ///< Line number of call
     501        );
     502
     503        #ifndef SWIG
     504        #define psMemSetRefCounter(vptr, count) p_psMemSetRefCounter(vptr, count, __FILE__, __LINE__)
     505        #endif // !SWIG
     506
     507        #endif // !DOXYGEN
     508        #endif // psMemSetRefCounter
     509
     510        /** Set callback for out-of-memory.
     511         *
     512         *  If not enough memory is available to satisfy a request by psAlloc or
     513         *  psRealloc, these functions attempt to find an alternative solution by
     514         *  calling the psMemExhaustedCallback, a function which may be set by the
     515         *  programmer in appropriate circumstances, rather than immediately fail.
     516         *  The typical use of such a feature may be when a program needs a large
     517         *  chunk of memory to do an operation, but the exact size is not critical.
     518         *  This feature gives the programmer the opportunity to make a smaller
     519         *  request and try again, limiting the size of the operating buffer.
     520         *
     521         *  @return psMemExhaustedCallback     old psMemExhaustedCallback function
     522         */
     523        psMemExhaustedCallback psMemExhaustedCallbackSet(
     524            psMemExhaustedCallback func        ///< Function to run at memory exhaustion
     525        );
     526
     527
     528        /** Set call back for when a particular memory block is allocated
     529         *
     530         *  A private variable, p_psMemAllocID, can be used to trace the allocation
     531         *  and freeing of specific memory blocks. If p_psMemAllocID is set and a
     532         *  memory block with that ID is allocated, psMemAllocCallback is called
     533         *  just before memory is returned to the calling function.
     534         *
     535         *  @return psMemAllocCallback      old psMemAllocCallback function
     536         */
     537        psMemAllocCallback psMemAllocCallbackSet(
     538            psMemAllocCallback func            ///< Function to run at memory allocation of specific mem block
     539        );
     540
     541
     542        /** Set call back for when a particular memory block is freed
     543         *
     544         *  A private variable, p_psMemFreeID, can be used to trace the freeing of
     545         *  specific memory blocks. If p_psMemFreeID is set and the memory block with
     546         *  the ID is about to be freed, the psMemFreeCallback callback is called just
     547         *  before the memory block is freed.
     548         *
     549         *  @return psMemFreeCallback          old psMemFreeCallback function
     550         */
     551        psMemFreeCallback psMemFreeCallbackSet(
     552            psMemFreeCallback func             ///< Function to run at memory free of specific mem block
     553        );
     554
     555
     556        /** get next memory ID
     557         *
     558         *  @return psMemId                 the next memory ID to be used
     559         */
     560        psMemId psMemGetId(void);
     561
     562
     563        /** get the last memory ID used
     564         *
     565         *  @return psMemId                 the last memory ID used
     566         */
     567        psMemId psMemGetLastId(void);
     568
     569
     570        /** set p_psMemAllocID to specific id
     571         *
     572         *  A private variable, p_psMemAllocID, can be used to trace the allocation
     573         *  and freeing of specific memory blocks. If p_psMemAllocID is set and a
     574         *  memory block with that ID is allocated, psMemAllocCallback is called
     575         *  just before memory is returned to the calling function.
     576         *
     577         *  @return psMemId
     578         *
     579         *  @see psMemAllocCallbackSet
     580         */
     581        psMemId psMemAllocCallbackSetID(
     582            psMemId id                         ///< ID to set
     583        );
     584
     585
     586        /** set p_psMemFreeID to id
     587         *
     588         *  A private variable, p_psMemFreeID, can be used to trace the freeing of
     589         *  specific memory blocks. If p_psMemFreeID is set and the memory block with
     590         *  the ID is about to be freed, the psMemFreeCallback callback is called just
     591         *  before the memory block is freed.
     592         *
     593         *  @return psMemId                 the old p_psMemFreeID
     594         *
     595         *  @see psMemFreeCallbackSet
     596         */
     597        psMemId psMemFreeCallbackSetID(
     598            psMemId id                         ///< ID to set
     599        );
     600
     601
     602        /** return statistics on memory usage
     603         *
     604         * @return the total amount of memory owned by psLib; if non-NULL also provide
     605         * a breakdown into allocated and allocated-and-persistent
     606         */
     607        size_t psMemStats(const bool print, ///< print details as they're found?
     608                          size_t *allocated, ///< memory that's currently allocated (but not persistent)
     609                          size_t *persistent); ///< persistent memory that's currently allocated
     610
     611        /** print detailed information about a psMemBlock
     612         *
     613         * This function prints a detailed description of a psMemBlock to output.
     614         *
     615         * @return the return status of fprintf()
     616         */
     617        int psMemBlockPrint(
     618            FILE *output,                       ///< FILE to write information too
     619            const psMemBlock *memBlock          ///< psMemBlock to be examined
     620        );
     621
     622
     623        /// @} end of SysUtils
     624
     625        #ifndef DOXYGEN
     626
     627        /*
     628         * Ensure that any program using malloc/realloc/free will fail to compile
     629         */
     630        #ifndef PS_ALLOW_MALLOC
     631        #ifdef __GNUC__
     632        #pragma GCC poison malloc realloc calloc free
     633        #else // __GNUC__
     634        #define malloc(S)       _Pragma("error Use of malloc is not allowed.  Use psAlloc instead.")
     635        #define realloc(P,S)    _Pragma("error Use of realloc is not allowed.  Use psRealloc instead.")
     636        #define calloc(S)       _Pragma("error Use of calloc is not allowed.  Use psAlloc instead.")
     637        #define free(P)         _Pragma("error Use of free is not allowed.  Use psFree instead.")
     638        #endif // ! __GNUC__
     639        #endif // #ifndef PS_ALLOW_MALLOC
     640
     641        #endif // #ifndef DOXYGEN
     642        #endif // #ifndef PS_MEMORY_H
  • trunk/psLib/src/sys/psTrace.c

    r11668 r11674  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.84 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2007-02-06 21:36:09 $
     11 *  @version $Revision: 1.85 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2007-02-07 01:15:49 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    118118
    119119    psMemSetPersistent((psPtr)comp->name,false);
    120     psFree(comp->name);
     120    psFree((void *)comp->name);
    121121}
    122122
  • trunk/psLib/src/types/psLookupTable.c

    r11668 r11674  
    77*  @author Ross Harman, MHPCC
    88*
    9 *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2007-02-06 21:36:09 $
     9*  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2007-02-07 01:15:50 $
    1111*
    1212*  Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
     
    270270{
    271271    psFree(table->values);
    272     psFree(table->filename);
    273     psFree(table->format);
     272    psFree((void *)table->filename);
     273    psFree((void *)table->format);
    274274}
    275275
Note: See TracChangeset for help on using the changeset viewer.