From 24e6f887162c47a555e4ed591f4833f0cab89de2 Mon Sep 17 00:00:00 2001 From: Betsy McPhail Date: Wed, 15 Jan 2020 16:15:01 -0500 Subject: [PATCH] Update 'inactive_override_cache' key Instead of just the function name, use '__qualname__.name'. --- include/pybind11/detail/internals.h | 6 +++--- include/pybind11/pybind11.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index a455715bfd..a87346434f 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -83,9 +83,9 @@ template using type_map = std::unordered_map; struct override_hash { - inline size_t operator()(const std::pair& v) const { + 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); + value ^= std::hash()(v.second); return value; } }; @@ -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, override_hash> inactive_override_cache; + std::unordered_set, override_hash> inactive_override_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 82003a9092..3d04a48ebf 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -2221,7 +2221,8 @@ inline function get_type_override(const void *this_ptr, const type_info *this_ty if (!self) return function(); handle type = type::handle_of(self); - auto key = std::make_pair(type.ptr(), name); + std::string full_name = type.attr("__qualname__").cast() + "." + name; + auto key = std::make_pair(type.ptr(), full_name); /* Cache functions that aren't overridden in Python to avoid many costly Python dictionary lookups below */