mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 14:45:12 +00:00
Also bring in try_initialization_using_shared_from_this() from smart_holder_type_casters.h. With this test_wip builds and succeeds.
This commit is contained in:
parent
fbf88cb298
commit
144ae8be51
@ -1967,6 +1967,31 @@ private:
|
|||||||
init_holder(inst, v_h, (const holder_type *) holder_ptr, v_h.value_ptr<type>());
|
init_holder(inst, v_h, (const holder_type *) holder_ptr, v_h.value_ptr<type>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename WrappedType>
|
||||||
|
static bool try_initialization_using_shared_from_this(holder_type *, WrappedType *, ...) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adopting existing approach used by type_caster_base, although it leads to somewhat fuzzy
|
||||||
|
// ownership semantics: if we detected via shared_from_this that a shared_ptr exists already,
|
||||||
|
// it is reused, irrespective of the return_value_policy in effect.
|
||||||
|
// "SomeBaseOfWrappedType" is needed because std::enable_shared_from_this is not necessarily a
|
||||||
|
// direct base of WrappedType.
|
||||||
|
template <typename WrappedType, typename SomeBaseOfWrappedType>
|
||||||
|
static bool try_initialization_using_shared_from_this(
|
||||||
|
holder_type *uninitialized_location,
|
||||||
|
WrappedType *value_ptr_w_t,
|
||||||
|
const std::enable_shared_from_this<SomeBaseOfWrappedType> *) {
|
||||||
|
auto shd_ptr = std::dynamic_pointer_cast<WrappedType>(
|
||||||
|
detail::try_get_shared_from_this(value_ptr_w_t));
|
||||||
|
if (!shd_ptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Note: inst->owned ignored.
|
||||||
|
new (uninitialized_location) holder_type(holder_type::from_shared_ptr(shd_ptr));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename H = holder_type,
|
template <typename H = holder_type,
|
||||||
detail::enable_if_t<std::is_same<H, pybindit::memory::smart_holder>::value, int> = 0>
|
detail::enable_if_t<std::is_same<H, pybindit::memory::smart_holder>::value, int> = 0>
|
||||||
static void init_instance(detail::instance *inst, const void *holder_const_void_ptr) {
|
static void init_instance(detail::instance *inst, const void *holder_const_void_ptr) {
|
||||||
|
Loading…
Reference in New Issue
Block a user