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

For c2py of stl types take argument by value and move elements #35

Closed
wants to merge 2 commits into from

Conversation

Wentzell
Copy link
Member

@Wentzell Wentzell commented Jun 5, 2020

No description provided.

@Wentzell Wentzell requested a review from parcollet June 5, 2020 12:48
@Wentzell Wentzell force-pushed the PR_C2PY_BY_VALUE branch from 01cd04c to b6b3393 Compare June 5, 2020 12:53
@Wentzell
Copy link
Member Author

Wentzell commented Jun 5, 2020

Passes all triqs + cthyb tests

@Wentzell
Copy link
Member Author

Wentzell commented Jun 5, 2020

This fixes TRIQS/triqs#755

Copy link
Member

@parcollet parcollet left a comment

Choose a reason for hiding this comment

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

Started the review.
Several fine points to discuss, not completely obvious to me

}
static PyObject *c2py(std::optional<T> op) {
if (!bool(op)) Py_RETURN_NONE;
return conv::c2py(std::move(*op));
Copy link
Member

Choose a reason for hiding this comment

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

Isn't rather
std::move(op).value() or *(std::move(op)) [ the second is somewhat less clear]
you have to move the op itself I think.. Not sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

There should be no problem with the syntax.

std::move(*op)

We invoke

T& operator*() &;

and then move from the T&.

pyref x1 = py_converter<T1>::c2py(std::get<0>(p));
pyref x2 = py_converter<T2>::c2py(std::get<1>(p));
static PyObject *c2py(std::pair<T1, T2> p) {
pyref x1 = py_converter<std::decay_t<T1>>::c2py(std::move(std::get<0>(p)));
Copy link
Member

Choose a reason for hiding this comment

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

Same question:
I would have said :
std::get<0>(std::move(p))
move p first, then using (4) in https://en.cppreference.com/w/cpp/utility/pair/get

Copy link
Member Author

Choose a reason for hiding this comment

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

So with std::get<1>(std::move(p)) we then use a p which has already been moved from? Isn't this something we want to avoid at all cost? Is this well-defined?

Copy link
Member Author

Choose a reason for hiding this comment

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

Even if its safe this will most definitely trigger false-positives for static analyzers / warnings that warn about use after move!?

@Wentzell
Copy link
Member Author

Wentzell commented Jun 5, 2020

@parcollet There is in fact one more aspect about this PR that needs to be discussed. We will no longer be able to e.g. convert a member std::vector<T> as a np.ndarray viewing the data.

@Wentzell
Copy link
Member Author

Most points here have been addressed. The Pull Request #37 is in fact an extension of this PR, so discussion should be continued there. I will close this as a duplicate.

@Wentzell Wentzell closed this Jun 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants