From 556f28a1a4f93ab79a7865e05037765516d8016b Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 3 Jul 2024 07:41:48 -0700 Subject: [PATCH] Add `smart_holder_from_shared_ptr()` specialization for `std::shared_ptr` Resolves one `// BAKEIN_WIP: Better Const2Mutbl`. --- .../detail/smart_holder_type_caster_support.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/include/pybind11/detail/smart_holder_type_caster_support.h b/include/pybind11/detail/smart_holder_type_caster_support.h index 699ce81a4..42f48d5ca 100644 --- a/include/pybind11/detail/smart_holder_type_caster_support.h +++ b/include/pybind11/detail/smart_holder_type_caster_support.h @@ -140,8 +140,7 @@ handle smart_holder_from_shared_ptr(const std::shared_ptr &src, auto src_raw_ptr = src.get(); assert(st.second != nullptr); - // BAKEIN_WIP: Better Const2Mutbl - void *src_raw_void_ptr = const_cast(static_cast(src_raw_ptr)); + void *src_raw_void_ptr = static_cast(src_raw_ptr); const detail::type_info *tinfo = st.second; if (handle existing_inst = find_registered_python_instance(src_raw_void_ptr, tinfo)) { // SMART_HOLDER_WIP: MISSING: Enforcement of consistency with existing smart_holder. @@ -166,6 +165,17 @@ handle smart_holder_from_shared_ptr(const std::shared_ptr &src, return inst.release(); } +template +handle smart_holder_from_shared_ptr(const std::shared_ptr &src, + return_value_policy policy, + handle parent, + const std::pair &st) { + return smart_holder_from_shared_ptr(std::const_pointer_cast(src), // Const2Mutbl + policy, + parent, + st); +} + template handle shared_ptr_to_python(const std::shared_ptr &shd_ptr, return_value_policy policy,