[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44465] trunk/blender/source/blender/bmesh : replace BMESH_ERROR with BMESH_ASSERT, most areas it was used are better suited to an assert anyway.
Campbell Barton
ideasman42 at gmail.com
Sun Feb 26 17:39:28 CET 2012
Revision: 44465
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44465
Author: campbellbarton
Date: 2012-02-26 16:39:21 +0000 (Sun, 26 Feb 2012)
Log Message:
-----------
replace BMESH_ERROR with BMESH_ASSERT, most areas it was used are better suited to an assert anyway.
also tag all error cases as UNLIKELY() for better branch prediction.
Modified Paths:
--------------
trunk/blender/source/blender/bmesh/bmesh.h
trunk/blender/source/blender/bmesh/bmesh_error.h
trunk/blender/source/blender/bmesh/intern/bmesh_mesh.c
trunk/blender/source/blender/bmesh/intern/bmesh_mods.c
trunk/blender/source/blender/bmesh/intern/bmesh_newcore.c
trunk/blender/source/blender/bmesh/intern/bmesh_structure.c
trunk/blender/source/blender/bmesh/intern/bmesh_walkers.c
trunk/blender/source/blender/bmesh/operators/bmo_subdivide.c
Modified: trunk/blender/source/blender/bmesh/bmesh.h
===================================================================
--- trunk/blender/source/blender/bmesh/bmesh.h 2012-02-26 15:38:28 UTC (rev 44464)
+++ trunk/blender/source/blender/bmesh/bmesh.h 2012-02-26 16:39:21 UTC (rev 44465)
@@ -110,9 +110,6 @@
/* #define BM_ELEM_SPARE (1<<6) */
/* #define BM_ELEM_NONORMCALC (1<<7) */ /* UNUSED */
-/* stub */
-void _bmesh_error(const char *at, const char *func);
-
/* Mesh Level Ops */
extern int bm_mesh_allocsize_default[4];
Modified: trunk/blender/source/blender/bmesh/bmesh_error.h
===================================================================
--- trunk/blender/source/blender/bmesh/bmesh_error.h 2012-02-26 15:38:28 UTC (rev 44464)
+++ trunk/blender/source/blender/bmesh/bmesh_error.h 2012-02-26 16:39:21 UTC (rev 44465)
@@ -71,6 +71,22 @@
/* BMESH_ERROR */
-#define BMESH_ERROR _bmesh_error(AT, __func__)
+
+/* _dummy_abort's defuned */
+#ifndef _dummy_abort
+# error "BLI_utildefines.h not included, '_dummy_abort' missing !"
+#endif
+
+/* this is meant to be higher level then BLI_assert(),
+ * its enabled even when in Release mode*/
+#define BMESH_ASSERT(a) \
+ (void)((!(a)) ? ( \
+ ( \
+ fprintf(stderr, \
+ "BMESH_ASSERT failed: %s, %s(), %d at \'%s\'\n", \
+ __FILE__, __func__, __LINE__, STRINGIFY(a)), \
+ _dummy_abort(), \
+ NULL)) : NULL)
+
#endif /* __BMESH_ERROR_H__ */
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_mesh.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_mesh.c 2012-02-26 15:38:28 UTC (rev 44464)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_mesh.c 2012-02-26 16:39:21 UTC (rev 44465)
@@ -50,19 +50,6 @@
/* used as an extern, defined in bmesh.h */
int bm_mesh_allocsize_default[4] = {512, 512, 2048, 512};
-/* bmesh_error stub */
-void _bmesh_error(const char *at, const char *func)
-{
- fprintf(stderr, "BM modelling error '%s', func '%s'!\n", at, func);
-
-#ifdef WITH_ASSERT_ABORT
- /* This placeholder assert makes modelling errors easier to catch
- * in the debugger, until bmesh_error is replaced with something
- * better. */
- abort();
-#endif
-}
-
static void bmesh_mempool_init(BMesh *bm, const int allocsize[4])
{
bm->vpool = BLI_mempool_create(sizeof(BMVert), allocsize[0], allocsize[0], FALSE, TRUE);
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_mods.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_mods.c 2012-02-26 15:38:28 UTC (rev 44464)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_mods.c 2012-02-26 16:39:21 UTC (rev 44465)
@@ -267,15 +267,15 @@
} while ((l1 = l1->next) != l_first);
}
- if (!jed) {
- BMESH_ERROR;
+ if (UNLIKELY(!jed)) {
+ BMESH_ASSERT(0);
return NULL;
}
l1 = jed->l;
- if (!l1) {
- BMESH_ERROR;
+ if (UNLIKELY(!l1)) {
+ BMESH_ASSERT(0);
return NULL;
}
@@ -615,8 +615,9 @@
BMLoop *l, *l2;
l = e1->l;
- if (!l) {
- BMESH_ERROR;
+
+ if (UNLIKELY(!l)) {
+ BMESH_ASSERT(0);
break;
}
@@ -646,8 +647,8 @@
BMLoop *l, *l2;
l = e1->l;
- if (!l) {
- BMESH_ERROR;
+ if (UNLIKELY(!l)) {
+ BMESH_ASSERT(0);
break;
}
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_newcore.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_newcore.c 2012-02-26 15:38:28 UTC (rev 44464)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_newcore.c 2012-02-26 16:39:21 UTC (rev 44465)
@@ -451,9 +451,7 @@
}
}
- if (err) {
- BMESH_ERROR;
- }
+ BMESH_ASSERT(err == 0);
return err;
}
@@ -791,15 +789,15 @@
int i = 0, c = 0;
do {
- if (!l2) {
- BMESH_ERROR;
+ if (UNLIKELY(!l2)) {
+ BMESH_ASSERT(0);
goto error;
}
i += BM_ELEM_API_FLAG_TEST(l2->f, flag) ? 1 : 0;
l2 = bmesh_radial_nextloop(l2);
- if (c >= BM_LOOP_RADIAL_MAX) {
- BMESH_ERROR;
+ if (UNLIKELY(c >= BM_LOOP_RADIAL_MAX)) {
+ BMESH_ASSERT(0);
goto error;
}
c++;
@@ -890,8 +888,8 @@
const char *err = NULL;
int i, tote = 0;
- if (!totface) {
- BMESH_ERROR;
+ if (UNLIKELY(!totface)) {
+ BMESH_ASSERT(0);
return NULL;
}
@@ -1288,11 +1286,11 @@
/* verify disk cycle */
edok = bmesh_disk_validate(valence1, ov->e, ov);
- if (!edok) BMESH_ERROR;
+ BMESH_ASSERT(edok != FALSE);
edok = bmesh_disk_validate(valence2, tv->e, tv);
- if (!edok) BMESH_ERROR;
+ BMESH_ASSERT(edok != FALSE);
edok = bmesh_disk_validate(2, nv->e, nv);
- if (!edok) BMESH_ERROR;
+ BMESH_ASSERT(edok != FALSE);
/* Split the radial cycle if presen */
nextl = e->l;
@@ -1358,21 +1356,20 @@
/* verify length of radial cycl */
edok = bmesh_radial_validate(radlen, e->l);
- if (!edok) BMESH_ERROR;
+ BMESH_ASSERT(edok != FALSE);
edok = bmesh_radial_validate(radlen, ne->l);
- if (!edok) BMESH_ERROR;
+ BMESH_ASSERT(edok != FALSE);
/* verify loop->v and loop->next->v pointers for */
for (i = 0, l = e->l; i < radlen; i++, l = l->radial_next) {
- if (!(l->e == e)) BMESH_ERROR;
- //if (!(l->radial_next == l)) BMESH_ERROR;
- if (l->prev->e != ne && l->next->e != ne) {
- BMESH_ERROR;
- }
+ BMESH_ASSERT(l->e == e);
+ //BMESH_ASSERT(l->radial_next == l);
+ BMESH_ASSERT(!(l->prev->e != ne && l->next->e != ne));
+
edok = bmesh_verts_in_edge(l->v, l->next->v, e);
- if (!edok) BMESH_ERROR;
- if (l->v == l->next->v) BMESH_ERROR;
- if (l->e == l->next->e) BMESH_ERROR;
+ BMESH_ASSERT(edok != FALSE);
+ BMESH_ASSERT(l->v != l->next->v);
+ BMESH_ASSERT(l->e != l->next->e);
/* verify loop cycle for kloop-> */
BM_CHECK_ELEMENT(bm, l);
@@ -1382,13 +1379,13 @@
}
/* verify loop->v and loop->next->v pointers for n */
for (i = 0, l = ne->l; i < radlen; i++, l = l->radial_next) {
- if (!(l->e == ne)) BMESH_ERROR;
- //if (!(l->radial_next == l)) BMESH_ERROR;
- if (l->prev->e != e && l->next->e != e) BMESH_ERROR;
+ BMESH_ASSERT(l->e == ne);
+ // BMESH_ASSERT(l->radial_next == l);
+ BMESH_ASSERT(!(l->prev->e != e && l->next->e != e));
edok = bmesh_verts_in_edge(l->v, l->next->v, ne);
- if (!edok) BMESH_ERROR;
- if (l->v == l->next->v) BMESH_ERROR;
- if (l->e == l->next->e) BMESH_ERROR;
+ BMESH_ASSERT(edok != FALSE);
+ BMESH_ASSERT(l->v != l->next->v);
+ BMESH_ASSERT(l->e != l->next->e);
BM_CHECK_ELEMENT(bm, l);
BM_CHECK_ELEMENT(bm, l->v);
@@ -1524,9 +1521,7 @@
/* Validate radial cycle of o */
edok = bmesh_radial_validate(radlen, oe->l);
- if (!edok) {
- BMESH_ERROR;
- }
+ BMESH_ASSERT(edok != FALSE);
}
/* deallocate edg */
@@ -1537,17 +1532,17 @@
/* Validate disk cycle lengths of ov, tv are unchange */
edok = bmesh_disk_validate(valence1, ov->e, ov);
- if (!edok) BMESH_ERROR;
+ BMESH_ASSERT(edok != FALSE);
edok = bmesh_disk_validate(valence2, tv->e, tv);
- if (!edok) BMESH_ERROR;
+ BMESH_ASSERT(edok != FALSE);
/* Validate loop cycle of all faces attached to o */
for (i = 0, l = oe->l; i < radlen; i++, l = bmesh_radial_nextloop(l)) {
- if (l->e != oe) BMESH_ERROR;
+ BMESH_ASSERT(l->e == oe);
edok = bmesh_verts_in_edge(l->v, l->next->v, oe);
- if (!edok) BMESH_ERROR;
+ BMESH_ASSERT(edok != FALSE);
edok = bmesh_loop_validate(l->f);
- if (!edok) BMESH_ERROR;
+ BMESH_ASSERT(edok != FALSE);
BM_CHECK_ELEMENT(bm, l);
BM_CHECK_ELEMENT(bm, l->v);
@@ -1723,7 +1718,7 @@
/* validate the new loop cycle */
edok = bmesh_loop_validate(f1);
- if (!edok) BMESH_ERROR;
+ BMESH_ASSERT(edok != FALSE);
return f1;
}
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_structure.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_structure.c 2012-02-26 15:38:28 UTC (rev 44464)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_structure.c 2012-02-26 16:39:21 UTC (rev 44465)
@@ -34,6 +34,8 @@
#include "bmesh.h"
#include "bmesh_private.h"
+#include <stdlib.h>
+
/**
* MISC utility functions.
*
@@ -365,8 +367,8 @@
return FALSE;
do {
- if (!l_iter) {
- BMESH_ERROR;
+ if (UNLIKELY(!l_iter)) {
+ BMESH_ASSERT(0);
return FALSE;
}
@@ -375,8 +377,8 @@
if (l_iter->v != l->e->v1 && l_iter->v != l->e->v2)
return FALSE;
- if (i > BM_LOOP_RADIAL_MAX) {
- BMESH_ERROR;
+ if (UNLIKELY(i > BM_LOOP_RADIAL_MAX)) {
+ BMESH_ASSERT(0);
return FALSE;
}
@@ -397,8 +399,8 @@
void bmesh_radial_remove_loop(BMLoop *l, BMEdge *e)
{
/* if e is non-NULL, l must be in the radial cycle of e */
- if (e && e != l->e) {
- BMESH_ERROR;
+ if (UNLIKELY(e && e != l->e)) {
+ BMESH_ASSERT(0);
}
if (l->radial_next != l) {
@@ -414,7 +416,7 @@
e->l = NULL;
}
else {
- BMESH_ERROR;
+ BMESH_ASSERT(0);
}
}
}
@@ -470,15 +472,15 @@
return 0;
do {
- if (!l_iter) {
+ if (UNLIKELY(!l_iter)) {
/* radial cycle is broken (not a circulat loop) */
- BMESH_ERROR;
+ BMESH_ASSERT(0);
return 0;
}
i++;
- if (i >= BM_LOOP_RADIAL_MAX) {
- BMESH_ERROR;
+ if (UNLIKELY(i >= BM_LOOP_RADIAL_MAX)) {
+ BMESH_ASSERT(0);
return -1;
}
} while ((l_iter = l_iter->radial_next) != l);
@@ -502,9 +504,9 @@
e->l = l;
}
- if (l->e && l->e != e) {
+ if (UNLIKELY(l->e && l->e != e)) {
/* l is already in a radial cycle for a different edge */
- BMESH_ERROR;
+ BMESH_ASSERT(0);
}
l->e = e;
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_walkers.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_walkers.c 2012-02-26 15:38:28 UTC (rev 44464)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_walkers.c 2012-02-26 16:39:21 UTC (rev 44465)
@@ -88,12 +88,12 @@
walker->visithash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "bmesh walkers 1");
- if (type >= BMW_MAXWALKERS || type < 0) {
- BMESH_ERROR;
+ if (UNLIKELY(type >= BMW_MAXWALKERS || type < 0)) {
fprintf(stderr,
"Invalid walker type in BMW_init; type: %d, "
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list