assertions.h revision f59fb0e83fd0a4b41700d3f5eebdc8d21b173c2e
116c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek// Copyright 2007-2010 Baptiste Lepilleur 216c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek// Distributed under MIT license, or public domain if desired and 316c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek// recognized in your jurisdiction. 416c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 516c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek 616c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek#ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED 716c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek# define CPPTL_JSON_ASSERTIONS_H_INCLUDED 816c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek 916c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek#include <stdlib.h> 102e331b938b38057e333fab0ba841130ea8467794Douglas Gregor 112e331b938b38057e333fab0ba841130ea8467794Douglas Gregor#if !defined(JSON_IS_AMALGAMATION) 122e331b938b38057e333fab0ba841130ea8467794Douglas Gregor# include <json/config.h> 1316c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek#endif // if !defined(JSON_IS_AMALGAMATION) 1416c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek 1516c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek#if JSON_USE_EXCEPTION 1616c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek#define JSON_ASSERT( condition ) assert( condition ); // @todo <= change this into an exception throw 177eaa8ae8692c5cd3eed8cb334fe5346470522091Douglas Gregor#define JSON_FAIL_MESSAGE( message ) throw std::runtime_error( message ); 1816c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek#else // JSON_USE_EXCEPTION 196931900f43cea558c6974075256c07728dbfecc6Douglas Gregor#define JSON_ASSERT( condition ) assert( condition ); 20283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor 21283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor// The call to assert() will show the failure message in debug builds. In 221f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor// release bugs we write to invalid memory in order to crash hard, so that a 23007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek// debugger or crash reporter gets the chance to take over. We still call exit() 24edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek// afterward in order to tell the compiler that this macro doesn't return. 2516c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek#define JSON_FAIL_MESSAGE( message ) { assert(false && message); strcpy(reinterpret_cast<char*>(666), message); exit(123); } 2616c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek 271f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor#endif 2816c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek 295bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas Gregor#define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) { JSON_FAIL_MESSAGE( message ) } 305bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas Gregor 315bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas Gregor#endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED 325bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas Gregor