Skip to content

Commit

Permalink
One way to deal with the order dependency issue. This is not the best…
Browse files Browse the repository at this point in the history
… way, more like a proof of concept.
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Jul 28, 2023
1 parent 7f8b208 commit eb09c6c
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions include/pybind11/detail/type_caster_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -713,13 +713,28 @@ class type_caster_generic {
// if we can find an exact match (or, for a simple C++ type, an inherited match); if
// so, we can safely reinterpret_cast to the relevant pointer.
if (bases.size() > 1) {
for (auto *base : bases) {
if (no_cpp_mi ? PyType_IsSubtype(base->type, typeinfo->type)
: base->type == typeinfo->type) {
this_.load_value(
reinterpret_cast<instance *>(src.ptr())->get_value_and_holder(base));
return true;
type_info *best_base = nullptr;
if (no_cpp_mi) {
for (auto *base : bases) {
if (PyType_IsSubtype(base->type, typeinfo->type)) {
if (best_base == nullptr
|| PyType_IsSubtype(base->type, best_base->type)) {
best_base = base;
}
}
}
} else {
for (auto *base : bases) {
if (base->type == typeinfo->type) {
best_base = base;
break;
}
}
}
if (best_base != nullptr) {
this_.load_value(
reinterpret_cast<instance *>(src.ptr())->get_value_and_holder(best_base));
return true;
}
}

Expand Down

0 comments on commit eb09c6c

Please sign in to comment.