Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Commit

Permalink
mdbx++: rework/fix move-assignment operators for "managed" classes.
Browse files Browse the repository at this point in the history
Replaces #270 and previous commit.
Fixed a half of erigontech/silkworm#575.
  • Loading branch information
erthink committed Feb 23, 2022
1 parent 3c574fc commit 464886a
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions mdbx.h++
Original file line number Diff line number Diff line change
Expand Up @@ -3453,7 +3453,15 @@ public:
void close(bool dont_sync = false);

env_managed(env_managed &&) = default;
using inherited::operator=;
env_managed &operator=(env_managed &&other) {
if (MDBX_UNLIKELY(handle_))
MDBX_CXX20_UNLIKELY {
assert(handle_ != other.handle_);
close();
}
inherited::operator=(std::move(other));
return *this;
}
env_managed(const env_managed &) = delete;
env_managed &operator=(const env_managed &) = delete;
virtual ~env_managed() noexcept;
Expand Down Expand Up @@ -3744,7 +3752,15 @@ class LIBMDBX_API_TYPE txn_managed : public txn {
public:
MDBX_CXX11_CONSTEXPR txn_managed() noexcept = default;
txn_managed(txn_managed &&) = default;
using inherited::operator=;
txn_managed &operator=(txn_managed &&other) {
if (MDBX_UNLIKELY(handle_))
MDBX_CXX20_UNLIKELY {
assert(handle_ != other.handle_);
abort();
}
inherited::operator=(std::move(other));
return *this;
}
txn_managed(const txn_managed &) = delete;
txn_managed &operator=(const txn_managed &) = delete;
~txn_managed() noexcept;
Expand Down Expand Up @@ -3939,7 +3955,16 @@ public:
void close();

cursor_managed(cursor_managed &&) = default;
using inherited::operator=;
cursor_managed &operator=(cursor_managed &&other) {
if (MDBX_UNLIKELY(handle_))
MDBX_CXX20_UNLIKELY {
assert(handle_ != other.handle_);
close();
}
inherited::operator=(std::move(other));
return *this;
}

cursor_managed(const cursor_managed &) = delete;
cursor_managed &operator=(const cursor_managed &) = delete;
~cursor_managed() noexcept { ::mdbx_cursor_close(handle_); }
Expand Down

0 comments on commit 464886a

Please sign in to comment.