Changeset 11694
- Timestamp:
- Feb 7, 2007, 3:59:28 PM (19 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 10 edited
-
astro/psTime.c (modified) (5 diffs)
-
sys/psConfigure.h (modified) (4 diffs)
-
sys/psError.h (modified) (12 diffs)
-
sys/psErrorCodes.h.in (modified) (7 diffs)
-
sys/psLine.h (modified) (6 diffs)
-
sys/psLogMsg.h (modified) (9 diffs)
-
sys/psMemory.h (modified) (3 diffs)
-
sys/psString.h (modified) (13 diffs)
-
sys/psTrace.h (modified) (11 diffs)
-
sys/psType.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astro/psTime.c
r11668 r11694 10 10 * @author Ross Harman, MHPCC 11 11 * 12 * @version $Revision: 1.1 09$ $Name: not supported by cvs2svn $13 * @date $Date: 2007-02-0 6 21:36:09$12 * @version $Revision: 1.110 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2007-02-08 01:59:28 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 899 899 900 900 // 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"); 902 902 903 903 // Lookup value from time metadata loaded from pslib.config … … 919 919 */ 920 920 // 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"); 922 922 923 923 // Lookup values to calculate prediction … … 1081 1081 #else 1082 1082 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"); 1084 1084 #endif 1085 1085 … … 1116 1116 #else 1117 1117 1118 psLogMsg( PS_FILE_LINE, PS_LOG_ERROR,1118 psLogMsg("psLib.astro", PS_LOG_ERROR, 1119 1119 _("Specified psTime postdates (%g) all tables of %s information."), mjd, "polar motion"); 1120 1120 #endif -
trunk/psLib/src/sys/psConfigure.h
r11248 r11694 11 11 * @author Robert DeSonia, MHPCC 12 12 * 13 * @version $Revision: 1.1 0$ $Name: not supported by cvs2svn $14 * @date $Date: 2007-0 1-23 22:47:23$13 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2007-02-08 01:59:28 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 32 32 void 33 33 ); 34 34 35 35 36 /** Get current psLib version (full identification) … … 53 54 ); 54 55 56 55 57 /** Removes persistant memory created with the psLibInit function. 56 58 * … … 64 66 ); 65 67 68 66 69 // Check the memory; intended for use on exit, but might be used elsewhere 67 70 void p_psMemoryCheck(void); 68 71 72 69 73 /// @} 70 74 #endif // #ifndef PS_CONFIGURE_H -
trunk/psLib/src/sys/psError.h
r11674 r11694 10 10 * @author RHL, Princeton 11 11 * @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 $ 15 16 * 16 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 55 56 ); 56 57 58 57 59 /** Get last error put on the error stack 58 60 * … … 64 66 psErr* psErrorLast(void); 65 67 68 66 69 /** Get errorCode of last error put on the error stack 67 70 * … … 70 73 psErrorCode psErrorCodeLast(void); 71 74 75 72 76 /** Clears the error stack. 73 77 * … … 77 81 void psErrorClear(void); 78 82 83 79 84 /** Get the error stack depth 80 85 * … … 82 87 */ 83 88 long psErrorGetStackSize(); 89 84 90 85 91 /** Prints error stack to specified open file descriptor … … 91 97 * 92 98 */ 93 #ifdef __GNUC__94 99 void psErrorStackPrint( 95 100 FILE* fd, ///< destination file descriptor 96 101 const char* format, ///< printf-style format of header line 97 102 ... ///< any parameters required in format 103 #ifdef __GNUC__ 98 104 ) __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__ 106 108 107 109 … … 120 122 va_list va ///< any parameters required in format 121 123 ); 122 #endif // #ifndef SWIG123 124 #ifdef DOXYGEN 124 #endif // ifndef SWIG 125 126 125 127 /** Reports an error message to the logging facility 126 128 * … … 133 135 * @return psErrorCode the given error code 134 136 */ 137 #ifdef DOXYGEN 135 138 psErrorCode psError( 136 139 psErrorCode code, ///< Error class code … … 139 142 ... ///< any parameters required in format 140 143 ); 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 166 145 psErrorCode p_psError( 167 146 const char* filename, ///< file name … … 172 151 const char* format, ///< printf-style format of header line 173 152 ... ///< any parameters required in format 153 #ifdef __GNUC__ 174 154 ) __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 186 164 187 165 /** Logs a warning message. 188 166 * 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 173 void psWarning( 174 const char* format, ///< printf-style format of header line 175 ... ///< any parameters required in format 176 ); 177 #else // #ifdef DOXYGEN 195 178 void p_psWarning( 196 179 const char* file, ///< file name … … 199 182 const char* format, ///< printf-style format of header line 200 183 ... ///< any parameters required in format 184 #ifdef __GNUC__ 201 185 ) __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__ 213 189 #ifndef SWIG 214 #define ps Error(code,new,...) p_psError(__FILE__,__LINE__,__func__,code,new,__VA_ARGS__)215 #define psWarning(...)p_psWarning(__FILE__,__LINE__,__func__,__VA_ARGS__)216 #endif // #ifndef SWIG217 218 #endif // ! DOXYGEN 190 #define psWarning(...) \ 191 p_psWarning(__FILE__,__LINE__,__func__,__VA_ARGS__) 192 #endif // ifndef SWIG 193 #endif // ifdef DOXYGEN 194 219 195 220 196 /** Create a new psErr struct -
trunk/psLib/src/sys/psErrorCodes.h.in
r11668 r11694 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-02-0 6 21:36:09$8 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-02-08 01:59:28 $ 10 10 * 11 11 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 32 32 } psErrorCode; 33 33 34 34 35 /** An error code with description 35 36 */ … … 41 42 psErrorDescription; 42 43 44 43 45 /** Allocates a new psErrorDescription 44 46 * … … 49 51 const char *description ///< the associated description 50 52 ); 53 51 54 52 55 /** Retrieves the description of an error code. … … 60 63 psErrorCode code ///< the associated error code 61 64 ); 65 62 66 63 67 /** Register an error code … … 73 77 ); 74 78 79 75 80 /** Clears error codes registered via psErrorRegister. 76 81 * … … 81 86 ); 82 87 88 83 89 /// @} 84 90 #endif // #ifndef PS_ERROR_CODES_H -
trunk/psLib/src/sys/psLine.h
r11618 r11694 9 9 * @author David Robbins, MHPCC 10 10 * 11 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $12 * @date $Date: 2007-02-0 3 06:01:42$11 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2007-02-08 01:59:28 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 30 30 psLine; 31 31 32 32 33 /** Allocates a line object of length Nline. 33 34 * … … 37 38 long Nline ///< length of line object to allocate 38 39 ); 40 39 41 40 42 /** Checks the type of a particular pointer. … … 47 49 psPtr ptr ///< the pointer whose type to check 48 50 ); 51 49 52 50 53 /** Initializes or re-initializes a line. … … 59 62 ); 60 63 64 61 65 /** Adds the line segment to the string. 62 66 * … … 70 74 const char *format, ///< printf-style format of line 71 75 ... ///< any parameters required in format 76 #ifdef __GNUC__ 77 ) __attribute__((format(printf, 2, 3))); 78 #else // ifdef __GNUC__ 72 79 ); 80 #endif // ifdef __GNUC__ 81 73 82 74 83 /// @} -
trunk/psLib/src/sys/psLogMsg.h
r11248 r11694 9 9 * @author Robert Lupton, Princeton University 10 10 * @author GLG, MHPCC 11 * @author Joshua Hoblitt, University of Hawaii 11 12 * 12 * @version $Revision: 1.3 8$ $Name: not supported by cvs2svn $13 * @date $Date: 2007-0 1-23 22:47:23$13 * @version $Revision: 1.39 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2007-02-08 01:59:28 $ 14 15 * 15 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 25 26 #include "psType.h" 26 27 28 29 ///< Status codes for log messages 30 enum { 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 41 enum { 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 27 47 /** This procedure sets the destination for future log messages. 28 48 * … … 36 56 ); 37 57 58 38 59 /** 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. 40 62 * 41 63 * @return int: The current file descriptor. 42 64 */ 43 65 int psLogGetDestination(); 66 44 67 45 68 /** This procedure sets the message level for future log messages. Subsequent … … 54 77 int level ///< Specifies the system log level 55 78 ); 79 56 80 57 81 /** This procedures returns the current log message level. … … 74 98 ); 75 99 100 76 101 /** This procedures uses a string to set the destination for which to send 77 102 * the corresponding log messages. … … 83 108 ); 84 109 110 85 111 /** This procedure logs a message to the destination set by a prior 86 112 * call to psLogSetDestination(), if myLevel is less than the level … … 89 115 * 90 116 */ 91 #ifdef __GNUC__92 117 void psLogMsg( 93 118 const char *name, ///< name of the log source … … 95 120 const char *format, ///< printf-style format command 96 121 ... 122 #ifdef __GNUC__ 97 123 ) __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__ 104 125 ); 105 #endif // __GNUC__126 #endif // ifdef __GNUC__ 106 127 107 #ifndef SWIG 128 108 129 /** This procedure is functionally equivalent to psLogMsg(), except that 109 130 * it takes a va_list as the message parameter, not a printf-style string. 110 131 * 111 132 */ 133 #ifndef SWIG 112 134 void psLogMsgV( 113 135 const char *name, ///< name of the log source … … 118 140 #endif // #ifndef SWIG 119 141 120 ///< Status codes for log messages121 enum {122 PS_LOG_ABORT = 0, ///< log message is a critical error, perform an abort after printing123 PS_LOG_ERROR, ///< log message is an error, but don't abort124 PS_LOG_WARN, ///< log message is a warning125 PS_LOG_INFO, ///< log message is informational only126 PS_LOG_DETAIL, ///< log message provides details of minor interest127 PS_LOG_MINUTIA, ///< log message provides very detailed information128 };129 130 ///< Destinations for log messages131 enum {132 PS_LOG_TO_NONE = 0, ///< turn off logging133 PS_LOG_TO_STDERR = 1, ///< log to system's stderr134 PS_LOG_TO_STDOUT = 2 ///< log to system's stdout135 };136 142 137 143 /// @} -
trunk/psLib/src/sys/psMemory.h
r11674 r11694 15 15 * @ingroup MemoryManagement 16 16 * 17 * @version $Revision: 1.6 7$ $Name: not supported by cvs2svn $18 * @date $Date: 2007-02-0 7 01:15:49$17 * @version $Revision: 1.68 $ $Name: not supported by cvs2svn $ 18 * @date $Date: 2007-02-08 01:59:28 $ 19 19 * 20 20 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 131 131 size_t size ///< Size required 132 132 ); 133 #else // #ifdef DOXYGEN133 #else // ifdef DOXYGEN 134 134 void *p_psAlloc( 135 135 const char *file, ///< File of caller … … 137 137 const char *func, ///< Function name of caller 138 138 size_t size ///< Size required 139 #ifdef __GNUC__139 #ifdef __GNUC__ 140 140 ) __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) \ 146 p_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 159 void 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 164 void 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 188 psFreeFunc psMemGetDeallocator( 189 void *ptr ///< the memory block 190 ); 191 #else // ifdef DOXYGEN 192 psFreeFunc 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 */ 216 bool 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 */ 229 bool 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 244 void 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 249 void 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 */ 270 bool 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 283 bool psMemGetPersistent( 284 void *ptr, ///< the memory block to check. 285 ); 286 #else // ifdef DOXYGEN 287 bool 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 307 void *psRealloc( 308 void *ptr, ///< Pointer to re-allocate 309 size_t size ///< Size required 310 ); 311 #else // ifdef DOXYGEN 312 void *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 335 void psFree( 336 void *ptr ///< Pointer to free, if NULL, function returns immediately. 337 ); 338 #else // ifdef DOXYGEN 339 #ifndef SWIG 340 #define psFree(ptr) \ 343 341 psMemDecrRefCounter(ptr) 344 #endif // !SWIG345 #endif // !DOXYGEN346 347 348 /** Check for memory leaks. This scans for allocated memory buffers not freed349 * 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 via351 * psGetMemId -# after the block of code to be checked, call this function352 * using the ID stored above. If all memory in the block that was allocated353 * 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 as356 * well.357 *358 * @return int number of memory blocks found as 'leaks', i.e., the number of359 * currently allocated memory blocks above id0 that have not been freed. @see360 * psAlloc, psFree, psgetMemId, psMemProblemCallbackSet361 */362 #ifdef DOXYGEN363 int psMemCheckLeaks(364 psMemId id0, ///< don't list blocks with id < id0365 psMemBlock ***array, ///< pointer to array of pointers to leaked blocks, or NULL366 FILE * fd, ///< print list of leaks to fd (or NULL)367 bool persistence ///< make check across all object even persistent ones368 );369 #else // ifdef DOXYGEN370 int p_psMemCheckLeaks(371 const char *file, ///< File of caller372 unsigned int lineno, ///< Line number of caller373 const char *func, ///< Function name of caller374 psMemId id0, ///< don't list blocks with id < id0375 psMemBlock ***array, ///< pointer to array of pointers to leaked blocks, or NULL376 FILE * fd, ///< print list of leaks to fd (or NULL)377 bool persistence ///< make check across all object even persistent ones378 );379 #ifndef SWIG380 #define psMemCheckLeaks(id0, array, fd, persistence) \381 p_psMemCheckLeaks(__FILE__, __LINE__, __func__, id0, array, fd, persistence)382 #endif // ifndef SWIG383 #endif // ifdef DOXYGEN384 385 386 /** Check for memory corruption. Scans all currently allocated memory buffers387 * and checks for corruptions, i.e., invalid markers that signify a buffer388 * under/overflow.389 *390 * @return int391 *392 */393 #ifdef DOXYGEN394 int psMemCheckCorruption(395 FILE *output, ///< FILE to write corrupted blocks too396 bool abort_on_error ///< Abort on detecting corruption?397 );398 #else // ifdef DOXYGEN399 int p_psMemCheckCorruption(400 const char *file, ///< File of caller401 unsigned int lineno, ///< Line number of caller402 const char *func, ///< Function name of caller403 FILE *output, ///< FILE to write corrupted blocks too404 bool abort_on_error ///< Abort on detecting corruption?405 );406 #ifndef SWIG407 #define psMemCheckCorruption(output, abort_on_error) \408 p_psMemCheckCorruption(__FILE__, __LINE__, __func__, output, abort_on_error)409 #endif // ifndef SWIG410 #endif // ifdef DOXYGEN411 412 413 /** Return reference counter414 *415 * @return psReferenceCount416 *417 */418 #ifdef DOXYGEN419 psReferenceCount psMemGetRefCounter(420 void *ptr ///< Pointer to get refCounter for421 );422 423 #else // ifdef DOXYGEN424 psReferenceCount p_psMemGetRefCounter(425 const char *file, ///< File of call426 unsigned int lineno, ///< Line number of call427 const char *func, ///< Function name of caller428 void *ptr ///< Pointer to get refCounter for429 );430 #ifndef SWIG431 #define psMemGetRefCounter(ptr) \432 p_psMemGetRefCounter(__FILE__, __LINE__, __func__, ptr)433 #endif // !SWIG434 #endif // !DOXYGEN435 436 437 /** Increment reference counter and return the pointer438 *439 * @return void *440 *441 */442 #ifdef DOXYGEN443 void *psMemIncrRefCounter(444 void *ptr ///< Pointer to increment refCounter, and return445 );446 #else // ifdef DOXYGEN447 void *p_psMemIncrRefCounter(448 const char *file, ///< File of call449 unsigned int lineno, ///< Line number of call450 const char *func, ///< Function name of caller451 void *ptr ///< Pointer to increment refCounter, and return452 );453 #ifndef SWIG454 #define psMemIncrRefCounter(ptr) \455 p_psMemIncrRefCounter(__FILE__, __LINE__, __func__, ptr)456 #endif // !SWIG457 #endif // !DOXYGEN458 459 460 /** Decrement reference counter and return the pointer461 *462 *463 * @return void * the pointer deremented in refCount, or NULL if pointer is464 * fully dereferenced.465 */466 #ifdef DOXYGEN467 void *psMemDecrRefCounter(468 void *ptr ///< Pointer to decrement refCounter, and return469 );470 #else // DOXYGEN471 void *p_psMemDecrRefCounter(472 const char *file, ///< File of call473 unsigned int lineno, ///< Line number of call474 const char *func, ///< Function name of caller475 void *ptr ///< Pointer to decrement refCounter, and return476 );477 #ifndef SWIG478 #define psMemDecrRefCounter(ptr) \479 p_psMemDecrRefCounter(__FILE__, __LINE__, __func__, ptr)480 #endif // !SWIG481 #endif // !DOXYGEN482 483 484 #if 0 // psMemSetRefCounter485 /** Set reference counter and return the pointer486 *487 * @return void * the pointer with refCount set, or NULL if pointer is488 * fully dereferenced.489 */490 #ifdef DOXYGEN491 void * psMemSetRefCounter(492 void * ptr, ///< Pointer to decrement refCounter, and return493 psReferenceCount count ///< New reference count494 );495 #else // DOXYGEN496 void * p_psMemSetRefCounter(497 void * vptr, ///< Pointer to decrement refCounter, and return498 psReferenceCount count, ///< New reference count499 const char *file, ///< File of call500 psS32 lineno ///< Line number of call501 );502 503 #ifndef SWIG504 #define psMemSetRefCounter(vptr, count) p_psMemSetRefCounter(vptr, count, __FILE__, __LINE__)505 #endif // !SWIG506 507 #endif // !DOXYGEN508 #endif // psMemSetRefCounter509 510 /** Set callback for out-of-memory.511 *512 * If not enough memory is available to satisfy a request by psAlloc or513 * psRealloc, these functions attempt to find an alternative solution by514 * calling the psMemExhaustedCallback, a function which may be set by the515 * programmer in appropriate circumstances, rather than immediately fail.516 * The typical use of such a feature may be when a program needs a large517 * 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 smaller519 * request and try again, limiting the size of the operating buffer.520 *521 * @return psMemExhaustedCallback old psMemExhaustedCallback function522 */523 psMemExhaustedCallback psMemExhaustedCallbackSet(524 psMemExhaustedCallback func ///< Function to run at memory exhaustion525 );526 527 528 /** Set call back for when a particular memory block is allocated529 *530 * A private variable, p_psMemAllocID, can be used to trace the allocation531 * and freeing of specific memory blocks. If p_psMemAllocID is set and a532 * memory block with that ID is allocated, psMemAllocCallback is called533 * just before memory is returned to the calling function.534 *535 * @return psMemAllocCallback old psMemAllocCallback function536 */537 psMemAllocCallback psMemAllocCallbackSet(538 psMemAllocCallback func ///< Function to run at memory allocation of specific mem block539 );540 541 542 /** Set call back for when a particular memory block is freed543 *544 * A private variable, p_psMemFreeID, can be used to trace the freeing of545 * specific memory blocks. If p_psMemFreeID is set and the memory block with546 * the ID is about to be freed, the psMemFreeCallback callback is called just547 * before the memory block is freed.548 *549 * @return psMemFreeCallback old psMemFreeCallback function550 */551 psMemFreeCallback psMemFreeCallbackSet(552 psMemFreeCallback func ///< Function to run at memory free of specific mem block553 );554 555 556 /** get next memory ID557 *558 * @return psMemId the next memory ID to be used559 */560 psMemId psMemGetId(void);561 562 563 /** get the last memory ID used564 *565 * @return psMemId the last memory ID used566 */567 psMemId psMemGetLastId(void);568 569 570 /** set p_psMemAllocID to specific id571 *572 * A private variable, p_psMemAllocID, can be used to trace the allocation573 * and freeing of specific memory blocks. If p_psMemAllocID is set and a574 * memory block with that ID is allocated, psMemAllocCallback is called575 * just before memory is returned to the calling function.576 *577 * @return psMemId578 *579 * @see psMemAllocCallbackSet580 */581 psMemId psMemAllocCallbackSetID(582 psMemId id ///< ID to set583 );584 585 586 /** set p_psMemFreeID to id587 *588 * A private variable, p_psMemFreeID, can be used to trace the freeing of589 * specific memory blocks. If p_psMemFreeID is set and the memory block with590 * the ID is about to be freed, the psMemFreeCallback callback is called just591 * before the memory block is freed.592 *593 * @return psMemId the old p_psMemFreeID594 *595 * @see psMemFreeCallbackSet596 */597 psMemId psMemFreeCallbackSetID(598 psMemId id ///< ID to set599 );600 601 602 /** return statistics on memory usage603 *604 * @return the total amount of memory owned by psLib; if non-NULL also provide605 * a breakdown into allocated and allocated-and-persistent606 */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 allocated610 611 /** print detailed information about a psMemBlock612 *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 too619 const psMemBlock *memBlock ///< psMemBlock to be examined620 );621 622 623 /// @} end of SysUtils624 625 #ifndef DOXYGEN626 627 /*628 * Ensure that any program using malloc/realloc/free will fail to compile629 */630 #ifndef PS_ALLOW_MALLOC631 #ifdef __GNUC__632 #pragma GCC poison malloc realloc calloc free633 #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_MALLOC640 641 #endif // #ifndef DOXYGEN642 #endif // #ifndef PS_MEMORY_H342 #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 361 int 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 368 int 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 392 int psMemCheckCorruption( 393 FILE *output, ///< FILE to write corrupted blocks too 394 bool abort_on_error ///< Abort on detecting corruption? 395 ); 396 #else // ifdef DOXYGEN 397 int 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 417 psReferenceCount psMemGetRefCounter( 418 void *ptr ///< Pointer to get refCounter for 419 ); 420 421 #else // ifdef DOXYGEN 422 psReferenceCount 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 441 void *psMemIncrRefCounter( 442 void *ptr ///< Pointer to increment refCounter, and return 443 ); 444 #else // ifdef DOXYGEN 445 void *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 465 void *psMemDecrRefCounter( 466 void *ptr ///< Pointer to decrement refCounter, and return 467 ); 468 #else // DOXYGEN 469 void *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 489 void * psMemSetRefCounter( 490 void * ptr, ///< Pointer to decrement refCounter, and return 491 psReferenceCount count ///< New reference count 492 ); 493 #else // DOXYGEN 494 void * 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 */ 521 psMemExhaustedCallback 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 */ 535 psMemAllocCallback 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 */ 549 psMemFreeCallback 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 */ 558 psMemId psMemGetId(void); 559 560 561 /** get the last memory ID used 562 * 563 * @return psMemId the last memory ID used 564 */ 565 psMemId 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 */ 579 psMemId 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 */ 595 psMemId 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 */ 605 size_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 */ 615 int 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 9 9 * @author Eric Van Alst, MHPCC 10 10 * @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 $ 14 15 * 15 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 31 32 32 33 /** This macro returns a (static buffer containing) "file:line" */ 34 #ifdef __GNUC__ 35 const char *p_psFileLine(const char *file, int line) __attribute__((deprecated)); 36 #else // ifdef __GNUC__ 33 37 const char *p_psFileLine(const char *file, int line); 38 #endif // ifdef __GNUC__ 34 39 #define PS_FILE_LINE p_psFileLine(__FILE__,__LINE__) 35 40 … … 42 47 ); 43 48 49 44 50 /** Checks the type of a particular pointer. 45 51 * 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. 47 54 * 48 55 * @return bool: True if the pointer matches a psString structure, false otherwise. … … 51 58 psPtr ptr ///< the pointer whose type to check 52 59 ); 60 53 61 54 62 /** Copies the input string … … 63 71 const char *string ///< Input string of characters to copy 64 72 ); 73 65 74 66 75 /** Copies the input string up to the specified number of characters … … 81 90 ); 82 91 92 83 93 /** Appends a format onto a string 84 94 * … … 88 98 * @return ssize_t: The length of the new string (excluding '\0') 89 99 */ 100 ssize_t psStringAppend( 101 char **dest, ///< existing string 102 const char *format, ///< format to append 103 ... ///< format arguments 90 104 #ifdef __GNUC__ 91 ssize_t psStringAppend(92 char **dest, ///< existing string93 const char *format, ///< format to append94 ... ///< format arguments95 105 ) __attribute__((format(printf, 2, 3))); 96 106 #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 */ 118 ssize_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 */ 132 ssize_t psStringPrepend( 98 133 char **dest, ///< existing string 99 134 const char *format, ///< format to append 100 135 ... ///< format arguments 101 );102 #endif // __GNUC__103 104 /** Appends a format onto a string105 *106 * This function shall allocate a new string if dest is NULL. dest shall be107 * 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 string113 const char *format, ///< format to append114 va_list ap ///< va_list of format arguments115 );116 117 /** Prepends a format onto a string118 *119 * This function shall allocate a new string if dest is NULL. dest shall be120 * automatically extended to the size of the new string.121 *122 * @return ssize_t: The length of the new string (excluding '\0')123 */124 136 #ifdef __GNUC__ 125 ssize_t psStringPrepend(126 char **dest, ///< existing string127 const char *format, ///< format to append128 ... ///< format arguments129 137 ) __attribute__((format(printf, 2, 3))); 130 138 # else // __GNUC__ 131 132 ssize_t psStringPrepend( 133 char **dest, ///< existing string 134 const char *format, ///< format to append 135 ... ///< format arguments 136 ); 139 ); 137 140 #endif // __GNUC__ 138 141 142 139 143 /** Prepends a format onto a string 140 144 * … … 149 153 va_list ap ///< va_list of format arguments 150 154 ); 155 151 156 152 157 /** Procedure to split the input string into a psList of psStrings. … … 163 168 ); 164 169 170 165 171 /** Procedure to split the input string into a psArray of psStrings. 166 172 * … … 176 182 ); 177 183 178 // Given the input string, search for all copies of the key, and replace with the replacement value179 // the input string may be freed if not needed184 // 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 180 186 /** Procedure to search an input string and substitute strings where desired. 181 187 * 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. 184 191 * 185 192 * @return ssize_t: the length of the new string (excluding '\0') … … 191 198 ); 192 199 200 193 201 // strip whitespace from head and tail of string 194 202 /** Procedure to strip the whitespace from the head and tail of a string. … … 199 207 char *string ///< input string to be stripped. 200 208 ); 209 201 210 202 211 /// Given a CVS keyword string, strip off the CVS-specific keyword to get the value … … 222 231 #endif // ifndef DOXYGEN 223 232 233 224 234 /// @} 225 235 #endif // #ifndef PS_STRING_H -
trunk/psLib/src/sys/psTrace.h
r11449 r11694 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.5 4$ $Name: not supported by cvs2svn $12 * @date $Date: 2007-0 1-31 00:38:46$11 * @version $Revision: 1.55 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2007-02-08 01:59:28 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 69 69 p_psComponent; 70 70 71 71 72 /** This procedure sets the trace format for future trace messages. The argument 72 73 * must be a character string consistsing of the letters H (host), L … … 82 83 ); 83 84 85 /** Sends a trace message. */ 84 86 #ifdef DOXYGEN 85 /** Sends a trace message. */86 87 void psTrace( 87 88 const char *facil, ///< facilty of interest … … 90 91 ... ///< trace message arguments 91 92 ); 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 104 94 void p_psTrace( 105 95 const char* file, ///< file name … … 110 100 const char *format, ///< printf-style format command 111 101 ... ///< trace message arguments 102 #ifdef __GNUC__ 112 103 ) __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__ 122 105 ); 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 124 113 125 114 /** Get the trace level … … 127 116 * @return int: Trace Level 128 117 */ 118 #ifdef DOXYGEN 119 int psTraceGetLevel( 120 const char *facil ///< facilty of interest 121 ); 122 #else // ifdef DOXYGEN 129 123 int p_psTraceGetLevel( 130 124 const char* file, ///< file name … … 133 127 const char *facil ///< facilty of interest 134 128 ); 129 #ifndef SWIG 130 #define psTraceGetLevel(facil) \ 131 p_psTraceGetLevel(__FILE__,__LINE__,__func__,facil) 132 #endif // ifndef SWIG 133 #endif // ifdef DOXYGEN 135 134 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 139 137 /** Sends a trace message. */ 140 138 void psTraceV( … … 144 142 va_list ap ///< varargs argument list 145 143 ); 146 #endif /* SWIG */ 147 #endif /* DOXYGEN */ 144 148 145 149 146 /** Set trace level … … 159 156 void psTraceReset(void); 160 157 158 161 159 /// print trace levels 162 160 void psTracePrintLevels(void); 161 163 162 164 163 /// Set the destination of future trace messages. … … 166 165 int fd ///< File descriptor 167 166 ); 167 168 168 169 169 /** Get the current destination for trace messages. … … 173 173 int psTraceGetDestination(void); 174 174 175 175 176 /// Return a psMetadata summarising the trace levels 176 177 psMetadata *psTraceLevels(void); 178 177 179 178 180 /// @} -
trunk/psLib/src/sys/psType.h
r11668 r11694 10 10 * @author Ross Harman, MHPCC 11 11 * 12 * @version $Revision: 1.5 5$ $Name: not supported by cvs2svn $13 * @date $Date: 2007-02-0 6 21:36:09$12 * @version $Revision: 1.56 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2007-02-08 01:59:28 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 59 59 psC32; 60 60 61 61 62 /** 64-bit complex value */ 62 63 typedef struct … … 65 66 } 66 67 psC64; 68 67 69 68 70 #else // SWIG
Note:
See TracChangeset
for help on using the changeset viewer.
