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

Pass callback and user data by value in realm_mongo_collection_<func> #6307

Merged
merged 1 commit into from
Feb 16, 2023

Conversation

desistefanova
Copy link
Contributor

@desistefanova desistefanova commented Feb 15, 2023

Fixes the C-API functions like realm_mongo_collection_find, realm_mongo_collection_find_one and so on.
The callback can not be found if its pointer is passed by reference.
It was not handled because the tests in realm-core don't call these methods with passing callbacks as arguments.
Related to the implementation in realm/realm-dart#1162

What, How & Why?

☑️ ToDos

  • [ ] 📝 Changelog update
  • [ ] 🚦 Tests (or not relevant)
  • [ ] C-API, if public C++ API changed.

@@ -948,7 +948,7 @@ RLM_API bool realm_mongo_collection_find(realm_mongodb_collection_t* collection,
return wrap_err([&] {
collection->find_bson(convert_to_bson<bson::BsonDocument>(filter_ejson),
to_mongodb_collection_find_options(options),
[&](util::Optional<bson::Bson> bson, util::Optional<AppError> app_error) {
[=](util::Optional<bson::Bson> bson, util::Optional<AppError> app_error) {
Copy link
Member

Choose a reason for hiding this comment

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

Only a minimal thing, I think the only thing you need to capture by copy is the callback, the rest of the data can be passed by reference. Although in 99% of the case, we are copying a ptr (thus equivalent to passing the arguments by reference), for realm_string_t filter_ejson we will be copying sizeof(ptr) + sizeof(size_t) bytes.
Not a big issue, since the amount of data copied will always be constant.

Copy link
Contributor Author

@desistefanova desistefanova Feb 15, 2023

Choose a reason for hiding this comment

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

I need to pass by value data, delete_data and callback. Otherwise when I receive the callback I can't access the data object. I can change it to [data, delete_data, callback] instead of [=], if you say that it is better.

@nicola-cab nicola-cab self-requested a review February 16, 2023 13:43
Copy link
Member

@nicola-cab nicola-cab left a comment

Choose a reason for hiding this comment

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

LGTM

@desistefanova desistefanova merged commit 006660c into master Feb 16, 2023
@desistefanova desistefanova deleted the ds/realm_mongo_collection_byvalue branch February 16, 2023 13:46
@kiburtse kiburtse mentioned this pull request Mar 3, 2023
3 tasks
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants