[Bf-blender-cvs] [0bae2662f45] master: Cleanup: Remove/replace C standard library assert() and header usages

Julian Eisel noreply at git.blender.org
Sat Oct 3 16:10:57 CEST 2020


Commit: 0bae2662f455c2866ce769fdc73b3068f8239bd0
Author: Julian Eisel
Date:   Sat Oct 3 16:01:59 2020 +0200
Branches: master
https://developer.blender.org/rB0bae2662f455c2866ce769fdc73b3068f8239bd0

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.

===================================================================

M	source/blender/blenkernel/intern/bpath.c
M	source/blender/blenkernel/intern/bvhutils.c
M	source/blender/blenkernel/intern/editmesh_tangent.c
M	source/blender/blenkernel/intern/lib_id.c
M	source/blender/blenkernel/intern/pbvh_bmesh.c
M	source/blender/blenkernel/intern/shrinkwrap.c
M	source/blender/blenkernel/intern/unit.c
M	source/blender/blenkernel/intern/volume.cc
M	source/blender/blenlib/intern/BLI_kdopbvh.c
M	source/blender/blenlib/intern/buffer.c
M	source/blender/blenlib/intern/math_color.c
M	source/blender/blenlib/intern/math_matrix.c
M	source/blender/blenlib/intern/math_rotation.c
M	source/blender/blenlib/intern/path_util.c
M	source/blender/bmesh/bmesh.h
M	source/blender/bmesh/bmesh_class.h
M	source/blender/editors/armature/armature_edit.c
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_layout.c
M	source/blender/editors/interface/interface_region_color_picker.c
M	source/blender/editors/interface/interface_region_menu_pie.c
M	source/blender/editors/interface/interface_region_menu_popup.c
M	source/blender/editors/interface/interface_region_popup.c
M	source/blender/editors/interface/interface_region_search.c
M	source/blender/editors/interface/interface_region_tooltip.c
M	source/blender/editors/interface/interface_utils.c
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/object/object_vgroup.c
M	source/blender/editors/physics/particle_edit.c
M	source/blender/editors/physics/particle_edit_undo.c
M	source/blender/editors/sculpt_paint/paint_hide.c
M	source/blender/editors/space_view3d/view3d_select.c
M	source/blender/makesdna/intern/makesdna.c
M	source/blender/makesrna/intern/rna_brush.c
M	source/blender/makesrna/intern/rna_ui.c
M	source/blender/makesrna/intern/rna_wm.c
M	source/blender/makesrna/intern/rna_wm_gizmo.c
M	source/blender/modifiers/intern/MOD_remesh.c
M	source/blender/nodes/texture/node_texture_util.c
M	source/blender/python/mathutils/mathutils.c
M	source/blender/windowmanager/intern/wm_files_link.c
M	source/blender/windowmanager/intern/wm_operators.c

===================================================================

diff --git a/source/blender/blenkernel/intern/bpath.c b/source/blender/blenkernel/intern/bpath.c
index 4ab8ea5a647..4ea9a26f0f8 100644
--- a/source/blender/blenkernel/intern/bpath.c
+++ b/source/blender/blenkernel/intern/bpath.c
@@ -27,7 +27,6 @@
 
 #include <sys/stat.h>
 
-#include <assert.h>
 #include <string.h>
 
 /* path/file handling stuff */
diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c
index 7440cc1f735..fd5cb33f02d 100644
--- a/source/blender/blenkernel/intern/bvhutils.c
+++ b/source/blender/blenkernel/intern/bvhutils.c
@@ -21,7 +21,6 @@
  * \ingroup bke
  */
 
-#include <assert.h>
 #include <math.h>
 #include <stdio.h>
 #include <string.h>
diff --git a/source/blender/blenkernel/intern/editmesh_tangent.c b/source/blender/blenkernel/intern/editmesh_tangent.c
index 897fc7e692b..b3f6b543daf 100644
--- a/source/blender/blenkernel/intern/editmesh_tangent.c
+++ b/source/blender/blenkernel/intern/editmesh_tangent.c
@@ -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;
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index f8f171bd9d7..675e3956102 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -24,7 +24,6 @@
  * allocate and free of all library data
  */
 
-#include <assert.h>
 #include <ctype.h>
 #include <stddef.h>
 #include <stdio.h>
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index a04fa1506d0..d31b0d54784 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -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
diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c
index 0ff5bdda9e9..9240851c07a 100644
--- a/source/blender/blenkernel/intern/shrinkwrap.c
+++ b/source/blender/blenkernel/intern/shrinkwrap.c
@@ -21,7 +21,6 @@
  * \ingroup bke
  */
 
-#include <assert.h>
 #include <float.h>
 #include <math.h>
 #include <memory.h>
diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c
index bfa031f0d64..a5418b8b8c5 100644
--- a/source/blender/blenkernel/intern/unit.c
+++ b/source/blender/blenkernel/intern/unit.c
@@ -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? */
 }
 
diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc
index 6394cfe39a6..79ed3d3d08d 100644
--- a/source/blender/blenkernel/intern/volume.cc
+++ b/source/blender/blenkernel/intern/volume.cc
@@ -154,7 +154,7 @@ static struct VolumeFileCache {
 
   ~VolumeFileCache()
   {
-    assert(cache.empty());
+    BLI_assert(cache.empty());
   }
 
   Entry *add_metadata_user(const Entry &template_entry)
diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c
index 73f8c2717b0..f126c5a977b 100644
--- a/source/blender/blenlib/intern/BLI_kdopbvh.c
+++ b/source/blender/blenlib/intern/BLI_kdopbvh.c
@@ -38,8 +38,6 @@
  *   #BLI_bvhtree_range_query
  */
 
-#include <assert.h>
-
 #include "MEM_guardedalloc.h"
 
 #include "BLI_alloca.h"
diff --git a/source/blender/blenlib/intern/buffer.c b/source/blender/blenlib/intern/buffer.c
index fb4350501cd..bac4786a2e9 100644
--- a/source/blender/blenlib/intern/buffer.c
+++ b/source/blender/blenlib/intern/buffer.c
@@ -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
diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c
index 4b62d6b9b5b..132aeb3ace2 100644
--- a/source/blender/blenlib/intern/math_color.c
+++ b/source/blender/blenlib/intern/math_color.c
@@ -24,8 +24,6 @@
  * \ingroup bli
  */
 
-#include <assert.h>
-
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
 
diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c
index 19bb6a2efba..656f37c9f18 100644
--- a/source/blender/blenlib/intern/math_matrix.c
+++ b/source/blender/blenlib/intern/math_matrix.c
@@ -24,7 +24,6 @@
  */
 
 #include "BLI_math.h"
-#include <assert.h>
 
 #include "BLI_strict_flags.h"
 
diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c
index 7c4ac934695..c7cd1901164 100644
--- a/source/blender/blenlib/intern/math_rotation.c
+++ b/source/blender/blenlib/intern/math_rotation.c
@@ -24,7 +24,6 @@
  */
 
 #include "BLI_math.h"
-#include <assert.h>
 
 #include "BLI_strict_flags.h"
 
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 6328c887063..d4f0467b31b 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -22,7 +22,6 @@
  * \ingroup bli
  */
 
-#include <assert.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/source/blender/bmesh/bmesh.h b/source/blender/bmesh/bmesh.h
index 9199801d1a1..22f7d50c144 100644
--- a/source/blender/bmesh/bmesh.h
+++ b/source/blender/bmesh/bmesh.h
@@ -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>
 
diff --git a/source/blender/bmesh/bmesh_class.h b/source/blender/bmesh/bmesh_class.h
index edb355993c1..0783bb445a2 100644
--- a/source/blender/bmesh/bmesh_class.h
+++ b/source/blender/bmesh/bmesh_class.h
@@ -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*/
 
diff --git a/source/blender/editors/armature/armature_edit.c b/source/blender/editors/armature/armature_edit.c
index dc7bad7acf6..b20d2738bda 100644
--- a/source/blender/editors/armature/armature_edit.c
+++ b/source/blender/editors/armature/armature_edit.c


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list