@@ -137,6 +137,7 @@ class type_caster_generic {
137
137
138
138
PYBIND11_NOINLINE static handle cast (const void *_src, return_value_policy policy, handle parent,
139
139
const std::type_info *type_info,
140
+ const std::type_info *type_info_backup,
140
141
void *(*copy_constructor)(const void *),
141
142
const void *existing_holder = nullptr) {
142
143
void *src = const_cast <void *>(_src);
@@ -153,6 +154,11 @@ class type_caster_generic {
153
154
return handle ((PyObject *) it_instance->second ).inc_ref ();
154
155
155
156
auto it = internals.registered_types_cpp .find (std::type_index (*type_info));
157
+ if (it == internals.registered_types_cpp .end ()) {
158
+ type_info = type_info_backup;
159
+ it = internals.registered_types_cpp .find (std::type_index (*type_info));
160
+ }
161
+
156
162
if (it == internals.registered_types_cpp .end ()) {
157
163
std::string tname = type_info->name ();
158
164
detail::clean_type_id (tname);
@@ -213,11 +219,11 @@ template <typename type, typename Enable = void> class type_caster : public type
213
219
static handle cast (const type &src, return_value_policy policy, handle parent) {
214
220
if (policy == return_value_policy::automatic)
215
221
policy = return_value_policy::copy;
216
- return type_caster_generic:: cast (&src, policy, parent, & typeid (type), ©_constructor );
222
+ return cast (&src, policy, parent);
217
223
}
218
224
219
225
static handle cast (const type *src, return_value_policy policy, handle parent) {
220
- return type_caster_generic::cast (src, policy, parent, &typeid (type), ©_constructor);
226
+ return type_caster_generic::cast (src, policy, parent, src ? & typeid (*src) : nullptr , &typeid (type), ©_constructor);
221
227
}
222
228
223
229
template <typename T> using cast_op_type = pybind11::detail::cast_op_type<T>;
@@ -664,7 +670,9 @@ template <typename type, typename holder_type> class type_caster_holder : public
664
670
665
671
static handle cast (const holder_type &src, return_value_policy policy, handle parent) {
666
672
return type_caster_generic::cast (
667
- src.get (), policy, parent, &typeid (type), ©_constructor, &src);
673
+ src.get (), policy, parent,
674
+ src.get () ? &typeid (*src.get ()) : nullptr , &typeid (type),
675
+ ©_constructor, &src);
668
676
}
669
677
670
678
protected:
0 commit comments