From 12c0eb38891f2d9b798659c5f707df7ebb79f2ca Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 5 Jul 2024 10:05:29 -0700 Subject: [PATCH] inline shared_ptr_to_python() in cast.h --- include/pybind11/cast.h | 11 ++++++++++- .../detail/smart_holder_type_caster_support.h | 15 --------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index d06508f90..db9b4fe16 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -885,7 +885,16 @@ public: static handle cast(const std::shared_ptr &src, return_value_policy policy, handle parent) { - return smart_holder_type_caster_support::shared_ptr_to_python(src, policy, parent); + const auto *ptr = src.get(); + auto st = type_caster_base::src_and_type(ptr); + if (st.second == nullptr) { + return handle(); // no type info: error will be set already + } + if (st.second->default_holder) { + return smart_holder_type_caster_support::smart_holder_from_shared_ptr( + src, policy, parent, st); + } + return type_caster_base::cast_holder(ptr, &src); } protected: diff --git a/include/pybind11/detail/smart_holder_type_caster_support.h b/include/pybind11/detail/smart_holder_type_caster_support.h index 987eeed1a..f442eed6c 100644 --- a/include/pybind11/detail/smart_holder_type_caster_support.h +++ b/include/pybind11/detail/smart_holder_type_caster_support.h @@ -177,21 +177,6 @@ handle smart_holder_from_shared_ptr(const std::shared_ptr &src, st); } -template -handle shared_ptr_to_python(const std::shared_ptr &shd_ptr, - return_value_policy policy, - handle parent) { - const auto *ptr = shd_ptr.get(); - auto st = type_caster_base::src_and_type(ptr); - if (st.second == nullptr) { - return handle(); // no type info: error will be set already - } - if (st.second->default_holder) { - return smart_holder_from_shared_ptr(shd_ptr, policy, parent, st); - } - return type_caster_base::cast_holder(ptr, &shd_ptr); -} - struct shared_ptr_parent_life_support { PyObject *parent; explicit shared_ptr_parent_life_support(PyObject *parent) : parent{parent} {