-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[BUG]: Pure Virtual Function Call When Creating Python-derived Instance via C++ Callback #5560
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
Comments
Compile: c++ -O3 -Wall -shared -std=c++11 -fPIC Python 3.9.21 (main, Mar 12 2025, 20:46:55) |
I change my class using trampoline_self_life_support, but it still "RuntimeError: Tried to call pure virtual function "A::go"" |
@rwgk Very thanks for your work! But for this issue type, can you support it! I find many this type issue question. |
I solve it!
|
Required prerequisites
What version (or hash if on master) of pybind11 are you using?
d28904f
Problem description
When creating a Python-derived class from a C++ base class (with a pure virtual function) via a callback, the Python override is not invoked. Instead, the program attempts to call the pure virtual function (A::go), resulting in a runtime error and segmentation fault.
Expected Behavior:
The overridden Python method (e.g., PyDerivedA.go) should be called, producing the expected output (e.g., "PyDerivedA go called!").
Actual Behavior:
The callback returns an instance of the Python-derived class, but due to improper conversion, the object loses its Python override bindings. When MyRun::Run is executed, it calls the pure virtual function A::go, triggering a runtime error and segmentation fault.
Reproducible example code
Is this a regression? Put the last known working version here if it is.
not a regression
The text was updated successfully, but these errors were encountered: