-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add note about module destructors #733
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
virtuald
commented
Mar 16, 2017
- Technique provided by @jagerman
- Fixes Documentation: module destructor #638
- Technique provided by @jagerman - Fixes pybind#638
This looks good. Quick question: can't the unused value simply be |
If I recall correctly, Python won't allow a nullptr for it. Of course, if you have some meaningful value, you should use it instead. |
Would |
Looking at the API docs for capsule:
Unless someone tries to get the pointer, I don't believe the API will ever try to dereference it, so in theory you could do |
Instead of a static local variable, how about amending the example to: // the capsule needs a non-null pointer to reference; if you don't have anything better, create a simple one:
int *data = new int(123);
py::capsule cleanup(data, [](PyObject * capsule) {
int *data = PyCapsule_GetPointer(capsule, nullptr);
// do cleanup here -- this function is called with the GIL held
delete data;
}); which also suggests an obvious way of how to pass data into the capsule. You should also add a note that |
I was surprised at how inelegant our way of dealing with I submitted a separate PR to deal with this before we document the API and then can't change it anymore #752. |
Can you update the PR to take the future changes into account? Thanks! |
closing in favor of #752 |
* nicer py::capsule destructor mechanism * added destructor-only version of capsule & tests * added documentation for module destructors (fixes #733)