diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-08-06 13:17:44 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-08-06 15:49:28 +0300 |
commit | ba20da7214e0a71e843b0a6a8b11e0173599a0f0 (patch) | |
tree | 5fb2cc754fb0c2e2797aa42c1fa9a1ebffe5cb5d /source/blender/blenlib/BLI_assert.h | |
parent | 73a43c9d8acfdb81aa324012bb30cae10c52f186 (diff) |
Cleanup: avoid debug-only includes for BLI_assert.h
Having includes in debug builds makes it possible to accidentally
break release builds.
Avoid this by moving calls to other modules out of BLI_assert.h
into BLI_assert.c
Diffstat (limited to 'source/blender/blenlib/BLI_assert.h')
-rw-r--r-- | source/blender/blenlib/BLI_assert.h | 43 |
1 files changed, 9 insertions, 34 deletions
diff --git a/source/blender/blenlib/BLI_assert.h b/source/blender/blenlib/BLI_assert.h index 603be115b35..7978f04dd9d 100644 --- a/source/blender/blenlib/BLI_assert.h +++ b/source/blender/blenlib/BLI_assert.h @@ -30,58 +30,33 @@ extern "C" { #endif -#ifndef NDEBUG /* for BLI_assert */ -# include <stdio.h> -#endif +/* Utility functions. */ +void _BLI_assert_print_pos(const char *file, const int line, const char *function, const char *id); +void _BLI_assert_print_backtrace(void); +void _BLI_assert_abort(void); #ifdef _MSC_VER # include <crtdbg.h> /* for _STATIC_ASSERT */ #endif -/* BLI_assert(), default only to print - * for aborting need to define WITH_ASSERT_ABORT - */ -/* For 'abort' only. */ -#include <stdlib.h> - #ifndef NDEBUG -# include "BLI_system.h" /* _BLI_ASSERT_PRINT_POS */ # if defined(__GNUC__) -# define _BLI_ASSERT_PRINT_POS(a) \ - fprintf(stderr, \ - "BLI_assert failed: %s:%d, %s(), at \'%s\'\n", \ - __FILE__, \ - __LINE__, \ - __func__, \ - #a) +# define _BLI_ASSERT_PRINT_POS(a) _BLI_assert_print_pos(__FILE__, __LINE__, __func__, # a) # elif defined(_MSC_VER) -# define _BLI_ASSERT_PRINT_POS(a) \ - fprintf(stderr, \ - "BLI_assert failed: %s:%d, %s(), at \'%s\'\n", \ - __FILE__, \ - __LINE__, \ - __FUNCTION__, \ - #a) +# define _BLI_ASSERT_PRINT_POS(a) _BLI_assert_print_pos(__FILE__, __LINE__, __func__, # a) # else -# define _BLI_ASSERT_PRINT_POS(a) \ - fprintf(stderr, "BLI_assert failed: %s:%d, at \'%s\'\n", __FILE__, __LINE__, #a) +# define _BLI_ASSERT_PRINT_POS(a) _BLI_assert_print_pos(__FILE__, __LINE__, "<?>", # a) # endif /* _BLI_ASSERT_ABORT */ # ifdef WITH_ASSERT_ABORT -# ifdef __GNUC__ -/* Cast to remove 'noreturn' attribute since this suppresses missing return statements, - * allowing changes to debug builds to accidentally to break release builds. */ -# define _BLI_ASSERT_ABORT ((void (*)(void))(*(((void **)abort)))) -# else -# define _BLI_ASSERT_ABORT abort -# endif +# define _BLI_ASSERT_ABORT _BLI_assert_abort # else # define _BLI_ASSERT_ABORT() (void)0 # endif /* BLI_assert */ # define BLI_assert(a) \ - (void)((!(a)) ? ((BLI_system_backtrace(stderr), \ + (void)((!(a)) ? ((_BLI_assert_print_backtrace(), \ _BLI_ASSERT_PRINT_POS(a), \ _BLI_ASSERT_ABORT(), \ NULL)) : \ |