@@ -908,8 +908,10 @@ template <typename type> class type_caster_base : public type_caster_generic {
908
908
make_copy_constructor (src), make_move_constructor (src));
909
909
}
910
910
911
- static handle cast_holder (const itype *src, const void *holder) {
911
+ static handle cast_holder (const itype *src, const void *holder, const std::type_info &holder_type ) {
912
912
auto st = src_and_type (src);
913
+ if (!same_type (*st.second ->holder_type , holder_type))
914
+ throw cast_error (std::string (" Unexpected holder type: " ) + holder_type.name () + " , expected: " + st.second ->holder_type ->name ());
913
915
return type_caster_generic::cast (
914
916
st.first , return_value_policy::take_ownership, {}, st.second ,
915
917
nullptr , nullptr , holder);
@@ -1516,7 +1518,7 @@ struct copyable_holder_caster : public type_caster_base<type> {
1516
1518
1517
1519
static handle cast (const holder_type &src, return_value_policy, handle) {
1518
1520
const auto *ptr = holder_helper<holder_type>::get (src);
1519
- return type_caster_base<type>::cast_holder (ptr, & src);
1521
+ return type_caster_base<type>::cast_holder (ptr, std::addressof ( src), typeid (holder_type) );
1520
1522
}
1521
1523
1522
1524
protected:
@@ -1528,6 +1530,8 @@ struct copyable_holder_caster : public type_caster_base<type> {
1528
1530
1529
1531
bool load_value (value_and_holder &&v_h) {
1530
1532
if (v_h.holder_constructed ()) {
1533
+ if (!same_type (*typeinfo->holder_type , typeid (holder_type)))
1534
+ throw cast_error (std::string (" Unexpected holder type: " ) + typeid (holder_type).name () + " , expected: " + typeinfo->holder_type ->name ());
1531
1535
value = v_h.value_ptr ();
1532
1536
holder = v_h.template holder <holder_type>();
1533
1537
return true ;
@@ -1574,7 +1578,7 @@ struct move_only_holder_caster {
1574
1578
1575
1579
static handle cast (holder_type &&src, return_value_policy, handle) {
1576
1580
auto *ptr = holder_helper<holder_type>::get (src);
1577
- return type_caster_base<type>::cast_holder (ptr, std::addressof (src));
1581
+ return type_caster_base<type>::cast_holder (ptr, std::addressof (src), typeid (holder_type) );
1578
1582
}
1579
1583
static constexpr auto name = type_caster_base<type>::name;
1580
1584
};
0 commit comments