mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 14:45:12 +00:00
inline unique_ptr_to_python() in cast.h
This commit is contained in:
parent
12c0eb3889
commit
e593589c61
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user