Small cleanup in detail/init.h: strip originally_smart_holder_type_casters_h namespace.

This commit is contained in:
Ralf W. Grosse-Kunstleve 2024-07-19 19:06:07 -07:00
parent 62b6c8e404
commit 35b1177f42

View File

@ -200,20 +200,13 @@ void construct(value_and_holder &v_h, Alias<Class> &&result, bool) {
#ifdef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT
namespace originally_smart_holder_type_casters_h {
template <typename T, typename D>
smart_holder smart_holder_from_unique_ptr(std::unique_ptr<T, D> &&unq_ptr,
bool void_cast_raw_ptr) {
smart_holder init_smart_holder_from_unique_ptr(std::unique_ptr<T, D> &&unq_ptr,
bool void_cast_raw_ptr) {
void *void_ptr = void_cast_raw_ptr ? static_cast<void *>(unq_ptr.get()) : nullptr;
return smart_holder::from_unique_ptr(std::move(unq_ptr), void_ptr);
}
template <typename T>
smart_holder smart_holder_from_shared_ptr(std::shared_ptr<T> shd_ptr) {
return smart_holder::from_shared_ptr(shd_ptr);
}
} // namespace originally_smart_holder_type_casters_h
template <typename Class,
typename D = std::default_delete<Cpp<Class>>,
detail::enable_if_t<is_smart_holder<Holder<Class>>::value, int> = 0>
@ -230,7 +223,7 @@ void construct(value_and_holder &v_h, std::unique_ptr<Cpp<Class>, D> &&unq_ptr,
// trampoline Python object alive. For types that don't inherit from enable_shared_from_this
// it does not matter if void_cast_raw_ptr is true or false, therefore it's not necessary
// to also inspect the type.
auto smhldr = originally_smart_holder_type_casters_h::smart_holder_from_unique_ptr(
auto smhldr = init_smart_holder_from_unique_ptr(
std::move(unq_ptr), /*void_cast_raw_ptr*/ Class::has_alias && is_alias<Class>(ptr));
v_h.value_ptr() = ptr;
v_h.type->init_instance(v_h.inst, &smhldr);
@ -244,8 +237,8 @@ void construct(value_and_holder &v_h,
bool /*need_alias*/) {
auto *ptr = unq_ptr.get();
no_nullptr(ptr);
auto smhldr = originally_smart_holder_type_casters_h::smart_holder_from_unique_ptr(
std::move(unq_ptr), /*void_cast_raw_ptr*/ true);
auto smhldr
= init_smart_holder_from_unique_ptr(std::move(unq_ptr), /*void_cast_raw_ptr*/ true);
v_h.value_ptr() = ptr;
v_h.type->init_instance(v_h.inst, &smhldr);
}
@ -259,7 +252,7 @@ void construct(value_and_holder &v_h, std::shared_ptr<Cpp<Class>> &&shd_ptr, boo
throw type_error("pybind11::init(): construction failed: returned std::shared_ptr pointee "
"is not an alias instance");
}
auto smhldr = originally_smart_holder_type_casters_h::smart_holder_from_shared_ptr(shd_ptr);
auto smhldr = smart_holder::from_shared_ptr(shd_ptr);
v_h.value_ptr() = ptr;
v_h.type->init_instance(v_h.inst, &smhldr);
}
@ -270,7 +263,7 @@ void construct(value_and_holder &v_h,
bool /*need_alias*/) {
auto *ptr = shd_ptr.get();
no_nullptr(ptr);
auto smhldr = originally_smart_holder_type_casters_h::smart_holder_from_shared_ptr(shd_ptr);
auto smhldr = smart_holder::from_shared_ptr(shd_ptr);
v_h.value_ptr() = ptr;
v_h.type->init_instance(v_h.inst, &smhldr);
}