Skip to content

Commit

Permalink
Apply equivalent of fbffea6 in smart_holder_type_casters.h
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Nov 8, 2023
1 parent 1410630 commit 5de9997
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions include/pybind11/detail/smart_holder_type_casters.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,25 @@ class modified_type_caster_generic_load_impl {
// 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) {
std::vector<type_info *> matching_bases;
for (auto *base : bases) {
if (no_cpp_mi ? PyType_IsSubtype(base->type, typeinfo->type)
: base->type == typeinfo->type) {
this_.load_value_and_holder(
reinterpret_cast<instance *>(src.ptr())->get_value_and_holder(base));
loaded_v_h_cpptype = base->cpptype;
reinterpret_cast_deemed_ok = true;
return true;
matching_bases.push_back(base);
}
}
if (!matching_bases.empty()) {
if (matching_bases.size() > 1) {
matching_bases.push_back(const_cast<type_info *>(typeinfo));
all_type_info_check_for_divergence(matching_bases);
}
this_.load_value_and_holder(
reinterpret_cast<instance *>(src.ptr())->get_value_and_holder(
matching_bases[0]));
loaded_v_h_cpptype = matching_bases[0]->cpptype;
reinterpret_cast_deemed_ok = true;
return true;
}
}

// Case 2c: C++ multiple inheritance is involved and we couldn't find an exact type
Expand Down

0 comments on commit 5de9997

Please sign in to comment.