do a fallback search over types to handle incompatible std::type_info* across module boundaries (fixes issue #4)

This commit is contained in:
Wenzel Jakob 2015-10-22 16:03:44 +02:00
parent 3419ee909f
commit fa1bfb2ec7
2 changed files with 14 additions and 3 deletions

View File

@ -101,10 +101,21 @@ public:
class type_caster_custom {
public:
PYBIND11_NOINLINE type_caster_custom(const std::type_info *type_info) {
auto const& registered_types = get_internals().registered_types;
auto & registered_types = get_internals().registered_types;
auto it = registered_types.find(type_info);
if (it != registered_types.end())
if (it != registered_types.end()) {
typeinfo = &it->second;
} else {
/* Unknown type?! Since std::type_info* often varies across
module boundaries, the following does an explicit check */
for (auto const &type : registered_types) {
if (strcmp(type.first->name(), type_info->name()) == 0) {
registered_types[type_info] = type.second;
typeinfo = &type.second;
break;
}
}
}
}
PYBIND11_NOINLINE bool load(PyObject *src, bool convert) {

View File

@ -135,7 +135,7 @@ template <typename type, typename holder_type = std::unique_ptr<type>> struct in
holder_type holder;
};
/// Additional type information which does not fit into the PyTypeObjet
/// Additional type information which does not fit into the PyTypeObject
struct type_info {
PyTypeObject *type;
size_t type_size;