/usr/include/CLAM/Assert.hxx is in libclam-dev 1.4.0-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | /*
* Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
* UNIVERSITAT POMPEU FABRA
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef _ASSERT_
#define _ASSERT_
/** @file Assert.hxx
* Bug hunting and detection facilities for developers.
*/
#include "Err.hxx"
namespace CLAM
{
/**
* @def CLAM_BREAKPOINT
* A macro containing break point assembler code for your platform.
* If you platform is not being considered by the header you will
* get an warning message when compiling.
*/
// Microsoft VisualC++ and ancestror MSC
#ifdef _MSC_VER
#define CLAM_BREAKPOINT {__asm {int 3}}
// MetroWorks Code Warrior
#elif defined (__MWERKS__)
#define CLAM_BREAKPOINT {_asm {int 3}}
// GNU GCC
#elif defined (__GNUC__) && (defined (__i386__) || defined(__x86_64__))
#define CLAM_BREAKPOINT {__asm__ (" int $3 "); }
/* g++ on powerpc linux */
#elif defined (__GNUC__) && defined (__powerpc__)
#define CLAM_BREAKPOINT {__asm__ (" .long 0x7d821008 "); }
/* g++ on powerpc macosx */
#elif defined (__GNUC__) && defined (__POWERPC__)
#define CLAM_BREAKPOINT {__asm__ (" .long 0x7d821008 "); }
// Insert your compiler here
#else
#warning Breakpoint code unknown for the platform. You can add it defining the CLAM_BREAKPOINT macro at file Assert.hxx.
#define CLAM_BREAKPOINT {}
#endif
#if ! defined(_DEBUG)
#define CLAM_USE_RELEASE_ASSERTS
#endif
/// Macro used when an assert fails
#if defined(CLAM_USE_RELEASE_ASSERTS)
#define CLAM_ABORT(message) \
do { \
throw CLAM::ErrAssertionFailed( message, __FILE__, __LINE__); \
} while(0)
#else
#define CLAM_ABORT(message) \
do { \
if ( !CLAM::ErrAssertionFailed::breakpointInCLAMAssertEnabled ) { \
throw CLAM::ErrAssertionFailed( message, __FILE__, __LINE__); \
} else { \
CLAM::ExecuteAssertFailedHandler ( message, __FILE__, __LINE__); \
CLAM_BREAKPOINT; \
} \
} while(0)
#endif
/// @name Assertions and checks
/// @{
/**
* @def CLAM_ASSERT(expresion,message)
* An assertion is a check on an expression that must be
* true given that all the contracts are fullfilled.
* Notice that this is NOT a regular (documented) check
* that will throw a (documented) error condition (Err).
* Asserts on debug mode (when the DEBUG macro is defined)
* will set a break point while in release mode (DEBUG is
* not defined) you may get an unexpected exception that
* can be catched by the application on the top level and
* do some backups actions.
* Any way, a descriptive message is displayed.
*
* Sometimes the check is not only an expression but a
* complete set of statements. In these cases, you can use
* CLAM_BEGIN_CHECK and CLAM_END_CHECK macros to enclose
* the whole check code and use CLAM_ASSERT for concrete
* expressions to check.
*
* You can change the default release mode assertion
* failed callback by using the SetAssertFailedHandler
* function.
*
* You can get a lightweight assertion using (with care)
* the CLAM_DEBUG_ASSERT that is ignored on debug mode.
* <b>By using the CLAM_DEBUG_ASSERT macro, the final
* application will not have the possibility of doing
* an honrous exit (backup data, bug log...)</b>
* Is worth to keep most of the asserts as CLAM_ASSERT.
*
* Anyway, for very performance depending applications
* you may use the CLAM_DISABLE_CHECKS to remove ALL the
* CLAM_ASSERT and CLAM_DEBUG_ASSERT and its related checks
* in whatever mode you use them.
*
* @param expression The expression that must be true.
* @param message A message that describes the unexpected
* runtime error to the programmer.
*/
/**
* @def CLAM_BEGIN_CHECK
* Marks the start of check code block that is tied to a CLAM_ASSERT
* and can be removed without affecting any functionality.
* You must use it on the same sense that CLAM_ASSERT is used.
* @see CLAM_ASSERT
* @see CLAM_END_CHECK
*/
/**
* @def CLAM_END_CHECK
* Ends a block of code started by CLAM_BEGIN_CHECK
* @see CLAM_BEGIN_CHECK
*/
#if defined(CLAM_DISABLE_CHECKS)
#define CLAM_BEGIN_CHECK if (0) {
#define CLAM_END_CHECK }
#define CLAM_ASSERT( expression, message )
#define CLAM_WARNING( expression, message )
#else
#define CLAM_BEGIN_CHECK {
#define CLAM_END_CHECK }
#define CLAM_ASSERT( expression, message ) \
do { \
if (!(expression)) { \
CLAM_ABORT(message); \
} } while (0)
#define CLAM_WARNING( expression, message ) \
do { \
if (!(expression)) { \
CLAM::ExecuteWarningHandler ( message, __FILE__, __LINE__); \
} } while (0)
#endif
/**
* @def CLAM_BEGIN_DEBUG_CHECK
* Is the same that CLAM_BEGIN_CHECK but for a CLAM_DEBUG_ASSERT
* instead of a CLAM_ASSERT.
* @see CLAM_DEBUG_ASSERT
* @see CLAM_BEGIN_CHECK
* @see CLAM_END_DEBUG_CHECK
*/
/**
* @def CLAM_END_DEBUG_CHECK
* Ends a block of code started by CLAM_BEGIN_DEBUG_CHECK
* @see CLAM_BEGIN_DEBUG_CHECK
*/
#if defined(CLAM_DISABLE_CHECKS) || defined(CLAM_USE_RELEASE_ASSERTS)
# define CLAM_BEGIN_DEBUG_CHECK if (0) {
# define CLAM_END_DEBUG_CHECK }
# define CLAM_DEBUG_ASSERT( expression, message )
# define CLAM_DEBUG_WARNING( expression, message )
#else
# define CLAM_BEGIN_DEBUG_CHECK {
# define CLAM_END_DEBUG_CHECK }
# define CLAM_DEBUG_ASSERT( expression, message ) \
do { \
if (!(expression)) { \
CLAM_ABORT(message); \
} } while (0)
# define CLAM_DEBUG_WARNING( expression, message ) \
do { \
if (!(expression)) { \
CLAM::ExecuteWarningHandler ( message, __FILE__, __LINE__); \
} } while (0)
#endif
/// @}
/**
* The exception thrown when an assertion fails.
* Don't throw it directly, use the assertion macro Assert instead
* because the Assert macro is sensible to the compilation conditions.
* Neither do any explicit declaration that this exception can
* be thrown from a function as you would have to do with any other
* exception.
* See the Error Notification Mechanisms documentation.
* @todo Subclass ErrAssertionFailed from Err.
* @see CLAM_ASSERT
* @see CLAM_BEGIN_CHECK
* @see CLAM_END_CHECK
*/
class ErrAssertionFailed : public Err {
public:
/** this bool is used for automatic-tesing CLAM asserts.
* by default is defined to true. But can be set to false where we
* want to test that a CLAM_ASSERT has occurred.
*/
static bool breakpointInCLAMAssertEnabled;
ErrAssertionFailed(const char* message, const char* filename, int linenumber);
virtual ~ErrAssertionFailed() throw () { }
};
/**
* The type of the asserts handlers.
* @param message A char pointer containing a description of the assertion
* @param fileName A char pointer containing the source file where the assertion is placed
* @param lineNumber The line of the source file where the assertion is placed
*/
typedef void (*AssertFailedHandlerType) (const char* message, const char* filename, int lineNumber);
/**
* Change the handler function called when an assertion fails.
* The function must have a prototype like that:
* <pre>
* void MyHandler (const char* message, const char* filename, int lineNumber);
* </pre>
* @param handler The new handler
* @return The old handler, for restoring purposes.
*/
AssertFailedHandlerType SetAssertFailedHandler(AssertFailedHandlerType handler);
/**
* (Don't use directly, use the CLAM_ASSERT macro instead) Execute the assert failed handler.
*/
void ExecuteAssertFailedHandler(const char* message, const char* filename, int linenumber);
/**
* The type of the warning handlers.
* @param message A char pointer containing a description of the warning
* @param fileName A char pointer containing the source file where the warning is placed
* @param lineNumber The line of the source file where the warning is placed
*/
typedef void (*WarningHandlerType) (const char* message, const char* filename, int lineNumber);
/**
* Change the handler function called when a warning is given.
* The function must have a prototype like that:
* <pre>
* void MyHandler (const char* message, const char* filename, int lineNumber);
* </pre>
* @param handler The new handler
* @return The old handler, for restoring purposes.
*/
WarningHandlerType SetWarningHandler(WarningHandlerType handler);
/**
* (Don't use directly, use the CLAM_WARNING macro instead) Execute the assert failed handler.
*/
void ExecuteWarningHandler(const char* message, const char* filename, int linenumber);
}
#endif //_ASSERT_
|