inline unique_ptr_to_python() in cast.h

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

View File

@ -993,8 +993,22 @@ public:
static handle
cast(std::unique_ptr<type, deleter> &&src, return_value_policy policy, handle parent) {
return smart_holder_type_caster_support::unique_ptr_to_python(
std::move(src), policy, parent);
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_unique_ptr(
std::move(src), policy, parent, st);
}
return type_caster_generic::cast(st.first,
return_value_policy::take_ownership,
{},
st.second,
nullptr,
nullptr,
std::addressof(src));
}
static handle

View File

@ -6,7 +6,6 @@
#include "common.h"
#include "dynamic_raw_ptr_cast_if_possible.h"
#include "internals.h"
#include "type_caster_base.h"
#include "typeid.h"
#include <cstdint>
@ -96,26 +95,6 @@ handle smart_holder_from_unique_ptr(std::unique_ptr<T const, D> &&src,
st);
}
template <typename T, typename D>
handle
unique_ptr_to_python(std::unique_ptr<T, D> &&unq_ptr, return_value_policy policy, handle parent) {
auto *src = unq_ptr.get();
auto st = type_caster_base<T>::src_and_type(src);
if (st.second == nullptr) {
return handle(); // no type info: error will be set already
}
if (st.second->default_holder) {
return smart_holder_from_unique_ptr(std::move(unq_ptr), policy, parent, st);
}
return type_caster_generic::cast(st.first,
return_value_policy::take_ownership,
{},
st.second,
nullptr,
nullptr,
std::addressof(unq_ptr));
}
template <typename T>
handle smart_holder_from_shared_ptr(const std::shared_ptr<T> &src,
return_value_policy policy,