Skip to content

Commit

Permalink
do a fallback search over types to handle incompatible std::type_info…
Browse files Browse the repository at this point in the history
…* across module boundaries (fixes issue #4)
  • Loading branch information
Wenzel Jakob committed Oct 22, 2015
1 parent 3419ee9 commit 8576559
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,20 @@ class descr {
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;
}
}
}
}

PYBIND11_NOINLINE bool load(PyObject *src, bool convert) {
Expand Down
2 changes: 1 addition & 1 deletion include/pybind11/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8576559

Please sign in to comment.