IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 11694


Ignore:
Timestamp:
Feb 7, 2007, 3:59:28 PM (19 years ago)
Author:
jhoblitt
Message:

./sys header file cleanup:

formatting/whitespace fixes
add a few additional gcc attributes
mark p_psFileLine as deprecated

Location:
trunk/psLib/src
Files:
10 edited

Legend:

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

    r11668 r11694  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.109 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2007-02-06 21:36:09 $
     12 *  @version $Revision: 1.110 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2007-02-08 01:59:28 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    899899
    900900        // Date too early for tables. Get default time delta value from metadata, and issue warning.
    901         psLogMsg(__func__,PS_LOG_WARN,_("Specified psTime predates (%g) all tables of %s information."),mjd,"UT1-UTC");
     901        psLogMsg("psLib.astro", PS_LOG_WARN,_("Specified psTime predates (%g) all tables of %s information."),mjd,"UT1-UTC");
    902902
    903903        // Lookup value from time metadata loaded from pslib.config
     
    919919        */
    920920        // Generate warning of postdate information
    921         psLogMsg(__func__,PS_LOG_WARN,_("Specified psTime postdates (%g) all tables of %s information."), mjd, "UT1-UTC");
     921        psLogMsg("psLib.astro", PS_LOG_WARN,_("Specified psTime postdates (%g) all tables of %s information."), mjd, "UT1-UTC");
    922922
    923923        // Lookup values to calculate prediction
     
    10811081        #else
    10821082
    1083         psLogMsg(PS_FILE_LINE, PS_LOG_ERROR, _("Specified psTime predates (%g) all tables of %s information."), mjd, "polar motion");
     1083        psLogMsg("psLib.astro", PS_LOG_ERROR, _("Specified psTime predates (%g) all tables of %s information."), mjd, "polar motion");
    10841084        #endif
    10851085
     
    11161116        #else
    11171117
    1118         psLogMsg(PS_FILE_LINE, PS_LOG_ERROR,
     1118        psLogMsg("psLib.astro", PS_LOG_ERROR,
    11191119                 _("Specified psTime postdates (%g) all tables of %s information."), mjd, "polar motion");
    11201120        #endif
  • trunk/psLib/src/sys/psConfigure.h

    r11248 r11694  
    1111 *  @author Robert DeSonia, MHPCC
    1212 *
    13  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2007-01-23 22:47:23 $
     13 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2007-02-08 01:59:28 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3232    void
    3333);
     34
    3435
    3536/** Get current psLib version (full identification)
     
    5354);
    5455
     56
    5557/** Removes persistant memory created with the psLibInit function.
    5658 *
     
    6466);
    6567
     68
    6669// Check the memory; intended for use on exit, but might be used elsewhere
    6770void p_psMemoryCheck(void);
    6871
     72
    6973/// @}
    7074#endif // #ifndef PS_CONFIGURE_H
  • trunk/psLib/src/sys/psError.h

    r11674 r11694  
    1010 *  @author RHL, Princeton
    1111 *  @author Eric Van Alst, MHPCC
    12  *
    13  *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2007-02-07 01:15:49 $
     12 *  @author Joshua Hoblitt, University of Hawaii
     13 *
     14 *  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2007-02-08 01:59:28 $
    1516 *
    1617 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5556);
    5657
     58
    5759/** Get last error put on the error stack
    5860 *
     
    6466psErr* psErrorLast(void);
    6567
     68
    6669/** Get errorCode of last error put on the error stack
    6770 *
     
    7073psErrorCode psErrorCodeLast(void);
    7174
     75
    7276/** Clears the error stack.
    7377 *
     
    7781void psErrorClear(void);
    7882
     83
    7984/** Get the error stack depth
    8085 *
     
    8287 */
    8388long psErrorGetStackSize();
     89
    8490
    8591/** Prints error stack to specified open file descriptor
     
    9197 *
    9298 */
    93 #ifdef __GNUC__
    9499void psErrorStackPrint(
    95100    FILE* fd,                          ///< destination file descriptor
    96101    const char* format,                ///< printf-style format of header line
    97102    ...                                ///< any parameters required in format
     103#ifdef __GNUC__
    98104) __attribute__((format(printf, 2, 3)));
    99 #else // __GNUC__
    100 void psErrorStackPrint(
    101     FILE* fd,                          ///< destination file descriptor
    102     const char* format,                ///< printf-style format of header line
    103     ...                                ///< any parameters required in format
    104 );
    105 #endif // __GNUC__
     105#else // ifdef __GNUC__
     106);
     107#endif // ifdef __GNUC__
    106108
    107109
     
    120122    va_list va                         ///< any parameters required in format
    121123);
    122 #endif // #ifndef SWIG
    123 
    124 #ifdef DOXYGEN
     124#endif // ifndef SWIG
     125
     126
    125127/** Reports an error message to the logging facility
    126128 *
     
    133135 *  @return psErrorCode    the given error code
    134136 */
     137#ifdef DOXYGEN
    135138psErrorCode psError(
    136139    psErrorCode code,                  ///< Error class code
     
    139142    ...                                ///< any parameters required in format
    140143);
    141 
    142 /** Logs a warning message.
    143  *
    144  *  This procedure logs a message to the destination set by a prior
    145  *  call to psLogSetDestination(), This is equivalent to calling
    146  *  psLogMsg with a level of PS_LOG_WARN.
    147  *
    148  */
    149 void psWarning(
    150     const char* format,                ///< printf-style format of header line
    151     ...                                ///< any parameters required in format
    152 );
    153 #else // #ifdef DOXYGEN
    154 
    155 /** Reports an error message to the logging facility
    156  *
    157  *  This function will invoke the psLogMsg function with a level of
    158  *  PS_LOG_ERROR and pass the parameters name and format to generate a proper
    159  *  log message.  This function is used to check a specific code location.
    160  *
    161  *  This function modifies the error stack.
    162  *
    163  *  @return psErrorcode    the given error code
    164  */
    165 #ifdef __GNUC__
     144#else // ifdef DOXYGEN
    166145psErrorCode p_psError(
    167146    const char* filename,              ///< file name
     
    172151    const char* format,                ///< printf-style format of header line
    173152    ...                                ///< any parameters required in format
     153#ifdef __GNUC__
    174154) __attribute__((format(printf, 6, 7)));
    175 #else // __GNUC__
    176 psErrorCode p_psError(
    177     const char* filename,              ///< file name
    178     unsigned int lineno,               ///< line number in file
    179     const char* func,                  ///< function name
    180     psErrorCode code,                  ///< Error class code
    181     bool new,                          ///< true if error originates at this location
    182     const char* format,                ///< printf-style format of header line
    183     ...                                ///< any parameters required in format
    184 );
    185 #endif // __GNUC__
     155#else // ifdef __GNUC__
     156);
     157#endif // ifdef __GNUC__
     158#ifndef SWIG
     159#define psError(code,new,...) \
     160      p_psError(__FILE__,__LINE__,__func__,code,new,__VA_ARGS__)
     161#endif // ifndef SWIG
     162#endif // ifdef DOXYGEN
     163
    186164
    187165/** Logs a warning message.
    188166 *
    189  *  This procedure logs a message to the destination set by a prior call to
    190  *  psLogSetDestination().  This is equivalent to calling psLogMsg with a level of
    191  *  PS_LOG_WARN.  This function is used to check a specific code location.
    192  *
    193 */
    194 #ifdef __GNUC__
     167 *  This procedure logs a message to the destination set by a prior
     168 *  call to psLogSetDestination(), This is equivalent to calling
     169 *  psLogMsg with a level of PS_LOG_WARN.
     170 *
     171 */
     172#ifdef DOXYGEN
     173void psWarning(
     174    const char* format,                ///< printf-style format of header line
     175    ...                                ///< any parameters required in format
     176);
     177#else // #ifdef DOXYGEN
    195178void p_psWarning(
    196179    const char* file,                  ///< file name
     
    199182    const char* format,                ///< printf-style format of header line
    200183    ...                                ///< any parameters required in format
     184#ifdef __GNUC__
    201185) __attribute__((format(printf, 4, 5)));
    202 #else // __GNUC__
    203 void p_psWarning(
    204     const char* file,                  ///< file name
    205     int lineno,                        ///< line number in file
    206     const char* func,                  ///< function name
    207     const char* format,                ///< printf-style format of header line
    208     ...                                ///< any parameters required in format
    209 );
    210 #endif // __GNUC__
    211 
    212 
     186#else // ifdef __GNUC__
     187);
     188#endif // ifdef __GNUC__
    213189#ifndef SWIG
    214 #define psError(code,new,...) p_psError(__FILE__,__LINE__,__func__,code,new,__VA_ARGS__)
    215 #define psWarning(...) p_psWarning(__FILE__,__LINE__,__func__,__VA_ARGS__)
    216 #endif // #ifndef SWIG
    217 
    218 #endif // ! DOXYGEN
     190#define psWarning(...) \
     191      p_psWarning(__FILE__,__LINE__,__func__,__VA_ARGS__)
     192#endif // ifndef SWIG
     193#endif // ifdef DOXYGEN
     194
    219195
    220196/** Create a new psErr struct
  • trunk/psLib/src/sys/psErrorCodes.h.in

    r11668 r11694  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-02-06 21:36:09 $
     8 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-02-08 01:59:28 $
    1010 *
    1111 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3232} psErrorCode;
    3333
     34
    3435/** An error code with description
    3536 */
     
    4142psErrorDescription;
    4243
     44
    4345/** Allocates a new psErrorDescription
    4446 *
     
    4951    const char *description            ///< the associated description
    5052);
     53
    5154
    5255/** Retrieves the description of an error code.
     
    6063    psErrorCode code                   ///< the associated error code
    6164);
     65
    6266
    6367/** Register an error code
     
    7377);
    7478
     79
    7580/** Clears error codes registered via psErrorRegister.
    7681 *
     
    8186);
    8287
     88
    8389/// @}
    8490#endif // #ifndef PS_ERROR_CODES_H
  • trunk/psLib/src/sys/psLine.h

    r11618 r11694  
    99 *  @author David Robbins, MHPCC
    1010 *
    11  *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2007-02-03 06:01:42 $
     11 *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2007-02-08 01:59:28 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3030psLine;
    3131
     32
    3233/** Allocates a line object of length Nline.
    3334 *
     
    3738    long Nline                         ///< length of line object to allocate
    3839);
     40
    3941
    4042/** Checks the type of a particular pointer.
     
    4749    psPtr ptr                          ///< the pointer whose type to check
    4850);
     51
    4952
    5053/** Initializes or re-initializes a line.
     
    5962);
    6063
     64
    6165/** Adds the line segment to the string.
    6266 *
     
    7074    const char *format,                ///< printf-style format of line
    7175    ...                                ///< any parameters required in format
     76#ifdef __GNUC__
     77) __attribute__((format(printf, 2, 3)));
     78#else // ifdef __GNUC__
    7279);
     80#endif // ifdef __GNUC__
     81
    7382
    7483/// @}
  • trunk/psLib/src/sys/psLogMsg.h

    r11248 r11694  
    99 *  @author Robert Lupton, Princeton University
    1010 *  @author GLG, MHPCC
     11 *  @author Joshua Hoblitt, University of Hawaii
    1112 *
    12  *  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2007-01-23 22:47:23 $
     13 *  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2007-02-08 01:59:28 $
    1415 *
    1516 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2526#include "psType.h"
    2627
     28
     29///< Status codes for log messages
     30enum {
     31    PS_LOG_ABORT = 0,                  ///< log message is a critical error, perform an abort after printing
     32    PS_LOG_ERROR,                      ///< log message is an error, but don't abort
     33    PS_LOG_WARN,                       ///< log message is a warning
     34    PS_LOG_INFO,                       ///< log message is informational only
     35    PS_LOG_DETAIL,                     ///< log message provides details of minor interest
     36    PS_LOG_MINUTIA,                    ///< log message provides very detailed information
     37};
     38
     39
     40///< Destinations for log messages
     41enum {
     42    PS_LOG_TO_NONE = 0,                ///< turn off logging
     43    PS_LOG_TO_STDERR = 1,              ///< log to system's stderr
     44    PS_LOG_TO_STDOUT = 2               ///< log to system's stdout
     45};
     46
    2747/** This procedure sets the destination for future log messages.
    2848 *
     
    3656);
    3757
     58
    3859/** This procedure returns the current log destination file descriptor.  If the
    39  *  destination has not been defined by the use, the descriptor for stdout is returned.
     60 * destination has not been defined by the use, the descriptor for stdout is
     61 * returned.
    4062 *
    4163 *  @return int:        The current file descriptor.
    4264 */
    4365int psLogGetDestination();
     66
    4467
    4568/** This procedure sets the message level for future log messages.  Subsequent
     
    5477    int level                          ///< Specifies the system log level
    5578);
     79
    5680
    5781/** This procedures returns the current log message level.
     
    7498);
    7599
     100
    76101/** This procedures uses a string to set the destination for which to send
    77102 *  the corresponding log messages.
     
    83108);
    84109
     110
    85111/** This procedure logs a message to the destination set by a prior
    86112 *  call to psLogSetDestination(), if myLevel is less than the level
     
    89115 *
    90116 */
    91 #ifdef __GNUC__
    92117void psLogMsg(
    93118    const char *name,                  ///< name of the log source
     
    95120    const char *format,                ///< printf-style format command
    96121    ...
     122#ifdef __GNUC__
    97123) __attribute__((format(printf, 3, 4)));
    98 #else // __GNUC__
    99 void psLogMsg(
    100     const char *name,                  ///< name of the log source
    101     int level,                         ///< severity level of this log message
    102     const char *format,                ///< printf-style format command
    103     ...
     124#else // ifdef __GNUC__
    104125);
    105 #endif // __GNUC__
     126#endif // ifdef __GNUC__
    106127
    107 #ifndef SWIG
     128
    108129/** This procedure is functionally equivalent to psLogMsg(), except that
    109130 *  it takes a va_list as the message parameter, not a printf-style string.
    110131 *
    111132 */
     133#ifndef SWIG
    112134void psLogMsgV(
    113135    const char *name,                  ///< name of the log source
     
    118140#endif // #ifndef SWIG
    119141
    120 ///< Status codes for log messages
    121 enum {
    122     PS_LOG_ABORT = 0,                  ///< log message is a critical error, perform an abort after printing
    123     PS_LOG_ERROR,                      ///< log message is an error, but don't abort
    124     PS_LOG_WARN,                       ///< log message is a warning
    125     PS_LOG_INFO,                       ///< log message is informational only
    126     PS_LOG_DETAIL,                     ///< log message provides details of minor interest
    127     PS_LOG_MINUTIA,                    ///< log message provides very detailed information
    128 };
    129 
    130 ///< Destinations for log messages
    131 enum {
    132     PS_LOG_TO_NONE = 0,                ///< turn off logging
    133     PS_LOG_TO_STDERR = 1,              ///< log to system's stderr
    134     PS_LOG_TO_STDOUT = 2               ///< log to system's stdout
    135 };
    136142
    137143/// @}
  • trunk/psLib/src/sys/psMemory.h

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

    r11616 r11694  
    99 * @author Eric Van Alst, MHPCC
    1010 * @author David Robbins, MHPCC
    11  *
    12  * @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
    13  * @date $Date: 2007-02-03 05:35:30 $
     11 * @author Joshua Hoblitt, University of Hawaii
     12 *
     13 * @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
     14 * @date $Date: 2007-02-08 01:59:28 $
    1415 *
    1516 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3132
    3233/** This macro returns a (static buffer containing) "file:line" */
     34#ifdef __GNUC__
     35const char *p_psFileLine(const char *file, int line) __attribute__((deprecated));
     36#else // ifdef __GNUC__
    3337const char *p_psFileLine(const char *file, int line);
     38#endif // ifdef __GNUC__
    3439#define PS_FILE_LINE p_psFileLine(__FILE__,__LINE__)
    3540
     
    4247);
    4348
     49
    4450/** Checks the type of a particular pointer.
    4551 *
    46  *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
     52 *  Uses the appropriate deallocation function in psMemBlock to check the ptr
     53 *  datatype.
    4754 *
    4855 *  @return bool:       True if the pointer matches a psString structure, false otherwise.
     
    5158    psPtr ptr                          ///< the pointer whose type to check
    5259);
     60
    5361
    5462/** Copies the input string
     
    6371    const char *string                 ///< Input string of characters to copy
    6472);
     73
    6574
    6675/** Copies the input string up to the specified number of characters
     
    8190);
    8291
     92
    8393/** Appends a format onto a string
    8494 *
     
    8898 * @return ssize_t:     The length of the new string (excluding '\0')
    8999 */
     100ssize_t psStringAppend(
     101    char **dest,                        ///< existing string
     102    const char *format,                 ///< format to append
     103    ...                                 ///< format arguments
    90104#ifdef __GNUC__
    91 ssize_t psStringAppend(
    92     char **dest,                        ///< existing string
    93     const char *format,                 ///< format to append
    94     ...                                 ///< format arguments
    95105) __attribute__((format(printf, 2, 3)));
    96106#else // __GNUC__
    97 ssize_t psStringAppend(
     107);
     108#endif // __GNUC__
     109
     110
     111/** Appends a format onto a string
     112 *
     113 * This function shall allocate a new string if dest is NULL.  dest shall be
     114 * automatically extended to the size of the new string.
     115 *
     116 * @return ssize_t:     The length of the new string (excluding '\0')
     117 */
     118ssize_t psStringAppendV(
     119    char **dest,                        ///< existing string
     120    const char *format,                 ///< format to append
     121    va_list ap                          ///< va_list of format arguments
     122);
     123
     124
     125/** Prepends a format onto a string
     126 *
     127 * This function shall allocate a new string if dest is NULL.  dest shall be
     128 * automatically extended to the size of the new string.
     129 *
     130 * @return ssize_t:     The length of the new string (excluding '\0')
     131 */
     132ssize_t psStringPrepend(
    98133    char **dest,                        ///< existing string
    99134    const char *format,                 ///< format to append
    100135    ...                                 ///< format arguments
    101 );
    102 #endif // __GNUC__
    103 
    104 /** Appends a format onto a string
    105  *
    106  * This function shall allocate a new string if dest is NULL.  dest shall be
    107  * automatically extended to the size of the new string.
    108  *
    109  * @return ssize_t:     The length of the new string (excluding '\0')
    110  */
    111 ssize_t psStringAppendV(
    112     char **dest,                        ///< existing string
    113     const char *format,                 ///< format to append
    114     va_list ap                          ///< va_list of format arguments
    115 );
    116 
    117 /** Prepends a format onto a string
    118  *
    119  * This function shall allocate a new string if dest is NULL.  dest shall be
    120  * automatically extended to the size of the new string.
    121  *
    122  * @return ssize_t:     The length of the new string (excluding '\0')
    123  */
    124136#ifdef __GNUC__
    125 ssize_t psStringPrepend(
    126     char **dest,                        ///< existing string
    127     const char *format,                 ///< format to append
    128     ...                                 ///< format arguments
    129137) __attribute__((format(printf, 2, 3)));
    130138# else // __GNUC__
    131 
    132     ssize_t psStringPrepend(
    133         char **dest,                        ///< existing string
    134         const char *format,                 ///< format to append
    135         ...                                 ///< format arguments
    136     );
     139);
    137140#endif // __GNUC__
    138141
     142
    139143/** Prepends a format onto a string
    140144 *
     
    149153    va_list ap                          ///< va_list of format arguments
    150154);
     155
    151156
    152157/** Procedure to split the input string into a psList of psStrings.
     
    163168);
    164169
     170
    165171/** Procedure to split the input string into a psArray of psStrings.
    166172 *
     
    176182);
    177183
    178 // Given the input string, search for all copies of the key, and replace with the replacement value
    179 // the input string may be freed if not needed
     184// Given the input string, search for all copies of the key, and replace with
     185// the replacement value the input string may be freed if not needed
    180186/** Procedure to search an input string and substitute strings where desired.
    181187 *
    182  *  The input string is searched for all instances of the key, which is then replaced with
    183  *  the replacement value wherever found.  The input string may be freed if not needed.
     188 *  The input string is searched for all instances of the key, which is then
     189 *  replaced with the replacement value wherever found.  The input string may
     190 *  be freed if not needed.
    184191 *
    185192 *  @return ssize_t:      the length of the new string (excluding '\0')
     
    191198);
    192199
     200
    193201// strip whitespace from head and tail of string
    194202/** Procedure to strip the whitespace from the head and tail of a string.
     
    199207    char *string                       ///< input string to be stripped.
    200208);
     209
    201210
    202211/// Given a CVS keyword string, strip off the CVS-specific keyword to get the value
     
    222231#endif // ifndef DOXYGEN
    223232
     233
    224234/// @}
    225235#endif // #ifndef PS_STRING_H
  • trunk/psLib/src/sys/psTrace.h

    r11449 r11694  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.54 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2007-01-31 00:38:46 $
     11 *  @version $Revision: 1.55 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2007-02-08 01:59:28 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6969p_psComponent;
    7070
     71
    7172/** This procedure sets the trace format for future trace messages.  The argument
    7273 *  must be a character string consistsing of the letters H (host), L
     
    8283);
    8384
     85/** Sends a trace message. */
    8486#ifdef DOXYGEN
    85 /** Sends a trace message. */
    8687void psTrace(
    8788    const char *facil,                 ///< facilty of interest
     
    9091    ...                                ///< trace message arguments
    9192);
    92 
    93 /** Get the trace level
    94  *
    95  *  @return int:    Trace Level
    96  */
    97 int psTraceGetLevel(
    98     const char *facil                  ///< facilty of interest
    99 );
    100 
    101 #else // DOXYGEN
    102 #ifdef __GNUC__
    103 /// Send a trace message
     93#else // ifdef DOXYGEN
    10494void p_psTrace(
    10595    const char* file,                  ///< file name
     
    110100    const char *format,                ///< printf-style format command
    111101    ...                                ///< trace message arguments
     102#ifdef __GNUC__
    112103) __attribute__((format(printf, 6, 7)));
    113 #else // __GNUC__
    114 void p_psTrace(
    115     const char* file,                  ///< file name
    116     int lineno,                        ///< line number in file
    117     const char* func,                  ///< function name
    118     const char *facil,                 ///< facilty of interest
    119     psS32 level,                       ///< desired trace level
    120     const char *format,                ///< printf-style format command
    121     ...                                ///< trace message arguments
     104#else // ifdef __GNUC__
    122105);
    123 #endif // __GNUC__
     106#endif // ifdef __GNUC__
     107#ifndef SWIG
     108#define psTrace(facil, level, ...) \
     109      p_psTrace(__FILE__,__LINE__,__func__,facil, level, __VA_ARGS__)
     110#endif // ifndef SWIG
     111#endif // ifdef DOXYGEN
     112
    124113
    125114/** Get the trace level
     
    127116 *  @return int:    Trace Level
    128117 */
     118#ifdef DOXYGEN
     119int psTraceGetLevel(
     120    const char *facil                  ///< facilty of interest
     121);
     122#else // ifdef DOXYGEN
    129123int p_psTraceGetLevel(
    130124    const char* file,                  ///< file name
     
    133127    const char *facil                  ///< facilty of interest
    134128);
     129#ifndef SWIG
     130#define psTraceGetLevel(facil) \
     131      p_psTraceGetLevel(__FILE__,__LINE__,__func__,facil)
     132#endif // ifndef SWIG
     133#endif // ifdef DOXYGEN
    135134
    136 #ifndef SWIG
    137 #define psTrace(facil, level, ...) p_psTrace(__FILE__,__LINE__,__func__,facil, level, __VA_ARGS__)
    138 #define psTraceGetLevel(facil) p_psTraceGetLevel(__FILE__,__LINE__,__func__,facil)
     135
     136
    139137/** Sends a trace message. */
    140138void psTraceV(
     
    144142    va_list ap                         ///< varargs argument list
    145143);
    146 #endif /* SWIG */
    147 #endif /* DOXYGEN */
     144
    148145
    149146/** Set trace level
     
    159156void psTraceReset(void);
    160157
     158
    161159/// print trace levels
    162160void psTracePrintLevels(void);
     161
    163162
    164163/// Set the destination of future trace messages.
     
    166165    int fd                             ///< File descriptor
    167166);
     167
    168168
    169169/** Get the current destination for trace messages.
     
    173173int psTraceGetDestination(void);
    174174
     175
    175176/// Return a psMetadata summarising the trace levels
    176177psMetadata *psTraceLevels(void);
     178
    177179
    178180/// @}
  • trunk/psLib/src/sys/psType.h

    r11668 r11694  
    1010*  @author Ross Harman, MHPCC
    1111*
    12 *  @version $Revision: 1.55 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2007-02-06 21:36:09 $
     12*  @version $Revision: 1.56 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2007-02-08 01:59:28 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5959psC32;
    6060
     61
    6162/** 64-bit complex value */
    6263typedef struct
     
    6566}
    6667psC64;
     68
    6769
    6870#else // SWIG
Note: See TracChangeset for help on using the changeset viewer.