Skip to content

Commit eb09c6c

Browse files
committed
One way to deal with the order dependency issue. This is not the best way, more like a proof of concept.
1 parent 7f8b208 commit eb09c6c

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

include/pybind11/detail/type_caster_base.h

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)