Skip to content
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

Fix casting of classes with mixed polymorphic inheritance #1084

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dean0x7d
Copy link
Member

Fixes #1080.

When a polymorphic class inherits from a non-polymorphic base, casting between the two adds an offset to account for the vtable pointer. Exposing such a base and derived type to Python currently results in undefined behavior (in practice, a wrong variable value or segfault due to the pointer offset). This PR fixes this by detecting when this kind of mixed inheritance takes place and marks the types as non-simple just like multiple inheritance. Everything else is taken care of by the existing non-simple type caster path which accounts for offset bases.

One problem is that this fix requires a modification of the internals ABI (bumped PYBIND11_INTERNALS_VERSION), so it's not a candidate for v2.2.1. There are currently ways to work around this (I'll update the issue) so that could work for now and the fix could be merged for v2.3.

@dean0x7d dean0x7d added this to the v2.3 milestone Sep 13, 2017
A polymorphic class can inherit from a non-polymorphic base.
@dean0x7d
Copy link
Member Author

Fixed the MSVC linker error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect binding when the derived class is polymorphic and the base is not
1 participant