MLib Alpha 1 API Reference

MLib Alpha 1 API Reference

Debug Macros

the following macros are useful for debugging


m_panic


  MLIB_API( void )  m_panic( const char*  fmt, ... );

print an error message, then aborts the current program in case of fatal failure..


input
fmt

printf-style format specifier string

...

additional string format parameters


m_log


  MLIB_API( void )  m_log( const char*  fmt, ... );

print a message to the debug log. The log is normally the standard output, but can be re-defined in certain builds


input
fmt

printf-style format specifier string

...

additional string format parameters


m_assert


#ifdef M_DEBUG_COMPILE_ASSERTS

#  define m_assert( condition )                                    \
          M_BEGIN_STMNT                                            \
            if ( !( condition ) )                                  \
              m_panic( "assertion '" #condition "' failed in"      \
                       " %s (%s:%d)\n", M__FUNC__, __FILE__,       \
                       __LINE__ );                                 \
          M_END_STMNT

#else

#  define m_assert( condition )                  M_DUMMY_STMNT

#endif

this macro is used to check assertions and is only compiled when M_DEBUG_COMPILE_ASSERTS is defined.

if the condition isn't true, the program is immediately aborted and an error (panic) message is printed to the error output



m_assert_log


#ifdef M_DEBUG_COMPILE_ASSERTS

#  define m_assert_log( condition, varformat )                     \
          M_BEGIN_STMNT                                            \
            if ( !( condition ) )                                  \
            {                                                      \
              m_log( "assertion '" #condition "' failed in"        \
                     " %s (%s:%d)\n", M__FUNC__, __FILE__,         \
                     __LINE__ );                                   \
              m_panic varformat;                                   \
          M_END_STMNT

#else

#  define m_assert_log( condition, varformat )   M_DUMMY_STMNT

#endif

a variant of m_assert . If the condition isn't true, the "varformat" message is sent to the log, then the program panics (i.e. aborts)



m_assert_unreached


#ifdef M_DEBUG_COMPILE_ASSERTS

#  define  m_assert_unreached                                              \
              m_panic( "unreachable code error in %s (%s:%d)\n",           \
                       M__FUNC__, __FILE__, __LINE__ );
#else

#  define m_assert_unreached                     M_DUMMY_STMNT

#endif

this macro must be used to indicate that normal execution should never reach a given point in the source code. This is generally useful in the default case of switch statements, in order to enfore valid input.



m_precheck


#ifdef M_DEBUG_COMPILE_ASSERTS

#  define  m_precheck( condition )                                            \
               M_BEGIN_STMNT                                                  \
                 if (!(condition))                                            \
                   m_panic( "pre-condition '" #condition "' failed in "       \
                            "%s (%s:%d)\n", M__FUNC__, __FILE__, __LINE__ );  \
               M_END_STMNT

#elif defined M_DEBUG_COMPILE_PRECHECKS

#  define  m_precheck( condition )                                          \
            M_BEGIN_STMNT                                                   \
              if (!(condition))                                             \
              {                                                             \
                M_ERROR(( "pre-condition '" #condition "' failed in "       \
                          "%s (%s:%d)\n", M__FUNC__, __FILE__, __LINE__ )); \
                return;                                                     \
              }                                                             \
            M_END_STMNT

#else

#  define  m_precheck( condition )            M_DUMMY_STMNT

#endif

this macro is used to perform pre-condition check in function entry points. If the input condition isn't true, then:

if M_DEBUG_COMPILE_ASSERTS is defined, it aborts the current program as m_assert

otherwise, if M_DEBUG_COMPILE_PRECHEKS , it prints an error message then return immediately from the current function

otherwise, it doesn't do anything.



m_precheck_val


#ifdef M_DEBUG_COMPILE_ASSERTS

#  define  m_precheck_val( condition, val )    m_precheck( condition )

#elif defined(M_DEBUG_COMPILE_PRECHECKS)

#  define  m_precheck_val( condition, val )                                 \
            M_BEGIN_STMNT                                                   \
              if (!(condition))                                             \
              {                                                             \
                M_ERROR(( "pre-condition '" #condition "' failed in "       \
                          "%s (%s:%d)\n", M__FUNC__, __FILE__, __LINE__ )); \
                return val;                                                 \
              }                                                             \
            M_END_STMNT

#else /* !COMPILE_ASSERTS && !COMPILE_PRECHECKS */

#define  m_precheck_val( condition, val )   M_DUMMY_STMNT

#endif

a variant of m_precheck that returns a value in case of failure. when the input condition isn't true, then:

if M_DEBUG_COMPILE_ASSERTS is defined, it aborts the current program as m_assert

otherwise, if M_DEBUG_COMPILE_PRECHEKS , it prints an error message then return immediately from the current function with value "val"

otherwise, it doesn't do anything.



generated on Tue Oct 09 23:59:46 2001