Fix naming of asserts.runtime_assert & assert -> debug_assert

Summary:
Merge branch 'dev' into rename_assert

Fix new files.

Remove cassert.

Reviewers: buda

Reviewed By: buda

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D66
This commit is contained in:
Dominik Gleich 2017-02-24 10:15:18 +01:00
parent af23253e7e
commit 82414b9111
39 changed files with 137 additions and 117 deletions

View File

@ -181,12 +181,12 @@ endif()
# custom assert control parameters
# Runtime assert, if value is OFF runtime asserts will be inactive during
# runtime. Default value is ON.
option(RUNTIME_ASSERT "Enable runtime assertions" ON)
message(STATUS "RUNTIME_ASSERT: ${RUNTIME_ASSERT}")
if(RUNTIME_ASSERT)
add_definitions(-DRUNTIME_ASSERT_ON)
# Debug assert, if value is OFF debug asserts will be inactive.
# Default value is ON.
option(DEBUG_ASSERT "Enable debug assertions" ON)
message(STATUS "DEBUG_ASSERT: ${DEBUG_ASSERT}")
if(DEBUG_ASSERT)
add_definitions(-DDEBUG_ASSERT_ON)
endif()
# by default on custom assert only the message, filename and line number will be

View File

@ -1,7 +1,6 @@
#pragma once
#include <atomic>
#include <cassert>
#include <memory>
#include <thread>
#include <vector>
@ -9,6 +8,7 @@
#include "communication/bolt/v1/bolt.hpp"
#include "io/network/server.hpp"
#include "logging/default.hpp"
#include "utils/assert.hpp"
namespace bolt {
@ -39,7 +39,7 @@ class Server : public io::Server<Server<Worker>> {
}
void on_connect() {
assert(idx < workers.size());
debug_assert(idx < workers.size(), "Invalid worker id.");
logger.trace("on connect");

View File

@ -1,6 +1,5 @@
#pragma once
#include <cassert>
#include <cstring>
#include <functional>

View File

@ -1,10 +1,10 @@
#pragma once
#include <atomic>
#include <cassert>
#include "threading/sync/lockable.hpp"
#include "threading/sync/spinlock.hpp"
#include "utils/assert.hpp"
template <class block_t = uint8_t, size_t chunk_size = 32768>
class DynamicBitset : Lockable<SpinLock> {
@ -21,17 +21,17 @@ class DynamicBitset : Lockable<SpinLock> {
}
block_t at(size_t k, size_t n, std::memory_order order) {
assert(k + n - 1 < size);
debug_assert(k + n - 1 < size, "Invalid index.");
return (block.load(order) >> k) & bitmask(n);
}
void set(size_t k, size_t n, std::memory_order order) {
assert(k + n - 1 < size);
debug_assert(k + n - 1 < size, "Invalid index.");
block.fetch_or(bitmask(n) << k, order);
}
void clear(size_t k, size_t n, std::memory_order order) {
assert(k + n - 1 < size);
debug_assert(k + n - 1 < size, "Invalid index.");
block.fetch_and(~(bitmask(n) << k), order);
}
@ -130,7 +130,7 @@ class DynamicBitset : Lockable<SpinLock> {
chunk->next.store(new Chunk());
}
assert(chunk != nullptr);
debug_assert(chunk != nullptr, "Chunk is nullptr.");
return *chunk;
}

View File

@ -1,8 +1,8 @@
#pragma once
#include <atomic>
#include <cassert>
#include <utility>
#include "utils/assert.hpp"
#include "utils/crtp.hpp"
// TODO: reimplement this. It's correct but somewhat inefecient and it could be
@ -63,7 +63,7 @@ class ConcurrentList {
IteratorBase() : list(nullptr), curr(nullptr) {}
IteratorBase(ConcurrentList *list) : list(list) {
assert(list != nullptr);
debug_assert(list != nullptr, "List is nullptr.");
// Increment number of iterators accessing list.
list->active_threads_no_++;
// Start from the begining of list.
@ -113,11 +113,11 @@ class ConcurrentList {
IteratorBase &operator=(IteratorBase &&other) = delete;
T &operator*() const {
assert(valid());
debug_assert(valid(), "Not valid data.");
return curr->data;
}
T *operator->() const {
assert(valid());
debug_assert(valid(), "Not valid data.");
return &(curr->data);
}
@ -125,7 +125,7 @@ class ConcurrentList {
// Iterating is wait free.
It &operator++() {
assert(valid());
debug_assert(valid(), "Not valid data.");
do {
prev = curr;
curr = load(curr->next);
@ -137,7 +137,7 @@ class ConcurrentList {
It &operator++(int) { return operator++(); }
bool is_removed() {
assert(valid());
debug_assert(valid(), "Not valid data.");
return load(curr->removed);
}
@ -176,7 +176,7 @@ class ConcurrentList {
// This can be improved with combinig the removed flag with prev.next or
// curr.next
bool remove() {
assert(valid());
debug_assert(valid(), "Not valid data.");
// Try to logically remove it.
if (cas(curr->removed, false, true)) {
// I removed it!!!

View File

@ -1,10 +1,10 @@
#pragma once
#include <algorithm>
#include <cassert>
#include <cmath>
#include <memory>
#include "utils/assert.hpp"
#include "utils/placeholder.hpp"
#include "utils/random/fast_binomial.hpp"
@ -242,28 +242,28 @@ class SkipList : private Lockable<lock_t> {
IteratorBase(const IteratorBase &) = default;
T &operator*() {
assert(node != nullptr);
debug_assert(node != nullptr, "Node is nullptr.");
return node->value();
}
T *operator->() {
assert(node != nullptr);
debug_assert(node != nullptr, "Node is nullptr.");
return &node->value();
}
operator T &() {
assert(node != nullptr);
debug_assert(node != nullptr, "Node is nullptr.");
return node->value();
}
It &operator++() {
assert(node != nullptr);
debug_assert(node != nullptr, "Node is nullptr.");
node = node->forward(0);
return this->derived();
}
bool has_next() {
assert(node != nullptr);
debug_assert(node != nullptr, "Node is nullptr.");
return node->forward(0) != nullptr;
}
@ -329,22 +329,22 @@ class SkipList : private Lockable<lock_t> {
}
T &operator*() {
assert(node_ != nullptr);
debug_assert(node_ != nullptr, "Node is nullptr.");
return node_->value();
}
T *operator->() {
assert(node_ != nullptr);
debug_assert(node_ != nullptr, "Node is nullptr.");
return &node_->value();
}
operator T &() {
assert(node_ != nullptr);
debug_assert(node_ != nullptr, "Node is nullptr.");
return node_->value();
}
ReverseIterator &operator++() {
assert(node_ != nullptr);
debug_assert(node_ != nullptr, "Node is nullptr.");
do {
next();
} while (node_->flags.is_marked());
@ -436,24 +436,24 @@ class SkipList : private Lockable<lock_t> {
MultiIterator(const MultiIterator &) = default;
T &operator*() {
assert(succs[0] != nullptr);
debug_assert(succs[0] != nullptr, "Node is nullptr.");
return succs[0]->value();
}
T *operator->() {
assert(succs[0] != nullptr);
debug_assert(succs[0] != nullptr, "Node is nullptr.");
return &succs[0]->value();
}
operator T &() {
assert(succs[0] != nullptr);
debug_assert(succs[0] != nullptr, "Node is nullptr.");
return succs[0]->value();
}
bool has_value() { return succs[0] != nullptr; }
MultiIterator &operator++() {
assert(succs[0] != nullptr);
debug_assert(succs[0] != nullptr, "Node is nullptr.");
// NOTE: This whole method can be optimized if it's valid to expect
// height
// of 1 on same key elements.
@ -500,14 +500,14 @@ class SkipList : private Lockable<lock_t> {
}
bool is_removed() {
assert(succs[0] != nullptr);
debug_assert(succs[0] != nullptr, "Node is nullptr.");
return succs[0]->flags.is_marked();
}
// True if this call successfuly removed value. ITERATOR IS'T ADVANCED.
// False may mean that data has already been removed.
bool remove() {
assert(succs[0] != nullptr);
debug_assert(succs[0] != nullptr, "Node is nullptr.");
// Calls skiplist remove method.
return skiplist->template remove<K>(
@ -529,7 +529,8 @@ class SkipList : private Lockable<lock_t> {
// true. That way that doesnt have to be done in constructor and
// ++ operator.
int level_found = succs[0]->height - 1;
assert(succs[0] == succs[level_found]);
debug_assert(succs[0] == succs[level_found], "Node is initialized.");
for (auto it = MultiIterator<K>(skiplist, item); it.has_value(); it++) {
if (it.succs[0] == succs[0]) { // Found it
@ -567,7 +568,7 @@ class SkipList : private Lockable<lock_t> {
friend class SkipList;
Accessor(SkipList *skiplist) : skiplist(skiplist) {
assert(skiplist != nullptr);
debug_assert(skiplist != nullptr, "Skiplist is nullptr.");
skiplist->gc.add_ref();
}

View File

@ -7,6 +7,7 @@
#include "memory/freelist.hpp"
#include "memory/lazy_gc.hpp"
#include "threading/sync/spinlock.hpp"
#include "utils/assert.hpp"
template <class T, class lock_t = SpinLock>
class SkiplistGC : public LazyGC<SkiplistGC<T, lock_t>, lock_t>,
@ -27,7 +28,7 @@ class SkiplistGC : public LazyGC<SkiplistGC<T, lock_t>, lock_t>,
// take freelist if there is no more threads
{
auto lock = this->acquire_unique();
assert(this->count > 0);
debug_assert(this->count > 0, "Count is equal to zero.");
--this->count;
if (this->count == 0) {
freelist.swap(local_freelist);

View File

@ -1,7 +1,7 @@
#pragma once
#include <cassert>
#include <cstring>
#include <functional>
#include "utils/assert.hpp"
#include "utils/crtp.hpp"
#include "utils/option_ptr.hpp"
@ -93,17 +93,20 @@ class RhBase {
IteratorBase(IteratorBase &&) = default;
D *operator*() {
assert(index < map->capacity && map->array[index].valid());
debug_assert(index < map->capacity && map->array[index].valid(),
"Either index is invalid or data is not valid.");
return map->array[index].ptr();
}
D *operator->() {
assert(index < map->capacity && map->array[index].valid());
debug_assert(index < map->capacity && map->array[index].valid(),
"Either index is invalid or data is not valid.");
return map->array[index].ptr();
}
It &operator++() {
assert(index < map->capacity && map->array[index].valid());
debug_assert(index < map->capacity && map->array[index].valid(),
"Either index is invalid or data is not valid.");
auto mask = map->mask();
do {
advanced++;

View File

@ -3,6 +3,7 @@
#include <cstring>
#include <functional>
#include "data_structures/map/rh_common.hpp"
#include "utils/assert.hpp"
#include "utils/crtp.hpp"
#include "utils/likely.hpp"
#include "utils/option.hpp"
@ -122,7 +123,7 @@ class RhHashMultiMap : public RhBase<K, D, init_size_pow2> {
// Inserts element with the given key.
void add(const K &key_in, D *data) {
assert(key_in == data->get_key());
debug_assert(key_in == data->get_key(), "Key doesn't match data key.");
if (count < capacity) {
auto key = std::ref(key_in);

View File

@ -30,13 +30,13 @@ class static_array {
// returns element reference on specific index
T &operator[](size_t index) {
runtime_assert(index < N, "Index " << index << " must be less than " << N);
debug_assert(index < N, "Index " << index << " must be less than " << N);
return data[index];
}
// returns const element reference on specific index
const T &operator[](size_t index) const {
runtime_assert(index < N, "Index " << index << " must be less than " << N);
debug_assert(index < N, "Index " << index << " must be less than " << N);
return data[index];
}

View File

@ -5,6 +5,7 @@
#include "storage/edge_accessor.hpp"
#include "storage/vertex.hpp"
#include "storage/vertex_accessor.hpp"
#include "utils/assert.hpp"
GraphDbAccessor::GraphDbAccessor(GraphDb& db)
: db_(db), transaction_(std::move(db.tx_engine.begin())) {}
@ -93,7 +94,7 @@ EdgeAccessor GraphDbAccessor::insert_edge(VertexAccessor& from,
void swap_out_edge(std::vector<mvcc::VersionList<Edge>*>& edges,
mvcc::VersionList<Edge>* edge) {
auto found = std::find(edges.begin(), edges.end(), edge);
assert(found != edges.end());
debug_assert(found != edges.end(), "Edge doesn't exist.");
std::swap(*found, edges.back());
edges.pop_back();
}

View File

@ -31,6 +31,7 @@
#include "storage/model/properties/all.hpp"
#include "storage/model/properties/flags.hpp"
#include "storage/vertex_accessor.hpp"
#include "utils/assert.hpp"
#include "utils/command_line/arguments.hpp"
#include "utils/option.hpp"
@ -180,7 +181,7 @@ class CSVImporter : public BaseImporter {
template <class TG>
typename PropertyFamily<TG>::PropertyType::PropertyFamilyKey property_key(
const char *name, Flags type) {
assert(false);
debug_assert(false, "Fail.");
}
// Returns filler for name:type in header_part. None if error occured.

View File

@ -1,11 +1,10 @@
#pragma once
#include <cassert>
#include "database/db_accessor.hpp"
#include "storage/model/typed_value.hpp"
#include "storage/model/typed_value_store.hpp"
#include "storage/vertex_accessor.hpp"
#include "utils/assert.hpp"
// Holder for element data which he can then insert as a vertex or edge into the
// database depending on the available data and called add_* method.
@ -36,7 +35,7 @@ class ElementSkeleton {
}
VertexAccessor add_vertex() {
assert(properties_e.empty());
debug_assert(properties_e.empty(), "Properties aren't empty.");
auto va = db.vertex_insert();
@ -55,15 +54,15 @@ class ElementSkeleton {
// Return error msg if unsuccessful
Option<std::string> add_edge() {
if (!from_va.is_present()) {
return make_option(std::string("From field must be seted"));
return make_option(std::string("From field must be set"));
}
if (!to_va.is_present()) {
return make_option(std::string("To field must be seted"));
return make_option(std::string("To field must be set"));
}
if (!type.is_present()) {
return make_option(std::string("Type field must be seted"));
return make_option(std::string("Type field must be set"));
}
assert(properties_v.empty());
debug_assert(properties_v.empty(), "Properties aren't empty.");
auto ve = db.edge_insert(from_va.get(), to_va.get());
ve.edge_type(*type.get());

View File

@ -1,6 +1,7 @@
#pragma once
#include "import/fillings/filler.hpp"
#include "utils/assert.hpp"
// Parses import local Id.
// TG - Type group
@ -14,7 +15,9 @@ class IdFiller : public Filler {
IdFiller(
Option<typename PropertyFamily<TG>::PropertyType::PropertyFamilyKey> key)
: key(key) {
assert(!key.is_present() || key.get().prop_type() == Type(Flags::Int64));
debug_assert(
!key.is_present() || key.get().prop_type() == Type(Flags::Int64),
"Invalid key property type.");
}
// Fills skeleton with data from str. Returns error description if

View File

@ -1,6 +1,5 @@
#pragma once
#include <cassert>
#include <cstdio>
#include <cstring>
#include <stdexcept>

View File

@ -6,7 +6,7 @@
Logger Log::logger(const std::string &name) {
// TODO: once when properties are refactored enable this
// runtime_assert(this != nullptr,
// debug_assert(this != nullptr,
// "This shouldn't be null. This method is "
// "called before the log object is created. "
// "E.g. static variables before main method.");

View File

@ -36,7 +36,7 @@ class Logger {
template <class Level, class... Args>
void emit(Args&&... args) {
runtime_assert(log != nullptr, "Log object has to be defined.");
debug_assert(log != nullptr, "Log object has to be defined.");
auto message = std::make_unique<Message<Level>>(
Timestamp::now(), name, fmt::format(std::forward<Args>(args)...));

View File

@ -2,7 +2,6 @@
#include <unistd.h>
#include <atomic>
#include <cassert>
#include <iostream>
namespace memory {

View File

@ -4,6 +4,7 @@
#include <atomic>
#include "transactions/commit_log.hpp"
#include "utils/assert.hpp"
namespace mvcc {
@ -66,7 +67,9 @@ class Hints {
};
public:
Hints() : cre(bits), exp(bits) { assert(bits.is_lock_free()); }
Hints() : cre(bits), exp(bits) {
debug_assert(bits.is_lock_free(), "Bits are not lock free.");
}
union HintBits {
uint8_t bits;

View File

@ -144,7 +144,8 @@ class Record : public Version<T> {
if (info.is_committed()) return hints.set_committed(), true;
assert(info.is_aborted());
debug_assert(info.is_aborted(),
"Info isn't aborted, but function would return as aborted.");
return hints.set_aborted(), false;
}
};

View File

@ -6,6 +6,7 @@
#include "memory/lazy_gc.hpp"
#include "mvcc/serialization_error.hpp"
#include "storage/locking/record_lock.hpp"
#include "utils/assert.hpp"
namespace mvcc {
@ -124,7 +125,7 @@ class VersionList {
*/
template <typename... Args>
T *insert(tx::Transaction &t, Args &&... args) {
assert(head == nullptr);
debug_assert(head == nullptr, "Head is not nullptr on creation.");
// create a first version of the record
// TODO replace 'new' with something better
@ -139,7 +140,7 @@ class VersionList {
}
T *update(tx::Transaction &t) {
assert(head != nullptr);
debug_assert(head != nullptr, "Head is nullptr on update.");
auto record = find(t);
// check if we found any visible records
@ -149,7 +150,7 @@ class VersionList {
}
T *update(T *record, tx::Transaction &t) {
assert(record != nullptr);
debug_assert(record != nullptr, "Record is nullptr on update.");
lock_and_validate(record, t);
// It could be done with unique_ptr but while this could mean memory
@ -167,7 +168,7 @@ class VersionList {
}
bool remove(tx::Transaction &t) {
assert(head != nullptr);
debug_assert(head != nullptr, "Head is nullptr on removal.");
auto record = find(t);
if (!record) return false;
@ -178,14 +179,15 @@ class VersionList {
}
void remove(T *record, tx::Transaction &t) {
assert(record != nullptr);
debug_assert(record != nullptr, "Record is nullptr on removal.");
lock_and_validate(record, t);
record->mark_deleted(t);
}
private:
void lock_and_validate(T *record, tx::Transaction &t) {
assert(record != nullptr);
debug_assert(record != nullptr,
"Record is nullptr on lock and validation.");
// take a lock on this node
t.take_lock(lock);
@ -195,7 +197,8 @@ class VersionList {
if (!record->tx.exp() || !record->exp_committed(t)) return;
// if it committed, then we have a serialization conflict
assert(record->hints.load().exp.is_committed());
debug_assert(record->hints.load().exp.is_committed(),
"Serialization conflict.");
throw SerializationError();
}

View File

@ -1,6 +1,5 @@
#include "query/backend/cpp/cypher_main_visitor.hpp"
#include <cassert>
#include <climits>
#include <string>
#include <unordered_map>
@ -8,6 +7,7 @@
#include <vector>
#include "query/backend/cpp/compiler_structures.hpp"
#include "utils/assert.hpp"
namespace {
// List of unnamed tokens visitor needs to use. This should be reviewed on every
@ -148,7 +148,7 @@ antlrcpp::Any CypherMainVisitor::visitRelationshipPattern(
antlrcpp::Any CypherMainVisitor::visitRelationshipDetail(
CypherParser::RelationshipDetailContext *) {
assert(false);
debug_assert(false, "Unimplemented.");
return 0;
}

View File

@ -1,6 +1,7 @@
#include "storage/record_accessor.hpp"
#include "storage/edge.hpp"
#include "storage/vertex.hpp"
#include "utils/assert.hpp"
template <typename TRecord>
RecordAccessor<TRecord>::RecordAccessor(mvcc::VersionList<TRecord> &vlist,
@ -8,7 +9,7 @@ RecordAccessor<TRecord>::RecordAccessor(mvcc::VersionList<TRecord> &vlist,
: vlist_(vlist),
record_(vlist_.find(db_accessor.transaction_)),
db_accessor_(db_accessor) {
assert(record_ != nullptr);
debug_assert(record_ != nullptr, "Record is nullptr.");
}
template <typename TRecord>
@ -16,7 +17,7 @@ RecordAccessor<TRecord>::RecordAccessor(mvcc::VersionList<TRecord> &vlist,
TRecord &record,
GraphDbAccessor &db_accessor)
: vlist_(vlist), record_(&record), db_accessor_(db_accessor) {
assert(record_ != nullptr);
debug_assert(record_ != nullptr, "Record is nullptr.");
}
template <typename TRecord>

View File

@ -92,20 +92,23 @@ class RecordAccessor {
* not actual values inside RecordAccessors.
*/
friend bool operator<(const RecordAccessor& a, const RecordAccessor& b) {
assert(&a.db_accessor_ ==
&b.db_accessor_); // assume the same db_accessor / transaction
debug_assert(&a.db_accessor_ == &b.db_accessor_,
"Not in the same transaction."); // assume the same
// db_accessor / transaction
return &a.vlist_ < &b.vlist_;
}
friend bool operator==(const RecordAccessor& a, const RecordAccessor& b) {
assert(&a.db_accessor_ ==
&b.db_accessor_); // assume the same db_accessor / transaction
debug_assert(&a.db_accessor_ == &b.db_accessor_,
"Not in the same transaction."); // assume the same
// db_accessor / transaction
return &a.vlist_ == &b.vlist_;
}
friend bool operator!=(const RecordAccessor& a, const RecordAccessor& b) {
assert(&a.db_accessor_ ==
&b.db_accessor_); // assume the same db_accessor / transaction
debug_assert(&a.db_accessor_ == &b.db_accessor_,
"Not in the same transaction."); // assume the same
// db_accessor / transaction
return !(a == b);
}

View File

@ -9,28 +9,28 @@
// Value extraction template instantiations
template <>
bool TypedValue::Value<bool>() const {
runtime_assert(type_ == TypedValue::Type::Bool,
debug_assert(type_ == TypedValue::Type::Bool,
"Incompatible template param and type");
return bool_v;
}
template <>
std::string TypedValue::Value<std::string>() const {
runtime_assert(type_ == TypedValue::Type::String,
debug_assert(type_ == TypedValue::Type::String,
"Incompatible template param and type");
return *string_v;
}
template <>
int TypedValue::Value<int>() const {
runtime_assert(type_ == TypedValue::Type::Int,
debug_assert(type_ == TypedValue::Type::Int,
"Incompatible template param and type");
return int_v;
}
template <>
float TypedValue::Value<float>() const {
runtime_assert(type_ == TypedValue::Type::Float,
debug_assert(type_ == TypedValue::Type::Float,
"Incompatible template param and type");
return float_v;
}

View File

@ -1,6 +1,5 @@
#pragma once
#include <cassert>
#include <iostream>
#include <memory>
#include <string>

View File

@ -1,7 +1,8 @@
#include "thread.hpp"
#include "utils/assert.hpp"
Thread::Thread(Thread &&other) {
assert(thread_id == UNINITIALIZED);
debug_assert(thread_id == UNINITIALIZED, "Thread was initialized before.");
thread_id = other.thread_id;
thread = std::move(other.thread);
}

View File

@ -1,7 +1,6 @@
#pragma once
#include <atomic>
#include <cassert>
#include <thread>
#include "utils/underlying_cast.hpp"

View File

@ -1,9 +1,9 @@
#pragma once
#include <cassert>
#include <memory>
#include <vector>
#include "storage/locking/lock_status.hpp"
#include "utils/assert.hpp"
namespace tx {
@ -15,7 +15,7 @@ class LockStore {
template <class... Args>
LockHolder(T *lock, Args &&... args) noexcept : lock(lock) {
assert(lock != nullptr);
debug_assert(lock != nullptr, "Lock is nullptr.");
auto status = lock->lock(std::forward<Args>(args)...);
if (status != LockStatus::Acquired) lock = nullptr;

View File

@ -1,6 +1,6 @@
/**
* Permanent Assert -> always active
* Runtime Assert -> active only if RUNTIME_ASSERT_ON is present
* Debug Assert -> active only if DEBUG_ASSERT_ON is present
*/
#pragma once
@ -50,10 +50,10 @@
* define which controls when the assertion will be active \
* \
* could be used wherever the standard C assert is used but \
* the user should not forget about RUNTIME_ASSERT_ON define \
* the user should not forget about DEBUG_ASSERT_ON define \
*/
#ifdef RUNTIME_ASSERT_ON
#define runtime_assert(condition, message) permanent_assert(condition, message)
#ifdef DEBUG_ASSERT_ON
#define debug_assert(condition, message) permanent_assert(condition, message)
#else
#define runtime_assert(condition, message)
#define debug_assert(condition, message)
#endif

View File

@ -111,7 +111,7 @@ struct FSEventBase {
struct WatchDescriptor : public FSEventBase {
WatchDescriptor(const fs::path &directory, const FSEventType type)
: FSEventBase(directory, type) {
runtime_assert(fs::is_directory(path),
debug_assert(fs::is_directory(path),
"The path parameter should be directory");
}
};
@ -318,7 +318,7 @@ class FSWatcher : public Loggable {
// TODO: figure out why (it is not easy)
if (((p - buffer_) + in_event_length) > IN_BUFF_LEN) break;
// here should be an assertion
// runtime_assert(in_event_length <= IN_BUFF_SLOT_LEN,
// debug_assert(in_event_length <= IN_BUFF_SLOT_LEN,
// "Inotify event length cannot be bigger
// than "
// "Inotify slot length");

View File

@ -1,9 +1,9 @@
#pragma once
#include <cassert>
#include <map>
#include <memory>
#include <vector>
#include "utils/assert.hpp"
namespace ioc {
@ -26,7 +26,7 @@ class Container {
Instance(std::shared_ptr<T>&& item) : item(item) {}
std::shared_ptr<T> get() override {
assert(item != nullptr);
debug_assert(item != nullptr, "Item is nullptr.");
return item;
}
@ -48,11 +48,11 @@ class Container {
template <class T>
std::shared_ptr<T> resolve() {
auto it = items.find(key<T>());
assert(it != items.end());
debug_assert(it != items.end(), "Key not found.");
// try to cast Holdable* to Item<T>*
auto item = dynamic_cast<Item<T>*>(it->second.get());
assert(item != nullptr);
debug_assert(item != nullptr, "Item is nullptr.");
return item->get();
}

View File

@ -1,5 +1,6 @@
#pragma once
#include "utils/assert.hpp"
#include "utils/option.hpp"
namespace iter {
@ -16,22 +17,22 @@ class RangeIterator {
: value(iter.next()), iter(Option<I>(std::move(iter))) {}
T &operator*() {
assert(value.is_present());
debug_assert(value.is_present(), "No value.");
return value.get();
}
T *operator->() {
assert(value.is_present());
debug_assert(value.is_present(), "No value.");
return &value.get();
}
operator T &() {
assert(value.is_present());
debug_assert(value.is_present(), "No value.");
return value.get();
}
RangeIterator &operator++() {
assert(iter.is_present());
debug_assert(iter.is_present(), "No value.");
value = iter.get().next();
return (*this);
}

View File

@ -1,9 +1,9 @@
#pragma once
#include <ext/aligned_buffer.h>
#include <cassert>
#include <cstring>
#include <utility>
#include "utils/assert.hpp"
// Optional object storage. It maybe has and maybe
// dosent have objet of type T.
@ -85,7 +85,7 @@ class Option {
bool is_present() const { return initialized; }
T &get() noexcept {
assert(initialized);
debug_assert(initialized, "Not initialized.");
return *data._M_ptr();
}
@ -107,7 +107,7 @@ class Option {
}
const T &get() const noexcept {
assert(initialized);
debug_assert(initialized, "Not initialized.");
return *data._M_ptr();
}
@ -148,7 +148,7 @@ class Option {
}
T take() {
assert(initialized);
debug_assert(initialized, "Not initialized.");
initialized = false;
return std::move(*data._M_ptr());
}

View File

@ -1,5 +1,7 @@
#pragma once
#include "utils/assert.hpp"
// Like option just for pointers. More efficent than option.
template <class T>
class OptionPtr {
@ -10,7 +12,7 @@ class OptionPtr {
bool is_present() { return ptr != nullptr; }
T *get() {
assert(is_present());
debug_assert(is_present(), "Data is not present.");
return ptr;
}

View File

@ -38,7 +38,7 @@ class Placeholder {
bool is_initialized() { return initialized; }
T &get() noexcept {
runtime_assert(initialized, "Placeholder object not initialized");
debug_assert(initialized, "Placeholder object not initialized");
return *data._M_ptr();
}
@ -46,7 +46,7 @@ class Placeholder {
* @return const reference to object.
*/
const T &get() const noexcept {
runtime_assert(initialized, "Placeholder object not initialized");
debug_assert(initialized, "Placeholder object not initialized");
return *data._M_ptr();
}

View File

@ -1,9 +1,9 @@
#pragma once
#include <cassert>
#include <cstring>
#include <string>
#include "utils/assert.hpp"
#include "utils/total_ordering.hpp"
#include "utils/total_ordering_with.hpp"
@ -18,17 +18,17 @@ class WeakString {
constexpr WeakString(const char* str, size_t len) : str(str), len(len) {}
const char& operator[](size_t idx) const {
assert(idx < len);
debug_assert(idx < len, "Index not smaller than length.");
return str[idx];
}
const char& front() const {
assert(len > 0);
debug_assert(len > 0, "String is empty.");
return str[0];
}
const char& back() const {
assert(len > 0);
debug_assert(len > 0, "String is empty.");
return str[len - 1];
}

View File

@ -8,7 +8,6 @@
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <cassert>
#include <fstream>
namespace sys {

View File

@ -10,6 +10,7 @@
#include <sys/ioctl.h>
#include <unistd.h>
#include "utils/assert.hpp"
#include "utils/random/xorshift128plus.hpp"
static thread_local Xorshift128plus rnd;
@ -43,7 +44,7 @@ int main(void) {
auto max = std::accumulate(
buckets.begin(), buckets.end(), 0u,
[](auto& acc, auto& x) { return std::max(acc, x.load()); });
assert(max != 0u);
debug_assert(max != 0u, "max is 0.");
std::cout << std::fixed;