-
Notifications
You must be signed in to change notification settings - Fork 165
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
Unit test for checking if table view from link list can be sync'ed #1390
Conversation
LangBindHelper::promote_to_write(sg, *hist); | ||
TableRef table1 = g.get_table("table1"); | ||
TableView view = table1->where().find_all(); | ||
Query query = static_cast<Query>(view.get_query()).get_table()->where(table1->get_linklist(0, 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static_cast, then assignment? Is core supposed to support this use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Struck me as suspicious too — a lot of methods on Query
return Query&
, so this is at high risk of operating on either temporaries or modifying the underlying Query for the TableView.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TableView::get_query
returns a const Query
, which this static_cast
casts away. An equivalent form would be:
Query query = const_cast<Query*>(&view.get_query())->get_table()->where(table1->get_linklist(0, 0));
Whether that's legal or not is another matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It must be copied then, because afaik static_cast
cannot touch const
ness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, ::get_table()
is not const.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static_cast
indeed cannot cast away constness. So this line is correct, even if it's written in a convoluted way. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should change our API to minimize this kind of usage if possible. Why is there even a get_query() on a TableView?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to what @finnschiermer said
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link query on a table view.
Why do you need to use get_query on the table view. Do you usually do that? |
You can't query a table view directly so you can to create a new query using the table view as a filter. Instead if |
Java code is: To minimize the code, there are no conditions now after |
@kneth I found the real cause of the crash now (it wasn't a bug in move_last_over() anyway). It occurs because your query is refering to a LinkList that you deleted earlier:
And sure, the code could be beautified and get_query() is also error prone to use (TableView may depend on a chain of further older queries, or may originate from something else than a Query, etc, etc). |
@rrrlasse Why does |
@rrrlasse Will you create an issue about |
I have created #1413 and closing this one. |
Translation of realm/realm-java#1886 to core/C++ that is, it is as close to how the Java binding is implemented as possible. A seg. fault happens in
sync_if_needed()
.Question to @realm/core: Is the Java binding doing something wrong?
Fun fact: Merging in #1392 does not resolved the issue.