27 #include <lal/LALAtomicDatatypes.h>
28 #include <lal/LALString.h>
30 #if defined(__cplusplus)
228 #define XLAL_PRINT_DEPRECATION_WARNING(replacement) \
230 static int _xlal_print_deprecation_warning_ = 1; \
231 if (_xlal_print_deprecation_warning_) { \
233 "\nDEPRECATION WARNING: program has invoked obsolete function %s(). " \
234 "Please see %s() for information about a replacement.\n", \
235 __func__, replacement); \
236 _xlal_print_deprecation_warning_ = 0; \
257 #define XLAL_PRINT_ERROR(...) \
258 XLALPrintErrorMessage(__func__, __FILE__, __LINE__, __VA_ARGS__)
270 #define XLAL_PRINT_WARNING(...) \
271 XLALPrintWarningMessage(__func__, __FILE__, __LINE__, __VA_ARGS__)
283 #define XLAL_PRINT_INFO(...) \
284 XLALPrintInfoMessage(__func__, __FILE__, __LINE__, __VA_ARGS__)
312 #define XLAL_REAL4_FAIL_NAN_INT 0x7fc001a1
313 #define XLAL_REAL8_FAIL_NAN_INT LAL_INT8_C(0x7ff80000000001a1)
325 volatile const union {
337 volatile const union {
349 volatile const union {
360 for (n = 0; n <
sizeof(val); ++n)
361 if (
a.s[n] != b.s[n])
370 volatile const union {
381 for (n = 0; n <
sizeof(val); ++n)
382 if (
a.s[n] != b.s[n])
388 #define XLAL_REAL4_FAIL_NAN ( XLALREAL4FailNaN() )
389 #define XLAL_REAL8_FAIL_NAN ( XLALREAL8FailNaN() )
392 #define XLAL_IS_REAL4_FAIL_NAN(val) XLALIsREAL4FailNaN(val)
393 #define XLAL_IS_REAL8_FAIL_NAN(val) XLALIsREAL8FailNaN(val)
482 void XLALPerror(
const char *func,
const char *
file,
int line,
int errnum);
485 #define XLAL_PERROR( ) XLALPerror(__func__, __FILE__, __LINE__, xlalErrno)
497 int line,
int errnum);
515 int line,
int errnum);
571 #define xlalErrno ( * XLALGetErrnoPtr() )
572 #define XLALErrorHandler ( * XLALGetErrorHandlerPtr() )
582 #define XLAL_TRY( statement, errnum ) \
584 XLALErrorHandlerType *xlalSaveErrorHandler; \
586 xlalSaveErrorHandler = XLALSetSilentErrorHandler(); \
587 xlalSaveErrno = xlalErrno; \
590 errnum = xlalErrno; \
591 xlalErrno = xlalSaveErrno; \
592 XLALSetErrorHandler(xlalSaveErrorHandler); \
600 #define XLAL_TRY_SILENT( statement, errnum ) \
602 int xlalSaveDebugLevel = lalDebugLevel; \
603 XLALClobberDebugLevel(xlalSaveDebugLevel & ~(LALERRORBIT | LALWARNINGBIT | LALINFOBIT | LALTRACEBIT)); \
604 XLAL_TRY(statement, errnum); \
605 XLALClobberDebugLevel(xlalSaveDebugLevel); \
645 #define _XLAL_ERROR_IMPL_(statement, errnum, ...) \
647 char _XLAL_ERROR_IMPL_buf_[1024]; \
648 XLALStringPrint(_XLAL_ERROR_IMPL_buf_, sizeof(_XLAL_ERROR_IMPL_buf_), "X" __VA_ARGS__); \
649 if (_XLAL_ERROR_IMPL_buf_[1] != 0) { \
650 XLAL_PRINT_ERROR("%s", &_XLAL_ERROR_IMPL_buf_[1]); \
652 XLALError(__func__, __FILE__, __LINE__, errnum); \
656 #define _XLAL_CHECK_IMPL_(statement, assertion, errnum, ...) \
658 if (!(assertion)) { \
659 char _XLAL_CHECK_IMPL_buf_[1024]; \
660 XLALStringPrint(_XLAL_CHECK_IMPL_buf_, sizeof(_XLAL_CHECK_IMPL_buf_), "X" __VA_ARGS__); \
661 if (_XLAL_CHECK_IMPL_buf_[1] != 0) { \
662 XLAL_PRINT_ERROR("%s", &_XLAL_CHECK_IMPL_buf_[1]); \
664 XLAL_PRINT_ERROR("Check failed: %s", #assertion); \
666 XLALError(__func__, __FILE__, __LINE__, errnum); \
687 #define XLAL_ERROR_VAL(val, ...) _XLAL_ERROR_IMPL_(return val, __VA_ARGS__)
700 #define XLAL_ERROR(...) _XLAL_ERROR_IMPL_(return (int)XLAL_FAILURE, __VA_ARGS__)
713 #define XLAL_ERROR_NULL(...) _XLAL_ERROR_IMPL_(return NULL, __VA_ARGS__)
726 #define XLAL_ERROR_VOID(...) _XLAL_ERROR_IMPL_(return, __VA_ARGS__)
739 #define XLAL_ERROR_REAL4(...) _XLAL_ERROR_IMPL_(return XLAL_REAL4_FAIL_NAN, __VA_ARGS__)
752 #define XLAL_ERROR_REAL8(...) _XLAL_ERROR_IMPL_(return XLAL_REAL8_FAIL_NAN, __VA_ARGS__)
765 #define XLAL_ERROR_MAIN(...) _XLAL_ERROR_IMPL_(return EXIT_FAILURE, __VA_ARGS__)
778 #define XLAL_ERROR_FAIL(...) _XLAL_ERROR_IMPL_(goto XLAL_FAIL, __VA_ARGS__)
795 #define XLAL_CHECK_VAL(val, assertion, ...) _XLAL_CHECK_IMPL_(return val, assertion, __VA_ARGS__)
810 #define XLAL_CHECK(assertion, ...) _XLAL_CHECK_IMPL_(return (int)XLAL_FAILURE, assertion, __VA_ARGS__)
825 #define XLAL_CHECK_NULL(assertion, ...) _XLAL_CHECK_IMPL_(return NULL, assertion, __VA_ARGS__)
840 #define XLAL_CHECK_VOID(assertion, ...) _XLAL_CHECK_IMPL_(return, assertion, __VA_ARGS__)
855 #define XLAL_CHECK_REAL4(assertion, ...) _XLAL_CHECK_IMPL_(return XLAL_REAL4_FAIL_NAN, assertion, __VA_ARGS__)
870 #define XLAL_CHECK_REAL8(assertion, ...) _XLAL_CHECK_IMPL_(return XLAL_REAL8_FAIL_NAN, assertion, __VA_ARGS__)
885 #define XLAL_CHECK_MAIN(assertion, ...) _XLAL_CHECK_IMPL_(return EXIT_FAILURE, assertion, __VA_ARGS__)
900 #define XLAL_CHECK_FAIL(assertion, ...) _XLAL_CHECK_IMPL_(goto XLAL_FAIL, assertion, __VA_ARGS__)
912 #define XLAL_CHECK_ABORT(assertion) \
914 if (!(assertion)) { \
915 XLAL_PRINT_ERROR("Check failed: %s", #assertion); \
916 lalAbortHook("XLAL_CHECK_ABORT() failed"); \
930 #define XLAL_CHECK_EXIT(assertion) \
932 if (!(assertion)) { \
933 XLAL_PRINT_ERROR("Check failed: %s", #assertion); \
946 #elif defined(__cplusplus)
#define _LAL_GCC_VPRINTF_FORMAT_(NFMT)
#define _LAL_GCC_PRINTF_FORMAT_(NFMT, NARG)
double REAL8
Double precision real floating-point number (8 bytes).
int64_t INT8
Eight-byte signed integer; on some platforms this is equivalent to long int instead.
int32_t INT4
Four-byte signed integer.
float REAL4
Single precision real floating-point number (4 bytes).
static _LAL_INLINE_ REAL8 XLALREAL8FailNaN(void)
Returns the value of the XLAL REAL8 failure NaN.
void XLALBacktraceErrorHandler(const char *func, const char *file, int line, int errnum)
The XLAL error handler that prints a function call backtrace then raises SIGABRT.
int int int int XLALVPrintError(const char *fmt, va_list ap) _LAL_GCC_VPRINTF_FORMAT_(1)
Prints an error message if error printing is enabled by lalDebugLevel.
void XLALVPrintWarningMessage(const char *func, const char *file, int line, const char *fmt, va_list ap) _LAL_GCC_VPRINTF_FORMAT_(4)
Print an warning message with standard XLAL formatting (if warning messages are enabled by lalDebugLe...
int XLALVPrintInfo(const char *fmt, va_list ap) _LAL_GCC_VPRINTF_FORMAT_(1)
Prints an info message if info printing is enabled by lalDebugLevel.
void XLALSilentErrorHandler(const char *func, const char *file, int line, int errnum)
A silent XLAL error handler.
void XLALError(const char *func, const char *file, int line, int errnum)
Routine to set the XLAL error number and invoke the XLAL error handler.
void XLALAbortErrorHandler(const char *func, const char *file, int line, int errnum)
The XLAL error handler that raises SIGABRT.
int * XLALGetErrnoPtr(void)
Function to return pointer to the XLAL error number.
XLALErrorHandlerType * XLALSetSilentErrorHandler(void)
Sets the error handler to a silent handler and returns the old handler.
int XLALVPrintWarning(const char *fmt, va_list ap) _LAL_GCC_VPRINTF_FORMAT_(1)
Prints a warning message if warning printing is enabled by lalDebugLevel.
const char * XLALErrorString(int errnum)
Returns the error message associated with an error number.
int XLALGetBaseErrno(void)
Gets the XLAL base error number ignoring the internal-function-failed flag.
int int int XLALPrintInfo(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
Prints an info message if info printing is enabled by lalDebugLevel.
#define XLAL_REAL4_FAIL_NAN_INT
Hexadecimal representation of REAL4 NaN failure bit pattern.
XLALErrorHandlerType ** XLALGetErrorHandlerPtr(void)
Function to return pointer to the XLAL error handler function pointer.
int XLALSetErrno(int errnum)
Sets the XLAL error number to errnum, returns the new value.
XLALErrorHandlerType * XLALSetDefaultErrorHandler(void)
Sets the error handler to the default handler and returns the old handler.
void void void XLALPrintInfoMessage(const char *func, const char *file, int line, const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(4
Print an info message with standard XLAL formatting (if info messages are enabled by lalDebugLevel).
void XLALExitErrorHandler(const char *func, const char *file, int line, int errnum)
The XLAL error handler that calls exit.
static _LAL_INLINE_ REAL4 XLALREAL4FailNaN(void)
Returns the value of the XLAL REAL4 failure NaN.
void XLALDefaultErrorHandler(const char *func, const char *file, int line, int errnum)
The default XLAL error handler.
void XLALVPrintInfoMessage(const char *func, const char *file, int line, const char *fmt, va_list ap) _LAL_GCC_VPRINTF_FORMAT_(4)
Print an error message with standard XLAL formatting (if error messages are enabled by lalDebugLevel)...
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
Prints an error message if error printing is enabled by lalDebugLevel.
int int XLALPrintWarning(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
Prints a warning message if warning printing is enabled by lalDebugLevel.
void void void void XLALVPrintErrorMessage(const char *func, const char *file, int line, const char *fmt, va_list ap) _LAL_GCC_VPRINTF_FORMAT_(4)
Print an error message with standard XLAL formatting (if error messages are enabled by lalDebugLevel)...
XLALErrorValue
XLAL error numbers and return values.
void XLALErrorHandlerType(const char *func, const char *file, int line, int errnum)
The XLAL error handler type.
void void XLALPrintWarningMessage(const char *func, const char *file, int line, const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(4
Print an warning message with standard XLAL formatting (if warning messages are enabled by lalDebugLe...
int XLALClearErrno(void)
Clears the XLAL error number, returns the old value.
int XLALPrintProgressBar(double)
Prints a progress bar at the "info" verbosity level.
static _LAL_INLINE_ int XLALIsREAL4FailNaN(REAL4 val)
Tests if a value is an XLAL REAL4 failure NaN.
void XLALPerror(const char *func, const char *file, int line, int errnum)
Prints an error message for a particular error code in a standard format.
void XLALPrintErrorMessage(const char *func, const char *file, int line, const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(4
Print an error message with standard XLAL formatting (if error messages are enabled by lalDebugLevel)...
#define XLAL_REAL8_FAIL_NAN_INT
Hexadecimal representation of REAL8 NaN failure bit pattern.
static _LAL_INLINE_ int XLALIsREAL8FailNaN(REAL8 val)
Tests if a value is an XLAL REAL8 failure NaN.
XLALErrorHandlerType * XLALSetErrorHandler(XLALErrorHandlerType *newHandler)
Sets the error handler to a new handler and returns the old handler.
@ XLAL_ESING
Apparent singularity detected.
@ XLAL_EUSR7
User-defined error 7.
@ XLAL_EBADLEN
Inconsistent or invalid length.
@ XLAL_EUSR4
User-defined error 4.
@ XLAL_EUSR6
User-defined error 6.
@ XLAL_EFPINEXCT
IEEE Floating point inexact error.
@ XLAL_EUNIT
Invalid units.
@ XLAL_EUSR9
User-defined error 9.
@ XLAL_EUSR3
User-defined error 3.
@ XLAL_EFREQ
Invalid freqency.
@ XLAL_EDIVERGE
Series is diverging.
@ XLAL_ENOMEM
Memory allocation error.
@ XLAL_EDATA
Invalid data.
@ XLAL_SUCCESS
Success return value (not an error number)
@ XLAL_EFPINVAL
IEEE Invalid floating point operation, eg sqrt(-1), 0/0.
@ XLAL_EFAULT
Invalid pointer.
@ XLAL_EUSR0
User-defined error 0.
@ XLAL_ERANGE
Output range error.
@ XLAL_ENOENT
No such file or directory.
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
@ XLAL_EMAXITER
Exceeded maximum number of iterations.
@ XLAL_ELOSS
Loss of accuracy.
@ XLAL_ETOL
Failed to reach specified tolerance.
@ XLAL_EERR
Internal error.
@ XLAL_EUSR2
User-defined error 2.
@ XLAL_EDOM
Input domain error.
@ XLAL_EUSR8
User-defined error 8.
@ XLAL_ETYPE
Wrong or unknown type.
@ XLAL_EUSR5
User-defined error 5.
@ XLAL_EUSR1
User-defined error 1.
@ XLAL_EDIMS
Wrong dimensions.
@ XLAL_EINVAL
Invalid argument.
@ XLAL_EFPOVRFLW
IEEE Floating point overflow error.
@ XLAL_EFAILED
Generic failure.
@ XLAL_ENOSYS
Function not implemented.
@ XLAL_EFPUNDFLW
IEEE Floating point underflow error.
@ XLAL_FAILURE
Failure return value (not an error number)
@ XLAL_ETIME
Invalid time.
@ XLAL_EFPDIV0
IEEE Division by zero floating point error.