Skip to content

Commit

Permalink
Update 'inactive_overload_cache' key
Browse files Browse the repository at this point in the history
Instead of just the function name, use '__qualname__.name'.
  • Loading branch information
BetsyMcPhail committed Jan 16, 2020
1 parent 101d201 commit a95aa69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 5 additions & 5 deletions include/pybind11/detail/internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ template <typename value_type>
using type_map = std::unordered_map<std::type_index, value_type, type_hash, type_equal_to>;

struct overload_hash {
inline size_t operator()(const std::pair<const PyObject *, const char *>& v) const {
size_t value = std::hash<const void *>()(v.first);
value ^= std::hash<const void *>()(v.second) + 0x9e3779b9 + (value<<6) + (value>>2);
return value;
inline size_t operator()(const std::pair<const PyObject *, std::string>& v) const {
size_t h1 = std::hash<const void *>()(v.first);
size_t h2 = std::hash<std::string>()(v.second);
return h1^h2;
}
};

Expand All @@ -97,7 +97,7 @@ struct internals {
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;
std::unordered_set<std::pair<const PyObject *, std::string>, overload_hash> inactive_overload_cache;
type_map<std::vector<bool (*)(PyObject *, void *&)>> direct_conversions;
std::unordered_map<const PyObject *, std::vector<PyObject *>> patients;
std::forward_list<void (*) (std::exception_ptr)> registered_exception_translators;
Expand Down
5 changes: 4 additions & 1 deletion include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -2426,7 +2426,10 @@ inline function get_type_overload(const void *this_ptr, const detail::type_info
if (!self)
return function();
handle type = self.get_type();
auto key = std::make_pair(type.ptr(), name);
/* N.B. This uses `__qualname__.name` instead of `name`
to resolve pybind11#1922. */
auto full_name = type.attr("__qualname__").cast<std::string>() + "." + name;
auto key = std::make_pair(type.ptr(), full_name);

/* Cache functions that aren't overloaded in Python to avoid
many costly Python dictionary lookups below */
Expand Down

0 comments on commit a95aa69

Please sign in to comment.