 |
LAL
7.1.7.1-56c71ae
|
|
Go to the documentation of this file. 22 #ifndef _LALSTATUSMACROS_H 23 #define _LALSTATUSMACROS_H 25 #include <lal/LALConfig.h> 35 #include <lal/LALDebugLevel.h> 36 #include <lal/LALMalloc.h> 37 #include <lal/LALDatatypes.h> 38 #include <lal/LALError.h> 39 #include <lal/XLALError.h> 49 #define LAL_EXLAL 16384 50 #define LAL_MSGEXLAL "Failure in an XLAL routine" 51 #define ABORTXLAL(sp) ABORT(sp,LAL_EXLAL,LAL_MSGEXLAL) 52 #define XLAL_CHECK_LAL(sp, assertion, ...) _XLAL_CHECK_IMPL_(ABORTXLAL(sp), assertion, __VA_ARGS__) 56 #define INITSTATUS( statusptr ) \ 57 do { if ( (statusptr) ) \ 59 INT4 level_ = (statusptr)->level ; \ 60 INT4 statp_ = (statusptr)->statusPtr ? 1 : 0 ; \ 61 memset( (statusptr), 0, sizeof( LALStatus ) ); \ 62 (statusptr)->level = level_ > 0 ? level_ : 1 ; \ 63 (statusptr)->Id = "$Id$"; \ 64 (statusptr)->function = __func__; \ 65 SETSTATUSFILELINE( statusptr ); \ 66 (void) LALTrace( statusptr, 0 ); \ 68 ABORT( statusptr, -2, "INITSTATUS: non-null status pointer" ); \ 69 else if ( xlalErrno ) \ 70 ABORT( statusptr, -16, "INITSTATUS: non-zero xlalErrno" ); \ 73 lalAbortHook( "Abort: function %s, file %s, line %d, %s\n" \ 74 " Null status pointer passed to function\n", \ 75 __func__, __FILE__, __LINE__, "$Id$" ); \ 78 #define RETURN( statusptr ) \ 81 SETSTATUSFILELINE( statusptr ); \ 82 if ( (statusptr)->statusCode ) \ 83 (void) LALError( statusptr, "RETURN:" ); \ 84 (void) LALTrace( statusptr, 1 ); \ 86 ABORT( statusptr, -32, "RETURN: untrapped XLAL error" ); \ 91 #define ATTATCHSTATUSPTR(statusptr) \ 92 do { if ( !(statusptr)->statusPtr ) \ 94 (statusptr)->statusPtr = (LALStatus *)LALCalloc( 1, sizeof( LALStatus ) );\ 95 if ( !(statusptr)->statusPtr ) \ 96 ABORT( statusptr, -4, "ATTATCHSTATUSPTR: memory allocation error" ); \ 97 (statusptr)->statusPtr->level = (statusptr)->level + 1; \ 100 ABORT( statusptr, -2, "ATTATCHSTATUSPTR: non-null status pointer" ); \ 103 #define DETATCHSTATUSPTR( statusptr ) \ 104 do { if ( (statusptr)->statusPtr ) \ 106 FREESTATUSPTR( statusptr ); \ 107 (statusptr)->statusCode = 0; \ 108 (statusptr)->statusDescription = NULL; \ 111 ABORT( statusptr, -8, "DETATCHSTATUSPTR: null status pointer" ); \ 114 #define ABORT( statusptr, code, mesg ) \ 115 do { if ( (statusptr)->statusPtr ) FREESTATUSPTR( statusptr ); \ 116 SETSTATUS( statusptr, code, mesg ); \ 118 (void) LALError( statusptr, "ABORT:" ); \ 119 (void) LALTrace( statusptr, 1 ); \ 124 #define ASSERT( assertion, statusptr, code, mesg ) 126 #define ASSERT( assertion, statusptr, code, mesg ) \ 127 do { if ( !(assertion) ) \ 129 if ( (statusptr)->statusPtr ) \ 130 FREESTATUSPTR( statusptr ); \ 131 SETSTATUS( statusptr, code, mesg ); \ 132 (void) LALError( statusptr, "Assertion \"" #assertion "\" failed:" ); \ 133 (void) LALTrace( statusptr, 1 ); \ 139 #define TRY( func, statusptr ) \ 140 do { if ( (func), (statusptr)->statusPtr->statusCode ) \ 142 SETSTATUS( statusptr, -1, "Recursive error" ); \ 143 (void) LALError( statusptr, "Function call \"" #func "\" failed:" ); \ 144 (void) LALTrace( statusptr, 1 ); \ 149 #define CHECKSTATUSPTR( statusptr ) \ 150 do { if ( (statusptr)->statusPtr->statusCode ) \ 152 SETSTATUS( statusptr, -1, "Recursive error" ); \ 153 (void) LALError( statusptr, "CHECKSTATUSPTR:" ); \ 154 (void) LALTrace( statusptr, 1 ); \ 159 #define FREESTATUSPTR( statusptr ) \ 162 LALStatus *next_ = (statusptr)->statusPtr->statusPtr; \ 163 LALFree( (statusptr)->statusPtr ); \ 164 (statusptr)->statusPtr = next_; \ 166 while ( (statusptr)->statusPtr ) 168 #define REPORTSTATUS( statusptr ) \ 172 for ( ptr_ = (statusptr); ptr_; ptr_ = ptr_->statusPtr ) \ 174 LALPrintError( "\nLevel %i: %s\n", ptr_->level, ptr_->Id ); \ 175 if ( ptr_->statusCode ) \ 176 LALPrintError( "\tStatus code %i: %s\n", ptr_->statusCode, \ 177 ptr_->statusDescription ); \ 179 LALPrintError( "\tStatus code 0: Nominal\n" ); \ 180 LALPrintError( "\tfunction %s, file %s, line %i\n", \ 181 ptr_->function, ptr_->file, ptr_->line ); \ 187 #define INITSTATUS( statusptr ) \ 188 do { if ( LALInitStatus( statusptr, __func__, "$Id$", __FILE__, __LINE__ ) ) return; } while ( 0 ) 190 #define RETURN( statusptr ) \ 191 do { if ( LALPrepareReturn( statusptr, __FILE__, __LINE__ ), 1 ) return; } while ( 0 ) 193 #define ATTATCHSTATUSPTR( statusptr ) \ 194 do { if ( LALAttatchStatusPtr( statusptr, __FILE__, __LINE__ ) ) return; } while ( 0 ) 196 #define DETATCHSTATUSPTR( statusptr ) \ 197 do { if ( LALDetatchStatusPtr( statusptr, __FILE__, __LINE__ ) ) return; } while ( 0 ) 199 #define ABORT( statusptr, code, mesg ) \ 200 do { if ( LALPrepareAbort( statusptr, code, mesg, __FILE__, __LINE__ ), 1 ) return; } while ( 0 ) 203 #define ASSERT( assertion, statusptr, code, mesg ) 205 #define ASSERT( assertion, statusptr, code, mesg ) \ 206 do { if ( !(assertion) ) \ 208 LALPrepareAssertFail( statusptr, code, mesg, \ 209 "Assertion \"" #assertion "\" failed:", \ 210 __FILE__, __LINE__ ); \ 216 #define TRY( func, statusptr ) \ 220 if ( LALCheckStatusPtr( statusptr, "Function call \"" #func "\" failed:", \ 221 __FILE__, __LINE__ ) ) \ 226 #define CHECKSTATUSPTR( statusptr ) \ 227 do { if ( LALCheckStatusPtr( statusptr, "CHECKSTATUSPTR:", __FILE__, __LINE__ ) ) return; } while ( 0 ) 233 #define BEGINFAIL( statusptr ) \ 235 if ( !(statusptr) ) \ 236 ABORT( statusptr, -8, "BEGINFAIL: null status pointer" ); \ 237 if ( !( (statusptr)->statusPtr ) ) \ 238 ABORT( statusptr, -8, "BEGINFAIL: null status pointer pointer" ); \ 239 if ( (statusptr)->statusPtr->statusCode ) { \ 240 LALStatus *statusPtrSave_ = (statusptr)->statusPtr; \ 241 (statusptr)->statusPtr = NULL; \ 242 ATTATCHSTATUSPTR( statusptr ); \ 245 #define ENDFAIL( statusptr ) \ 247 DETATCHSTATUSPTR( statusptr ); \ 248 (statusptr)->statusPtr = statusPtrSave_; \ 249 SETSTATUS( statusptr, -1, "Recursive error" ); \ 250 (void) LALError( statusptr, "ENDFAIL:" ); \ 251 (void) LALTrace( statusptr, 1 ); \ 256 #define SETSTATUSFILELINE( statusptr ) \ 257 ( ( void ) ( (statusptr)->file = __FILE__, (statusptr)->line = __LINE__ ) ) 259 #define SETSTATUS( statusptr, code, mesg ) \ 260 ( SETSTATUSFILELINE( statusptr ), \ 261 (statusptr)->statusDescription = (mesg), \ 262 (statusptr)->statusCode = (code) ) 267 #elif defined(__cplusplus)