mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-11 08:03:55 +00:00
Restoring init_holder overload for std::enable_shared_from_this and original tests/test_smart_ptr.py.
This commit is contained in:
parent
e5b38a4459
commit
7a74bfede7
@ -1577,7 +1577,6 @@ private:
|
||||
}
|
||||
// clang-format off
|
||||
|
||||
#ifdef JUNK
|
||||
/// Initialize holder object, variant 1: object derives from enable_shared_from_this
|
||||
template <typename T>
|
||||
static void init_holder(detail::instance *inst, detail::value_and_holder &v_h,
|
||||
@ -1595,7 +1594,6 @@ private:
|
||||
v_h.set_holder_constructed();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void init_holder_from_existing(const detail::value_and_holder &v_h,
|
||||
const holder_type *holder_ptr, std::true_type /*is_copy_constructible*/) {
|
||||
|
@ -205,11 +205,9 @@ def test_shared_ptr_from_this_and_references():
|
||||
ref = s.ref # init_holder_helper(holder_ptr=false, owned=false, bad_wp=false)
|
||||
assert stats.alive() == 2
|
||||
assert s.set_ref(ref)
|
||||
# assert s.set_holder(
|
||||
# ref
|
||||
# ) # std::enable_shared_from_this can create a holder from a reference
|
||||
# RuntimeError: Unable to cast from non-held to held instance (T& to Holder<T>) of type
|
||||
# 'std::shared_ptr<(anonymous namespace)::SharedFromThisRef::B>''
|
||||
assert s.set_holder(
|
||||
ref
|
||||
) # std::enable_shared_from_this can create a holder from a reference
|
||||
|
||||
bad_wp = s.bad_wp # init_holder_helper(holder_ptr=false, owned=false, bad_wp=true)
|
||||
assert stats.alive() == 2
|
||||
@ -228,18 +226,14 @@ def test_shared_ptr_from_this_and_references():
|
||||
) # init_holder_helper(holder_ptr=true, owned=false, bad_wp=false)
|
||||
assert stats.alive() == 3
|
||||
assert s.set_ref(holder_ref)
|
||||
# assert s.set_holder(holder_ref)
|
||||
# RuntimeError: Unable to cast from non-held to held instance (T& to Holder<T>) of type
|
||||
# 'std::shared_ptr<(anonymous namespace)::SharedFromThisRef::B>''
|
||||
assert s.set_holder(holder_ref)
|
||||
|
||||
holder_copy = (
|
||||
s.holder_copy
|
||||
) # init_holder_helper(holder_ptr=true, owned=true, bad_wp=false)
|
||||
assert stats.alive() == 3
|
||||
assert s.set_ref(holder_copy)
|
||||
# assert s.set_holder(holder_copy)
|
||||
# RuntimeError: Unable to cast from non-held to held instance (T& to Holder<T>) of type
|
||||
# 'std::shared_ptr<(anonymous namespace)::SharedFromThisRef::B>''
|
||||
assert s.set_holder(holder_copy)
|
||||
|
||||
del ref, bad_wp, copy, holder_ref, holder_copy, s
|
||||
assert stats.alive() == 0
|
||||
|
Loading…
Reference in New Issue
Block a user