Cleanup: Remove/replace C standard library assert() and header usages

We have our own assert implementation, `BLI_assert()` that is prefered over the
C standard library one. Its output is more consistent across compilers and
makes termination on assert failure optional (through `WITH_ASSERT_ABORT`).

In many places we'd include the C library header without ever accessing it.
This commit is contained in:
Julian Eisel 2020-10-03 16:01:59 +02:00
parent e839179b01
commit 0bae2662f4
42 changed files with 30 additions and 74 deletions

View File

@ -27,7 +27,6 @@
#include <sys/stat.h>
#include <assert.h>
#include <string.h>
/* path/file handling stuff */

View File

@ -21,7 +21,6 @@
* \ingroup bke
*/
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <string.h>

View File

@ -104,7 +104,7 @@ static void emdm_ts_GetPosition(const SMikkTSpaceContext *pContext,
const int face_num,
const int vert_index)
{
// assert(vert_index >= 0 && vert_index < 4);
// BLI_assert(vert_index >= 0 && vert_index < 4);
SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
const BMLoop **lt;
const BMLoop *l;
@ -138,7 +138,7 @@ static void emdm_ts_GetTextureCoordinate(const SMikkTSpaceContext *pContext,
const int face_num,
const int vert_index)
{
// assert(vert_index >= 0 && vert_index < 4);
// BLI_assert(vert_index >= 0 && vert_index < 4);
SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
const BMLoop **lt;
const BMLoop *l;
@ -176,7 +176,7 @@ static void emdm_ts_GetNormal(const SMikkTSpaceContext *pContext,
const int face_num,
const int vert_index)
{
// assert(vert_index >= 0 && vert_index < 4);
// BLI_assert(vert_index >= 0 && vert_index < 4);
SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
const BMLoop **lt;
const BMLoop *l;
@ -221,7 +221,7 @@ static void emdm_ts_SetTSpace(const SMikkTSpaceContext *pContext,
const int face_num,
const int vert_index)
{
// assert(vert_index >= 0 && vert_index < 4);
// BLI_assert(vert_index >= 0 && vert_index < 4);
SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
const BMLoop **lt;
const BMLoop *l;

View File

@ -24,7 +24,6 @@
* allocate and free of all library data
*/
#include <assert.h>
#include <ctype.h>
#include <stddef.h>
#include <stdio.h>

View File

@ -36,8 +36,6 @@
#include "bmesh.h"
#include "pbvh_intern.h"
#include <assert.h>
/* Avoid skinny faces */
#define USE_EDGEQUEUE_EVEN_SUBDIV
#ifdef USE_EDGEQUEUE_EVEN_SUBDIV

View File

@ -21,7 +21,6 @@
* \ingroup bke
*/
#include <assert.h>
#include <float.h>
#include <math.h>
#include <memory.h>

View File

@ -18,7 +18,6 @@
* \ingroup bke
*/
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
@ -395,7 +394,8 @@ static const struct bUnitCollection *bUnitSystems[][B_UNIT_TYPE_TOT] = {
static const bUnitCollection *unit_get_system(int system, int type)
{
assert((system > -1) && (system < UNIT_SYSTEM_TOT) && (type > -1) && (type < B_UNIT_TYPE_TOT));
BLI_assert((system > -1) && (system < UNIT_SYSTEM_TOT) && (type > -1) &&
(type < B_UNIT_TYPE_TOT));
return bUnitSystems[system][type]; /* Select system to use: metric/imperial/other? */
}

View File

@ -154,7 +154,7 @@ static struct VolumeFileCache {
~VolumeFileCache()
{
assert(cache.empty());
BLI_assert(cache.empty());
}
Entry *add_metadata_user(const Entry &template_entry)

View File

@ -38,8 +38,6 @@
* #BLI_bvhtree_range_query
*/
#include <assert.h>
#include "MEM_guardedalloc.h"
#include "BLI_alloca.h"

View File

@ -30,8 +30,8 @@
* BLI_buffer_declare_static(int, my_int_array, BLI_BUFFER_NOP, 32);
*
* BLI_buffer_append(my_int_array, int, 42);
* assert(my_int_array.count == 1);
* assert(BLI_buffer_at(my_int_array, int, 0) == 42);
* BLI_assert(my_int_array.count == 1);
* BLI_assert(BLI_buffer_at(my_int_array, int, 0) == 42);
*
* BLI_buffer_free(&my_int_array);
* \endcode

View File

@ -24,8 +24,6 @@
* \ingroup bli
*/
#include <assert.h>
#include "BLI_math.h"
#include "BLI_utildefines.h"

View File

@ -24,7 +24,6 @@
*/
#include "BLI_math.h"
#include <assert.h>
#include "BLI_strict_flags.h"

View File

@ -24,7 +24,6 @@
*/
#include "BLI_math.h"
#include <assert.h>
#include "BLI_strict_flags.h"

View File

@ -22,7 +22,6 @@
* \ingroup bli
*/
#include <assert.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

View File

@ -190,7 +190,6 @@
#include "DNA_customdata_types.h" /* BMesh struct in bmesh_class.h uses */
#include "DNA_listBase.h" /* selection history uses */
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -395,17 +395,17 @@ typedef bool (*BMLoopFilterFunc)(const BMLoop *, void *user_data);
#define BM_ELEM_CD_SET_INT(ele, offset, f) \
{ \
CHECK_TYPE_NONCONST(ele); \
assert(offset != -1); \
BLI_assert(offset != -1); \
*((int *)((char *)(ele)->head.data + (offset))) = (f); \
} \
(void)0
#define BM_ELEM_CD_GET_INT(ele, offset) \
(assert(offset != -1), *((int *)((char *)(ele)->head.data + (offset))))
(BLI_assert(offset != -1), *((int *)((char *)(ele)->head.data + (offset))))
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
# define BM_ELEM_CD_GET_VOID_P(ele, offset) \
(assert(offset != -1), \
(BLI_assert(offset != -1), \
_Generic(ele, \
GENERIC_TYPE_ANY(POINTER_OFFSET((ele)->head.data, offset), \
_BM_GENERIC_TYPE_ELEM_NONCONST), \
@ -413,22 +413,22 @@ typedef bool (*BMLoopFilterFunc)(const BMLoop *, void *user_data);
_BM_GENERIC_TYPE_ELEM_CONST)))
#else
# define BM_ELEM_CD_GET_VOID_P(ele, offset) \
(assert(offset != -1), (void *)((char *)(ele)->head.data + (offset)))
(BLI_assert(offset != -1), (void *)((char *)(ele)->head.data + (offset)))
#endif
#define BM_ELEM_CD_SET_FLOAT(ele, offset, f) \
{ \
CHECK_TYPE_NONCONST(ele); \
assert(offset != -1); \
BLI_assert(offset != -1); \
*((float *)((char *)(ele)->head.data + (offset))) = (f); \
} \
(void)0
#define BM_ELEM_CD_GET_FLOAT(ele, offset) \
(assert(offset != -1), *((float *)((char *)(ele)->head.data + (offset))))
(BLI_assert(offset != -1), *((float *)((char *)(ele)->head.data + (offset))))
#define BM_ELEM_CD_GET_FLOAT_AS_UCHAR(ele, offset) \
(assert(offset != -1), (uchar)(BM_ELEM_CD_GET_FLOAT(ele, offset) * 255.0f))
(BLI_assert(offset != -1), (uchar)(BM_ELEM_CD_GET_FLOAT(ele, offset) * 255.0f))
/*forward declarations*/

View File

@ -22,8 +22,6 @@
* \ingroup edarmature
*/
#include <assert.h>
#include "DNA_armature_types.h"
#include "DNA_constraint_types.h"
#include "DNA_object_types.h"
@ -415,7 +413,7 @@ static int armature_calc_roll_exec(bContext *C, wmOperator *op)
copy_v3_v3(vec, mat[2]);
}
else { /* Axis */
assert(type <= 5);
BLI_assert(type <= 5);
if (type < 3) {
vec[type] = 1.0f;
}

View File

@ -21,7 +21,6 @@
* \ingroup edinterface
*/
#include <assert.h>
#include <ctype.h>
#include <float.h>
#include <limits.h>
@ -6213,7 +6212,7 @@ static void ui_ndofedit_but_HSVCUBE(uiButHSVCube *hsv_but,
CLAMP(hsv[2], hsv_but->but.softmin, hsv_but->but.softmax);
break;
default:
assert(!"invalid hsv type");
BLI_assert(!"invalid hsv type");
break;
}

View File

@ -18,7 +18,6 @@
* \ingroup edinterface
*/
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <stdlib.h>
@ -1192,7 +1191,7 @@ static uiBut *uiItemFullO_ptr_ex(uiLayout *layout,
but = uiDefButO_ptr(block, UI_BTYPE_BUT, ot, context, name, 0, 0, w, UI_UNIT_Y, NULL);
}
assert(but->optype != NULL);
BLI_assert(but->optype != NULL);
if (flag & UI_ITEM_R_NO_BG) {
layout->emboss = prev_emboss;

View File

@ -23,7 +23,6 @@
* Color Picker Region & Color Utils
*/
#include <assert.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>

View File

@ -23,7 +23,6 @@
* Pie Menu Region
*/
#include <assert.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>

View File

@ -23,7 +23,6 @@
* PopUp Menu Region
*/
#include <assert.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>

View File

@ -23,7 +23,6 @@
* PopUp Region (Generic)
*/
#include <assert.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>

View File

@ -23,7 +23,6 @@
* Search Box Region & Interaction
*/
#include <assert.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>

View File

@ -32,7 +32,6 @@
* For now it's not a priority, so leave as-is.
*/
#include <assert.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>

View File

@ -21,7 +21,6 @@
* \ingroup edinterface
*/
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -21,7 +21,6 @@
* \ingroup edinterface
*/
#include <assert.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
@ -3046,7 +3045,7 @@ void ui_draw_gradient(const rcti *rect,
copy_v3_v3(col1[3], col1[2]);
break;
default:
assert(!"invalid 'type' argument");
BLI_assert(!"invalid 'type' argument");
hsv_to_rgb(1.0, 1.0, 1.0, &col1[2][0], &col1[2][1], &col1[2][2]);
copy_v3_v3(col1[0], col1[2]);
copy_v3_v3(col1[1], col1[2]);

View File

@ -21,7 +21,6 @@
* \ingroup edobj
*/
#include <assert.h>
#include <math.h>
#include <stddef.h>
#include <string.h>

View File

@ -21,7 +21,6 @@
* \ingroup edphys
*/
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

View File

@ -21,7 +21,6 @@
* \ingroup edphys
*/
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

View File

@ -59,8 +59,6 @@
/* For undo push. */
#include "sculpt_intern.h"
#include <assert.h>
/* Return true if the element should be hidden/shown. */
static bool is_effected(PartialVisArea area,
float planes[4][4],

View File

@ -21,7 +21,6 @@
* \ingroup spview3d
*/
#include <assert.h>
#include <float.h>
#include <math.h>
#include <stdio.h>

View File

@ -43,7 +43,6 @@
#define DNA_DEPRECATED_ALLOW
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -18,7 +18,6 @@
* \ingroup RNA
*/
#include <assert.h>
#include <stdlib.h>
#include "DNA_brush_types.h"

View File

@ -65,8 +65,6 @@ const EnumPropertyItem rna_enum_uilist_layout_type_items[] = {
#ifdef RNA_RUNTIME
# include <assert.h>
# include "MEM_guardedalloc.h"
# include "RNA_access.h"
@ -993,7 +991,7 @@ static void rna_Menu_bl_description_set(PointerRNA *ptr, const char *value)
BLI_strncpy(str, value, RNA_DYN_DESCR_MAX); /* utf8 already ensured */
}
else {
assert(!"setting the bl_description on a non-builtin menu");
BLI_assert(!"setting the bl_description on a non-builtin menu");
}
}

View File

@ -512,8 +512,6 @@ const EnumPropertyItem rna_enum_wm_report_items[] = {
#ifdef RNA_RUNTIME
# include <assert.h>
# include "BLI_string_utils.h"
# include "WM_api.h"
@ -1747,7 +1745,7 @@ static void rna_Operator_bl_idname_set(PointerRNA *ptr, const char *value)
BLI_strncpy(str, value, OP_MAX_TYPENAME); /* utf8 already ensured */
}
else {
assert(!"setting the bl_idname on a non-builtin operator");
BLI_assert(!"setting the bl_idname on a non-builtin operator");
}
}
@ -1759,7 +1757,7 @@ static void rna_Operator_bl_label_set(PointerRNA *ptr, const char *value)
BLI_strncpy(str, value, OP_MAX_TYPENAME); /* utf8 already ensured */
}
else {
assert(!"setting the bl_label on a non-builtin operator");
BLI_assert(!"setting the bl_label on a non-builtin operator");
}
}
@ -1771,7 +1769,7 @@ static void rna_Operator_bl_translation_context_set(PointerRNA *ptr, const char
BLI_strncpy(str, value, RNA_DYN_DESCR_MAX); /* utf8 already ensured */
}
else {
assert(!"setting the bl_translation_context on a non-builtin operator");
BLI_assert(!"setting the bl_translation_context on a non-builtin operator");
}
}
@ -1783,7 +1781,7 @@ static void rna_Operator_bl_description_set(PointerRNA *ptr, const char *value)
BLI_strncpy(str, value, RNA_DYN_DESCR_MAX); /* utf8 already ensured */
}
else {
assert(!"setting the bl_description on a non-builtin operator");
BLI_assert(!"setting the bl_description on a non-builtin operator");
}
}
@ -1795,7 +1793,7 @@ static void rna_Operator_bl_undo_group_set(PointerRNA *ptr, const char *value)
BLI_strncpy(str, value, OP_MAX_TYPENAME); /* utf8 already ensured */
}
else {
assert(!"setting the bl_undo_group on a non-builtin operator");
BLI_assert(!"setting the bl_undo_group on a non-builtin operator");
}
}

View File

@ -45,8 +45,6 @@
#ifdef RNA_RUNTIME
# include <assert.h>
# include "BLI_string_utils.h"
# include "WM_api.h"
@ -240,7 +238,7 @@ static void rna_Gizmo_bl_idname_set(PointerRNA *ptr, const char *value)
BLI_strncpy(str, value, MAX_NAME); /* utf8 already ensured */
}
else {
assert(!"setting the bl_idname on a non-builtin operator");
BLI_assert(!"setting the bl_idname on a non-builtin operator");
}
}
@ -632,7 +630,7 @@ static void rna_GizmoGroup_bl_idname_set(PointerRNA *ptr, const char *value)
BLI_strncpy(str, value, MAX_NAME); /* utf8 already ensured */
}
else {
assert(!"setting the bl_idname on a non-builtin operator");
BLI_assert(!"setting the bl_idname on a non-builtin operator");
}
}
@ -644,7 +642,7 @@ static void rna_GizmoGroup_bl_label_set(PointerRNA *ptr, const char *value)
BLI_strncpy(str, value, MAX_NAME); /* utf8 already ensured */
}
else {
assert(!"setting the bl_label on a non-builtin operator");
BLI_assert(!"setting the bl_label on a non-builtin operator");
}
}

View File

@ -50,7 +50,6 @@
#include "MOD_modifiertypes.h"
#include "MOD_ui_common.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>

View File

@ -38,7 +38,6 @@
*/
#include "node_texture_util.h"
#include <assert.h>
bool tex_node_poll_default(bNodeType *UNUSED(ntype), bNodeTree *ntree)
{

View File

@ -546,7 +546,7 @@ int EXPP_FloatsAreEqual(float af, float bf, int maxDiff)
const int test = SIGNMASK(ai ^ bi);
int diff, v1, v2;
assert((0 == test) || (0xFFFFFFFF == test));
BLI_assert((0 == test) || (0xFFFFFFFF == test));
diff = (ai ^ (test & 0x7fffffff)) - bi;
v1 = maxDiff + diff;
v2 = maxDiff - diff;

View File

@ -23,7 +23,6 @@
* Functions for dealing with append/link operators and helpers.
*/
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>

View File

@ -24,7 +24,6 @@
* as well as some generic operators and shared operator properties.
*/
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>