-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Returning new instances of a derived type via a virtual factory function fails to keep the derived type alive #1774
Comments
I believe this may be the 5th issue that tracks this problem :P Related issues:
I've worked around this in our fork of While my patch above works and is conservative for object lifetime, it may be costly (in object code and possibly runtime performance). Also, the above code is strongly coupled to also supporting Simpler workarounds, suggested in the aforementioned issues, point towards making something like As far as issue tracking goes, I'll try to see which thread has the best recommendations, and see if we can consolidate the current duplicates. EDIT (2020/06/17): |
Ahh, sorry about the duplicate. Yeah, I dug into it in a debugger over the weekend a little bit - I was thinking something along the lines of making the trampoline class store a handle to the underlying python object would be a necessity. |
@yeswalrus what is the reproducible example, exactly? Thanks! |
Closing this in lieu of #1333 for tracking. |
Given a virtual function meant to return new instances of a type via a pointer to a base class, and a derived type declared in python, the return value cast won't keep the python object alive, resulting in a failure when attempting to call the virtual method on the new instance via the pointer. Because this function is called from c++, the return value policy has no effect.
Reproducible example code
https://github.com/yeswalrus/pybind11/tree/virtual-vector-return
The text was updated successfully, but these errors were encountered: