mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-29 08:32:02 +00:00
inline shared_ptr_to_python() in cast.h
This commit is contained in:
parent
0b7a628a04
commit
12c0eb3889
@ -885,7 +885,16 @@ public:
|
||||
|
||||
static handle
|
||||
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:
|
||||
|
@ -177,21 +177,6 @@ handle smart_holder_from_shared_ptr(const std::shared_ptr<T const> &src,
|
||||
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 {
|
||||
PyObject *parent;
|
||||
explicit shared_ptr_parent_life_support(PyObject *parent) : parent{parent} {
|
||||
|
Loading…
Reference in New Issue
Block a user