-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Support pointer-to-member-function in def_buffer #858
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
Conversation
The inclusion of |
The use of An overload that accepts a member function pointer and converts it into lambda, on the other hand, could work, and shouldn't be noticeably more code. Also, |
Ok, I'll give it another go. I guess the simplest thing then would be to provide an overload of |
I've reworked it and changed the PR title to reflect the new version. I haven't flattened the history at this point. Do you think it is also worth adding an overload for pointer to data member (so that the class can initialise a buffer_info member when constructed and then we just pass a pointer to that member to def_buffer? |
The pypy build is crashing. Is that expected due to https://bitbucket.org/pypy/pypy/issues/2444 (the other to_python test in the file is disabled because of that, but I don't want to do the same here until someone can confirm that I'm not just hiding a real bug, particularly since that pypy bug seems into indicate a leak rather than a double-free. |
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.
Should be OK to skip the test on PyPy. Looks like the same issue as the existing test. The rest looks good to me. I've just noted a minor brace style issue.
tests/test_buffers.cpp
Outdated
@@ -74,6 +74,34 @@ class Matrix { | |||
float *m_data; | |||
}; | |||
|
|||
struct PTMFBuffer | |||
{ |
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.
Brace style: same line.
tests/test_buffers.cpp
Outdated
}; | ||
|
||
class ConstPTMFBuffer | ||
{ |
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.
Same.
Fixed, thanks. |
Looks good to me. |
Can you squash the changes and update the commit messages into a single commit? |
Sure. Should I do that as a force-push to the branch? |
Yup. |
Closes pybind#857, by adding overloads to def_buffer that match pointers to member functions and wrap them in lambdas.
Done, and also added the marker to disable the new test in PyPy. Once Travis and Appveyor are happy I think it should be good to go. |
Looks like the last appveyor test got stuck, but all the rest passed so this is good to go. |
Closes #857. Instead of calling the function object directly, it wraps
it in std::bind and then immediately calls that. This is a poor-man's
form of std::invoke (not available in C++11 or C++14).