Skip to content
Merged
Changes from 3 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
34 changes: 19 additions & 15 deletions include/zenoh/api/bytes.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ class Bytes : public Owned<::z_owned_bytes_t> {
template <class Allocator>
Bytes(std::vector<uint8_t, Allocator>&& v) : Bytes() {
std::vector<uint8_t, Allocator>* ptr = new std::vector<uint8_t, Allocator>(std::move(v));
auto d = [p = ptr]() mutable { delete p; };
using D = decltype(d);
using Dval = std::remove_reference_t<D>;
using DroppableType = typename detail::closures::Droppable<Dval>;
auto drop = DroppableType::into_context(std::move(d));
struct VectorDeleter {
std::vector<uint8_t, Allocator>* ptr;
void operator()() { delete ptr; };
};
using DroppableType = typename detail::closures::Droppable<VectorDeleter>;
auto drop = DroppableType::into_context(std::move(VectorDeleter({.ptr = ptr})));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is not a valid C++17 code, aggregate initialization is only available, starting from C++20. Just into_context(std::move(VectorDeleter{ptr})) (or even just into_context(VectorDeleter{ptr})) should be good enough, the question stays though why std::move on lambda fails ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Damn, your are right this is also an c++20 feature...

I honestly don't know why the move fails on msvc. From my point of view it is valid, and gcc and clang are fine with it...
The compile error is also not really helpful on this one.. (see ros2/rmw_zenoh#968 (comment) for details).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hm, I'm wondering will something simple like auto&& d = [p = ptr]() mutable { delete p; }; solve the problem ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

just tried it, nope...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The ros2 CI has just enforced c++20 as minimum, so now the compiler error is also visible there in english :
https://ci.ros2.org/job/ci_windows/27622/console

Any more ideas on what to try ?

::z_bytes_from_buf(interop::as_owned_c_ptr(*this), ptr->data(), ptr->size(),
detail::closures::_zenoh_drop_with_context, drop);
}
Expand All @@ -89,11 +90,12 @@ class Bytes : public Owned<::z_owned_bytes_t> {
/// @brief Construct by moving a string.
Bytes(std::string&& v) : Bytes() {
std::string* ptr = new std::string(std::move(v));
auto d = [p = ptr]() mutable { delete p; };
using D = decltype(d);
using Dval = std::remove_reference_t<D>;
using DroppableType = typename detail::closures::Droppable<Dval>;
auto drop = DroppableType::into_context(std::move(d));
struct StringDeleter {
std::string* ptr;
void operator()() { delete ptr; }
};
using DroppableType = typename detail::closures::Droppable<StringDeleter>;
auto drop = DroppableType::into_context(std::move(StringDeleter({.ptr = ptr})));
::z_bytes_from_buf(interop::as_owned_c_ptr(*this), reinterpret_cast<uint8_t*>(ptr->data()), ptr->size(),
detail::closures::_zenoh_drop_with_context, drop);
}
Expand All @@ -108,11 +110,13 @@ class Bytes : public Owned<::z_owned_bytes_t> {
Bytes(uint8_t* ptr, size_t len, Deleter deleter) : Bytes() {
static_assert(std::is_invocable_r<void, Deleter, uint8_t*>::value,
"deleter should be callable with the following signature: void deleter(uint8_t* data)");
auto d = [p = ptr, del = std::move(deleter)]() mutable { del(p); };
using D = decltype(d);
using Dval = std::remove_reference_t<D>;
using DroppableType = typename detail::closures::Droppable<Dval>;
auto drop = DroppableType::into_context(std::move(d));
struct CustomDeleter {
uint8_t* ptr;
Deleter deleter;
void operator()() { deleter(ptr); }
};
using DroppableType = typename detail::closures::Droppable<CustomDeleter>;
auto drop = DroppableType::into_context(std::move(CustomDeleter({.ptr = ptr, .deleter = std::move(deleter)})));
::z_bytes_from_buf(interop::as_owned_c_ptr(*this), ptr, len, detail::closures::_zenoh_drop_with_context, drop);
}

Expand Down