From 4f8959c6953e2cb24243b38485d7bb6d8b3d4e1b Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Thu, 23 Aug 2018 11:16:52 -0400 Subject: [PATCH] include: Use ceph_assert for asserts Signed-off-by: Adam C. Emerson --- src/include/CompatSet.h | 6 +- src/include/Context.h | 16 ++--- src/include/buffer.h | 14 ++++- src/include/compact_map.h | 2 +- src/include/compact_set.h | 2 +- src/include/cpp-btree/btree.h | 107 +++++++++++++++++----------------- src/include/denc.h | 2 +- src/include/elist.h | 26 ++++----- src/include/encoding.h | 2 +- src/include/filepath.h | 4 +- src/include/frag.h | 28 ++++----- src/include/interval_set.h | 42 ++++++------- src/include/lru.h | 22 +++---- src/include/mempool.h | 4 +- src/include/on_exit.h | 6 +- src/include/rangeset.h | 14 ++--- src/include/util.h | 2 +- src/include/xlist.h | 39 +++++++------ 18 files changed, 176 insertions(+), 162 deletions(-) diff --git a/src/include/CompatSet.h b/src/include/CompatSet.h index 47f86a4e722f7..a9e15f76f5df7 100644 --- a/src/include/CompatSet.h +++ b/src/include/CompatSet.h @@ -46,8 +46,8 @@ struct CompatSet { friend std::ostream& operator<<(std::ostream& out, const CompatSet& compat); FeatureSet() : mask(1), names() {} void insert(const Feature& f) { - assert(f.id > 0); - assert(f.id < 64); + ceph_assert(f.id > 0); + ceph_assert(f.id < 64); mask |= ((uint64_t)1<::const_iterator i = names.find(f); - assert(i != names.end()); + ceph_assert(i != names.end()); return i->second; } diff --git a/src/include/Context.h b/src/include/Context.h index 4cd77850cb677..b5e582702f602 100644 --- a/src/include/Context.h +++ b/src/include/Context.h @@ -276,7 +276,7 @@ private: void sub_finish(ContextType* sub, int r) { lock.Lock(); #ifdef DEBUG_GATHER - assert(waitfor.count(sub)); + ceph_assert(waitfor.count(sub)); waitfor.erase(sub); #endif --sub_existing_count; @@ -338,12 +338,12 @@ public: } void set_finisher(ContextType *onfinish_) { Mutex::Locker l(lock); - assert(!onfinish); + ceph_assert(!onfinish); onfinish = onfinish_; } void activate() { lock.Lock(); - assert(activated == false); + ceph_assert(activated == false); activated = true; if (sub_existing_count != 0) { lock.Unlock(); @@ -354,7 +354,7 @@ public: } ContextType *new_sub() { Mutex::Locker l(lock); - assert(activated == false); + ceph_assert(activated == false); sub_created_count++; sub_existing_count++; ContextType *s = new C_GatherSub(this); @@ -425,7 +425,7 @@ public: } ~C_GatherBuilderBase() { if (c_gather) { - assert(activated); // Don't forget to activate your C_Gather! + ceph_assert(activated); // Don't forget to activate your C_Gather! } else { delete finisher; @@ -440,7 +440,7 @@ public: void activate() { if (!c_gather) return; - assert(finisher != NULL); + ceph_assert(finisher != NULL); activated = true; c_gather->activate(); } @@ -456,13 +456,13 @@ public: return (c_gather != NULL); } int num_subs_created() { - assert(!activated); + ceph_assert(!activated); if (c_gather == NULL) return 0; return c_gather->get_sub_created_count(); } int num_subs_remaining() { - assert(!activated); + ceph_assert(!activated); if (c_gather == NULL) return 0; return c_gather->get_sub_existing_count(); diff --git a/src/include/buffer.h b/src/include/buffer.h index fec3a2aeeeea0..c35f262a9abb6 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -345,11 +345,19 @@ namespace buffer CEPH_BUFFER_API { // modifiers void set_offset(unsigned o) { +#ifdef __CEPH__ + ceph_assert(raw_length() >= o); +#else assert(raw_length() >= o); +#endif _off = o; } void set_length(unsigned l) { +#ifdef __CEPH__ + ceph_assert(raw_length() >= l); +#else assert(raw_length() >= l); +#endif _len = l; } @@ -749,7 +757,11 @@ namespace buffer CEPH_BUFFER_API { it++) { len += (*it).length(); } +#ifdef __CEPH__ + ceph_assert(len == _len); +#else assert(len == _len); +#endif // __CEPH__ #endif return _len; } @@ -927,7 +939,7 @@ namespace buffer CEPH_BUFFER_API { int write_fd_zero_copy(int fd) const; template void prepare_iov(VectorT *piov) const { - assert(_buffers.size() <= IOV_MAX); + ceph_assert(_buffers.size() <= IOV_MAX); piov->resize(_buffers.size()); unsigned n = 0; for (auto& p : _buffers) { diff --git a/src/include/compact_map.h b/src/include/compact_map.h index 39a9ab4f40c76..3ccb798227d92 100644 --- a/src/include/compact_map.h +++ b/src/include/compact_map.h @@ -183,7 +183,7 @@ public: } iterator erase (iterator p) { if (map) { - assert(this == p.map); + ceph_assert(this == p.map); auto it = map->erase(p.it); if (map->empty()) { free_internal(); diff --git a/src/include/compact_set.h b/src/include/compact_set.h index 10510a8e3435b..ba743fb0e1cd0 100644 --- a/src/include/compact_set.h +++ b/src/include/compact_set.h @@ -142,7 +142,7 @@ public: } iterator erase (iterator p) { if (set) { - assert(this == p.set); + ceph_assert(this == p.set); auto it = set->erase(p.it); if (set->empty()) { free_internal(); diff --git a/src/include/cpp-btree/btree.h b/src/include/cpp-btree/btree.h index 48635159dc0ba..22872b6ba30e7 100644 --- a/src/include/cpp-btree/btree.h +++ b/src/include/cpp-btree/btree.h @@ -100,7 +100,6 @@ #ifndef UTIL_BTREE_BTREE_H__ #define UTIL_BTREE_BTREE_H__ -#include #include #include #include @@ -115,6 +114,8 @@ #include #include +#include "include/assert.h" + namespace btree { // Inside a btree method, if we just call swap(), it will choose the @@ -533,7 +534,7 @@ class btree_node { // be a leaf. bool is_root() const { return parent()->leaf(); } void make_root() { - assert(parent()->is_root()); + ceph_assert(parent()->is_root()); fields_.parent = fields_.parent->parent(); } @@ -1263,7 +1264,7 @@ class btree : public Params::key_compare { } void delete_internal_node(node_type *node) { node->destroy(); - assert(node != root()); + ceph_assert(node != root()); mutable_internal_allocator()->deallocate( reinterpret_cast(node), sizeof(internal_fields)); } @@ -1419,7 +1420,7 @@ class btree : public Params::key_compare { // btree_node methods template inline void btree_node

::insert_value(int i, const value_type &x) { - assert(i <= count()); + ceph_assert(i <= count()); value_init(count(), x); for (int j = count(); j > i; --j) { value_swap(j, this, j - 1); @@ -1439,7 +1440,7 @@ inline void btree_node

::insert_value(int i, const value_type &x) { template inline void btree_node

::remove_value(int i) { if (!leaf()) { - assert(child(i + 1)->count() == 0); + ceph_assert(child(i + 1)->count() == 0); for (int j = i + 1; j < count(); ++j) { *mutable_child(j) = child(j + 1); child(j)->set_position(j); @@ -1456,11 +1457,11 @@ inline void btree_node

::remove_value(int i) { template void btree_node

::rebalance_right_to_left(btree_node *src, int to_move) { - assert(parent() == src->parent()); - assert(position() + 1 == src->position()); - assert(src->count() >= count()); - assert(to_move >= 1); - assert(to_move <= src->count()); + ceph_assert(parent() == src->parent()); + ceph_assert(position() + 1 == src->position()); + ceph_assert(src->count() >= count()); + ceph_assert(to_move >= 1); + ceph_assert(to_move <= src->count()); // Make room in the left node for the new values. for (int i = 0; i < to_move; ++i) { @@ -1490,7 +1491,7 @@ void btree_node

::rebalance_right_to_left(btree_node *src, int to_move) { set_child(1 + count() + i, src->child(i)); } for (int i = 0; i <= src->count() - to_move; ++i) { - assert(i + to_move <= src->max_count()); + ceph_assert(i + to_move <= src->max_count()); src->set_child(i, src->child(i + to_move)); *src->mutable_child(i + to_move) = NULL; } @@ -1503,11 +1504,11 @@ void btree_node

::rebalance_right_to_left(btree_node *src, int to_move) { template void btree_node

::rebalance_left_to_right(btree_node *dest, int to_move) { - assert(parent() == dest->parent()); - assert(position() + 1 == dest->position()); - assert(count() >= dest->count()); - assert(to_move >= 1); - assert(to_move <= count()); + ceph_assert(parent() == dest->parent()); + ceph_assert(position() + 1 == dest->position()); + ceph_assert(count() >= dest->count()); + ceph_assert(to_move >= 1); + ceph_assert(to_move <= count()); // Make room in the right node for the new values. for (int i = 0; i < to_move; ++i) { @@ -1548,7 +1549,7 @@ void btree_node

::rebalance_left_to_right(btree_node *dest, int to_move) { template void btree_node

::split(btree_node *dest, int insert_position) { - assert(dest->count() == 0); + ceph_assert(dest->count() == 0); // We bias the split based on the position being inserted. If we're // inserting at the beginning of the left node then bias the split to put @@ -1562,7 +1563,7 @@ void btree_node

::split(btree_node *dest, int insert_position) { dest->set_count(count() / 2); } set_count(count() - dest->count()); - assert(count() >= 1); + ceph_assert(count() >= 1); // Move values from the left sibling to the right sibling. for (int i = 0; i < dest->count(); ++i) { @@ -1580,7 +1581,7 @@ void btree_node

::split(btree_node *dest, int insert_position) { if (!leaf()) { for (int i = 0; i <= dest->count(); ++i) { - assert(child(count() + i + 1) != NULL); + ceph_assert(child(count() + i + 1) != NULL); dest->set_child(i, child(count() + i + 1)); *mutable_child(count() + i + 1) = NULL; } @@ -1589,8 +1590,8 @@ void btree_node

::split(btree_node *dest, int insert_position) { template void btree_node

::merge(btree_node *src) { - assert(parent() == src->parent()); - assert(position() + 1 == src->position()); + ceph_assert(parent() == src->parent()); + ceph_assert(position() + 1 == src->position()); // Move the delimiting value to the left node. value_init(count()); @@ -1621,7 +1622,7 @@ void btree_node

::merge(btree_node *src) { template void btree_node

::swap(btree_node *x) { - assert(leaf() == x->leaf()); + ceph_assert(leaf() == x->leaf()); // Swap the values. for (int i = count(); i < x->count(); ++i) { @@ -1663,10 +1664,10 @@ void btree_node

::swap(btree_node *x) { template void btree_iterator::increment_slow() { if (node->leaf()) { - assert(position >= node->count()); + ceph_assert(position >= node->count()); self_type save(*this); while (position == node->count() && !node->is_root()) { - assert(node->parent()->child(node->position()) == node); + ceph_assert(node->parent()->child(node->position()) == node); position = node->position(); node = node->parent(); } @@ -1674,7 +1675,7 @@ void btree_iterator::increment_slow() { *this = save; } } else { - assert(position < node->count()); + ceph_assert(position < node->count()); node = node->child(position + 1); while (!node->leaf()) { node = node->child(0); @@ -1703,10 +1704,10 @@ void btree_iterator::increment_by(int count) { template void btree_iterator::decrement_slow() { if (node->leaf()) { - assert(position <= -1); + ceph_assert(position <= -1); self_type save(*this); while (position < 0 && !node->is_root()) { - assert(node->parent()->child(node->position()) == node); + ceph_assert(node->parent()->child(node->position()) == node); position = node->position() - 1; node = node->parent(); } @@ -1714,7 +1715,7 @@ void btree_iterator::decrement_slow() { *this = save; } } else { - assert(position >= 0); + ceph_assert(position >= 0); node = node->child(position); while (!node->leaf()) { node = node->child(node->count()); @@ -1865,8 +1866,8 @@ typename btree

::iterator btree

::erase(iterator iter) { // Deletion of a value on an internal node. Swap the key with the largest // value of our left child. This is easy, we just decrement iter. iterator tmp_iter(iter--); - assert(iter.node->leaf()); - assert(!compare_keys(tmp_iter.key(), iter.key())); + ceph_assert(iter.node->leaf()); + ceph_assert(!compare_keys(tmp_iter.key(), iter.key())); iter.node->value_swap(iter.position, tmp_iter.node, tmp_iter.position); internal_delete = true; --*mutable_size(); @@ -1970,15 +1971,15 @@ void btree

::swap(self_type &x) { template void btree

::verify() const { if (root() != NULL) { - assert(size() == internal_verify(root(), NULL, NULL)); - assert(leftmost() == (++const_iterator(root(), -1)).node); - assert(rightmost() == (--const_iterator(root(), root()->count())).node); - assert(leftmost()->leaf()); - assert(rightmost()->leaf()); + ceph_assert(size() == internal_verify(root(), NULL, NULL)); + ceph_assert(leftmost() == (++const_iterator(root(), -1)).node); + ceph_assert(rightmost() == (--const_iterator(root(), root()->count())).node); + ceph_assert(leftmost()->leaf()); + ceph_assert(rightmost()->leaf()); } else { - assert(size() == 0); - assert(leftmost() == NULL); - assert(rightmost() == NULL); + ceph_assert(size() == 0); + ceph_assert(leftmost() == NULL); + ceph_assert(rightmost() == NULL); } } @@ -1986,7 +1987,7 @@ template void btree

::rebalance_or_split(iterator *iter) { node_type *&node = iter->node; int &insert_position = iter->position; - assert(node->count() == node->max_count()); + ceph_assert(node->count() == node->max_count()); // First try to make room on the node by rebalancing. node_type *parent = node->parent(); @@ -2006,14 +2007,14 @@ void btree

::rebalance_or_split(iterator *iter) { ((left->count() + to_move) < left->max_count())) { left->rebalance_right_to_left(node, to_move); - assert(node->max_count() - node->count() == to_move); + ceph_assert(node->max_count() - node->count() == to_move); insert_position = insert_position - to_move; if (insert_position < 0) { insert_position = insert_position + left->count() + 1; node = left; } - assert(node->count() < node->max_count()); + ceph_assert(node->count() < node->max_count()); return; } } @@ -2039,7 +2040,7 @@ void btree

::rebalance_or_split(iterator *iter) { node = right; } - assert(node->count() < node->max_count()); + ceph_assert(node->count() < node->max_count()); return; } } @@ -2059,7 +2060,7 @@ void btree

::rebalance_or_split(iterator *iter) { parent = new_internal_root_node(); parent->set_child(0, root()); *mutable_root() = parent; - assert(*mutable_rightmost() == parent->child(0)); + ceph_assert(*mutable_rightmost() == parent->child(0)); } else { // The root node is an internal node. We do not want to create a new root // node because the root node is special and holds the size of the tree @@ -2163,7 +2164,7 @@ void btree

::try_shrink() { } // Deleted the last item on the root node, shrink the height of the tree. if (root()->leaf()) { - assert(size() == 0); + ceph_assert(size() == 0); delete_leaf_node(root()); *mutable_root() = NULL; } else { @@ -2209,7 +2210,7 @@ btree

::internal_insert(iterator iter, const value_type &v) { if (iter.node->max_count() < kNodeValues) { // Insertion into the root where the root is smaller that the full node // size. Simply grow the size of the root node. - assert(iter.node == root()); + ceph_assert(iter.node == root()); iter.node = new_leaf_root_node( std::min(kNodeValues, 2 * iter.node->max_count())); iter.node->swap(root()); @@ -2364,23 +2365,23 @@ void btree

::internal_dump( template int btree

::internal_verify( const node_type *node, const key_type *lo, const key_type *hi) const { - assert(node->count() > 0); - assert(node->count() <= node->max_count()); + ceph_assert(node->count() > 0); + ceph_assert(node->count() <= node->max_count()); if (lo) { - assert(!compare_keys(node->key(0), *lo)); + ceph_assert(!compare_keys(node->key(0), *lo)); } if (hi) { - assert(!compare_keys(*hi, node->key(node->count() - 1))); + ceph_assert(!compare_keys(*hi, node->key(node->count() - 1))); } for (int i = 1; i < node->count(); ++i) { - assert(!compare_keys(node->key(i), node->key(i - 1))); + ceph_assert(!compare_keys(node->key(i), node->key(i - 1))); } int count = node->count(); if (!node->leaf()) { for (int i = 0; i <= node->count(); ++i) { - assert(node->child(i) != NULL); - assert(node->child(i)->parent() == node); - assert(node->child(i)->position() == i); + ceph_assert(node->child(i) != NULL); + ceph_assert(node->child(i)->parent() == node); + ceph_assert(node->child(i)->position() == i); count += internal_verify( node->child(i), (i == 0) ? lo : &node->key(i - 1), diff --git a/src/include/denc.h b/src/include/denc.h index 3a332ed48bfbc..b1bd7802ddb65 100644 --- a/src/include/denc.h +++ b/src/include/denc.h @@ -1631,7 +1631,7 @@ inline std::enable_if_t decode_nohead( uint32_t *struct_len) { \ const char *pos = p.get_pos(); \ char *end = *start_pos + *struct_len; \ - assert(pos <= end); \ + ceph_assert(pos <= end); \ if (pos < end) { \ p.advance(end - pos); \ } \ diff --git a/src/include/elist.h b/src/include/elist.h index 6719b9c92d840..38be35dbff33a 100644 --- a/src/include/elist.h +++ b/src/include/elist.h @@ -36,7 +36,7 @@ public: item(T i=0) : _prev(this), _next(this) {} ~item() { - assert(!is_on_list()); + ceph_assert(!is_on_list()); } item(const item& other) = delete; @@ -48,7 +48,7 @@ public: bool remove_myself() { if (_next == this) { - assert(_prev == this); + ceph_assert(_prev == this); return false; } _next->_prev = _prev; @@ -58,14 +58,14 @@ public: } void insert_after(item *other) { - assert(other->empty()); + ceph_assert(other->empty()); other->_prev = this; other->_next = _next; _next->_prev = other; _next = other; } void insert_before(item *other) { - assert(other->empty()); + ceph_assert(other->empty()); other->_next = this; other->_prev = _prev; _prev->_next = other; @@ -73,7 +73,7 @@ public: } T get_item(size_t offset) { - assert(offset); + ceph_assert(offset); return (T)(((char *)this) - offset); } }; @@ -88,7 +88,7 @@ public: elist(size_t o) : _head(NULL), item_offset(o) {} ~elist() { - assert(_head.empty()); + ceph_assert(_head.empty()); } bool empty() const { @@ -112,20 +112,20 @@ public: } T front(size_t o=0) { - assert(!_head.empty()); + ceph_assert(!_head.empty()); return _head._next->get_item(o ? o : item_offset); } T back(size_t o=0) { - assert(!_head.empty()); + ceph_assert(!_head.empty()); return _head._prev->get_item(o ? o : item_offset); } void pop_front() { - assert(!empty()); + ceph_assert(!empty()); _head._next->remove_myself(); } void pop_back() { - assert(!empty()); + ceph_assert(!empty()); _head._prev->remove_myself(); } @@ -148,14 +148,14 @@ public: iterator(item *h, size_t o, mode_t m) : head(h), cur(h->_next), next(cur->_next), item_offset(o), mode(m) { - assert(item_offset > 0); + ceph_assert(item_offset > 0); } T operator*() { return cur->get_item(item_offset); } iterator& operator++() { - assert(cur); - assert(cur != head); + ceph_assert(cur); + ceph_assert(cur != head); if (mode == MAGIC) { // if 'cur' appears to be valid, use that. otherwise, // use cached 'next'. diff --git a/src/include/encoding.h b/src/include/encoding.h index 130d5dee379f2..757bde705c7c7 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -520,7 +520,7 @@ inline void decode(T &o, const bufferlist& bl) { auto p = bl.begin(); decode(o, p); - assert(p.end()); + ceph_assert(p.end()); } // boost optional diff --git a/src/include/filepath.h b/src/include/filepath.h index 418aa92a2d6ce..832016ac1bc89 100644 --- a/src/include/filepath.h +++ b/src/include/filepath.h @@ -134,7 +134,7 @@ class filepath { const string& last_dentry() const { if (bits.empty() && path.length() > 0) parse_bits(); - assert(!bits.empty()); + ceph_assert(!bits.empty()); return bits[ bits.size()-1 ]; } @@ -186,7 +186,7 @@ class filepath { rebuild_path(); } void append(const filepath& a) { - assert(a.pure_relative()); + ceph_assert(a.pure_relative()); for (unsigned i=0; i 0); + ceph_assert(bits() > 0); return frag_t(ceph_frag_parent(_enc)); } // splitting frag_t make_child(int i, int nb) const { - assert(i < (1<& fragments) const { - assert(nb > 0); + ceph_assert(nb > 0); unsigned nway = 1 << nb; for (unsigned i=0; i spread); + ceph_assert(nb > spread); // add an intermediary split merge(parent, nb, false); @@ -451,7 +451,7 @@ public: } lgeneric_dout(cct, 10) << "force_to_leaf done" << dendl; - assert(is_leaf(x)); + ceph_assert(is_leaf(x)); return true; } diff --git a/src/include/interval_set.h b/src/include/interval_set.h index 575ac5ef2f4d5..825bcf2e4d787 100644 --- a/src/include/interval_set.h +++ b/src/include/interval_set.h @@ -244,7 +244,7 @@ class interval_set { void intersection_size_asym(const interval_set &s, const interval_set &l) { typename decltype(m)::const_iterator ps = s.m.begin(), pl; - assert(ps != s.m.end()); + ceph_assert(ps != s.m.end()); T offset = ps->first; bool first = true; typename decltype(m)::iterator mi = m.begin(); @@ -280,7 +280,7 @@ class interval_set { T start = std::max(ps->first, pl->first); T en = std::min(ps->first + ps->second, offset); - assert(en > start); + ceph_assert(en > start); typename decltype(m)::value_type i{start, en - start}; mi = m.insert(mi, i); _size += i.second; @@ -376,7 +376,7 @@ class interval_set { if (p == m.end()) return false; if (p->first > i) return false; if (p->first+p->second <= i) return false; - assert(p->first <= i && p->first+p->second > i); + ceph_assert(p->first <= i && p->first+p->second > i); if (pstart) *pstart = p->first; if (plen) @@ -388,7 +388,7 @@ class interval_set { if (p == m.end()) return false; if (p->first > start) return false; if (p->first+p->second <= start) return false; - assert(p->first <= start && p->first+p->second > start); + ceph_assert(p->first <= start && p->first+p->second > start); if (p->first+p->second < start+len) return false; return true; } @@ -406,12 +406,12 @@ class interval_set { return m.empty(); } T range_start() const { - assert(!empty()); + ceph_assert(!empty()); typename Map::const_iterator p = m.begin(); return p->first; } T range_end() const { - assert(!empty()); + ceph_assert(!empty()); typename Map::const_iterator p = m.end(); p--; return p->first+p->second; @@ -419,20 +419,20 @@ class interval_set { // interval start after p (where p not in set) bool starts_after(T i) const { - assert(!contains(i)); + ceph_assert(!contains(i)); typename Map::const_iterator p = find_inc(i); if (p == m.end()) return false; return true; } T start_after(T i) const { - assert(!contains(i)); + ceph_assert(!contains(i)); typename Map::const_iterator p = find_inc(i); return p->first; } // interval end that contains start T end_after(T start) const { - assert(contains(start)); + ceph_assert(contains(start)); typename Map::const_iterator p = find_inc(start); return p->first+p->second; } @@ -443,7 +443,7 @@ class interval_set { void insert(T start, T len, T *pstart=0, T *plen=0) { //cout << "insert " << start << "~" << len << endl; - assert(len > 0); + ceph_assert(len > 0); _size += len; typename Map::iterator p = find_adj_m(start); if (p == m.end()) { @@ -486,7 +486,7 @@ class interval_set { m.erase(p); m[start] = len + psecond; // append to front } else { - assert(p->first > start+len); + ceph_assert(p->first > start+len); if (pstart) *pstart = start; if (plen) @@ -504,7 +504,7 @@ class interval_set { void erase(iterator &i) { _size -= i.get_len(); - assert(_size >= 0); + ceph_assert(_size >= 0); m.erase(i._iter); } @@ -517,13 +517,13 @@ class interval_set { typename Map::iterator p = find_inc_m(start); _size -= len; - assert(_size >= 0); + ceph_assert(_size >= 0); - assert(p != m.end()); - assert(p->first <= start); + ceph_assert(p != m.end()); + ceph_assert(p->first <= start); T before = start - p->first; - assert(p->second >= before+len); + ceph_assert(p->second >= before+len); T after = p->second - before - len; if (before) { if (claim && claim(p->first, before)) { @@ -560,8 +560,8 @@ class interval_set { void intersection_of(const interval_set &a, const interval_set &b) { - assert(&a != this); - assert(&b != this); + ceph_assert(&a != this); + ceph_assert(&b != this); clear(); const interval_set *s, *l; @@ -610,7 +610,7 @@ class interval_set { T start = std::max(pa->first, pb->first); T en = std::min(pa->first+pa->second, pb->first+pb->second); - assert(en > start); + ceph_assert(en > start); typename decltype(m)::value_type i{start, en - start}; mi = m.insert(mi, i); _size += i.second; @@ -627,8 +627,8 @@ class interval_set { } void union_of(const interval_set &a, const interval_set &b) { - assert(&a != this); - assert(&b != this); + ceph_assert(&a != this); + ceph_assert(&b != this); clear(); //cout << "union_of" << endl; diff --git a/src/include/lru.h b/src/include/lru.h index c52cb567bf158..1e30cdfe8ca22 100644 --- a/src/include/lru.h +++ b/src/include/lru.h @@ -62,12 +62,12 @@ public: while (!pintail.empty()) { lru_remove(pintail.front()); } - assert(num_pinned == 0); + ceph_assert(num_pinned == 0); } // insert at top of lru void lru_insert_top(LRUObject *o) { - assert(!o->lru); + ceph_assert(!o->lru); o->lru = this; top.push_front(&o->lru_link); if (o->lru_pinned) num_pinned++; @@ -76,7 +76,7 @@ public: // insert at mid point in lru void lru_insert_mid(LRUObject *o) { - assert(!o->lru); + ceph_assert(!o->lru); o->lru = this; bottom.push_front(&o->lru_link); if (o->lru_pinned) num_pinned++; @@ -85,7 +85,7 @@ public: // insert at bottom of lru void lru_insert_bot(LRUObject *o) { - assert(!o->lru); + ceph_assert(!o->lru); o->lru = this; bottom.push_back(&o->lru_link); if (o->lru_pinned) num_pinned++; @@ -96,7 +96,7 @@ public: LRUObject *lru_remove(LRUObject *o) { if (!o->lru) return o; auto list = o->lru_link.get_list(); - assert(list == &top || list == &bottom || list == &pintail); + ceph_assert(list == &top || list == &bottom || list == &pintail); o->lru_link.remove_myself(); if (o->lru_pinned) num_pinned--; o->lru = nullptr; @@ -109,9 +109,9 @@ public: if (!o->lru) { lru_insert_top(o); } else { - assert(o->lru == this); + ceph_assert(o->lru == this); auto list = o->lru_link.get_list(); - assert(list == &top || list == &bottom || list == &pintail); + ceph_assert(list == &top || list == &bottom || list == &pintail); top.push_front(&o->lru_link); adjust(); } @@ -123,9 +123,9 @@ public: if (!o->lru) { lru_insert_mid(o); } else { - assert(o->lru == this); + ceph_assert(o->lru == this); auto list = o->lru_link.get_list(); - assert(list == &top || list == &bottom || list == &pintail); + ceph_assert(list == &top || list == &bottom || list == &pintail); if (list == &top) return false; bottom.push_front(&o->lru_link); adjust(); @@ -138,9 +138,9 @@ public: if (!o->lru) { lru_insert_bot(o); } else { - assert(o->lru == this); + ceph_assert(o->lru == this); auto list = o->lru_link.get_list(); - assert(list == &top || list == &bottom || list == &pintail); + ceph_assert(list == &top || list == &bottom || list == &pintail); bottom.push_back(&o->lru_link); adjust(); } diff --git a/src/include/mempool.h b/src/include/mempool.h index 886fbf44032b7..a07d167e36a99 100644 --- a/src/include/mempool.h +++ b/src/include/mempool.h @@ -514,10 +514,10 @@ bool operator!=(const std::vector>& lh #define MEMPOOL_CLASS_HELPERS() \ void *operator new(size_t size); \ void *operator new[](size_t size) noexcept { \ - assert(0 == "no array new"); \ + ceph_assert(0 == "no array new"); \ return nullptr; } \ void operator delete(void *); \ - void operator delete[](void *) { assert(0 == "no array delete"); } + void operator delete[](void *) { ceph_assert(0 == "no array delete"); } // Use this in some particular .cc file to match each class with a diff --git a/src/include/on_exit.h b/src/include/on_exit.h index 47d222c7cc132..1642c68204053 100644 --- a/src/include/on_exit.h +++ b/src/include/on_exit.h @@ -2,9 +2,9 @@ #define CEPH_ON_EXIT_H #include -#include #include +#include "include/assert.h" /* * Create a static instance at the file level to get callbacks called when the * process exits via main() or exit(). @@ -15,8 +15,8 @@ class OnExitManager { typedef void (*callback_t)(void *arg); OnExitManager() { - [[maybe_unused]] int ret = pthread_mutex_init(&lock_, NULL); - assert(ret == 0); + int ret = pthread_mutex_init(&lock_, NULL); + ceph_assert(ret == 0); } ~OnExitManager() { diff --git a/src/include/rangeset.h b/src/include/rangeset.h index 51c1c840551d8..e7e3d047c72aa 100644 --- a/src/include/rangeset.h +++ b/src/include/rangeset.h @@ -141,12 +141,12 @@ public: // ... bool contains(T val) { if (theset.get_range_for(val) == theset.ranges.end()) return false; - assert(!empty()); + ceph_assert(!empty()); return true; } void insert(T val) { - assert(!contains(val)); + ceph_assert(!contains(val)); map_iterator left = theset.get_range_for(val-1); map_iterator right = theset.get_range_for(val+1); @@ -187,24 +187,24 @@ public: bool empty() { if (theset.ranges.empty()) { - assert(_size == 0); + ceph_assert(_size == 0); return true; } - assert(_size>0); + ceph_assert(_size>0); return false; } T first() { - assert(!empty()); + ceph_assert(!empty()); map_iterator it = theset.ranges.begin(); return it->first; } void erase(T val) { - assert(contains(val)); + ceph_assert(contains(val)); map_iterator it = theset.get_range_for(val); - assert(it != theset.ranges.end()); + ceph_assert(it != theset.ranges.end()); // entire range if (val == it->first && val == it->second) { diff --git a/src/include/util.h b/src/include/util.h index caccaa9ca317f..62d4b6f35d599 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -34,7 +34,7 @@ struct ceph_data_stats { } void dump(Formatter *f) const { - assert(f != NULL); + ceph_assert(f != NULL); f->dump_int("total", byte_total); f->dump_int("used", byte_used); f->dump_int("avail", byte_avail); diff --git a/src/include/xlist.h b/src/include/xlist.h index 1d06e55cafa2f..0204155e169c5 100644 --- a/src/include/xlist.h +++ b/src/include/xlist.h @@ -15,11 +15,12 @@ #ifndef CEPH_XLIST_H #define CEPH_XLIST_H -#include "include/assert.h" #include #include #include +#include "include/assert.h" + template class xlist { public: @@ -30,7 +31,7 @@ public: item(T i) : _item(i), _prev(0), _next(0), _list(0) {} ~item() { - assert(!is_on_list()); + ceph_assert(!is_on_list()); //remove_myself(); } @@ -43,17 +44,17 @@ public: bool remove_myself() { if (_list) { _list->remove(this); - assert(_list == 0); + ceph_assert(_list == 0); return true; } else return false; } void move_to_front() { - assert(_list); + ceph_assert(_list); _list->push_front(this); } void move_to_back() { - assert(_list); + ceph_assert(_list); _list->push_back(this); } }; @@ -74,24 +75,24 @@ public: xlist() : _front(0), _back(0), _size(0) {} ~xlist() { - assert(_size == 0); - assert(_front == 0); - assert(_back == 0); + ceph_assert(_size == 0); + ceph_assert(_front == 0); + ceph_assert(_back == 0); } size_t size() const { - assert((bool)_front == (bool)_size); + ceph_assert((bool)_front == (bool)_size); return _size; } bool empty() const { - assert((bool)_front == (bool)_size); + ceph_assert((bool)_front == (bool)_size); return _front == 0; } void clear() { while (_front) remove(_front); - assert((bool)_front == (bool)_size); + ceph_assert((bool)_front == (bool)_size); } void push_front(item *i) { @@ -123,7 +124,7 @@ public: _size++; } void remove(item *i) { - assert(i->_list == this); + ceph_assert(i->_list == this); if (i->_prev) i->_prev->_next = i->_next; @@ -137,7 +138,7 @@ public: i->_list = 0; i->_next = i->_prev = 0; - assert((bool)_front == (bool)_size); + ceph_assert((bool)_front == (bool)_size); } T front() { return static_cast(_front->_item); } @@ -147,11 +148,11 @@ public: const T back() const { return static_cast(_back->_item); } void pop_front() { - assert(!empty()); + ceph_assert(!empty()); remove(_front); } void pop_back() { - assert(!empty()); + ceph_assert(!empty()); remove(_back); } @@ -162,8 +163,8 @@ public: iterator(item *i = 0) : cur(i) {} T operator*() { return static_cast(cur->_item); } iterator& operator++() { - assert(cur); - assert(cur->_list); + ceph_assert(cur); + ceph_assert(cur->_list); cur = cur->_next; return *this; } @@ -186,8 +187,8 @@ public: const_iterator(item *i = 0) : cur(i) {} const T operator*() { return static_cast(cur->_item); } const_iterator& operator++() { - assert(cur); - assert(cur->_list); + ceph_assert(cur); + ceph_assert(cur->_list); cur = cur->_next; return *this; } -- 2.39.5