|
15 | 15 | # include "Hash/CityHash.h" |
16 | 16 | #endif |
17 | 17 | #ifdef INK_ENABLE_STL |
18 | | -# include <exception> |
| 18 | +# ifdef INK_ENABLE_EXCEPTIONS |
| 19 | +# include <exception> |
| 20 | +# endif |
19 | 21 | # include <stdexcept> |
20 | 22 | # include <optional> |
21 | 23 | # include <cctype> |
|
30 | 32 | // Platform specific defines // |
31 | 33 |
|
32 | 34 | #ifdef INK_ENABLE_UNREAL |
33 | | -# define inkZeroMemory(buff, len) FMemory::Memset(buff, 0, len) |
34 | | -# define inkAssert(condition, text, ...) checkf(condition, TEXT(text), ##__VA_ARGS__) |
35 | | -# define inkFail(text, ...) checkf(false, TEXT(text), ##__VA_ARGS__) |
36 | | -# define FORMAT_STRING_STR "%hs" |
| 35 | +# define inkZeroMemory(buff, len) FMemory::Memset(buff, 0, len) |
| 36 | +# define FORMAT_STRING_STR "%hs" |
37 | 37 | #else |
38 | 38 | # define inkZeroMemory ink::internal::zero_memory |
39 | | -# define inkAssert ink::ink_assert |
40 | | -# define inkFail(...) ink::ink_assert(false, __VA_ARGS__) |
41 | 39 | # define FORMAT_STRING_STR "%s" |
42 | 40 | #endif |
43 | 41 |
|
| 42 | +#ifdef INK_ENABLE_UNREAL |
| 43 | +# define inkAssert(condition, text, ...) checkf(condition, TEXT(text), ##__VA_ARGS__) |
| 44 | +# define inkFail(text, ...) checkf(false, TEXT(text), ##__VA_ARGS__) |
| 45 | +#else |
| 46 | +# define inkAssert ink::ink_assert |
| 47 | +# define inkFail(...) ink::ink_assert(false, __VA_ARGS__) |
| 48 | +#endif |
| 49 | + |
44 | 50 | namespace ink |
45 | 51 | { |
46 | 52 | /** define basic numeric type |
@@ -175,7 +181,7 @@ namespace internal |
175 | 181 | #endif |
176 | 182 | } // namespace internal |
177 | 183 |
|
178 | | -#ifdef INK_ENABLE_STL |
| 184 | +#ifdef INK_ENABLE_EXCEPTIONS |
179 | 185 | /** exception type thrown if something goes wrong */ |
180 | 186 | using ink_exception = std::runtime_error; |
181 | 187 | #else |
@@ -209,10 +215,17 @@ void ink_assert(bool condition, const char* msg = nullptr, Args... args) |
209 | 215 | size_t size = snprintf(nullptr, 0, msg, args...) + 1; |
210 | 216 | char* message = static_cast<char*>(malloc(size)); |
211 | 217 | snprintf(message, size, msg, args...); |
212 | | - throw ink_exception(message); |
213 | | - } else { |
214 | | - throw ink_exception(msg); |
| 218 | + msg = message; |
215 | 219 | } |
| 220 | + |
| 221 | +# ifdef INK_ENABLE_EXCEPTIONS |
| 222 | + throw ink_exception(msg); |
| 223 | +# elif defined(INK_ENABLE_CSTD) |
| 224 | + fprintf(stderr, "Ink Assert: %s\n", msg); |
| 225 | + abort(); |
| 226 | +# else |
| 227 | +# error "This path needs a way to warn and then terminate, otherwise it'll silently fail" |
| 228 | +# endif |
216 | 229 | } |
217 | 230 | } |
218 | 231 |
|
|
0 commit comments