Improve type safety of internals.registered_types_cpp

This commit is contained in:
Dean Moldovan 2017-08-20 17:18:33 +02:00
parent 96997a4b9d
commit 669aa29461
2 changed files with 5 additions and 5 deletions

View File

@ -169,7 +169,7 @@ inline detail::type_info *get_local_type_info(const std::type_index &tp) {
auto &locals = registered_local_types_cpp();
auto it = locals.find(tp);
if (it != locals.end())
return (detail::type_info *) it->second;
return it->second;
return nullptr;
}
@ -177,7 +177,7 @@ inline detail::type_info *get_global_type_info(const std::type_index &tp) {
auto &types = get_internals().registered_types_cpp;
auto it = types.find(tp);
if (it != types.end())
return (detail::type_info *) it->second;
return it->second;
return nullptr;
}

View File

@ -65,7 +65,7 @@ struct overload_hash {
/// Whenever binary incompatible changes are made to this structure,
/// `PYBIND11_INTERNALS_VERSION` must be incremented.
struct internals {
type_map<void *> registered_types_cpp; // std::type_index -> type_info
type_map<type_info *> registered_types_cpp; // std::type_index -> pybind11's type information
std::unordered_map<PyTypeObject *, std::vector<type_info *>> registered_types_py; // PyTypeObject* -> base type_info(s)
std::unordered_multimap<const void *, instance*> registered_instances; // void * -> instance*
std::unordered_set<std::pair<const PyObject *, const char *>, overload_hash> inactive_overload_cache;
@ -196,8 +196,8 @@ PYBIND11_NOINLINE inline internals &get_internals() {
}
/// Works like `internals.registered_types_cpp`, but for module-local registered types:
PYBIND11_NOINLINE inline type_map<void *> &registered_local_types_cpp() {
static type_map<void *> locals{};
PYBIND11_NOINLINE inline type_map<type_info *> &registered_local_types_cpp() {
static type_map<type_info *> locals{};
return locals;
}