mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 06:35:12 +00:00
This commit is contained in:
parent
05417a47ce
commit
52c3f4cc30
@ -217,7 +217,7 @@ void construct(value_and_holder &v_h, std::shared_ptr<Cpp<Class>> &&shd_ptr, boo
|
|||||||
if (Class::has_alias && need_alias && !is_alias<Class>(ptr))
|
if (Class::has_alias && need_alias && !is_alias<Class>(ptr))
|
||||||
throw type_error("pybind11::init(): construction failed: returned std::shared_ptr pointee "
|
throw type_error("pybind11::init(): construction failed: returned std::shared_ptr pointee "
|
||||||
"is not an alias instance");
|
"is not an alias instance");
|
||||||
auto smhldr = type_caster<Cpp<Class>>::template smart_holder_from_shared_ptr(shd_ptr);
|
auto smhldr = type_caster<Cpp<Class>>::template smart_holder_from_shared_ptr(shd_ptr);
|
||||||
v_h.value_ptr() = ptr;
|
v_h.value_ptr() = ptr;
|
||||||
v_h.type->init_instance(v_h.inst, &smhldr);
|
v_h.type->init_instance(v_h.inst, &smhldr);
|
||||||
}
|
}
|
||||||
@ -230,7 +230,7 @@ void construct(value_and_holder &v_h,
|
|||||||
bool /*need_alias*/) {
|
bool /*need_alias*/) {
|
||||||
auto *ptr = shd_ptr.get();
|
auto *ptr = shd_ptr.get();
|
||||||
no_nullptr(ptr);
|
no_nullptr(ptr);
|
||||||
auto smhldr = type_caster<Alias<Class>>::template smart_holder_from_shared_ptr(shd_ptr);
|
auto smhldr = type_caster<Alias<Class>>::template smart_holder_from_shared_ptr(shd_ptr);
|
||||||
v_h.value_ptr() = ptr;
|
v_h.value_ptr() = ptr;
|
||||||
v_h.type->init_instance(v_h.inst, &smhldr);
|
v_h.type->init_instance(v_h.inst, &smhldr);
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ struct smart_holder {
|
|||||||
bool pointee_depends_on_holder_owner : 1; // SMART_HOLDER_WIP: See PR #2839.
|
bool pointee_depends_on_holder_owner : 1; // SMART_HOLDER_WIP: See PR #2839.
|
||||||
|
|
||||||
// Design choice: smart_holder is movable but not copyable.
|
// Design choice: smart_holder is movable but not copyable.
|
||||||
smart_holder(smart_holder &&) = default;
|
smart_holder(smart_holder &&) = default;
|
||||||
smart_holder(const smart_holder &) = delete;
|
smart_holder(const smart_holder &) = delete;
|
||||||
smart_holder &operator=(smart_holder &&) = delete;
|
smart_holder &operator=(smart_holder &&) = delete;
|
||||||
smart_holder &operator=(const smart_holder &) = delete;
|
smart_holder &operator=(const smart_holder &) = delete;
|
||||||
@ -219,7 +219,7 @@ struct smart_holder {
|
|||||||
smart_holder hld;
|
smart_holder hld;
|
||||||
hld.vptr.reset(raw_ptr, [](void *) {});
|
hld.vptr.reset(raw_ptr, [](void *) {});
|
||||||
hld.vptr_is_using_noop_deleter = true;
|
hld.vptr_is_using_noop_deleter = true;
|
||||||
hld.is_populated = true;
|
hld.is_populated = true;
|
||||||
return hld;
|
return hld;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,7 +254,7 @@ struct smart_holder {
|
|||||||
else
|
else
|
||||||
hld.vptr.reset(raw_ptr, std::move(gd));
|
hld.vptr.reset(raw_ptr, std::move(gd));
|
||||||
hld.vptr_is_using_builtin_delete = true;
|
hld.vptr_is_using_builtin_delete = true;
|
||||||
hld.is_populated = true;
|
hld.is_populated = true;
|
||||||
return hld;
|
return hld;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,7 +298,7 @@ struct smart_holder {
|
|||||||
static smart_holder from_unique_ptr(std::unique_ptr<T, D> &&unq_ptr,
|
static smart_holder from_unique_ptr(std::unique_ptr<T, D> &&unq_ptr,
|
||||||
bool void_cast_raw_ptr = false) {
|
bool void_cast_raw_ptr = false) {
|
||||||
smart_holder hld;
|
smart_holder hld;
|
||||||
hld.rtti_uqp_del = &typeid(D);
|
hld.rtti_uqp_del = &typeid(D);
|
||||||
hld.vptr_is_using_builtin_delete = is_std_default_delete<T>(*hld.rtti_uqp_del);
|
hld.vptr_is_using_builtin_delete = is_std_default_delete<T>(*hld.rtti_uqp_del);
|
||||||
guarded_delete gd{nullptr, false};
|
guarded_delete gd{nullptr, false};
|
||||||
if (hld.vptr_is_using_builtin_delete)
|
if (hld.vptr_is_using_builtin_delete)
|
||||||
@ -327,9 +327,9 @@ struct smart_holder {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
static smart_holder from_shared_ptr(std::shared_ptr<T> shd_ptr) {
|
static smart_holder from_shared_ptr(std::shared_ptr<T> shd_ptr) {
|
||||||
smart_holder hld;
|
smart_holder hld;
|
||||||
hld.vptr = std::static_pointer_cast<void>(shd_ptr);
|
hld.vptr = std::static_pointer_cast<void>(shd_ptr);
|
||||||
hld.vptr_is_external_shared_ptr = true;
|
hld.vptr_is_external_shared_ptr = true;
|
||||||
hld.is_populated = true;
|
hld.is_populated = true;
|
||||||
return hld;
|
return hld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,7 +308,7 @@ struct smart_holder_type_caster_class_hooks : smart_holder_type_caster_base_tag
|
|||||||
v_h.set_instance_registered();
|
v_h.set_instance_registered();
|
||||||
}
|
}
|
||||||
auto uninitialized_location = std::addressof(v_h.holder<holder_type>());
|
auto uninitialized_location = std::addressof(v_h.holder<holder_type>());
|
||||||
auto value_ptr_w_t = v_h.value_ptr<WrappedType>();
|
auto value_ptr_w_t = v_h.value_ptr<WrappedType>();
|
||||||
bool pointee_depends_on_holder_owner
|
bool pointee_depends_on_holder_owner
|
||||||
= dynamic_raw_ptr_cast_if_possible<AliasType>(value_ptr_w_t) != nullptr;
|
= dynamic_raw_ptr_cast_if_possible<AliasType>(value_ptr_w_t) != nullptr;
|
||||||
if (holder_void_ptr) {
|
if (holder_void_ptr) {
|
||||||
@ -627,21 +627,21 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T>,
|
|||||||
if (handle existing_inst = find_registered_python_instance(src, tinfo))
|
if (handle existing_inst = find_registered_python_instance(src, tinfo))
|
||||||
return existing_inst;
|
return existing_inst;
|
||||||
|
|
||||||
auto inst = reinterpret_steal<object>(make_new_instance(tinfo->type));
|
auto inst = reinterpret_steal<object>(make_new_instance(tinfo->type));
|
||||||
auto wrapper = reinterpret_cast<instance *>(inst.ptr());
|
auto wrapper = reinterpret_cast<instance *>(inst.ptr());
|
||||||
wrapper->owned = false;
|
wrapper->owned = false;
|
||||||
void *&valueptr = values_and_holders(wrapper).begin()->value_ptr();
|
void *&valueptr = values_and_holders(wrapper).begin()->value_ptr();
|
||||||
|
|
||||||
switch (policy) {
|
switch (policy) {
|
||||||
case return_value_policy::automatic:
|
case return_value_policy::automatic:
|
||||||
case return_value_policy::take_ownership:
|
case return_value_policy::take_ownership:
|
||||||
valueptr = src;
|
valueptr = src;
|
||||||
wrapper->owned = true;
|
wrapper->owned = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case return_value_policy::automatic_reference:
|
case return_value_policy::automatic_reference:
|
||||||
case return_value_policy::reference:
|
case return_value_policy::reference:
|
||||||
valueptr = src;
|
valueptr = src;
|
||||||
wrapper->owned = false;
|
wrapper->owned = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -683,7 +683,7 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T>,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case return_value_policy::reference_internal:
|
case return_value_policy::reference_internal:
|
||||||
valueptr = src;
|
valueptr = src;
|
||||||
wrapper->owned = false;
|
wrapper->owned = false;
|
||||||
keep_alive_impl(inst, parent);
|
keep_alive_impl(inst, parent);
|
||||||
break;
|
break;
|
||||||
@ -724,22 +724,22 @@ struct smart_holder_type_caster<std::shared_ptr<T>> : smart_holder_type_caster_l
|
|||||||
return none().release();
|
return none().release();
|
||||||
|
|
||||||
auto src_raw_ptr = src.get();
|
auto src_raw_ptr = src.get();
|
||||||
auto st = type_caster_base<T>::src_and_type(src_raw_ptr);
|
auto st = type_caster_base<T>::src_and_type(src_raw_ptr);
|
||||||
if (st.second == nullptr)
|
if (st.second == nullptr)
|
||||||
return handle(); // no type info: error will be set already
|
return handle(); // no type info: error will be set already
|
||||||
|
|
||||||
void *src_raw_void_ptr = static_cast<void *>(src_raw_ptr);
|
void *src_raw_void_ptr = static_cast<void *>(src_raw_ptr);
|
||||||
const detail::type_info *tinfo = st.second;
|
const detail::type_info *tinfo = st.second;
|
||||||
if (handle existing_inst = find_registered_python_instance(src_raw_void_ptr, tinfo))
|
if (handle existing_inst = find_registered_python_instance(src_raw_void_ptr, tinfo))
|
||||||
// SMART_HOLDER_WIP: MISSING: Enforcement of consistency with existing smart_holder.
|
// SMART_HOLDER_WIP: MISSING: Enforcement of consistency with existing smart_holder.
|
||||||
// SMART_HOLDER_WIP: MISSING: keep_alive.
|
// SMART_HOLDER_WIP: MISSING: keep_alive.
|
||||||
return existing_inst;
|
return existing_inst;
|
||||||
|
|
||||||
auto inst = reinterpret_steal<object>(make_new_instance(tinfo->type));
|
auto inst = reinterpret_steal<object>(make_new_instance(tinfo->type));
|
||||||
auto *inst_raw_ptr = reinterpret_cast<instance *>(inst.ptr());
|
auto *inst_raw_ptr = reinterpret_cast<instance *>(inst.ptr());
|
||||||
inst_raw_ptr->owned = true;
|
inst_raw_ptr->owned = true;
|
||||||
void *&valueptr = values_and_holders(inst_raw_ptr).begin()->value_ptr();
|
void *&valueptr = values_and_holders(inst_raw_ptr).begin()->value_ptr();
|
||||||
valueptr = src_raw_void_ptr;
|
valueptr = src_raw_void_ptr;
|
||||||
|
|
||||||
auto smhldr = pybindit::memory::smart_holder::from_shared_ptr(src);
|
auto smhldr = pybindit::memory::smart_holder::from_shared_ptr(src);
|
||||||
tinfo->init_instance(inst_raw_ptr, static_cast<const void *>(&smhldr));
|
tinfo->init_instance(inst_raw_ptr, static_cast<const void *>(&smhldr));
|
||||||
@ -791,11 +791,11 @@ struct smart_holder_type_caster<std::unique_ptr<T, D>> : smart_holder_type_caste
|
|||||||
return none().release();
|
return none().release();
|
||||||
|
|
||||||
auto src_raw_ptr = src.get();
|
auto src_raw_ptr = src.get();
|
||||||
auto st = type_caster_base<T>::src_and_type(src_raw_ptr);
|
auto st = type_caster_base<T>::src_and_type(src_raw_ptr);
|
||||||
if (st.second == nullptr)
|
if (st.second == nullptr)
|
||||||
return handle(); // no type info: error will be set already
|
return handle(); // no type info: error will be set already
|
||||||
|
|
||||||
void *src_raw_void_ptr = static_cast<void *>(src_raw_ptr);
|
void *src_raw_void_ptr = static_cast<void *>(src_raw_ptr);
|
||||||
const detail::type_info *tinfo = st.second;
|
const detail::type_info *tinfo = st.second;
|
||||||
if (handle existing_inst = find_registered_python_instance(src_raw_void_ptr, tinfo)) {
|
if (handle existing_inst = find_registered_python_instance(src_raw_void_ptr, tinfo)) {
|
||||||
auto *self_life_support
|
auto *self_life_support
|
||||||
@ -819,11 +819,11 @@ struct smart_holder_type_caster<std::unique_ptr<T, D>> : smart_holder_type_caste
|
|||||||
throw cast_error("Invalid unique_ptr: another instance owns this pointer already.");
|
throw cast_error("Invalid unique_ptr: another instance owns this pointer already.");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto inst = reinterpret_steal<object>(make_new_instance(tinfo->type));
|
auto inst = reinterpret_steal<object>(make_new_instance(tinfo->type));
|
||||||
auto *inst_raw_ptr = reinterpret_cast<instance *>(inst.ptr());
|
auto *inst_raw_ptr = reinterpret_cast<instance *>(inst.ptr());
|
||||||
inst_raw_ptr->owned = true;
|
inst_raw_ptr->owned = true;
|
||||||
void *&valueptr = values_and_holders(inst_raw_ptr).begin()->value_ptr();
|
void *&valueptr = values_and_holders(inst_raw_ptr).begin()->value_ptr();
|
||||||
valueptr = src_raw_void_ptr;
|
valueptr = src_raw_void_ptr;
|
||||||
|
|
||||||
auto smhldr = pybindit::memory::smart_holder::from_unique_ptr(std::move(src),
|
auto smhldr = pybindit::memory::smart_holder::from_unique_ptr(std::move(src),
|
||||||
/*void_cast_raw_ptr*/ false);
|
/*void_cast_raw_ptr*/ false);
|
||||||
|
@ -41,7 +41,7 @@ struct trampoline_self_life_support {
|
|||||||
void *value_void_ptr = v_h.value_ptr();
|
void *value_void_ptr = v_h.value_ptr();
|
||||||
if (value_void_ptr != nullptr) {
|
if (value_void_ptr != nullptr) {
|
||||||
PyGILState_STATE threadstate = PyGILState_Ensure();
|
PyGILState_STATE threadstate = PyGILState_Ensure();
|
||||||
v_h.value_ptr() = nullptr;
|
v_h.value_ptr() = nullptr;
|
||||||
v_h.holder<pybindit::memory::smart_holder>().release_disowned();
|
v_h.holder<pybindit::memory::smart_holder>().release_disowned();
|
||||||
detail::deregister_instance(v_h.inst, value_void_ptr, v_h.type);
|
detail::deregister_instance(v_h.inst, value_void_ptr, v_h.type);
|
||||||
Py_DECREF((PyObject *) v_h.inst); // Must be after deregister.
|
Py_DECREF((PyObject *) v_h.inst); // Must be after deregister.
|
||||||
|
@ -11,7 +11,7 @@ struct movable_int {
|
|||||||
int valu;
|
int valu;
|
||||||
movable_int(int v) : valu{v} {}
|
movable_int(int v) : valu{v} {}
|
||||||
movable_int(movable_int &&other) noexcept {
|
movable_int(movable_int &&other) noexcept {
|
||||||
valu = other.valu;
|
valu = other.valu;
|
||||||
other.valu = 91;
|
other.valu = 91;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -36,13 +36,13 @@ private:
|
|||||||
|
|
||||||
TEST_CASE("from_raw_ptr_unowned+as_raw_ptr_unowned", "[S]") {
|
TEST_CASE("from_raw_ptr_unowned+as_raw_ptr_unowned", "[S]") {
|
||||||
static int value = 19;
|
static int value = 19;
|
||||||
auto hld = smart_holder::from_raw_ptr_unowned(&value);
|
auto hld = smart_holder::from_raw_ptr_unowned(&value);
|
||||||
REQUIRE(*hld.as_raw_ptr_unowned<int>() == 19);
|
REQUIRE(*hld.as_raw_ptr_unowned<int>() == 19);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("from_raw_ptr_unowned+as_lvalue_ref", "[S]") {
|
TEST_CASE("from_raw_ptr_unowned+as_lvalue_ref", "[S]") {
|
||||||
static int value = 19;
|
static int value = 19;
|
||||||
auto hld = smart_holder::from_raw_ptr_unowned(&value);
|
auto hld = smart_holder::from_raw_ptr_unowned(&value);
|
||||||
REQUIRE(hld.as_lvalue_ref<int>() == 19);
|
REQUIRE(hld.as_lvalue_ref<int>() == 19);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,28 +58,28 @@ TEST_CASE("from_raw_ptr_unowned+as_rvalue_ref", "[S]") {
|
|||||||
|
|
||||||
TEST_CASE("from_raw_ptr_unowned+as_raw_ptr_release_ownership", "[E]") {
|
TEST_CASE("from_raw_ptr_unowned+as_raw_ptr_release_ownership", "[E]") {
|
||||||
static int value = 19;
|
static int value = 19;
|
||||||
auto hld = smart_holder::from_raw_ptr_unowned(&value);
|
auto hld = smart_holder::from_raw_ptr_unowned(&value);
|
||||||
REQUIRE_THROWS_WITH(hld.as_raw_ptr_release_ownership<int>(),
|
REQUIRE_THROWS_WITH(hld.as_raw_ptr_release_ownership<int>(),
|
||||||
"Cannot disown non-owning holder (as_raw_ptr_release_ownership).");
|
"Cannot disown non-owning holder (as_raw_ptr_release_ownership).");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("from_raw_ptr_unowned+as_unique_ptr", "[E]") {
|
TEST_CASE("from_raw_ptr_unowned+as_unique_ptr", "[E]") {
|
||||||
static int value = 19;
|
static int value = 19;
|
||||||
auto hld = smart_holder::from_raw_ptr_unowned(&value);
|
auto hld = smart_holder::from_raw_ptr_unowned(&value);
|
||||||
REQUIRE_THROWS_WITH(hld.as_unique_ptr<int>(),
|
REQUIRE_THROWS_WITH(hld.as_unique_ptr<int>(),
|
||||||
"Cannot disown non-owning holder (as_unique_ptr).");
|
"Cannot disown non-owning holder (as_unique_ptr).");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("from_raw_ptr_unowned+as_unique_ptr_with_deleter", "[E]") {
|
TEST_CASE("from_raw_ptr_unowned+as_unique_ptr_with_deleter", "[E]") {
|
||||||
static int value = 19;
|
static int value = 19;
|
||||||
auto hld = smart_holder::from_raw_ptr_unowned(&value);
|
auto hld = smart_holder::from_raw_ptr_unowned(&value);
|
||||||
REQUIRE_THROWS_WITH((hld.as_unique_ptr<int, helpers::functor_builtin_delete<int>>()),
|
REQUIRE_THROWS_WITH((hld.as_unique_ptr<int, helpers::functor_builtin_delete<int>>()),
|
||||||
"Missing unique_ptr deleter (as_unique_ptr).");
|
"Missing unique_ptr deleter (as_unique_ptr).");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("from_raw_ptr_unowned+as_shared_ptr", "[S]") {
|
TEST_CASE("from_raw_ptr_unowned+as_shared_ptr", "[S]") {
|
||||||
static int value = 19;
|
static int value = 19;
|
||||||
auto hld = smart_holder::from_raw_ptr_unowned(&value);
|
auto hld = smart_holder::from_raw_ptr_unowned(&value);
|
||||||
REQUIRE(*hld.as_shared_ptr<int>() == 19);
|
REQUIRE(*hld.as_shared_ptr<int>() == 19);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,28 +90,28 @@ TEST_CASE("from_raw_ptr_take_ownership+as_lvalue_ref", "[S]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("from_raw_ptr_take_ownership+as_raw_ptr_release_ownership1", "[S]") {
|
TEST_CASE("from_raw_ptr_take_ownership+as_raw_ptr_release_ownership1", "[S]") {
|
||||||
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
|
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
|
||||||
auto new_owner = std::unique_ptr<int>(hld.as_raw_ptr_release_ownership<int>());
|
auto new_owner = std::unique_ptr<int>(hld.as_raw_ptr_release_ownership<int>());
|
||||||
REQUIRE(!hld.has_pointee());
|
REQUIRE(!hld.has_pointee());
|
||||||
REQUIRE(*new_owner == 19);
|
REQUIRE(*new_owner == 19);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("from_raw_ptr_take_ownership+as_raw_ptr_release_ownership2", "[E]") {
|
TEST_CASE("from_raw_ptr_take_ownership+as_raw_ptr_release_ownership2", "[E]") {
|
||||||
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
|
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
|
||||||
auto shd_ptr = hld.as_shared_ptr<int>();
|
auto shd_ptr = hld.as_shared_ptr<int>();
|
||||||
REQUIRE_THROWS_WITH(hld.as_raw_ptr_release_ownership<int>(),
|
REQUIRE_THROWS_WITH(hld.as_raw_ptr_release_ownership<int>(),
|
||||||
"Cannot disown use_count != 1 (as_raw_ptr_release_ownership).");
|
"Cannot disown use_count != 1 (as_raw_ptr_release_ownership).");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr1", "[S]") {
|
TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr1", "[S]") {
|
||||||
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
|
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
|
||||||
std::unique_ptr<int> new_owner = hld.as_unique_ptr<int>();
|
std::unique_ptr<int> new_owner = hld.as_unique_ptr<int>();
|
||||||
REQUIRE(!hld.has_pointee());
|
REQUIRE(!hld.has_pointee());
|
||||||
REQUIRE(*new_owner == 19);
|
REQUIRE(*new_owner == 19);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr2", "[E]") {
|
TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr2", "[E]") {
|
||||||
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
|
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
|
||||||
auto shd_ptr = hld.as_shared_ptr<int>();
|
auto shd_ptr = hld.as_shared_ptr<int>();
|
||||||
REQUIRE_THROWS_WITH(hld.as_unique_ptr<int>(), "Cannot disown use_count != 1 (as_unique_ptr).");
|
REQUIRE_THROWS_WITH(hld.as_unique_ptr<int>(), "Cannot disown use_count != 1 (as_unique_ptr).");
|
||||||
}
|
}
|
||||||
@ -123,7 +123,7 @@ TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr_with_deleter", "[E]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("from_raw_ptr_take_ownership+as_shared_ptr", "[S]") {
|
TEST_CASE("from_raw_ptr_take_ownership+as_shared_ptr", "[S]") {
|
||||||
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
|
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
|
||||||
std::shared_ptr<int> new_owner = hld.as_shared_ptr<int>();
|
std::shared_ptr<int> new_owner = hld.as_shared_ptr<int>();
|
||||||
REQUIRE(hld.has_pointee());
|
REQUIRE(hld.has_pointee());
|
||||||
REQUIRE(*new_owner == 19);
|
REQUIRE(*new_owner == 19);
|
||||||
@ -155,7 +155,7 @@ TEST_CASE("from_raw_ptr_take_ownership+disown+release_disowned", "[S]") {
|
|||||||
|
|
||||||
TEST_CASE("from_raw_ptr_take_ownership+disown+ensure_is_not_disowned", "[E]") {
|
TEST_CASE("from_raw_ptr_take_ownership+disown+ensure_is_not_disowned", "[E]") {
|
||||||
const char *context = "test_case";
|
const char *context = "test_case";
|
||||||
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
|
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
|
||||||
hld.ensure_is_not_disowned(context); // Does not throw.
|
hld.ensure_is_not_disowned(context); // Does not throw.
|
||||||
std::unique_ptr<int> new_owner(hld.as_raw_ptr_unowned<int>());
|
std::unique_ptr<int> new_owner(hld.as_raw_ptr_unowned<int>());
|
||||||
hld.disown();
|
hld.disown();
|
||||||
@ -327,7 +327,7 @@ TEST_CASE("indestructible_int-from_raw_ptr_unowned+as_raw_ptr_unowned", "[S]") {
|
|||||||
// Using placement new instead of plain new, to not trigger leak sanitizer errors.
|
// Using placement new instead of plain new, to not trigger leak sanitizer errors.
|
||||||
static std::aligned_storage<sizeof(zombie), alignof(zombie)>::type memory_block[1];
|
static std::aligned_storage<sizeof(zombie), alignof(zombie)>::type memory_block[1];
|
||||||
auto *value = new (memory_block) zombie(19);
|
auto *value = new (memory_block) zombie(19);
|
||||||
auto hld = smart_holder::from_raw_ptr_unowned(value);
|
auto hld = smart_holder::from_raw_ptr_unowned(value);
|
||||||
REQUIRE(hld.as_raw_ptr_unowned<zombie>()->valu == 19);
|
REQUIRE(hld.as_raw_ptr_unowned<zombie>()->valu == 19);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,7 +341,7 @@ TEST_CASE("from_raw_ptr_take_ownership+as_shared_ptr-outliving_smart_holder", "[
|
|||||||
// Exercises guarded_builtin_delete flag_ptr validity past destruction of smart_holder.
|
// Exercises guarded_builtin_delete flag_ptr validity past destruction of smart_holder.
|
||||||
std::shared_ptr<int> longer_living;
|
std::shared_ptr<int> longer_living;
|
||||||
{
|
{
|
||||||
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
|
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
|
||||||
longer_living = hld.as_shared_ptr<int>();
|
longer_living = hld.as_shared_ptr<int>();
|
||||||
}
|
}
|
||||||
REQUIRE(*longer_living == 19);
|
REQUIRE(*longer_living == 19);
|
||||||
@ -352,7 +352,7 @@ TEST_CASE("from_unique_ptr_with_deleter+as_shared_ptr-outliving_smart_holder", "
|
|||||||
std::shared_ptr<int> longer_living;
|
std::shared_ptr<int> longer_living;
|
||||||
{
|
{
|
||||||
std::unique_ptr<int, helpers::functor_builtin_delete<int>> orig_owner(new int(19));
|
std::unique_ptr<int, helpers::functor_builtin_delete<int>> orig_owner(new int(19));
|
||||||
auto hld = smart_holder::from_unique_ptr(std::move(orig_owner));
|
auto hld = smart_holder::from_unique_ptr(std::move(orig_owner));
|
||||||
longer_living = hld.as_shared_ptr<int>();
|
longer_living = hld.as_shared_ptr<int>();
|
||||||
}
|
}
|
||||||
REQUIRE(*longer_living == 19);
|
REQUIRE(*longer_living == 19);
|
||||||
|
@ -9,8 +9,8 @@ namespace class_sh_disowning_mi {
|
|||||||
|
|
||||||
// Diamond inheritance (copied from test_multiple_inheritance.cpp).
|
// Diamond inheritance (copied from test_multiple_inheritance.cpp).
|
||||||
struct B {
|
struct B {
|
||||||
int val_b = 10;
|
int val_b = 10;
|
||||||
B() = default;
|
B() = default;
|
||||||
B(const B &) = default;
|
B(const B &) = default;
|
||||||
virtual ~B() = default;
|
virtual ~B() = default;
|
||||||
};
|
};
|
||||||
|
@ -57,12 +57,12 @@ std::unique_ptr<atyp_udcp const, sddc> rtrn_udcp() { return std::unique_ptr<atyp
|
|||||||
// Minimalistic approach to achieve full coverage of construct() overloads for constructing
|
// Minimalistic approach to achieve full coverage of construct() overloads for constructing
|
||||||
// smart_holder from unique_ptr and shared_ptr returns.
|
// smart_holder from unique_ptr and shared_ptr returns.
|
||||||
struct with_alias {
|
struct with_alias {
|
||||||
int val = 0;
|
int val = 0;
|
||||||
virtual ~with_alias() = default;
|
virtual ~with_alias() = default;
|
||||||
// Some compilers complain about implicitly defined versions of some of the following:
|
// Some compilers complain about implicitly defined versions of some of the following:
|
||||||
with_alias() = default;
|
with_alias() = default;
|
||||||
with_alias(const with_alias &) = default;
|
with_alias(const with_alias &) = default;
|
||||||
with_alias(with_alias &&) = default;
|
with_alias(with_alias &&) = default;
|
||||||
with_alias &operator=(const with_alias &) = default;
|
with_alias &operator=(const with_alias &) = default;
|
||||||
with_alias &operator=(with_alias &&) = default;
|
with_alias &operator=(with_alias &&) = default;
|
||||||
};
|
};
|
||||||
|
@ -15,7 +15,7 @@ struct base_template {
|
|||||||
int base_id;
|
int base_id;
|
||||||
|
|
||||||
// Some compilers complain about implicitly defined versions of some of the following:
|
// Some compilers complain about implicitly defined versions of some of the following:
|
||||||
base_template(const base_template &) = default;
|
base_template(const base_template &) = default;
|
||||||
base_template(base_template &&) noexcept = default;
|
base_template(base_template &&) noexcept = default;
|
||||||
base_template &operator=(const base_template &) = default;
|
base_template &operator=(const base_template &) = default;
|
||||||
base_template &operator=(base_template &&) noexcept = default;
|
base_template &operator=(base_template &&) noexcept = default;
|
||||||
|
@ -9,14 +9,14 @@ namespace class_sh_trampoline_basic {
|
|||||||
|
|
||||||
template <int SerNo> // Using int as a trick to easily generate a series of types.
|
template <int SerNo> // Using int as a trick to easily generate a series of types.
|
||||||
struct Abase {
|
struct Abase {
|
||||||
int val = 0;
|
int val = 0;
|
||||||
virtual ~Abase() = default;
|
virtual ~Abase() = default;
|
||||||
Abase(int val_) : val{val_} {}
|
Abase(int val_) : val{val_} {}
|
||||||
int Get() const { return val * 10 + 3; }
|
int Get() const { return val * 10 + 3; }
|
||||||
virtual int Add(int other_val) const = 0;
|
virtual int Add(int other_val) const = 0;
|
||||||
|
|
||||||
// Some compilers complain about implicitly defined versions of some of the following:
|
// Some compilers complain about implicitly defined versions of some of the following:
|
||||||
Abase(const Abase &) = default;
|
Abase(const Abase &) = default;
|
||||||
Abase(Abase &&) noexcept = default;
|
Abase(Abase &&) noexcept = default;
|
||||||
Abase &operator=(const Abase &) = default;
|
Abase &operator=(const Abase &) = default;
|
||||||
Abase &operator=(Abase &&) noexcept = default;
|
Abase &operator=(Abase &&) noexcept = default;
|
||||||
|
@ -68,12 +68,12 @@ TEST_SUBMODULE(class_sh_trampoline_self_life_support, m) {
|
|||||||
case 2: { // operator= lvalue
|
case 2: { // operator= lvalue
|
||||||
std::unique_ptr<Big5> lv(new Big5Trampoline);
|
std::unique_ptr<Big5> lv(new Big5Trampoline);
|
||||||
*lv = *obj_trampoline;
|
*lv = *obj_trampoline;
|
||||||
o2 = py::cast(std::move(lv));
|
o2 = py::cast(std::move(lv));
|
||||||
} break;
|
} break;
|
||||||
case 3: { // operator= rvalue
|
case 3: { // operator= rvalue
|
||||||
std::unique_ptr<Big5> rv(new Big5Trampoline);
|
std::unique_ptr<Big5> rv(new Big5Trampoline);
|
||||||
*rv = std::move(*obj_trampoline);
|
*rv = std::move(*obj_trampoline);
|
||||||
o2 = py::cast(std::move(rv));
|
o2 = py::cast(std::move(rv));
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -21,9 +21,9 @@ struct SpBase {
|
|||||||
return (bool) py::detail::get_object_handle(this, tinfo);
|
return (bool) py::detail::get_object_handle(this, tinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
SpBase() = default;
|
SpBase() = default;
|
||||||
SpBase(const SpBase &) = delete;
|
SpBase(const SpBase &) = delete;
|
||||||
virtual ~SpBase() = default;
|
virtual ~SpBase() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::shared_ptr<SpBase> pass_through_shd_ptr(const std::shared_ptr<SpBase> &obj) { return obj; }
|
std::shared_ptr<SpBase> pass_through_shd_ptr(const std::shared_ptr<SpBase> &obj) { return obj; }
|
||||||
|
@ -18,7 +18,7 @@ public:
|
|||||||
std::uint64_t getVal() const { return val_; }
|
std::uint64_t getVal() const { return val_; }
|
||||||
|
|
||||||
virtual std::unique_ptr<Class> clone() const = 0;
|
virtual std::unique_ptr<Class> clone() const = 0;
|
||||||
virtual int foo() const = 0;
|
virtual int foo() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Class() = default;
|
Class() = default;
|
||||||
|
@ -14,7 +14,7 @@ public:
|
|||||||
int get_int() const { return 213; }
|
int get_int() const { return 213; }
|
||||||
|
|
||||||
pointee(const pointee &) = delete;
|
pointee(const pointee &) = delete;
|
||||||
pointee(pointee &&) = delete;
|
pointee(pointee &&) = delete;
|
||||||
pointee &operator=(const pointee &) = delete;
|
pointee &operator=(const pointee &) = delete;
|
||||||
pointee &operator=(pointee &&) = delete;
|
pointee &operator=(pointee &&) = delete;
|
||||||
};
|
};
|
||||||
|
@ -13,7 +13,7 @@ public:
|
|||||||
virtual int get() const { return 101; }
|
virtual int get() const { return 101; }
|
||||||
|
|
||||||
// Some compilers complain about implicitly defined versions of some of the following:
|
// Some compilers complain about implicitly defined versions of some of the following:
|
||||||
Base() = default;
|
Base() = default;
|
||||||
Base(const Base &) = default;
|
Base(const Base &) = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ struct number_bucket {
|
|||||||
explicit number_bucket(std::size_t data_size = 0) : data(data_size, 1.0) {}
|
explicit number_bucket(std::size_t data_size = 0) : data(data_size, 1.0) {}
|
||||||
|
|
||||||
double sum() const {
|
double sum() const {
|
||||||
std::size_t n = 0;
|
std::size_t n = 0;
|
||||||
double s = 0;
|
double s = 0;
|
||||||
const double *a = &*data.begin();
|
const double *a = &*data.begin();
|
||||||
const double *e = &*data.end();
|
const double *e = &*data.end();
|
||||||
while (a != e) {
|
while (a != e) {
|
||||||
@ -34,8 +34,8 @@ struct number_bucket {
|
|||||||
std::cerr << "Incompatible data sizes (add)." << std::endl;
|
std::cerr << "Incompatible data sizes (add)." << std::endl;
|
||||||
std::terminate();
|
std::terminate();
|
||||||
}
|
}
|
||||||
std::size_t n = 0;
|
std::size_t n = 0;
|
||||||
double *a = &*data.begin();
|
double *a = &*data.begin();
|
||||||
const double *e = &*data.end();
|
const double *e = &*data.end();
|
||||||
const double *b = &*other.data.begin();
|
const double *b = &*other.data.begin();
|
||||||
while (a != e) {
|
while (a != e) {
|
||||||
@ -47,7 +47,7 @@ struct number_bucket {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
number_bucket(const number_bucket &) = delete;
|
number_bucket(const number_bucket &) = delete;
|
||||||
number_bucket(number_bucket &&) = delete;
|
number_bucket(number_bucket &&) = delete;
|
||||||
number_bucket &operator=(const number_bucket &) = delete;
|
number_bucket &operator=(const number_bucket &) = delete;
|
||||||
number_bucket &operator=(number_bucket &&) = delete;
|
number_bucket &operator=(number_bucket &&) = delete;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user