Blender  V2.59
MT_assert.h
Go to the documentation of this file.
00001 /*
00002 * $Id: MT_assert.h 35158 2011-02-25 11:49:19Z jesterking $
00003 * ***** BEGIN GPL LICENSE BLOCK *****
00004 *
00005 * This program is free software; you can redistribute it and/or
00006 * modify it under the terms of the GNU General Public License
00007 * as published by the Free Software Foundation; either version 2
00008 * of the License, or (at your option) any later version.
00009 *
00010 * This program is distributed in the hope that it will be useful,
00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 * GNU General Public License for more details.
00014 *
00015 * You should have received a copy of the GNU General Public License
00016 * along with this program; if not, write to the Free Software Foundation,
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018 *
00019 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00020 * All rights reserved.
00021 *
00022 * The Original Code is: all of this file.
00023 *
00024 * Contributor(s): none yet.
00025 *
00026 * ***** END GPL LICENSE BLOCK *****
00027 */
00028 
00034 #ifndef MT_ASSERT_H
00035 #define MT_ASSERT_H
00036 
00037 #include <signal.h>
00038 #include <stdlib.h>
00039 #include <assert.h>
00040 
00041 
00042 // So it can be used from C
00043 #ifdef __cplusplus
00044 #define MT_CDECL extern "C"
00045 #else
00046 #define MT_CDECL
00047 #endif
00048 
00049 // Ask the user if they wish to abort/break, ignore, or ignore for good.
00050 // file, line, predicate form the message to ask, *do_assert should be set
00051 // to 0 to ignore.
00052 // returns 1 to break, false to ignore
00053 MT_CDECL int MT_QueryAssert(const char *file, int line, const char *predicate, int *do_assert);
00054 
00055 
00056 #if !defined(DEBUG)
00057 #define MT_assert(predicate) ((void)0)
00058 #define BREAKPOINT() ((void)0)
00059 #else 
00060 
00061 // BREAKPOINT() will cause a break into the debugger
00062 #if defined(__i386) && defined(__GNUC__)
00063 // gcc on intel...
00064 #define BREAKPOINT() \
00065 asm("int $3")
00066 #elif defined(_MSC_VER)
00067 // Visual C++ (on Intel)
00068 #define BREAKPOINT() \
00069 { _asm int 3 }
00070 #elif defined(SIGTRAP)
00071 // POSIX compatible...
00072 #define BREAKPOINT() \
00073 raise(SIGTRAP);
00074 #else
00075 // FIXME: Don't know how to do a decent break!
00076 // Add some code for your cpu type, or get a posix
00077 // system.
00078 // abort instead
00079 #define BREAKPOINT() \
00080 abort();
00081 #endif /* breakpoint */
00082 
00083 
00084 #if defined(_WIN32) && !defined(__GNUC__)
00085 #define MT_assert(predicate) assert(predicate)
00086 #else
00087 
00088 
00089 
00090 // Abort the program if predicate is not true
00091 #define MT_assert(predicate)                                                                    \
00092 {                                                                                               \
00093         static int do_assert = 1;                                                               \
00094         if (!(predicate) && MT_QueryAssert(__FILE__, __LINE__, #predicate, &do_assert))         \
00095         {                                                                                       \
00096                 BREAKPOINT();                                                                   \
00097         }                                                                                       \
00098 }
00099 #endif /* windows */
00100 
00101 #endif /* !defined(DEBUG) */
00102 
00103 #endif
00104