mdbx++: rework/fix move-assignment operators for "managed" classes.

Replaces https://github.com/erthink/libmdbx/pull/270 and previous commit.
Fixed a half of https://github.com/torquem-ch/silkworm/issues/575.
This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2022-02-23 18:41:22 +03:00
parent 3c574fca99
commit 464886ab61

View File

@ -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;
@ -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;
@ -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_); }