File tree Expand file tree Collapse file tree 1 file changed +21
-6
lines changed Expand file tree Collapse file tree 1 file changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -713,13 +713,28 @@ class type_caster_generic {
713713 // if we can find an exact match (or, for a simple C++ type, an inherited match); if
714714 // so, we can safely reinterpret_cast to the relevant pointer.
715715 if (bases.size () > 1 ) {
716- for (auto *base : bases) {
717- if (no_cpp_mi ? PyType_IsSubtype (base->type , typeinfo->type )
718- : base->type == typeinfo->type ) {
719- this_.load_value (
720- reinterpret_cast <instance *>(src.ptr ())->get_value_and_holder (base));
721- return true ;
716+ type_info *best_base = nullptr ;
717+ if (no_cpp_mi) {
718+ for (auto *base : bases) {
719+ if (PyType_IsSubtype (base->type , typeinfo->type )) {
720+ if (best_base == nullptr
721+ || PyType_IsSubtype (base->type , best_base->type )) {
722+ best_base = base;
723+ }
724+ }
722725 }
726+ } else {
727+ for (auto *base : bases) {
728+ if (base->type == typeinfo->type ) {
729+ best_base = base;
730+ break ;
731+ }
732+ }
733+ }
734+ if (best_base != nullptr ) {
735+ this_.load_value (
736+ reinterpret_cast <instance *>(src.ptr ())->get_value_and_holder (best_base));
737+ return true ;
723738 }
724739 }
725740
You can’t perform that action at this time.
0 commit comments