Uh oh!
There was an error while loading. Please reload this page.
Add note about module destructors - #733
Conversation
virtuald
commented
Mar 16, 2017
- Technique provided by @jagerman
- FixesDocumentation: module destructor #638
- Technique provided by @jagerman - Fixespybind#638
wjakob
commented
Mar 16, 2017
This looks good. Quick question: can't the unused value simply be |
jagerman
commented
Mar 16, 2017
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. |
dean0x7d
commented
Mar 16, 2017
Would |
virtuald
commented
Mar 16, 2017
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 = newint(123);
py::capsule cleanup(data, [](PyObject * capsule) {
int *data = PyCapsule_GetPointer(capsule, nullptr);
// do cleanup here -- this function is called with the GIL helddelete data;
});which also suggests an obvious way of how to pass data into the capsule. You should also add a note that |
wjakob
commented
Mar 20, 2017
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. |
wjakob
commented
Mar 20, 2017
Can you update the PR to take the future changes into account? Thanks! |
wjakob
commented
Mar 22, 2017
closing in favor of #752 |
* nicer py::capsule destructor mechanism * added destructor-only version of capsule & tests * added documentation for module destructors (fixes#733)