diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-02-26 20:39:21 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-02-26 20:39:21 +0400 |
commit | 03f5758b48457b5d76239d78f3f374195d1104ab (patch) | |
tree | e245eb650e3794bf08e55dac38a3fb14a1ef8d51 /source | |
parent | 5970adaccfe4bd1faf24dd88fdba3e0801af792a (diff) |
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.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/bmesh/bmesh.h | 3 | ||||
-rw-r--r-- | source/blender/bmesh/bmesh_error.h | 18 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh.c | 13 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mods.c | 17 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_newcore.c | 69 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_structure.c | 28 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_walkers.c | 4 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_subdivide.c | 5 |
8 files changed, 77 insertions, 80 deletions
diff --git a/source/blender/bmesh/bmesh.h b/source/blender/bmesh/bmesh.h index 6ea864fe9e3..61f4cc62ae4 100644 --- a/source/blender/bmesh/bmesh.h +++ b/source/blender/bmesh/bmesh.h @@ -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]; diff --git a/source/blender/bmesh/bmesh_error.h b/source/blender/bmesh/bmesh_error.h index 2e96599c957..79ca9f61b94 100644 --- a/source/blender/bmesh/bmesh_error.h +++ b/source/blender/bmesh/bmesh_error.h @@ -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__ */ diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c index 7d8e55347f5..a1f95739f49 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.c +++ b/source/blender/bmesh/intern/bmesh_mesh.c @@ -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); diff --git a/source/blender/bmesh/intern/bmesh_mods.c b/source/blender/bmesh/intern/bmesh_mods.c index 2816c3e4910..bb9ad533308 100644 --- a/source/blender/bmesh/intern/bmesh_mods.c +++ b/source/blender/bmesh/intern/bmesh_mods.c @@ -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; } diff --git a/source/blender/bmesh/intern/bmesh_newcore.c b/source/blender/bmesh/intern/bmesh_newcore.c index dbb44f2cbc3..980066fad25 100644 --- a/source/blender/bmesh/intern/bmesh_newcore.c +++ b/source/blender/bmesh/intern/bmesh_newcore.c @@ -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; } diff --git a/source/blender/bmesh/intern/bmesh_structure.c b/source/blender/bmesh/intern/bmesh_structure.c index a90208540b9..509cfbaae61 100644 --- a/source/blender/bmesh/intern/bmesh_structure.c +++ b/source/blender/bmesh/intern/bmesh_structure.c @@ -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; diff --git a/source/blender/bmesh/intern/bmesh_walkers.c b/source/blender/bmesh/intern/bmesh_walkers.c index 4fe54bfaa01..d9163360717 100644 --- a/source/blender/bmesh/intern/bmesh_walkers.c +++ b/source/blender/bmesh/intern/bmesh_walkers.c @@ -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) { diff --git a/source/blender/bmesh/operators/bmo_subdivide.c b/source/blender/bmesh/operators/bmo_subdivide.c index 9a8f26ddeeb..7d90a6b71ca 100644 --- a/source/blender/bmesh/operators/bmo_subdivide.c +++ b/source/blender/bmesh/operators/bmo_subdivide.c @@ -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; |