replace BMESH_ERROR with BMESH_ASSERT, most areas it was used are better suited to...
authorCampbell Barton <ideasman42@gmail.com>
Sun, 26 Feb 2012 16:39:21 +0000 (16:39 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 26 Feb 2012 16:39:21 +0000 (16:39 +0000)
also tag all error cases as UNLIKELY() for better branch prediction.

source/blender/bmesh/bmesh.h
source/blender/bmesh/bmesh_error.h
source/blender/bmesh/intern/bmesh_mesh.c
source/blender/bmesh/intern/bmesh_mods.c
source/blender/bmesh/intern/bmesh_newcore.c
source/blender/bmesh/intern/bmesh_structure.c
source/blender/bmesh/intern/bmesh_walkers.c
source/blender/bmesh/operators/bmo_subdivide.c

index 6ea864fe9e3d97f41c3a0c04e0256e76fdcae60d..61f4cc62ae4ad9032f338028684cccb8583938d5 100644 (file)
@@ -110,9 +110,6 @@ struct EditMesh;
 /* #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];
 
index 2e96599c957af6cdba99d1a94ade52c5c091d860..79ca9f61b949afbc72728ff6336c5aca35721991 100644 (file)
@@ -71,6 +71,22 @@ int BMO_error_catch_op(BMesh *bm, BMOperator *catchop, int errorcode, char **msg
 
 
 /* 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__ */
index 7d8e55347f5b1a12447f71ad712ed6a7b8f3fba4..a1f95739f49357c2765e89984162150fe16249ab 100644 (file)
 /* 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);
index 2816c3e491089b6099f32c16500a46b5af5ff985..bb9ad533308d45a7c00f208f8dfc00c23c555aa4 100644 (file)
@@ -267,15 +267,15 @@ BMFace *BM_faces_join_pair(BMesh *bm, BMFace *f1, BMFace *f2, BMEdge *e)
                } 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 @@ BMVert *BM_edge_split(BMesh *bm, BMEdge *e, BMVert *v, BMEdge **ne, float percen
                                BMLoop *l, *l2;
                                
                                l = e1->l;
-                               if (!l) {
-                                       BMESH_ERROR;
+
+                               if (UNLIKELY(!l)) {
+                                       BMESH_ASSERT(0);
                                        break;
                                }
                                
@@ -646,8 +647,8 @@ BMVert *BM_edge_split(BMesh *bm, BMEdge *e, BMVert *v, BMEdge **ne, float percen
                        BMLoop *l, *l2;
                        
                        l = e1->l;
-                       if (!l) {
-                               BMESH_ERROR;
+                       if (UNLIKELY(!l)) {
+                               BMESH_ASSERT(0);
                                break;
                        }
                        
index dbb44f2cbc3be57857172f0643dcfb7875754e8b..980066fad2589a1e5c7d59371de147778a3224e1 100644 (file)
@@ -451,9 +451,7 @@ int bmesh_check_element(BMesh *UNUSED(bm), void *element, const char htype)
                }
        }
 
-       if (err) {
-               BMESH_ERROR;
-       }
+       BMESH_ASSERT(err == 0);
 
        return err;
 }
@@ -791,15 +789,15 @@ static int count_flagged_radial(BMesh *bm, BMLoop *l, int flag)
        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 @@ BMFace *BM_faces_join(BMesh *bm, BMFace **faces, int totface)
        const char *err = NULL;
        int i, tote = 0;
 
-       if (!totface) {
-               BMESH_ERROR;
+       if (UNLIKELY(!totface)) {
+               BMESH_ASSERT(0);
                return NULL;
        }
 
@@ -1288,11 +1286,11 @@ BMVert *bmesh_semv(BMesh *bm, BMVert *tv, BMEdge *e, BMEdge **re)
 
        /* 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 @@ BMVert *bmesh_semv(BMesh *bm, BMVert *tv, BMEdge *e, BMEdge **re)
 
                /* 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 @@ BMVert *bmesh_semv(BMesh *bm, BMVert *tv, BMEdge *e, BMEdge **re)
                }
                /* 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 @@ struct BMEdge *bmesh_jekv(BMesh *bm, BMEdge *ke, BMVert *kv, const short check_e
 
                                /* 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 @@ struct BMEdge *bmesh_jekv(BMesh *bm, BMEdge *ke, BMVert *kv, const short check_e
 
                        /* 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 @@ BMFace *bmesh_jfke(BMesh *bm, BMFace *f1, BMFace *f2, BMEdge *e)
 
        /* validate the new loop cycle */
        edok = bmesh_loop_validate(f1);
-       if (!edok) BMESH_ERROR;
+       BMESH_ASSERT(edok != FALSE);
        
        return f1;
 }
index a90208540b9857dc3975e8dc7d847e73aff7c496..509cfbaae61231d2dcc7c5a6de1dbc55d641f2a8 100644 (file)
@@ -34,6 +34,8 @@
 #include "bmesh.h"
 #include "bmesh_private.h"
 
+#include <stdlib.h>
+
 /**
  *     MISC utility functions.
  *
@@ -365,8 +367,8 @@ int bmesh_radial_validate(int radlen, BMLoop *l)
                return FALSE;
 
        do {
-               if (!l_iter) {
-                       BMESH_ERROR;
+               if (UNLIKELY(!l_iter)) {
+                       BMESH_ASSERT(0);
                        return FALSE;
                }
                
@@ -375,8 +377,8 @@ int bmesh_radial_validate(int radlen, BMLoop *l)
                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 @@ int bmesh_radial_validate(int radlen, BMLoop *l)
 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 @@ void bmesh_radial_remove_loop(BMLoop *l, BMEdge *e)
                                e->l = NULL;
                        }
                        else {
-                               BMESH_ERROR;
+                               BMESH_ASSERT(0);
                        }
                }
        }
@@ -470,15 +472,15 @@ int bmesh_radial_length(BMLoop *l)
                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 @@ void bmesh_radial_append(BMEdge *e, BMLoop *l)
                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;
index 4fe54bfaa01d7869019f483db7bfa866aa64dab4..d9163360717fa89c549543233e05a9cfd7b217e6 100644 (file)
@@ -88,12 +88,12 @@ void BMW_init(BMWalker *walker, BMesh *bm, int type,
 
        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, "
                        "searchmask: (v:%d, e:%d, l:%d, f:%d), flag: %d\n",
                        type, mask_vert, mask_edge, mask_loop, mask_face, layer);
+               BMESH_ASSERT(0);
        }
        
        if (type != BMW_CUSTOM) {
index 9a8f26ddeeb6aae29d808a5eeda38e2655a5d2d6..7d90a6b71cae53cb959f8159024d71650a2a0aa9 100644 (file)
@@ -494,9 +494,8 @@ static void quad_4edge_subdivide(BMesh *bm, BMFace *UNUSED(face), BMVert **verts
                for (a = 0; a < numcuts; a++) {
                        v = subdivideedgenum(bm, e, &temp, a, numcuts, params, &ne,
                                             v1, v2);
-                       if (!v) {
-                               BMESH_ERROR;
-                       }
+
+                       BMESH_ASSERT(v != NULL);
 
                        BMO_elem_flag_enable(bm, ne, ELE_INNER);
                        lines[(i + 1) * s + a + 1] = v;