From a95aa6983c422f8a12c8181d7236bf85886b9291 Mon Sep 17 00:00:00 2001 From: Betsy McPhail Date: Wed, 15 Jan 2020 16:15:01 -0500 Subject: [PATCH] Update 'inactive_overload_cache' key Instead of just the function name, use '__qualname__.name'. --- include/pybind11/detail/internals.h | 10 +++++----- include/pybind11/pybind11.h | 5 ++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index cedb360f9ee..7afdb86ff1b 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -83,10 +83,10 @@ template using type_map = std::unordered_map; struct overload_hash { - inline size_t operator()(const std::pair& v) const { - size_t value = std::hash()(v.first); - value ^= std::hash()(v.second) + 0x9e3779b9 + (value<<6) + (value>>2); - return value; + inline size_t operator()(const std::pair& v) const { + size_t h1 = std::hash()(v.first); + size_t h2 = std::hash()(v.second); + return h1^h2; } }; @@ -97,7 +97,7 @@ struct internals { type_map registered_types_cpp; // std::type_index -> pybind11's type information std::unordered_map> registered_types_py; // PyTypeObject* -> base type_info(s) std::unordered_multimap registered_instances; // void * -> instance* - std::unordered_set, overload_hash> inactive_overload_cache; + std::unordered_set, overload_hash> inactive_overload_cache; type_map> direct_conversions; std::unordered_map> patients; std::forward_list registered_exception_translators; diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index bc1104281fb..184f1cfe296 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -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() + "." + 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 */