Skip to content

Commit fa1bfb2

Browse files
author
Wenzel Jakob
committed
do a fallback search over types to handle incompatible std::type_info* across module boundaries (fixes issue #4)
1 parent 3419ee9 commit fa1bfb2

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

include/pybind11/cast.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,21 @@ class descr {
101101
class type_caster_custom {
102102
public:
103103
PYBIND11_NOINLINE type_caster_custom(const std::type_info *type_info) {
104-
auto const& registered_types = get_internals().registered_types;
104+
auto & registered_types = get_internals().registered_types;
105105
auto it = registered_types.find(type_info);
106-
if (it != registered_types.end())
106+
if (it != registered_types.end()) {
107107
typeinfo = &it->second;
108+
} else {
109+
/* Unknown type?! Since std::type_info* often varies across
110+
module boundaries, the following does an explicit check */
111+
for (auto const &type : registered_types) {
112+
if (strcmp(type.first->name(), type_info->name()) == 0) {
113+
registered_types[type_info] = type.second;
114+
typeinfo = &type.second;
115+
break;
116+
}
117+
}
118+
}
108119
}
109120

110121
PYBIND11_NOINLINE bool load(PyObject *src, bool convert) {

include/pybind11/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ template <typename type, typename holder_type = std::unique_ptr<type>> struct in
135135
holder_type holder;
136136
};
137137

138-
/// Additional type information which does not fit into the PyTypeObjet
138+
/// Additional type information which does not fit into the PyTypeObject
139139
struct type_info {
140140
PyTypeObject *type;
141141
size_t type_size;

0 commit comments

Comments
 (0)