|
7 | 7 | #define CPPTL_JSON_ASSERTIONS_H_INCLUDED
|
8 | 8 |
|
9 | 9 | #include <stdlib.h>
|
| 10 | +#include <sstream> |
10 | 11 |
|
11 | 12 | #if !defined(JSON_IS_AMALGAMATION)
|
12 | 13 | #include "config.h"
|
|
16 | 17 | #include <stdexcept>
|
17 | 18 | #define JSON_ASSERT(condition) \
|
18 | 19 | assert(condition); // @todo <= change this into an exception throw
|
19 |
| -#define JSON_FAIL_MESSAGE(message) throw std::runtime_error(message); |
| 20 | +#define JSON_FAIL_MESSAGE(message) do{std::ostringstream oss; oss << message; throw std::runtime_error(oss.str());}while(0) |
| 21 | +//#define JSON_FAIL_MESSAGE(message) throw std::runtime_error(message) |
20 | 22 | #else // JSON_USE_EXCEPTION
|
21 | 23 | #define JSON_ASSERT(condition) assert(condition);
|
22 | 24 |
|
23 | 25 | // 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. |
| 26 | +// release bugs we abort, for a core-dump or debugger. |
27 | 27 | #define JSON_FAIL_MESSAGE(message) \
|
28 | 28 | { \
|
29 |
| - assert(false&& message); \ |
30 |
| - strcpy(reinterpret_cast<char*>(666), message); \ |
31 |
| - exit(123); \ |
| 29 | + std::ostringstream oss; oss << message; \ |
| 30 | + assert(false && oss.str().c_str()); \ |
| 31 | + abort(); \ |
32 | 32 | }
|
33 | 33 |
|
| 34 | + |
34 | 35 | #endif
|
35 | 36 |
|
36 | 37 | #define JSON_ASSERT_MESSAGE(condition, message) \
|
37 | 38 | if (!(condition)) { \
|
38 |
| - JSON_FAIL_MESSAGE(message) \ |
| 39 | + JSON_FAIL_MESSAGE(message); \ |
39 | 40 | }
|
40 | 41 |
|
41 | 42 | #endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED
|
0 commit comments