inline shared_ptr_to_python() in cast.h

This commit is contained in:
Ralf W. Grosse-Kunstleve 2024-07-05 10:05:29 -07:00
parent 0b7a628a04
commit 12c0eb3889
2 changed files with 10 additions and 16 deletions

View File

@ -885,7 +885,16 @@ public:
static handle static handle
cast(const std::shared_ptr<type> &src, return_value_policy policy, handle parent) { cast(const std::shared_ptr<type> &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<type>::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<type>::cast_holder(ptr, &src);
} }
protected: protected:

View File

@ -177,21 +177,6 @@ handle smart_holder_from_shared_ptr(const std::shared_ptr<T const> &src,
st); st);
} }
template <typename T>
handle shared_ptr_to_python(const std::shared_ptr<T> &shd_ptr,
return_value_policy policy,
handle parent) {
const auto *ptr = shd_ptr.get();
auto st = type_caster_base<T>::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<T>::cast_holder(ptr, &shd_ptr);
}
struct shared_ptr_parent_life_support { struct shared_ptr_parent_life_support {
PyObject *parent; PyObject *parent;
explicit shared_ptr_parent_life_support(PyObject *parent) : parent{parent} { explicit shared_ptr_parent_life_support(PyObject *parent) : parent{parent} {