00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef ILL_except
00025 #define ILL_except
00026
00027
00028
00029
00030
00031
00032
00033 # ifdef __GNUC__
00034 # if __GNUC__ > 2 || (__GNUC__ == 2 \
00035 && __GNUC_MINOR__ >= (defined __cplusplus ? 6 : 4))
00036 # define __DEV_FUNCTION__ __PRETTY_FUNCTION__
00037 # else
00038 # define __DEV_FUNCTION__ ((__const char *) 0)
00039 # endif
00040 # else
00041 # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
00042 # define __DEV_FUNCTION__ __func__
00043 # else
00044 # define __DEV_FUNCTION__ ((const char *) 0)
00045 # endif
00046 # endif
00047
00048
00049
00050 extern void ILL_report (
00051 const char *msg,
00052 const char *fct,
00053 const char *file,
00054 unsigned int line,
00055 int with_source_info);
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 #define ILL_GENERAL_ERROR -1
00068 #define ILL_NO_MEMORY 2
00069 #define ILL_NULL_PTR 3
00070
00071 #define ILL_REPORT(msg,with) \
00072 ILL_report(msg, __DEV_FUNCTION__, __FILE__, __LINE__, with)
00073 #ifdef NDEBUG
00074 #define ILL_REPRT(msg) \
00075 ILL_report(msg, __DEV_FUNCTION__, __FILE__, __LINE__, 0)
00076 #else
00077 #define ILL_REPRT(msg) \
00078 ILL_report(msg, __DEV_FUNCTION__, __FILE__, __LINE__, 1)
00079 #endif
00080
00081 #define ILL_RESULT(expr, msg) \
00082 { \
00083 if (TRACE > 0) { ILL_RETURN(expr, msg); } \
00084 return expr; \
00085 }
00086
00087 #define ILL_RETURN_PTR(ptr, msg) \
00088 { void *ILL_RETURN_p = ptr; \
00089 if (ILL_RETURN_p == NULL) { \
00090 if (TRACE > 0) ILL_REPRT(msg); \
00091 } \
00092 return ILL_RETURN_p; \
00093 }
00094
00095 #ifdef NDEBUG
00096 #define ILL_RETURN(expr, msg) \
00097 { \
00098 if (expr != 0) { \
00099 if (TRACE > 0) ILL_REPRT(msg); \
00100 } \
00101 return expr; \
00102 }
00103
00104 #else
00105 #define ILL_RETURN(expr, msg) \
00106 { \
00107 if (expr != 0) { \
00108 ILL_REPRT(msg); \
00109 } \
00110 ILL_IFTRACE("%s: returning %d\n", __DEV_FUNCTION__, expr); \
00111 return expr; \
00112 }
00113 #endif
00114
00115 #define ILL_CHECKnull(expr, msg) \
00116 { if ((expr) == NULL) { \
00117 ILL_REPRT(msg); \
00118 rval = ILL_NULL_PTR; \
00119 goto CLEANUP; \
00120 } }
00121
00122 #define ILL_FAILtrue(expr, msg) \
00123 { if (expr) { \
00124 ILL_REPRT(msg); \
00125 rval = ILL_GENERAL_ERROR; \
00126 goto CLEANUP; \
00127 } }
00128
00129 #define ILL_FAILtrue_no_rval(expr, msg) \
00130 { if (expr) { \
00131 ILL_REPRT(msg); \
00132 goto CLEANUP; \
00133 } }
00134
00135
00136 #define ILL_FAILfalse(expr, msg) ILL_FAILtrue(!(expr), msg)
00137 #define ILL_FAILfalse_no_rval(expr, msg) ILL_FAILtrue_no_rval(!(expr), msg)
00138
00139 #define ILL_ERROR(rval, msg) { \
00140 fprintf(stderr, "%s\n", msg); \
00141 rval = 1; goto CLEANUP; \
00142 }
00143 #define ILL_CLEANUP_IF(rval) { if ((rval) != 0) { goto CLEANUP; } }
00144 #define ILL_CLEANUP goto CLEANUP
00145
00146 #define ILL_SAFE_MALLOC(lhs, n, type) \
00147 { lhs = ILL_UTIL_SAFE_MALLOC(n, type, lhs); \
00148 if (lhs == NULL) { \
00149 ILL_REPRT("Out of memory"); \
00150 rval = ILL_NO_MEMORY; \
00151 goto CLEANUP; \
00152 }}
00153
00154 #define ILL_SAFE_MALLOC_no_rval(lhs, n, type) \
00155 { lhs = ILL_UTIL_SAFE_MALLOC(n, type, lhs); \
00156 if (lhs == NULL) { \
00157 ILL_REPRT("Out of memory"); \
00158 goto CLEANUP; \
00159 }}
00160
00161
00162 #define ILL_NEW(ptr, type) ILL_SAFE_MALLOC(ptr, 1, type)
00163 #define ILL_NEW_no_rval(ptr, type) ILL_SAFE_MALLOC_no_rval(ptr, 1, type)
00164
00165
00166 extern int __QS_SB_VERB;
00167 #endif