Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls: Restructure gnutls_datum move operator, adding construstor #2214

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/net/tls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,16 @@ struct gnutls_datum : public gnutls_datum_t {
size = 0;
}
gnutls_datum(const gnutls_datum&) = delete;
gnutls_datum(gnutls_datum&& d)
{
data = std::exchange(d.data, nullptr);
size = std::exchange(d.size, 0);
}
gnutls_datum& operator=(gnutls_datum&& other) {
if (this == &other) {
return *this;
}
if (data != nullptr) {
::gnutls_free(data);
if (this != &other) {
this->~gnutls_datum();
new (this) gnutls_datum(std::move(other));
Copy link
Contributor

@tchaikov tchaikov Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, i understand the motivation. but, personally, i am not in favor of calling destructor manually and using placement new unless really necessary. they hurt the readability. and the new move-ctor is never used. i'd defer the review to seastar maintainers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only motivation is that we tend to use this pattern elsewhere in seastar etc. Plus it is delegating operations. :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see. i just don't really like this pattern, despite that it is repeating itself in seastar =( . and yeah, it reuses the dtor in a very obvious way.. but still.. i just cannot convince myself that i like it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm at fault for introducing it but I now regret it, it's likely not totally safe wrt the standard.

}
data = std::exchange(other.data, nullptr);
size = std::exchange(other.size, 0);
return *this;
}
~gnutls_datum() {
Expand Down