Fix casting of classes with mixed polymorphic inheritance #1084
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 (bumpedPYBIND11_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.