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

made closure param mutable #677

Merged
merged 11 commits into from
Sep 12, 2024
Merged

made closure param mutable #677

merged 11 commits into from
Sep 12, 2024

Conversation

milyin
Copy link
Contributor

@milyin milyin commented Sep 12, 2024

Fix related to eclipse-zenoh/zenoh#1372

Preparation for further making z_take operation for z_loaned_xxx_t* callback parameters. This will allow user to take ownership of data passed to callback without clone operation.
This update is unsafe for C++, as in the zenoh-cpp it's already possible to perform std::move as soon as the callback parameter is not const. But in this update this is unsafe as on the rust side the non-owned objects are actually passed to callback. I.e. on rust side it's now &mut Sample represented as z_loaned_sample_t*. This means that it's prohibited at this moment to convert z_loaned_sample_t* to z_owned_sample_t* (which is Option<Sample> on rust side). But zenoh-cpp is built on assumption that it's safe to do this conversion because until this moment it was not possible to get z_loaned_xxx_t* reference directly to object other than z_owned_xxx_t.

The safety correction will be made in separate update to accelerate C++ API updating and to make verifying of safety update easier

Copy link

PR missing one of the required labels: {'enhancement', 'documentation', 'new feature', 'dependencies', 'internal', 'breaking-change', 'bug'}

Copy link

PR missing one of the required labels: {'documentation', 'dependencies', 'breaking-change', 'enhancement', 'internal', 'new feature', 'bug'}

@milyin milyin added the enhancement New feature or request label Sep 12, 2024
@@ -1927,7 +1927,7 @@ const struct z_loaned_closure_sample_t *z_closure_sample_loan(const struct z_own
#if defined(UNSTABLE)
ZENOHC_API
void z_closure_zid_call(const struct z_loaned_closure_zid_t *closure,
const z_id_t *z_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

z_id_t is non-owned object, there is no benefit in having it non-const, also leads to questions whether the user is in the right to call free on it ?

@milyin milyin marked this pull request as ready for review September 12, 2024 15:29
@Mallets Mallets merged commit 98f1521 into main Sep 12, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants