Skip to content

Commit 0e080f5

Browse files
BetsyMcPhailEricCousineau-TRI
authored andcommitted
Update 'inactive_override_cache' key
Instead of just the function name, use '__qualname__.name'.
1 parent 98f1bbb commit 0e080f5

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

include/pybind11/detail/internals.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ template <typename value_type>
8383
using type_map = std::unordered_map<std::type_index, value_type, type_hash, type_equal_to>;
8484

8585
struct override_hash {
86-
inline size_t operator()(const std::pair<const PyObject *, const char *>& v) const {
86+
inline size_t operator()(const std::pair<const PyObject *, std::string>& v) const {
8787
size_t value = std::hash<const void *>()(v.first);
88-
value ^= std::hash<const void *>()(v.second) + 0x9e3779b9 + (value<<6) + (value>>2);
88+
value ^= std::hash<std::string>();
8989
return value;
9090
}
9191
};
@@ -97,7 +97,7 @@ struct internals {
9797
type_map<type_info *> registered_types_cpp; // std::type_index -> pybind11's type information
9898
std::unordered_map<PyTypeObject *, std::vector<type_info *>> registered_types_py; // PyTypeObject* -> base type_info(s)
9999
std::unordered_multimap<const void *, instance*> registered_instances; // void * -> instance*
100-
std::unordered_set<std::pair<const PyObject *, const char *>, override_hash> inactive_override_cache;
100+
std::unordered_set<std::pair<const PyObject *, std::string>, override_hash> inactive_override_cache;
101101
type_map<std::vector<bool (*)(PyObject *, void *&)>> direct_conversions;
102102
std::unordered_map<const PyObject *, std::vector<PyObject *>> patients;
103103
std::forward_list<void (*) (std::exception_ptr)> registered_exception_translators;

include/pybind11/pybind11.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2221,7 +2221,8 @@ inline function get_type_override(const void *this_ptr, const type_info *this_ty
22212221
if (!self)
22222222
return function();
22232223
handle type = type::handle_of(self);
2224-
auto key = std::make_pair(type.ptr(), name);
2224+
std::string full_name = type.attr("__qualname__").cast<std::string>() + "." + name;
2225+
auto key = std::make_pair(type.ptr(), full_name);
22252226

22262227
/* Cache functions that aren't overridden in Python to avoid
22272228
many costly Python dictionary lookups below */

0 commit comments

Comments
 (0)