except.h

Go to the documentation of this file.
00001 /****************************************************************************/
00002 /*                                                                          */
00003 /*  This file is part of QSopt_ex.                                          */
00004 /*                                                                          */
00005 /*  (c) Copyright 2006 by David Applegate, William Cook, Sanjeeb Dash,      */
00006 /*  and Daniel Espinoza                                                     */
00007 /*                                                                          */
00008 /*  Sanjeeb Dash ownership of copyright in QSopt_ex is derived from his     */
00009 /*  copyright in QSopt.                                                     */
00010 /*                                                                          */
00011 /*  This code may be used under the terms of the GNU General Public License */
00012 /*  (Version 2.1 or later) as published by the Free Software Foundation.    */
00013 /*                                                                          */
00014 /*  Alternatively, use is granted for research purposes only.               */
00015 /*                                                                          */
00016 /*  It is your choice of which of these two licenses you are operating      */
00017 /*  under.                                                                  */
00018 /*                                                                          */
00019 /*  We make no guarantees about the correctness or usefulness of this code. */
00020 /*                                                                          */
00021 /****************************************************************************/
00022 
00023 /* RCSINFO $Id: except.h,v 1.3 2003/11/05 17:02:10 meven Exp $ */
00024 #ifndef ILL_except
00025 #define ILL_except
00026 
00027 /* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
00028    which contains the name of the function currently being defined.
00029 #  define __DEV_FUNCTION__     __PRETTY_FUNCTION__
00030    This is broken in G++ before version 2.6.
00031    C9x has a similar variable called __func__, but prefer the GCC one since
00032    it demangles C++ function names.  */
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 /* put debugger breakpoint here */
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 /* printed message looks as follows
00058  *
00059  * with_source_info == 0:   <msg> + "\n"
00060  *
00061  * with_source_info == 1:   if (fct != NULL) 
00062  *                              <msg> + " in function <fct>\n";
00063  *                          else 
00064  *                              <msg> + " in file <file> line <line>\n"; 
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 /* we define debugging verbosity for singular basis */
00166 extern int __QS_SB_VERB;
00167 #endif

Generated on Thu Mar 29 09:32:29 2012 for QSopt_ex by  doxygen 1.4.7