Leon Scroggins III | f59fb0e | 2014-05-28 15:19:42 -0400 | [diff] [blame] | 1 | // Copyright 2007-2010 Baptiste Lepilleur |
| 2 | // Distributed under MIT license, or public domain if desired and |
| 3 | // recognized in your jurisdiction. |
| 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE |
| 5 | |
| 6 | #ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED |
Derek Sollenberger | 2eb3b4d | 2016-01-11 14:41:40 -0500 | [diff] [blame] | 7 | #define CPPTL_JSON_ASSERTIONS_H_INCLUDED |
Leon Scroggins III | f59fb0e | 2014-05-28 15:19:42 -0400 | [diff] [blame] | 8 | |
| 9 | #include <stdlib.h> |
| 10 | |
| 11 | #if !defined(JSON_IS_AMALGAMATION) |
Derek Sollenberger | 2eb3b4d | 2016-01-11 14:41:40 -0500 | [diff] [blame] | 12 | #include "config.h" |
Leon Scroggins III | f59fb0e | 2014-05-28 15:19:42 -0400 | [diff] [blame] | 13 | #endif // if !defined(JSON_IS_AMALGAMATION) |
| 14 | |
| 15 | #if JSON_USE_EXCEPTION |
Derek Sollenberger | 2eb3b4d | 2016-01-11 14:41:40 -0500 | [diff] [blame] | 16 | #include <stdexcept> |
| 17 | #define JSON_ASSERT(condition) \ |
| 18 | assert(condition); // @todo <= change this into an exception throw |
| 19 | #define JSON_FAIL_MESSAGE(message) throw std::runtime_error(message); |
| 20 | #else // JSON_USE_EXCEPTION |
| 21 | #define JSON_ASSERT(condition) assert(condition); |
Leon Scroggins III | f59fb0e | 2014-05-28 15:19:42 -0400 | [diff] [blame] | 22 | |
| 23 | // The call to assert() will show the failure message in debug builds. In |
| 24 | // release bugs we write to invalid memory in order to crash hard, so that a |
| 25 | // debugger or crash reporter gets the chance to take over. We still call exit() |
| 26 | // afterward in order to tell the compiler that this macro doesn't return. |
Derek Sollenberger | 2eb3b4d | 2016-01-11 14:41:40 -0500 | [diff] [blame] | 27 | #define JSON_FAIL_MESSAGE(message) \ |
| 28 | { \ |
| 29 | assert(false&& message); \ |
| 30 | strcpy(reinterpret_cast<char*>(666), message); \ |
| 31 | exit(123); \ |
| 32 | } |
Leon Scroggins III | f59fb0e | 2014-05-28 15:19:42 -0400 | [diff] [blame] | 33 | |
| 34 | #endif |
| 35 | |
Derek Sollenberger | 2eb3b4d | 2016-01-11 14:41:40 -0500 | [diff] [blame] | 36 | #define JSON_ASSERT_MESSAGE(condition, message) \ |
| 37 | if (!(condition)) { \ |
| 38 | JSON_FAIL_MESSAGE(message) \ |
| 39 | } |
Leon Scroggins III | f59fb0e | 2014-05-28 15:19:42 -0400 | [diff] [blame] | 40 | |
| 41 | #endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED |