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
This commit is contained in:
parent
73a43c9d8a
commit
ba20da7214
|
@ -25,6 +25,8 @@
|
|||
|
||||
/* BLI_array_alloca / alloca */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
# if defined(__cplusplus) && (__cplusplus > 199711L)
|
||||
# define BLI_array_alloca(arr, realsize) (decltype(arr)) alloca(sizeof(*arr) * (realsize))
|
||||
|
|
|
@ -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)) : \
|
||||
|
|
|
@ -37,6 +37,7 @@ set(INC_SYS
|
|||
set(SRC
|
||||
intern/BLI_args.c
|
||||
intern/BLI_array.c
|
||||
intern/BLI_assert.c
|
||||
intern/BLI_dial_2d.c
|
||||
intern/BLI_dynstr.c
|
||||
intern/BLI_filelist.c
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \ingroup bli
|
||||
*
|
||||
* Helper functions for BLI_assert.h header.
|
||||
*/
|
||||
|
||||
#include "BLI_assert.h" /* Own include. */
|
||||
#include "BLI_system.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void _BLI_assert_print_pos(const char *file, int line, const char *function, const char *id)
|
||||
{
|
||||
fprintf(stderr, "BLI_assert failed: %s:%d, %s(), at \'%s\'\n", file, line, function, id);
|
||||
}
|
||||
|
||||
void _BLI_assert_print_backtrace(void)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
BLI_system_backtrace(stderr);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap to remove 'noreturn' attribute since this suppresses missing return statements,
|
||||
* allowing changes to debug builds to accidentally to break release builds.
|
||||
*
|
||||
* For example `BLI_assert(0);` at the end of a function that returns a value,
|
||||
* will hide that it's missing a return.
|
||||
*/
|
||||
void _BLI_assert_abort(void)
|
||||
{
|
||||
abort();
|
||||
}
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
|
|
|
@ -35,6 +35,7 @@ blender_include_dirs(
|
|||
set(SRC
|
||||
dna_utils.c
|
||||
makesdna.c
|
||||
../../blenlib/intern/BLI_assert.c
|
||||
../../blenlib/intern/BLI_ghash.c
|
||||
../../blenlib/intern/BLI_ghash_utils.c
|
||||
../../blenlib/intern/BLI_memarena.c
|
||||
|
@ -126,6 +127,7 @@ set(INC_SYS
|
|||
)
|
||||
|
||||
set(SRC
|
||||
../../blenlib/intern/BLI_assert.c
|
||||
../../blenlib/intern/BLI_ghash.c
|
||||
../../blenlib/intern/BLI_ghash_utils.c
|
||||
../../blenlib/intern/BLI_linklist.c
|
||||
|
|
|
@ -54,6 +54,7 @@
|
|||
#include "BLI_ghash.h"
|
||||
#include "BLI_memarena.h"
|
||||
#include "BLI_sys_types.h" /* for intptr_t support */
|
||||
#include "BLI_system.h" /* for 'BLI_system_backtrace' stub. */
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "dna_utils.h"
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLI_system.h" /* for 'BLI_system_backtrace' stub. */
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "RNA_define.h"
|
||||
|
|
Loading…
Reference in New Issue