Change various asserts to not be included in release builds
This commit is contained in:
@@ -118,7 +118,7 @@ class Kdtree {
|
||||
}
|
||||
|
||||
this->Build(elements.begin(), elements.end());
|
||||
assert(initial_count == this->Count());
|
||||
dbg_assert(initial_count == this->Count());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ class Kdtree {
|
||||
CoordT ec = this->xyfunc(element, dim);
|
||||
/* Which side to remove from */
|
||||
size_t next = (ec < nc) ? n.left : n.right;
|
||||
assert(next != INVALID_NODE); // node must exist somewhere and must be found before a leaf is reached
|
||||
dbg_assert(next != INVALID_NODE); // node must exist somewhere and must be found before a leaf is reached
|
||||
/* Descend */
|
||||
size_t new_branch = this->RemoveRecursive(element, next, level + 1);
|
||||
if (new_branch != next) {
|
||||
@@ -317,7 +317,7 @@ class Kdtree {
|
||||
return this->unbalanced > this->Count() / 4;
|
||||
}
|
||||
|
||||
/** Verify that the invariant is true for a sub-tree, assert if not */
|
||||
/** Verify that the invariant is true for a sub-tree, dbg_assert if not */
|
||||
void CheckInvariant(size_t node_idx, int level, CoordT min_x, CoordT max_x, CoordT min_y, CoordT max_y)
|
||||
{
|
||||
if (node_idx == INVALID_NODE) return;
|
||||
@@ -326,10 +326,10 @@ class Kdtree {
|
||||
CoordT cx = this->xyfunc(n.element, 0);
|
||||
CoordT cy = this->xyfunc(n.element, 1);
|
||||
|
||||
assert(cx >= min_x);
|
||||
assert(cx < max_x);
|
||||
assert(cy >= min_y);
|
||||
assert(cy < max_y);
|
||||
dbg_assert(cx >= min_x);
|
||||
dbg_assert(cx < max_x);
|
||||
dbg_assert(cy >= min_y);
|
||||
dbg_assert(cy < max_y);
|
||||
|
||||
if (level % 2 == 0) {
|
||||
// split in dimension 0 = x
|
||||
@@ -431,7 +431,7 @@ public:
|
||||
/** Get number of elements stored in tree */
|
||||
size_t Count() const
|
||||
{
|
||||
assert(this->free_list.size() <= this->nodes.size());
|
||||
dbg_assert(this->free_list.size() <= this->nodes.size());
|
||||
return this->nodes.size() - this->free_list.size();
|
||||
}
|
||||
|
||||
@@ -442,7 +442,7 @@ public:
|
||||
*/
|
||||
T FindNearest(CoordT x, CoordT y) const
|
||||
{
|
||||
assert(this->Count() > 0);
|
||||
dbg_assert(this->Count() > 0);
|
||||
|
||||
CoordT xy[2] = { x, y };
|
||||
return this->FindNearestRecursive(xy, this->root, 0).first;
|
||||
@@ -460,8 +460,8 @@ public:
|
||||
template <typename Outputter>
|
||||
void FindContained(CoordT x1, CoordT y1, CoordT x2, CoordT y2, const Outputter &outputter) const
|
||||
{
|
||||
assert(x1 < x2);
|
||||
assert(y1 < y2);
|
||||
dbg_assert(x1 < x2);
|
||||
dbg_assert(y1 < y2);
|
||||
|
||||
if (this->Count() == 0) return;
|
||||
|
||||
|
@@ -35,9 +35,9 @@ DEFINE_POOL_METHOD(inline)::Pool(const char *name) :
|
||||
first_free(0),
|
||||
first_unused(0),
|
||||
items(0),
|
||||
#ifdef WITH_ASSERT
|
||||
#ifdef WITH_FULL_dbg_assertS
|
||||
checked(0),
|
||||
#endif /* WITH_ASSERT */
|
||||
#endif /* WITH_FULL_dbg_assertS */
|
||||
cleaning(false),
|
||||
data(nullptr),
|
||||
free_bitmap(nullptr),
|
||||
@@ -52,8 +52,8 @@ DEFINE_POOL_METHOD(inline)::Pool(const char *name) :
|
||||
*/
|
||||
DEFINE_POOL_METHOD(inline void)::ResizeFor(size_t index)
|
||||
{
|
||||
assert(index >= this->size);
|
||||
assert(index < Tmax_size);
|
||||
dbg_assert(index >= this->size);
|
||||
dbg_assert(index < Tmax_size);
|
||||
|
||||
size_t new_size = std::min(Tmax_size, Align(index + 1, std::max<uint>(64, Tgrowth_step)));
|
||||
|
||||
@@ -88,14 +88,14 @@ DEFINE_POOL_METHOD(inline size_t)::FindFirstFree()
|
||||
return this->first_unused;
|
||||
}
|
||||
|
||||
assert(this->first_unused == this->size);
|
||||
dbg_assert(this->first_unused == this->size);
|
||||
|
||||
if (this->first_unused < Tmax_size) {
|
||||
this->ResizeFor(this->first_unused);
|
||||
return this->first_unused;
|
||||
}
|
||||
|
||||
assert(this->first_unused == Tmax_size);
|
||||
dbg_assert(this->first_unused == Tmax_size);
|
||||
|
||||
return NO_FREE_ITEM;
|
||||
}
|
||||
@@ -109,14 +109,14 @@ DEFINE_POOL_METHOD(inline size_t)::FindFirstFree()
|
||||
*/
|
||||
DEFINE_POOL_METHOD(inline void *)::AllocateItem(size_t size, size_t index)
|
||||
{
|
||||
assert(this->data[index] == nullptr);
|
||||
dbg_assert(this->data[index] == nullptr);
|
||||
|
||||
this->first_unused = std::max(this->first_unused, index + 1);
|
||||
this->items++;
|
||||
|
||||
Titem *item;
|
||||
if (Tcache && this->alloc_cache != nullptr) {
|
||||
assert(sizeof(Titem) == size);
|
||||
dbg_assert(sizeof(Titem) == size);
|
||||
item = (Titem *)this->alloc_cache;
|
||||
this->alloc_cache = this->alloc_cache->next;
|
||||
if (Tzero) {
|
||||
@@ -145,10 +145,10 @@ DEFINE_POOL_METHOD(void *)::GetNew(size_t size)
|
||||
{
|
||||
size_t index = this->FindFirstFree();
|
||||
|
||||
#ifdef WITH_ASSERT
|
||||
assert(this->checked != 0);
|
||||
#ifdef WITH_FULL_dbg_assertS
|
||||
dbg_assert(this->checked != 0);
|
||||
this->checked--;
|
||||
#endif /* WITH_ASSERT */
|
||||
#endif /* WITH_FULL_dbg_assertS */
|
||||
if (index == NO_FREE_ITEM) {
|
||||
error("%s: no more free items", this->name);
|
||||
}
|
||||
@@ -189,8 +189,8 @@ DEFINE_POOL_METHOD(void *)::GetNew(size_t size, size_t index)
|
||||
*/
|
||||
DEFINE_POOL_METHOD(void)::FreeItem(size_t index)
|
||||
{
|
||||
assert(index < this->size);
|
||||
assert(this->data[index] != nullptr);
|
||||
dbg_assert(index < this->size);
|
||||
dbg_assert(this->data[index] != nullptr);
|
||||
if (Tcache) {
|
||||
AllocCache *ac = (AllocCache *)this->data[index];
|
||||
ac->next = this->alloc_cache;
|
||||
@@ -213,7 +213,7 @@ DEFINE_POOL_METHOD(void)::CleanPool()
|
||||
for (size_t i = 0; i < this->first_unused; i++) {
|
||||
delete this->Get(i); // 'delete nullptr;' is very valid
|
||||
}
|
||||
assert(this->items == 0);
|
||||
dbg_assert(this->items == 0);
|
||||
free(this->data);
|
||||
free(this->free_bitmap);
|
||||
this->first_unused = this->first_free = this->size = 0;
|
||||
|
@@ -109,7 +109,7 @@ struct Pool : PoolBase {
|
||||
*/
|
||||
inline Titem *Get(size_t index)
|
||||
{
|
||||
assert_msg(index < this->first_unused, "index: " PRINTF_SIZE ", first_unused: " PRINTF_SIZE ", name: %s", index, this->first_unused, this->name);
|
||||
dbg_assert_msg(index < this->first_unused, "index: " PRINTF_SIZE ", first_unused: " PRINTF_SIZE ", name: %s", index, this->first_unused, this->name);
|
||||
return this->data[index];
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ struct Pool : PoolBase {
|
||||
{
|
||||
if (p == nullptr) return;
|
||||
Titem *pn = (Titem *)p;
|
||||
assert_msg(pn == Tpool->Get(pn->index), "name: %s", Tpool->name);
|
||||
dbg_assert_msg(pn == Tpool->Get(pn->index), "name: %s", Tpool->name);
|
||||
Tpool->FreeItem(pn->index);
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ struct Pool : PoolBase {
|
||||
* memory are the same (because of possible inheritance).
|
||||
* Use { size_t index = item->index; delete item; new (index) item; }
|
||||
* instead to make sure destructor is called and no memory leaks. */
|
||||
assert_msg(ptr != Tpool->data[i], "name: %s", Tpool->name);
|
||||
dbg_assert_msg(ptr != Tpool->data[i], "name: %s", Tpool->name);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
Reference in New Issue
Block a user