Remove all uses of PYBIND11_SMART_HOLDER_ENABLED under include/pybind11

This commit is contained in:
Ralf W. Grosse-Kunstleve 2025-02-18 20:06:46 -08:00
parent fcc8fbcd5b
commit 324f29df40
No known key found for this signature in database
6 changed files with 8 additions and 59 deletions

View File

@ -836,8 +836,6 @@ protected:
holder_type holder; holder_type holder;
}; };
#ifdef PYBIND11_SMART_HOLDER_ENABLED
template <typename, typename SFINAE = void> template <typename, typename SFINAE = void>
struct copyable_holder_caster_shared_ptr_with_smart_holder_support_enabled : std::true_type {}; struct copyable_holder_caster_shared_ptr_with_smart_holder_support_enabled : std::true_type {};
@ -968,8 +966,6 @@ protected:
std::shared_ptr<type> shared_ptr_storage; std::shared_ptr<type> shared_ptr_storage;
}; };
#endif // PYBIND11_SMART_HOLDER_ENABLED
/// Specialize for the common std::shared_ptr, so users don't need to /// Specialize for the common std::shared_ptr, so users don't need to
template <typename T> template <typename T>
class type_caster<std::shared_ptr<T>> : public copyable_holder_caster<T, std::shared_ptr<T>> {}; class type_caster<std::shared_ptr<T>> : public copyable_holder_caster<T, std::shared_ptr<T>> {};
@ -990,8 +986,6 @@ struct move_only_holder_caster {
static constexpr auto name = type_caster_base<type>::name; static constexpr auto name = type_caster_base<type>::name;
}; };
#ifdef PYBIND11_SMART_HOLDER_ENABLED
template <typename, typename SFINAE = void> template <typename, typename SFINAE = void>
struct move_only_holder_caster_unique_ptr_with_smart_holder_support_enabled : std::true_type {}; struct move_only_holder_caster_unique_ptr_with_smart_holder_support_enabled : std::true_type {};
@ -1129,8 +1123,6 @@ public:
std::shared_ptr<std::unique_ptr<type, deleter>> unique_ptr_storage; std::shared_ptr<std::unique_ptr<type, deleter>> unique_ptr_storage;
}; };
#endif // PYBIND11_SMART_HOLDER_ENABLED
template <typename type, typename deleter> template <typename type, typename deleter>
class type_caster<std::unique_ptr<type, deleter>> class type_caster<std::unique_ptr<type, deleter>>
: public move_only_holder_caster<type, std::unique_ptr<type, deleter>> {}; : public move_only_holder_caster<type, std::unique_ptr<type, deleter>> {};
@ -1169,10 +1161,8 @@ struct is_holder_type
template <typename base, typename deleter> template <typename base, typename deleter>
struct is_holder_type<base, std::unique_ptr<base, deleter>> : std::true_type {}; struct is_holder_type<base, std::unique_ptr<base, deleter>> : std::true_type {};
#ifdef PYBIND11_SMART_HOLDER_ENABLED
template <typename base> template <typename base>
struct is_holder_type<base, smart_holder> : std::true_type {}; struct is_holder_type<base, smart_holder> : std::true_type {};
#endif
#ifdef PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION // See PR #4888 #ifdef PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION // See PR #4888

View File

@ -198,8 +198,6 @@ void construct(value_and_holder &v_h, Alias<Class> &&result, bool) {
v_h.value_ptr() = new Alias<Class>(std::move(result)); v_h.value_ptr() = new Alias<Class>(std::move(result));
} }
#ifdef PYBIND11_SMART_HOLDER_ENABLED
template <typename T, typename D> template <typename T, typename D>
smart_holder init_smart_holder_from_unique_ptr(std::unique_ptr<T, D> &&unq_ptr, smart_holder init_smart_holder_from_unique_ptr(std::unique_ptr<T, D> &&unq_ptr,
bool void_cast_raw_ptr) { bool void_cast_raw_ptr) {
@ -268,8 +266,6 @@ void construct(value_and_holder &v_h,
v_h.type->init_instance(v_h.inst, &smhldr); v_h.type->init_instance(v_h.inst, &smhldr);
} }
#endif // PYBIND11_SMART_HOLDER_ENABLED
// Implementing class for py::init<...>() // Implementing class for py::init<...>()
template <typename... Args> template <typename... Args>
struct constructor { struct constructor {

View File

@ -511,8 +511,6 @@ inline PyThreadState *get_thread_state_unchecked() {
void keep_alive_impl(handle nurse, handle patient); void keep_alive_impl(handle nurse, handle patient);
inline PyObject *make_new_instance(PyTypeObject *type); inline PyObject *make_new_instance(PyTypeObject *type);
#ifdef PYBIND11_SMART_HOLDER_ENABLED
// PYBIND11:REMINDER: Needs refactoring of existing pybind11 code. // PYBIND11:REMINDER: Needs refactoring of existing pybind11 code.
inline bool deregister_instance(instance *self, void *valptr, const type_info *tinfo); inline bool deregister_instance(instance *self, void *valptr, const type_info *tinfo);
@ -868,8 +866,6 @@ struct load_helper : value_and_holder_helper {
PYBIND11_NAMESPACE_END(smart_holder_type_caster_support) PYBIND11_NAMESPACE_END(smart_holder_type_caster_support)
#endif // PYBIND11_SMART_HOLDER_ENABLED
class type_caster_generic { class type_caster_generic {
public: public:
PYBIND11_NOINLINE explicit type_caster_generic(const std::type_info &type_info) PYBIND11_NOINLINE explicit type_caster_generic(const std::type_info &type_info)
@ -974,7 +970,6 @@ public:
// Base methods for generic caster; there are overridden in copyable_holder_caster // Base methods for generic caster; there are overridden in copyable_holder_caster
void load_value(value_and_holder &&v_h) { void load_value(value_and_holder &&v_h) {
#ifdef PYBIND11_SMART_HOLDER_ENABLED
if (typeinfo->holder_enum_v == detail::holder_enum_t::smart_holder) { if (typeinfo->holder_enum_v == detail::holder_enum_t::smart_holder) {
smart_holder_type_caster_support::value_and_holder_helper v_h_helper; smart_holder_type_caster_support::value_and_holder_helper v_h_helper;
v_h_helper.loaded_v_h = v_h; v_h_helper.loaded_v_h = v_h;
@ -984,7 +979,6 @@ public:
return; return;
} }
} }
#endif
auto *&vptr = v_h.value_ptr(); auto *&vptr = v_h.value_ptr();
// Lazy allocation for unallocated values: // Lazy allocation for unallocated values:
if (vptr == nullptr) { if (vptr == nullptr) {

View File

@ -5,29 +5,18 @@
#pragma once #pragma once
#include "common.h" #include "common.h"
#include "internals.h" #include "struct_smart_holder.h"
#include <type_traits> #include <type_traits>
#ifdef PYBIND11_SMART_HOLDER_ENABLED
# include "struct_smart_holder.h"
#endif
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
#ifdef PYBIND11_SMART_HOLDER_ENABLED
using pybindit::memory::smart_holder; using pybindit::memory::smart_holder;
#endif
PYBIND11_NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
#ifdef PYBIND11_SMART_HOLDER_ENABLED
template <typename H> template <typename H>
using is_smart_holder = std::is_same<H, smart_holder>; using is_smart_holder = std::is_same<H, smart_holder>;
#else
template <typename>
struct is_smart_holder : std::false_type {};
#endif
PYBIND11_NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -1663,8 +1663,6 @@ PYBIND11_NAMESPACE_END(detail)
template <typename T, typename D, typename SFINAE = void> template <typename T, typename D, typename SFINAE = void>
struct property_cpp_function : detail::property_cpp_function_classic<T, D> {}; struct property_cpp_function : detail::property_cpp_function_classic<T, D> {};
#ifdef PYBIND11_SMART_HOLDER_ENABLED
PYBIND11_NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
template <typename T, typename D, typename SFINAE = void> template <typename T, typename D, typename SFINAE = void>
@ -1842,9 +1840,7 @@ struct property_cpp_function<
detail::both_t_and_d_use_type_caster_base<T, typename D::element_type>>::value>> detail::both_t_and_d_use_type_caster_base<T, typename D::element_type>>::value>>
: detail::property_cpp_function_sh_unique_ptr_member<T, D> {}; : detail::property_cpp_function_sh_unique_ptr_member<T, D> {};
#endif // PYBIND11_SMART_HOLDER_ENABLED #if defined(PYBIND11_USE_SMART_HOLDER_AS_DEFAULT)
#if defined(PYBIND11_USE_SMART_HOLDER_AS_DEFAULT) && defined(PYBIND11_SMART_HOLDER_ENABLED)
// NOTE: THIS IS MEANT FOR STRESS-TESTING ONLY! // NOTE: THIS IS MEANT FOR STRESS-TESTING ONLY!
// As of PR #5257, for production use, there is no longer a strong reason to make // As of PR #5257, for production use, there is no longer a strong reason to make
// smart_holder the default holder: // smart_holder the default holder:
@ -1911,7 +1907,6 @@ public:
// A more fitting name would be uses_unique_ptr_holder. // A more fitting name would be uses_unique_ptr_holder.
record.default_holder = detail::is_instantiation<std::unique_ptr, holder_type>::value; record.default_holder = detail::is_instantiation<std::unique_ptr, holder_type>::value;
#ifdef PYBIND11_SMART_HOLDER_ENABLED
if (detail::is_instantiation<std::unique_ptr, holder_type>::value) { if (detail::is_instantiation<std::unique_ptr, holder_type>::value) {
record.holder_enum_v = detail::holder_enum_t::std_unique_ptr; record.holder_enum_v = detail::holder_enum_t::std_unique_ptr;
} else if (detail::is_instantiation<std::shared_ptr, holder_type>::value) { } else if (detail::is_instantiation<std::shared_ptr, holder_type>::value) {
@ -1921,7 +1916,6 @@ public:
} else { } else {
record.holder_enum_v = detail::holder_enum_t::custom_holder; record.holder_enum_v = detail::holder_enum_t::custom_holder;
} }
#endif
set_operator_new<type>(&record); set_operator_new<type>(&record);
@ -2263,8 +2257,6 @@ 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>());
} }
#ifdef PYBIND11_SMART_HOLDER_ENABLED
template <typename WrappedType> template <typename WrappedType>
static bool try_initialization_using_shared_from_this(holder_type *, WrappedType *, ...) { static bool try_initialization_using_shared_from_this(holder_type *, WrappedType *, ...) {
return false; return false;
@ -2324,8 +2316,6 @@ private:
v_h.set_holder_constructed(); v_h.set_holder_constructed();
} }
#endif // PYBIND11_SMART_HOLDER_ENABLED
// Deallocates an instance; via holder, if constructed; otherwise via operator delete. // Deallocates an instance; via holder, if constructed; otherwise via operator delete.
// NOTE: The Python error indicator needs to cleared BEFORE this function is called. // NOTE: The Python error indicator needs to cleared BEFORE this function is called.
// This is because we could be deallocating while cleaning up after a Python exception. // This is because we could be deallocating while cleaning up after a Python exception.
@ -2391,8 +2381,6 @@ private:
} }
}; };
#ifdef PYBIND11_SMART_HOLDER_ENABLED
// Supports easier switching between py::class_<T> and py::class_<T, py::smart_holder>: // Supports easier switching between py::class_<T> and py::class_<T, py::smart_holder>:
// users can simply replace the `_` in `class_` with `h` or vice versa. // users can simply replace the `_` in `class_` with `h` or vice versa.
template <typename type_, typename... options> template <typename type_, typename... options>
@ -2401,8 +2389,6 @@ public:
using class_<type_, smart_holder, options...>::class_; using class_<type_, smart_holder, options...>::class_;
}; };
#endif
/// Binds an existing constructor taking arguments Args... /// Binds an existing constructor taking arguments Args...
template <typename... Args> template <typename... Args>
detail::initimpl::constructor<Args...> init() { detail::initimpl::constructor<Args...> init() {

View File

@ -4,10 +4,6 @@
#pragma once #pragma once
#include "detail/internals.h"
#ifdef PYBIND11_SMART_HOLDER_ENABLED
#include "detail/common.h" #include "detail/common.h"
#include "detail/using_smart_holder.h" #include "detail/using_smart_holder.h"
#include "detail/value_and_holder.h" #include "detail/value_and_holder.h"
@ -62,5 +58,3 @@ struct trampoline_self_life_support {
}; };
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
#endif // PYBIND11_SMART_HOLDER_ENABLED