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