Browse Source

Add more asserts

pull/1502/merge
Antonio SJ Musumeci 2 weeks ago
committed by trapexit
parent
commit
099ce2d91d
  1. 24
      src/assert.hpp
  2. 9
      src/dirinfo.hpp
  3. 15
      src/fileinfo.hpp

24
src/assert.hpp

@ -30,3 +30,27 @@ namespace assert
struct StaticAssert<true> 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

9
src/dirinfo.hpp

@ -42,6 +42,7 @@ inline
uint64_t uint64_t
DirInfo::to_fh() const DirInfo::to_fh() const
{ {
ASSERT_NOT_NULL(this);
return reinterpret_cast<u64>(this); return reinterpret_cast<u64>(this);
} }
@ -49,5 +50,11 @@ inline
DirInfo* DirInfo*
DirInfo::from_fh(const u64 fh_) DirInfo::from_fh(const u64 fh_)
{ {
return reinterpret_cast<DirInfo*>(fh_);
DirInfo *rv;
rv = reinterpret_cast<DirInfo*>(fh_);
ASSERT_NOT_NULL(rv);
return rv;
} }

15
src/fileinfo.hpp

@ -18,6 +18,7 @@
#pragma once #pragma once
#include "assert.hpp"
#include "branch.hpp" #include "branch.hpp"
#include "fh.hpp" #include "fh.hpp"
#include "fs_path.hpp" #include "fs_path.hpp"
@ -42,7 +43,6 @@ public:
branch(*branch_), branch(*branch_),
direct_io(direct_io_) direct_io(direct_io_)
{ {
mutex_init(mutex);
} }
FileInfo(const int fd_, FileInfo(const int fd_,
@ -54,7 +54,6 @@ public:
branch(branch_), branch(branch_),
direct_io(direct_io_) direct_io(direct_io_)
{ {
mutex_init(mutex);
} }
FileInfo(const FileInfo *fi_) FileInfo(const FileInfo *fi_)
@ -63,7 +62,6 @@ public:
branch(fi_->branch), branch(fi_->branch),
direct_io(fi_->direct_io) direct_io(fi_->direct_io)
{ {
mutex_init(mutex);
} }
public: public:
@ -73,13 +71,14 @@ public:
int fd; int fd;
Branch branch; Branch branch;
u32 direct_io:1; u32 direct_io:1;
mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
Mutex mutex;
}; };
inline inline
u64 u64
FileInfo::to_fh() const FileInfo::to_fh() const
{ {
ASSERT_NOT_NULL(this);
return reinterpret_cast<u64>(this); return reinterpret_cast<u64>(this);
} }
@ -87,5 +86,11 @@ inline
FileInfo* FileInfo*
FileInfo::from_fh(const u64 fh_) 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…
Cancel
Save