Skip to content

Commit

Permalink
Small cleanup in detail/init.h: strip `originally_smart_holder_type_c…
Browse files Browse the repository at this point in the history
…asters_h` namespace.
  • Loading branch information
rwgk committed Jul 20, 2024
1 parent 62b6c8e commit 35b1177
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions include/pybind11/detail/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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);
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 35b1177

Please sign in to comment.