error_macros.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. /*************************************************************************/
  2. /* error_macros.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef ERROR_MACROS_H
  31. #define ERROR_MACROS_H
  32. #include "core/safe_refcount.h"
  33. #include "core/typedefs.h"
  34. /**
  35. * Error macros. Unlike exceptions and asserts, these macros try to maintain consistency and stability
  36. * inside the code. It is recommended to always return processable data, so in case of an error,
  37. * the engine can keep working well.
  38. * In most cases, bugs and/or invalid data are not fatal and should never allow a perfectly running application
  39. * to fail or crash.
  40. */
  41. /**
  42. * Pointer to the error macro printing function. Reassign to any function to have errors printed
  43. */
  44. /** Function used by the error macros */
  45. // function, file, line, error, explanation
  46. enum ErrorHandlerType {
  47. ERR_HANDLER_ERROR,
  48. ERR_HANDLER_WARNING,
  49. ERR_HANDLER_SCRIPT,
  50. ERR_HANDLER_SHADER,
  51. };
  52. class String;
  53. typedef void (*ErrorHandlerFunc)(void *, const char *, const char *, int p_line, const char *, const char *, ErrorHandlerType p_type);
  54. struct ErrorHandlerList {
  55. ErrorHandlerFunc errfunc;
  56. void *userdata;
  57. ErrorHandlerList *next;
  58. ErrorHandlerList() {
  59. errfunc = nullptr;
  60. next = nullptr;
  61. userdata = nullptr;
  62. }
  63. };
  64. void add_error_handler(ErrorHandlerList *p_handler);
  65. void remove_error_handler(ErrorHandlerList *p_handler);
  66. void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
  67. void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
  68. void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const char *p_message, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
  69. void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, const char *p_message, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
  70. void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const String &p_message, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
  71. void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, const String &p_message, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
  72. void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const char *p_message = "", bool fatal = false);
  73. void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const String &p_message, bool fatal = false);
  74. void _err_flush_stdout();
  75. #ifndef _STR
  76. #define _STR(m_x) #m_x
  77. #define _MKSTR(m_x) _STR(m_x)
  78. #endif
  79. #define _FNL __FILE__ ":"
  80. /** An index has failed if m_index<0 or m_index >=m_size, the function exits */
  81. #ifdef __GNUC__
  82. //#define FUNCTION_STR __PRETTY_FUNCTION__ - too annoying
  83. #define FUNCTION_STR __FUNCTION__
  84. #else
  85. #define FUNCTION_STR __FUNCTION__
  86. #endif
  87. // Don't use this directly; instead, use any of the CRASH_* macros
  88. #ifdef _MSC_VER
  89. #define GENERATE_TRAP \
  90. __debugbreak(); \
  91. /* Avoid warning about control paths */ \
  92. for (;;) { \
  93. }
  94. #else
  95. #define GENERATE_TRAP __builtin_trap();
  96. #endif
  97. // (*): See https://stackoverflow.com/questions/257418/do-while-0-what-is-it-good-for
  98. /**
  99. * If `m_index` is less than 0 or greater than or equal to `m_size`, prints a generic
  100. * error message and returns from the function. This macro should be preferred to
  101. * `ERR_FAIL_COND` for bounds checking.
  102. */
  103. #define ERR_FAIL_INDEX(m_index, m_size) \
  104. if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
  105. _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
  106. return; \
  107. } else \
  108. ((void)0)
  109. /**
  110. * If `m_index` is less than 0 or greater than or equal to `m_size`, prints a custom
  111. * error message and returns from the function. This macro should be preferred to
  112. * `ERR_FAIL_COND_MSG` for bounds checking.
  113. */
  114. #define ERR_FAIL_INDEX_MSG(m_index, m_size, m_msg) \
  115. if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
  116. _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg); \
  117. return; \
  118. } else \
  119. ((void)0)
  120. /**
  121. * If `m_index` is less than 0 or greater than or equal to `m_size`,
  122. * prints a generic error message and returns the value specified in `m_retval`.
  123. * This macro should be preferred to `ERR_FAIL_COND_V` for bounds checking.
  124. */
  125. #define ERR_FAIL_INDEX_V(m_index, m_size, m_retval) \
  126. if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
  127. _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
  128. return m_retval; \
  129. } else \
  130. ((void)0)
  131. /**
  132. * If `m_index` is less than 0 or greater than or equal to `m_size`,
  133. * prints a custom error message and returns the value specified in `m_retval`.
  134. * This macro should be preferred to `ERR_FAIL_COND_V_MSG` for bounds checking.
  135. */
  136. #define ERR_FAIL_INDEX_V_MSG(m_index, m_size, m_retval, m_msg) \
  137. if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
  138. _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg); \
  139. return m_retval; \
  140. } else \
  141. ((void)0)
  142. /**
  143. * If `m_index` is greater than or equal to `m_size`,
  144. * prints a generic error message and returns the value specified in `m_retval`.
  145. * This macro should be preferred to `ERR_FAIL_COND_V` for unsigned bounds checking.
  146. */
  147. #define ERR_FAIL_UNSIGNED_INDEX(m_index, m_size) \
  148. if (unlikely((m_index) >= (m_size))) { \
  149. _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
  150. return; \
  151. } else \
  152. ((void)0)
  153. /**
  154. * If `m_index` is greater than or equal to `m_size`,
  155. * prints a generic error message and returns the value specified in `m_retval`.
  156. * This macro should be preferred to `ERR_FAIL_COND_V` for unsigned bounds checking.
  157. */
  158. #define ERR_FAIL_UNSIGNED_INDEX_V(m_index, m_size, m_retval) \
  159. if (unlikely((m_index) >= (m_size))) { \
  160. _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
  161. return m_retval; \
  162. } else \
  163. ((void)0)
  164. /**
  165. * If `m_index` is greater than or equal to `m_size`,
  166. * prints a custom error message and returns the value specified in `m_retval`.
  167. * This macro should be preferred to `ERR_FAIL_COND_V_MSG` for unsigned bounds checking.
  168. */
  169. #define ERR_FAIL_UNSIGNED_INDEX_V_MSG(m_index, m_size, m_retval, m_msg) \
  170. if (unlikely((m_index) >= (m_size))) { \
  171. _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg); \
  172. return m_retval; \
  173. } else \
  174. ((void)0)
  175. /**
  176. * If `m_index` is less than 0 or greater than or equal to `m_size`,
  177. * crashes the engine immediately with a generic error message.
  178. * Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
  179. * This macro should be preferred to `CRASH_COND` for bounds checking.
  180. */
  181. #define CRASH_BAD_INDEX(m_index, m_size) \
  182. if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
  183. _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", true); \
  184. GENERATE_TRAP \
  185. } else \
  186. ((void)0)
  187. /**
  188. * If `m_index` is less than 0 or greater than or equal to `m_size`,
  189. * crashes the engine immediately with a custom error message.
  190. * Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
  191. * This macro should be preferred to `CRASH_COND` for bounds checking.
  192. */
  193. #define CRASH_BAD_INDEX_MSG(m_index, m_size, m_msg) \
  194. if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
  195. _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg, true); \
  196. GENERATE_TRAP \
  197. } else \
  198. ((void)0)
  199. /**
  200. * If `m_index` is greater than or equal to `m_size`,
  201. * crashes the engine immediately with a generic error message.
  202. * Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
  203. * This macro should be preferred to `CRASH_COND` for bounds checking.
  204. */
  205. #define CRASH_BAD_UNSIGNED_INDEX(m_index, m_size) \
  206. if (unlikely((m_index) >= (m_size))) { \
  207. _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", true); \
  208. GENERATE_TRAP \
  209. } else \
  210. ((void)0)
  211. /**
  212. * If `m_param` is `null`, prints a generic error message and returns from the function.
  213. */
  214. #define ERR_FAIL_NULL(m_param) \
  215. if (unlikely(!m_param)) { \
  216. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null."); \
  217. return; \
  218. } else \
  219. ((void)0)
  220. /**
  221. * If `m_param` is `null`, prints a custom error message and returns from the function.
  222. */
  223. #define ERR_FAIL_NULL_MSG(m_param, m_msg) \
  224. if (unlikely(!m_param)) { \
  225. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null.", m_msg); \
  226. return; \
  227. } else \
  228. ((void)0)
  229. /**
  230. * If `m_param` is `null`, prints a generic error message and returns the value specified in `m_retval`.
  231. */
  232. #define ERR_FAIL_NULL_V(m_param, m_retval) \
  233. if (unlikely(!m_param)) { \
  234. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null."); \
  235. return m_retval; \
  236. } else \
  237. ((void)0)
  238. /**
  239. * If `m_param` is `null`, prints a custom error message and returns the value specified in `m_retval`.
  240. */
  241. #define ERR_FAIL_NULL_V_MSG(m_param, m_retval, m_msg) \
  242. if (unlikely(!m_param)) { \
  243. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null.", m_msg); \
  244. return m_retval; \
  245. } else \
  246. ((void)0)
  247. /**
  248. * If `m_cond` evaluates to `true`, prints a generic error message and returns from the function.
  249. */
  250. #define ERR_FAIL_COND(m_cond) \
  251. if (unlikely(m_cond)) { \
  252. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true."); \
  253. return; \
  254. } else \
  255. ((void)0)
  256. /**
  257. * If `m_cond` evaluates to `true`, prints a custom error message and returns from the function.
  258. */
  259. #define ERR_FAIL_COND_MSG(m_cond, m_msg) \
  260. if (unlikely(m_cond)) { \
  261. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true.", m_msg); \
  262. return; \
  263. } else \
  264. ((void)0)
  265. /**
  266. * If `m_cond` evaluates to `true`, crashes the engine immediately with a generic error message.
  267. * Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
  268. */
  269. #define CRASH_COND(m_cond) \
  270. if (unlikely(m_cond)) { \
  271. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Condition \"" _STR(m_cond) "\" is true."); \
  272. GENERATE_TRAP \
  273. } else \
  274. ((void)0)
  275. /**
  276. * If `m_cond` evaluates to `true`, crashes the engine immediately with a custom error message.
  277. * Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
  278. */
  279. #define CRASH_COND_MSG(m_cond, m_msg) \
  280. if (unlikely(m_cond)) { \
  281. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Condition \"" _STR(m_cond) "\" is true.", m_msg); \
  282. GENERATE_TRAP \
  283. } else \
  284. ((void)0)
  285. /**
  286. * If `m_cond` evaluates to `true`, prints a generic error message and returns the value specified in `m_retval`.
  287. */
  288. #define ERR_FAIL_COND_V(m_cond, m_retval) \
  289. if (unlikely(m_cond)) { \
  290. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Returned: " _STR(m_retval)); \
  291. return m_retval; \
  292. } else \
  293. ((void)0)
  294. /**
  295. * If `m_cond` evaluates to `true`, prints a custom error message and returns the value specified in `m_retval`.
  296. */
  297. #define ERR_FAIL_COND_V_MSG(m_cond, m_retval, m_msg) \
  298. if (unlikely(m_cond)) { \
  299. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Returned: " _STR(m_retval), m_msg); \
  300. return m_retval; \
  301. } else \
  302. ((void)0)
  303. /**
  304. * If `m_cond` evaluates to `true`, prints a custom error message and continues the loop the macro is located in.
  305. */
  306. #define ERR_CONTINUE(m_cond) \
  307. if (unlikely(m_cond)) { \
  308. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Continuing."); \
  309. continue; \
  310. } else \
  311. ((void)0)
  312. /**
  313. * If `m_cond` evaluates to `true`, prints a custom error message and continues the loop the macro is located in.
  314. */
  315. #define ERR_CONTINUE_MSG(m_cond, m_msg) \
  316. if (unlikely(m_cond)) { \
  317. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Continuing.", m_msg); \
  318. continue; \
  319. } else \
  320. ((void)0)
  321. /**
  322. * If `m_cond` evaluates to `true`, prints a generic error message and breaks from the loop the macro is located in.
  323. */
  324. #define ERR_BREAK(m_cond) \
  325. if (unlikely(m_cond)) { \
  326. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Breaking."); \
  327. break; \
  328. } else \
  329. ((void)0)
  330. /**
  331. * If `m_cond` evaluates to `true`, prints a custom error message and breaks from the loop the macro is located in.
  332. */
  333. #define ERR_BREAK_MSG(m_cond, m_msg) \
  334. if (unlikely(m_cond)) { \
  335. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Breaking.", m_msg); \
  336. break; \
  337. } else \
  338. ((void)0)
  339. /**
  340. * Prints a generic error message and returns from the function.
  341. */
  342. #define ERR_FAIL() \
  343. if (true) { \
  344. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method failed."); \
  345. return; \
  346. } else \
  347. ((void)0)
  348. /**
  349. * Prints a custom error message and returns from the function.
  350. */
  351. #define ERR_FAIL_MSG(m_msg) \
  352. if (true) { \
  353. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method failed.", m_msg); \
  354. return; \
  355. } else \
  356. ((void)0)
  357. /**
  358. * Prints a generic error message and returns the value specified in `m_retval`.
  359. */
  360. #define ERR_FAIL_V(m_retval) \
  361. if (true) { \
  362. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method failed. Returning: " __STR(m_retval)); \
  363. return m_retval; \
  364. } else \
  365. ((void)0)
  366. /**
  367. * Prints a custom error message and returns the value specified in `m_retval`.
  368. */
  369. #define ERR_FAIL_V_MSG(m_retval, m_msg) \
  370. if (true) { \
  371. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method failed. Returning: " __STR(m_retval), m_msg); \
  372. return m_retval; \
  373. } else \
  374. ((void)0)
  375. /**
  376. * Crashes the engine immediately with a generic error message.
  377. * Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
  378. */
  379. #define CRASH_NOW() \
  380. if (true) { \
  381. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Method failed."); \
  382. void _err_flush_stdout(); \
  383. GENERATE_TRAP \
  384. } else \
  385. ((void)0)
  386. /**
  387. * Crashes the engine immediately with a custom error message.
  388. * Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
  389. */
  390. #define CRASH_NOW_MSG(m_msg) \
  391. if (true) { \
  392. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Method failed.", m_msg); \
  393. void _err_flush_stdout(); \
  394. GENERATE_TRAP \
  395. } else \
  396. ((void)0)
  397. /**
  398. * Prints an error message without returning.
  399. */
  400. #define ERR_PRINT(m_string) \
  401. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string)
  402. /**
  403. * Prints an error message without returning, but only do so once in the application lifecycle.
  404. * This can be used to avoid spamming the console with error messages.
  405. */
  406. #define ERR_PRINT_ONCE(m_string) \
  407. if (true) { \
  408. static bool first_print = true; \
  409. if (first_print) { \
  410. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string); \
  411. first_print = false; \
  412. } \
  413. } else \
  414. ((void)0)
  415. /**
  416. * Prints a warning message without returning. To warn about deprecated usage,
  417. * use `WARN_DEPRECATED` or `WARN_DEPRECATED_MSG` instead.
  418. */
  419. #define WARN_PRINT(m_string) \
  420. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string, ERR_HANDLER_WARNING)
  421. /**
  422. * Prints a warning message without returning, but only do so once in the application lifecycle.
  423. * This can be used to avoid spamming the console with warning messages.
  424. */
  425. #define WARN_PRINT_ONCE(m_string) \
  426. if (true) { \
  427. static bool first_print = true; \
  428. if (first_print) { \
  429. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string, ERR_HANDLER_WARNING); \
  430. first_print = false; \
  431. } \
  432. } else \
  433. ((void)0)
  434. /**
  435. * Prints a generic deprecation warning message without returning.
  436. * This should be preferred to `WARN_PRINT` for deprecation warnings.
  437. */
  438. #define WARN_DEPRECATED \
  439. if (true) { \
  440. static SafeFlag warning_shown; \
  441. if (!warning_shown.is_set()) { \
  442. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "This method has been deprecated and will be removed in the future.", ERR_HANDLER_WARNING); \
  443. warning_shown.set(); \
  444. } \
  445. } else \
  446. ((void)0)
  447. /**
  448. * Prints a custom deprecation warning message without returning.
  449. * This should be preferred to `WARN_PRINT` for deprecation warnings.
  450. */
  451. #define WARN_DEPRECATED_MSG(m_msg) \
  452. if (true) { \
  453. static SafeFlag warning_shown; \
  454. if (!warning_shown.is_set()) { \
  455. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "This method has been deprecated and will be removed in the future.", m_msg, ERR_HANDLER_WARNING); \
  456. warning_shown.set(); \
  457. } \
  458. } else \
  459. ((void)0)
  460. #endif
  461. /**
  462. * This should be a 'free' assert for program flow and should not be needed in any releases,
  463. * only used in dev builds.
  464. */
  465. #ifdef DEV_ENABLED
  466. #define DEV_ASSERT(m_cond) \
  467. if (unlikely(!(m_cond))) { \
  468. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: DEV_ASSERT failed \"" _STR(m_cond) "\" is false."); \
  469. void _err_flush_stdout(); \
  470. GENERATE_TRAP \
  471. } else \
  472. ((void)0)
  473. #else
  474. #define DEV_ASSERT(m_cond)
  475. #endif
  476. /**
  477. * These should be 'free' checks for program flow and should not be needed in any releases,
  478. * only used in dev builds.
  479. */
  480. #ifdef DEV_ENABLED
  481. #define DEV_CHECK(m_cond) \
  482. if (unlikely(!(m_cond))) { \
  483. ERR_PRINT("DEV_CHECK failed \"" _STR(m_cond) "\" is false."); \
  484. } else \
  485. ((void)0)
  486. #else
  487. #define DEV_CHECK(m_cond)
  488. #endif
  489. #ifdef DEV_ENABLED
  490. #define DEV_CHECK_ONCE(m_cond) \
  491. if (unlikely(!(m_cond))) { \
  492. ERR_PRINT_ONCE("DEV_CHECK_ONCE failed \"" _STR(m_cond) "\" is false."); \
  493. } else \
  494. ((void)0)
  495. #else
  496. #define DEV_CHECK_ONCE(m_cond)
  497. #endif