Skip to content

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 dean0x7d force-pushed the fix-mixed-inheritance branch from 5b642fc to 2ce3b6c Compare September 16, 2017 10:55
@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