mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-11-20 06:56:27 -05:00
Add more asserts
This commit is contained in:
parent
624f82b400
commit
184464f60a
3 changed files with 42 additions and 6 deletions
|
|
@ -30,3 +30,27 @@ namespace assert
|
|||
struct StaticAssert<true>
|
||||
{};
|
||||
}
|
||||
|
||||
#ifdef NDEBUG
|
||||
|
||||
#define ASSERT_NOT_NULL(ptr)
|
||||
|
||||
#else
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#define ASSERT_NOT_NULL(ptr) \
|
||||
do { \
|
||||
auto *_tmp = (ptr); \
|
||||
if((_tmp) == nullptr) { \
|
||||
std::cerr << "ASSERT_NOT_NULL failed\n" \
|
||||
<< " expression: \"" #ptr "\"\n" \
|
||||
<< " file: " << __FILE__ << "\n" \
|
||||
<< " line: " << __LINE__ << "\n" \
|
||||
<< " function: " << __func__ << "\n"; \
|
||||
assert((_tmp) != nullptr); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ inline
|
|||
uint64_t
|
||||
DirInfo::to_fh() const
|
||||
{
|
||||
ASSERT_NOT_NULL(this);
|
||||
return reinterpret_cast<u64>(this);
|
||||
}
|
||||
|
||||
|
|
@ -49,5 +50,11 @@ inline
|
|||
DirInfo*
|
||||
DirInfo::from_fh(const u64 fh_)
|
||||
{
|
||||
return reinterpret_cast<DirInfo*>(fh_);
|
||||
DirInfo *rv;
|
||||
|
||||
rv = reinterpret_cast<DirInfo*>(fh_);
|
||||
|
||||
ASSERT_NOT_NULL(rv);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "assert.hpp"
|
||||
#include "branch.hpp"
|
||||
#include "fh.hpp"
|
||||
#include "fs_path.hpp"
|
||||
|
|
@ -42,7 +43,6 @@ public:
|
|||
branch(*branch_),
|
||||
direct_io(direct_io_)
|
||||
{
|
||||
mutex_init(mutex);
|
||||
}
|
||||
|
||||
FileInfo(const int fd_,
|
||||
|
|
@ -54,7 +54,6 @@ public:
|
|||
branch(branch_),
|
||||
direct_io(direct_io_)
|
||||
{
|
||||
mutex_init(mutex);
|
||||
}
|
||||
|
||||
FileInfo(const FileInfo *fi_)
|
||||
|
|
@ -63,7 +62,6 @@ public:
|
|||
branch(fi_->branch),
|
||||
direct_io(fi_->direct_io)
|
||||
{
|
||||
mutex_init(mutex);
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
@ -73,13 +71,14 @@ public:
|
|||
int fd;
|
||||
Branch branch;
|
||||
u32 direct_io:1;
|
||||
mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
Mutex mutex;
|
||||
};
|
||||
|
||||
inline
|
||||
u64
|
||||
FileInfo::to_fh() const
|
||||
{
|
||||
ASSERT_NOT_NULL(this);
|
||||
return reinterpret_cast<u64>(this);
|
||||
}
|
||||
|
||||
|
|
@ -87,5 +86,11 @@ inline
|
|||
FileInfo*
|
||||
FileInfo::from_fh(const u64 fh_)
|
||||
{
|
||||
return reinterpret_cast<FileInfo*>(fh_);
|
||||
FileInfo *rv;
|
||||
|
||||
rv = reinterpret_cast<FileInfo*>(fh_);
|
||||
|
||||
ASSERT_NOT_NULL(rv);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue