error_macros.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. /*************************************************************************/
  2. /* error_macros.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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. #ifndef _STR
  75. #define _STR(m_x) #m_x
  76. #define _MKSTR(m_x) _STR(m_x)
  77. #endif
  78. #define _FNL __FILE__ ":"
  79. /** An index has failed if m_index<0 or m_index >=m_size, the function exits */
  80. #ifdef __GNUC__
  81. //#define FUNCTION_STR __PRETTY_FUNCTION__ - too annoying
  82. #define FUNCTION_STR __FUNCTION__
  83. #else
  84. #define FUNCTION_STR __FUNCTION__
  85. #endif
  86. // Don't use this directly; instead, use any of the CRASH_* macros
  87. #ifdef _MSC_VER
  88. #define GENERATE_TRAP \
  89. __debugbreak(); \
  90. /* Avoid warning about control paths */ \
  91. for (;;) { \
  92. }
  93. #else
  94. #define GENERATE_TRAP __builtin_trap();
  95. #endif
  96. // (*): See https://stackoverflow.com/questions/257418/do-while-0-what-is-it-good-for
  97. /**
  98. * If `m_index` is less than 0 or greater than or equal to `m_size`, prints a generic
  99. * error message and returns from the function. This macro should be preferred to
  100. * `ERR_FAIL_COND` for bounds checking.
  101. */
  102. #define ERR_FAIL_INDEX(m_index, m_size) \
  103. if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
  104. _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
  105. return; \
  106. } else \
  107. ((void)0)
  108. /**
  109. * If `m_index` is less than 0 or greater than or equal to `m_size`, prints a custom
  110. * error message and returns from the function. This macro should be preferred to
  111. * `ERR_FAIL_COND_MSG` for bounds checking.
  112. */
  113. #define ERR_FAIL_INDEX_MSG(m_index, m_size, m_msg) \
  114. if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
  115. _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg); \
  116. return; \
  117. } else \
  118. ((void)0)
  119. /**
  120. * If `m_index` is less than 0 or greater than or equal to `m_size`,
  121. * prints a generic error message and returns the value specified in `m_retval`.
  122. * This macro should be preferred to `ERR_FAIL_COND_V` for bounds checking.
  123. */
  124. #define ERR_FAIL_INDEX_V(m_index, m_size, m_retval) \
  125. if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
  126. _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
  127. return m_retval; \
  128. } else \
  129. ((void)0)
  130. /**
  131. * If `m_index` is less than 0 or greater than or equal to `m_size`,
  132. * prints a custom error message and returns the value specified in `m_retval`.
  133. * This macro should be preferred to `ERR_FAIL_COND_V_MSG` for bounds checking.
  134. */
  135. #define ERR_FAIL_INDEX_V_MSG(m_index, m_size, m_retval, m_msg) \
  136. if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
  137. _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg); \
  138. return m_retval; \
  139. } else \
  140. ((void)0)
  141. /**
  142. * If `m_index` is greater than or equal to `m_size`,
  143. * prints a generic error message and returns the value specified in `m_retval`.
  144. * This macro should be preferred to `ERR_FAIL_COND_V` for unsigned bounds checking.
  145. */
  146. #define ERR_FAIL_UNSIGNED_INDEX(m_index, m_size) \
  147. if (unlikely((m_index) >= (m_size))) { \
  148. _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
  149. return; \
  150. } else \
  151. ((void)0)
  152. /**
  153. * If `m_index` is greater than or equal to `m_size`,
  154. * prints a generic error message and returns the value specified in `m_retval`.
  155. * This macro should be preferred to `ERR_FAIL_COND_V` for unsigned bounds checking.
  156. */
  157. #define ERR_FAIL_UNSIGNED_INDEX_V(m_index, m_size, m_retval) \
  158. if (unlikely((m_index) >= (m_size))) { \
  159. _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
  160. return m_retval; \
  161. } else \
  162. ((void)0)
  163. /**
  164. * If `m_index` is greater than or equal to `m_size`,
  165. * prints a custom error message and returns the value specified in `m_retval`.
  166. * This macro should be preferred to `ERR_FAIL_COND_V_MSG` for unsigned bounds checking.
  167. */
  168. #define ERR_FAIL_UNSIGNED_INDEX_V_MSG(m_index, m_size, m_retval, m_msg) \
  169. if (unlikely((m_index) >= (m_size))) { \
  170. _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg); \
  171. return m_retval; \
  172. } else \
  173. ((void)0)
  174. /**
  175. * If `m_index` is less than 0 or greater than or equal to `m_size`,
  176. * crashes the engine immediately with a generic error message.
  177. * Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
  178. * This macro should be preferred to `CRASH_COND` for bounds checking.
  179. */
  180. #define CRASH_BAD_INDEX(m_index, m_size) \
  181. if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
  182. _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", true); \
  183. GENERATE_TRAP \
  184. } else \
  185. ((void)0)
  186. /**
  187. * If `m_index` is less than 0 or greater than or equal to `m_size`,
  188. * crashes the engine immediately with a custom error message.
  189. * Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
  190. * This macro should be preferred to `CRASH_COND` for bounds checking.
  191. */
  192. #define CRASH_BAD_INDEX_MSG(m_index, m_size, m_msg) \
  193. if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
  194. _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg, true); \
  195. GENERATE_TRAP \
  196. } else \
  197. ((void)0)
  198. /**
  199. * If `m_index` is greater than or equal to `m_size`,
  200. * crashes the engine immediately with a generic error message.
  201. * Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
  202. * This macro should be preferred to `CRASH_COND` for bounds checking.
  203. */
  204. #define CRASH_BAD_UNSIGNED_INDEX(m_index, m_size) \
  205. if (unlikely((m_index) >= (m_size))) { \
  206. _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", true); \
  207. GENERATE_TRAP \
  208. } else \
  209. ((void)0)
  210. /**
  211. * If `m_param` is `null`, prints a generic error message and returns from the function.
  212. */
  213. #define ERR_FAIL_NULL(m_param) \
  214. if (unlikely(!m_param)) { \
  215. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null."); \
  216. return; \
  217. } else \
  218. ((void)0)
  219. /**
  220. * If `m_param` is `null`, prints a custom error message and returns from the function.
  221. */
  222. #define ERR_FAIL_NULL_MSG(m_param, m_msg) \
  223. if (unlikely(!m_param)) { \
  224. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null.", m_msg); \
  225. return; \
  226. } else \
  227. ((void)0)
  228. /**
  229. * If `m_param` is `null`, prints a generic error message and returns the value specified in `m_retval`.
  230. */
  231. #define ERR_FAIL_NULL_V(m_param, m_retval) \
  232. if (unlikely(!m_param)) { \
  233. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null."); \
  234. return m_retval; \
  235. } else \
  236. ((void)0)
  237. /**
  238. * If `m_param` is `null`, prints a custom error message and returns the value specified in `m_retval`.
  239. */
  240. #define ERR_FAIL_NULL_V_MSG(m_param, m_retval, m_msg) \
  241. if (unlikely(!m_param)) { \
  242. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null.", m_msg); \
  243. return m_retval; \
  244. } else \
  245. ((void)0)
  246. /**
  247. * If `m_cond` evaluates to `true`, prints a generic error message and returns from the function.
  248. */
  249. #define ERR_FAIL_COND(m_cond) \
  250. if (unlikely(m_cond)) { \
  251. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true."); \
  252. return; \
  253. } else \
  254. ((void)0)
  255. /**
  256. * If `m_cond` evaluates to `true`, prints a custom error message and returns from the function.
  257. */
  258. #define ERR_FAIL_COND_MSG(m_cond, m_msg) \
  259. if (unlikely(m_cond)) { \
  260. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true.", m_msg); \
  261. return; \
  262. } else \
  263. ((void)0)
  264. /**
  265. * If `m_cond` evaluates to `true`, crashes the engine immediately with a generic error message.
  266. * Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
  267. */
  268. #define CRASH_COND(m_cond) \
  269. if (unlikely(m_cond)) { \
  270. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Condition \"" _STR(m_cond) "\" is true."); \
  271. GENERATE_TRAP \
  272. } else \
  273. ((void)0)
  274. /**
  275. * If `m_cond` evaluates to `true`, crashes the engine immediately with a custom error message.
  276. * Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
  277. */
  278. #define CRASH_COND_MSG(m_cond, m_msg) \
  279. if (unlikely(m_cond)) { \
  280. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Condition \"" _STR(m_cond) "\" is true.", m_msg); \
  281. GENERATE_TRAP \
  282. } else \
  283. ((void)0)
  284. /**
  285. * If `m_cond` evaluates to `true`, prints a generic error message and returns the value specified in `m_retval`.
  286. */
  287. #define ERR_FAIL_COND_V(m_cond, m_retval) \
  288. if (unlikely(m_cond)) { \
  289. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Returned: " _STR(m_retval)); \
  290. return m_retval; \
  291. } else \
  292. ((void)0)
  293. /**
  294. * If `m_cond` evaluates to `true`, prints a custom error message and returns the value specified in `m_retval`.
  295. */
  296. #define ERR_FAIL_COND_V_MSG(m_cond, m_retval, m_msg) \
  297. if (unlikely(m_cond)) { \
  298. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Returned: " _STR(m_retval), m_msg); \
  299. return m_retval; \
  300. } else \
  301. ((void)0)
  302. /**
  303. * If `m_cond` evaluates to `true`, prints a custom error message and continues the loop the macro is located in.
  304. */
  305. #define ERR_CONTINUE(m_cond) \
  306. if (unlikely(m_cond)) { \
  307. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Continuing."); \
  308. continue; \
  309. } else \
  310. ((void)0)
  311. /**
  312. * If `m_cond` evaluates to `true`, prints a custom error message and continues the loop the macro is located in.
  313. */
  314. #define ERR_CONTINUE_MSG(m_cond, m_msg) \
  315. if (unlikely(m_cond)) { \
  316. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Continuing.", m_msg); \
  317. continue; \
  318. } else \
  319. ((void)0)
  320. /**
  321. * If `m_cond` evaluates to `true`, prints a generic error message and breaks from the loop the macro is located in.
  322. */
  323. #define ERR_BREAK(m_cond) \
  324. if (unlikely(m_cond)) { \
  325. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Breaking."); \
  326. break; \
  327. } else \
  328. ((void)0)
  329. /**
  330. * If `m_cond` evaluates to `true`, prints a custom error message and breaks from the loop the macro is located in.
  331. */
  332. #define ERR_BREAK_MSG(m_cond, m_msg) \
  333. if (unlikely(m_cond)) { \
  334. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Breaking.", m_msg); \
  335. break; \
  336. } else \
  337. ((void)0)
  338. /**
  339. * Prints a generic error message and returns from the function.
  340. */
  341. #define ERR_FAIL() \
  342. if (true) { \
  343. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method failed."); \
  344. return; \
  345. } else \
  346. ((void)0)
  347. /**
  348. * Prints a custom error message and returns from the function.
  349. */
  350. #define ERR_FAIL_MSG(m_msg) \
  351. if (true) { \
  352. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method failed.", m_msg); \
  353. return; \
  354. } else \
  355. ((void)0)
  356. /**
  357. * Prints a generic error message and returns the value specified in `m_retval`.
  358. */
  359. #define ERR_FAIL_V(m_retval) \
  360. if (true) { \
  361. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method failed. Returning: " __STR(m_retval)); \
  362. return m_retval; \
  363. } else \
  364. ((void)0)
  365. /**
  366. * Prints a custom error message and returns the value specified in `m_retval`.
  367. */
  368. #define ERR_FAIL_V_MSG(m_retval, m_msg) \
  369. if (true) { \
  370. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method failed. Returning: " __STR(m_retval), m_msg); \
  371. return m_retval; \
  372. } else \
  373. ((void)0)
  374. /**
  375. * Crashes the engine immediately with a generic error message.
  376. * Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
  377. */
  378. #define CRASH_NOW() \
  379. if (true) { \
  380. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Method failed."); \
  381. GENERATE_TRAP \
  382. } else \
  383. ((void)0)
  384. /**
  385. * Crashes the engine immediately with a custom error message.
  386. * Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
  387. */
  388. #define CRASH_NOW_MSG(m_msg) \
  389. if (true) { \
  390. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Method failed.", m_msg); \
  391. GENERATE_TRAP \
  392. } else \
  393. ((void)0)
  394. /**
  395. * Prints an error message without returning.
  396. */
  397. #define ERR_PRINT(m_string) \
  398. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string)
  399. /**
  400. * Prints an error message without returning, but only do so once in the application lifecycle.
  401. * This can be used to avoid spamming the console with error messages.
  402. */
  403. #define ERR_PRINT_ONCE(m_string) \
  404. if (true) { \
  405. static bool first_print = true; \
  406. if (first_print) { \
  407. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string); \
  408. first_print = false; \
  409. } \
  410. } else \
  411. ((void)0)
  412. /**
  413. * Prints a warning message without returning. To warn about deprecated usage,
  414. * use `WARN_DEPRECATED` or `WARN_DEPRECATED_MSG` instead.
  415. */
  416. #define WARN_PRINT(m_string) \
  417. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string, ERR_HANDLER_WARNING)
  418. /**
  419. * Prints a warning message without returning, but only do so once in the application lifecycle.
  420. * This can be used to avoid spamming the console with warning messages.
  421. */
  422. #define WARN_PRINT_ONCE(m_string) \
  423. if (true) { \
  424. static bool first_print = true; \
  425. if (first_print) { \
  426. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string, ERR_HANDLER_WARNING); \
  427. first_print = false; \
  428. } \
  429. } else \
  430. ((void)0)
  431. /**
  432. * Prints a generic deprecation warning message without returning.
  433. * This should be preferred to `WARN_PRINT` for deprecation warnings.
  434. */
  435. #define WARN_DEPRECATED \
  436. if (true) { \
  437. static SafeFlag warning_shown; \
  438. if (!warning_shown.is_set()) { \
  439. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "This method has been deprecated and will be removed in the future.", ERR_HANDLER_WARNING); \
  440. warning_shown.set(); \
  441. } \
  442. } else \
  443. ((void)0)
  444. /**
  445. * Prints a custom deprecation warning message without returning.
  446. * This should be preferred to `WARN_PRINT` for deprecation warnings.
  447. */
  448. #define WARN_DEPRECATED_MSG(m_msg) \
  449. if (true) { \
  450. static SafeFlag warning_shown; \
  451. if (!warning_shown.is_set()) { \
  452. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "This method has been deprecated and will be removed in the future.", m_msg, ERR_HANDLER_WARNING); \
  453. warning_shown.set(); \
  454. } \
  455. } else \
  456. ((void)0)
  457. #endif
  458. /**
  459. * This should be a 'free' assert for program flow and should not be needed in any releases,
  460. * only used in dev builds.
  461. */
  462. #ifdef DEV_ENABLED
  463. #define DEV_ASSERT(m_cond) \
  464. if (unlikely(!(m_cond))) { \
  465. _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: DEV_ASSERT failed \"" _STR(m_cond) "\" is false."); \
  466. GENERATE_TRAP \
  467. } else \
  468. ((void)0)
  469. #else
  470. #define DEV_ASSERT(m_cond)
  471. #endif
  472. /**
  473. * These should be 'free' checks for program flow and should not be needed in any releases,
  474. * only used in dev builds.
  475. */
  476. #ifdef DEV_ENABLED
  477. #define DEV_CHECK(m_cond) \
  478. if (unlikely(!(m_cond))) { \
  479. ERR_PRINT("DEV_CHECK failed \"" _STR(m_cond) "\" is false."); \
  480. } else \
  481. ((void)0)
  482. #else
  483. #define DEV_CHECK(m_cond)
  484. #endif
  485. #ifdef DEV_ENABLED
  486. #define DEV_CHECK_ONCE(m_cond) \
  487. if (unlikely(!(m_cond))) { \
  488. ERR_PRINT_ONCE("DEV_CHECK_ONCE failed \"" _STR(m_cond) "\" is false."); \
  489. } else \
  490. ((void)0)
  491. #else
  492. #define DEV_CHECK_ONCE(m_cond)
  493. #endif