diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3f237012..d8607ee98 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -102,20 +102,6 @@ jobs: python: '3.12' args: > -DCMAKE_CXX_FLAGS="/DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT /GR /EHsc" - # Exercise PYBIND11_SMART_HOLDER_DISABLE - # with recent (or ideally latest) released Python version. - - runs-on: ubuntu-latest - python: '3.12' - args: > - -DCMAKE_CXX_FLAGS="-DPYBIND11_SMART_HOLDER_DISABLE" - - runs-on: macos-13 - python: '3.12' - args: > - -DCMAKE_CXX_FLAGS="-DPYBIND11_SMART_HOLDER_DISABLE" - - runs-on: windows-2022 - python: '3.12' - args: > - -DCMAKE_CXX_FLAGS="/DPYBIND11_SMART_HOLDER_DISABLE /GR /EHsc" exclude: # The setup-python action currently doesn't have graalpy for windows - python: 'graalpy-24.1' diff --git a/include/pybind11/attr.h b/include/pybind11/attr.h index 1b513f54d..726711935 100644 --- a/include/pybind11/attr.h +++ b/include/pybind11/attr.h @@ -339,9 +339,7 @@ struct type_record { /// Solves pybind/pybind11#1446 bool release_gil_before_calling_cpp_dtor : 1; -#ifdef PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT holder_enum_t holder_enum_v = holder_enum_t::undefined; -#endif PYBIND11_NOINLINE void add_base(const std::type_info &base, void *(*caster)(void *) ) { auto *base_info = detail::get_type_info(base, false); diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 9ab547b6f..09c262afa 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -836,8 +836,6 @@ protected: holder_type holder; }; -#ifdef PYBIND11_SMART_HOLDER_ENABLED - template struct copyable_holder_caster_shared_ptr_with_smart_holder_support_enabled : std::true_type {}; @@ -928,13 +926,13 @@ protected: return; } throw cast_error("Unable to cast from non-held to held instance (T& to Holder) " -# if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) +#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) "(#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for " "type information)"); -# else +#else "of type '" + type_id>() + "''"); -# endif +#endif } template , @@ -968,8 +966,6 @@ protected: std::shared_ptr shared_ptr_storage; }; -#endif // PYBIND11_SMART_HOLDER_ENABLED - /// Specialize for the common std::shared_ptr, so users don't need to template class type_caster> : public copyable_holder_caster> {}; @@ -990,8 +986,6 @@ struct move_only_holder_caster { static constexpr auto name = type_caster_base::name; }; -#ifdef PYBIND11_SMART_HOLDER_ENABLED - template struct move_only_holder_caster_unique_ptr_with_smart_holder_support_enabled : std::true_type {}; @@ -1129,8 +1123,6 @@ public: std::shared_ptr> unique_ptr_storage; }; -#endif // PYBIND11_SMART_HOLDER_ENABLED - template class type_caster> : public move_only_holder_caster> {}; @@ -1169,10 +1161,8 @@ struct is_holder_type template struct is_holder_type> : std::true_type {}; -#ifdef PYBIND11_SMART_HOLDER_ENABLED template struct is_holder_type : std::true_type {}; -#endif #ifdef PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION // See PR #4888 diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index f119474c1..5e225f8c1 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -605,11 +605,8 @@ struct instance { bool simple_instance_registered : 1; /// If true, get_internals().patients has an entry for this object bool has_patients : 1; -// Cannot use PYBIND11_INTERNALS_VERSION >= 106 here without refactoring. -#if PYBIND11_VERSION_MAJOR >= 3 /// If true, this Python object needs to be kept alive for the lifetime of the C++ value. bool is_alias : 1; -#endif /// Initializes all of the above type/values/holders data (but not the instance values /// themselves) diff --git a/include/pybind11/detail/init.h b/include/pybind11/detail/init.h index 8fba2f8e7..ed95afe58 100644 --- a/include/pybind11/detail/init.h +++ b/include/pybind11/detail/init.h @@ -198,8 +198,6 @@ void construct(value_and_holder &v_h, Alias &&result, bool) { v_h.value_ptr() = new Alias(std::move(result)); } -#ifdef PYBIND11_SMART_HOLDER_ENABLED - template smart_holder init_smart_holder_from_unique_ptr(std::unique_ptr &&unq_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); } -#endif // PYBIND11_SMART_HOLDER_ENABLED - // Implementing class for py::init<...>() template struct constructor { diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index beba642aa..d8b7f693e 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -37,15 +37,11 @@ /// further ABI-incompatible changes may be made before the ABI is officially /// changed to the new version. #ifndef PYBIND11_INTERNALS_VERSION -# if PYBIND11_VERSION_MAJOR >= 3 -# define PYBIND11_INTERNALS_VERSION 106 -# else -# define PYBIND11_INTERNALS_VERSION 6 -# endif +# define PYBIND11_INTERNALS_VERSION 106 #endif -#if PYBIND11_INTERNALS_VERSION < 6 -# error "PYBIND11_INTERNALS_VERSION 6 is the minimum for all platforms for pybind11v3." +#if PYBIND11_INTERNALS_VERSION < 106 +# error "PYBIND11_INTERNALS_VERSION 106 is the minimum (SPECIAL SITUATION)." #endif PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) @@ -215,10 +211,6 @@ struct internals { } }; -#if PYBIND11_INTERNALS_VERSION >= 106 - -# define PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT - enum class holder_enum_t : uint8_t { undefined, std_unique_ptr, // Default, lacking interop with std::shared_ptr. @@ -227,13 +219,6 @@ enum class holder_enum_t : uint8_t { custom_holder, }; -#endif - -#if defined(PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT) \ - && !defined(PYBIND11_SMART_HOLDER_DISABLE) -# define PYBIND11_SMART_HOLDER_ENABLED -#endif - /// Additional type information which does not fit into the PyTypeObject. /// Changes to this struct also require bumping `PYBIND11_INTERNALS_VERSION`. struct type_info { @@ -262,9 +247,7 @@ struct type_info { bool default_holder : 1; /* true if this is a type registered with py::module_local */ bool module_local : 1; -#ifdef PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT holder_enum_t holder_enum_v = holder_enum_t::undefined; -#endif }; #define PYBIND11_INTERNALS_ID \ diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index 097d176f6..9618b2181 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -511,8 +511,6 @@ inline PyThreadState *get_thread_state_unchecked() { void keep_alive_impl(handle nurse, handle patient); inline PyObject *make_new_instance(PyTypeObject *type); -#ifdef PYBIND11_SMART_HOLDER_ENABLED - // PYBIND11:REMINDER: Needs refactoring of existing pybind11 code. 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) -#endif // PYBIND11_SMART_HOLDER_ENABLED - class type_caster_generic { public: 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 void load_value(value_and_holder &&v_h) { -#ifdef PYBIND11_SMART_HOLDER_ENABLED if (typeinfo->holder_enum_v == detail::holder_enum_t::smart_holder) { smart_holder_type_caster_support::value_and_holder_helper v_h_helper; v_h_helper.loaded_v_h = v_h; @@ -984,7 +979,6 @@ public: return; } } -#endif auto *&vptr = v_h.value_ptr(); // Lazy allocation for unallocated values: if (vptr == nullptr) { diff --git a/include/pybind11/detail/using_smart_holder.h b/include/pybind11/detail/using_smart_holder.h index b2d2606af..57f99b95f 100644 --- a/include/pybind11/detail/using_smart_holder.h +++ b/include/pybind11/detail/using_smart_holder.h @@ -5,29 +5,18 @@ #pragma once #include "common.h" -#include "internals.h" +#include "struct_smart_holder.h" #include -#ifdef PYBIND11_SMART_HOLDER_ENABLED -# include "struct_smart_holder.h" -#endif - PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -#ifdef PYBIND11_SMART_HOLDER_ENABLED using pybindit::memory::smart_holder; -#endif PYBIND11_NAMESPACE_BEGIN(detail) -#ifdef PYBIND11_SMART_HOLDER_ENABLED template using is_smart_holder = std::is_same; -#else -template -struct is_smart_holder : std::false_type {}; -#endif PYBIND11_NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/include/pybind11/detail/value_and_holder.h b/include/pybind11/detail/value_and_holder.h index ca37d70ad..64c55cc59 100644 --- a/include/pybind11/detail/value_and_holder.h +++ b/include/pybind11/detail/value_and_holder.h @@ -7,6 +7,7 @@ #include "common.h" #include +#include #include PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index a09aafec6..b4fdccfce 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1448,9 +1448,7 @@ protected: tinfo->simple_ancestors = true; tinfo->default_holder = rec.default_holder; tinfo->module_local = rec.module_local; -#ifdef PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT tinfo->holder_enum_v = rec.holder_enum_v; -#endif with_internals([&](internals &internals) { auto tindex = std::type_index(*rec.type); @@ -1665,8 +1663,6 @@ PYBIND11_NAMESPACE_END(detail) template struct property_cpp_function : detail::property_cpp_function_classic {}; -#ifdef PYBIND11_SMART_HOLDER_ENABLED - PYBIND11_NAMESPACE_BEGIN(detail) template @@ -1844,9 +1840,7 @@ struct property_cpp_function< detail::both_t_and_d_use_type_caster_base>::value>> : detail::property_cpp_function_sh_unique_ptr_member {}; -#endif // PYBIND11_SMART_HOLDER_ENABLED - -#if defined(PYBIND11_USE_SMART_HOLDER_AS_DEFAULT) && defined(PYBIND11_SMART_HOLDER_ENABLED) +#if defined(PYBIND11_USE_SMART_HOLDER_AS_DEFAULT) // NOTE: THIS IS MEANT FOR STRESS-TESTING ONLY! // As of PR #5257, for production use, there is no longer a strong reason to make // smart_holder the default holder: @@ -1854,7 +1848,6 @@ struct property_cpp_function< // Running the pybind11 unit tests with smart_holder as the default holder is to ensure // that `py::smart_holder` / `py::classh` is backward-compatible with all pre-existing // functionality. -# define PYBIND11_ACTUALLY_USING_SMART_HOLDER_AS_DEFAULT template using default_holder_type = smart_holder; #else @@ -1913,7 +1906,6 @@ public: // A more fitting name would be uses_unique_ptr_holder. record.default_holder = detail::is_instantiation::value; -#ifdef PYBIND11_SMART_HOLDER_ENABLED if (detail::is_instantiation::value) { record.holder_enum_v = detail::holder_enum_t::std_unique_ptr; } else if (detail::is_instantiation::value) { @@ -1923,7 +1915,6 @@ public: } else { record.holder_enum_v = detail::holder_enum_t::custom_holder; } -#endif set_operator_new(&record); @@ -2265,8 +2256,6 @@ private: init_holder(inst, v_h, (const holder_type *) holder_ptr, v_h.value_ptr()); } -#ifdef PYBIND11_SMART_HOLDER_ENABLED - template static bool try_initialization_using_shared_from_this(holder_type *, WrappedType *, ...) { return false; @@ -2326,8 +2315,6 @@ private: v_h.set_holder_constructed(); } -#endif // PYBIND11_SMART_HOLDER_ENABLED - // Deallocates an instance; via holder, if constructed; otherwise via operator delete. // 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. @@ -2393,8 +2380,6 @@ private: } }; -#ifdef PYBIND11_SMART_HOLDER_ENABLED - // Supports easier switching between py::class_ and py::class_: // users can simply replace the `_` in `class_` with `h` or vice versa. template @@ -2403,8 +2388,6 @@ public: using class_::class_; }; -#endif - /// Binds an existing constructor taking arguments Args... template detail::initimpl::constructor init() { diff --git a/include/pybind11/trampoline_self_life_support.h b/include/pybind11/trampoline_self_life_support.h index d988e75a3..484045bb1 100644 --- a/include/pybind11/trampoline_self_life_support.h +++ b/include/pybind11/trampoline_self_life_support.h @@ -4,13 +4,9 @@ #pragma once -#include "detail/internals.h" - -#ifdef PYBIND11_SMART_HOLDER_ENABLED - -# include "detail/common.h" -# include "detail/using_smart_holder.h" -# include "detail/value_and_holder.h" +#include "detail/common.h" +#include "detail/using_smart_holder.h" +#include "detail/value_and_holder.h" PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) @@ -62,5 +58,3 @@ struct trampoline_self_life_support { }; PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) - -#endif // PYBIND11_SMART_HOLDER_ENABLED diff --git a/tests/test_class.cpp b/tests/test_class.cpp index e4c0328db..86c8d3701 100644 --- a/tests/test_class.cpp +++ b/tests/test_class.cpp @@ -109,11 +109,7 @@ TEST_SUBMODULE(class_, m) { struct ToBeHeldByUniquePtr {}; py::class_>(m, "ToBeHeldByUniquePtr") .def(py::init<>()); -#ifdef PYBIND11_SMART_HOLDER_ENABLED m.def("pass_unique_ptr", [](std::unique_ptr &&) {}); -#else - m.attr("pass_unique_ptr") = py::none(); -#endif // test_inheritance class Pet { @@ -636,7 +632,7 @@ CHECK_NOALIAS(8); CHECK_HOLDER(1, unique); CHECK_HOLDER(2, unique); CHECK_HOLDER(3, unique); -#ifndef PYBIND11_ACTUALLY_USING_SMART_HOLDER_AS_DEFAULT +#ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT CHECK_HOLDER(4, unique); CHECK_HOLDER(5, unique); #endif diff --git a/tests/test_class.py b/tests/test_class.py index 44a558247..b8102ec63 100644 --- a/tests/test_class.py +++ b/tests/test_class.py @@ -51,8 +51,6 @@ def test_instance_new(): def test_pass_unique_ptr(): obj = m.ToBeHeldByUniquePtr() - if m.pass_unique_ptr is None: - pytest.skip("smart_holder not available.") with pytest.raises(RuntimeError) as execinfo: m.pass_unique_ptr(obj) assert str(execinfo.value).startswith( diff --git a/tests/test_class_sh_basic.cpp b/tests/test_class_sh_basic.cpp index 1d23cd62e..ee973c273 100644 --- a/tests/test_class_sh_basic.cpp +++ b/tests/test_class_sh_basic.cpp @@ -144,24 +144,7 @@ class LocalUnusualOpRef : UnusualOpRef {}; // To avoid clashing with `py::class_ py::object CastUnusualOpRefConstRef(const LocalUnusualOpRef &cref) { return py::cast(cref); } py::object CastUnusualOpRefMovable(LocalUnusualOpRef &&mvbl) { return py::cast(std::move(mvbl)); } -} // namespace class_sh_basic -} // namespace pybind11_tests - -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_basic::atyp) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_basic::uconsumer) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_basic::SharedPtrStash) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_basic::LocalUnusualOpRef) - -namespace pybind11_tests { -namespace class_sh_basic { - TEST_SUBMODULE(class_sh_basic, m) { - m.attr("defined_PYBIND11_SMART_HOLDER_ENABLED") = -#ifndef PYBIND11_SMART_HOLDER_ENABLED - false; -#else - true; - namespace py = pybind11; py::classh(m, "atyp").def(py::init<>()).def(py::init([](const std::string &mtxt) { @@ -260,7 +243,6 @@ TEST_SUBMODULE(class_sh_basic, m) { []() { return CastUnusualOpRefConstRef(LocalUnusualOpRef()); }); m.def("CallCastUnusualOpRefMovable", []() { return CastUnusualOpRefMovable(LocalUnusualOpRef()); }); -#endif // PYBIND11_SMART_HOLDER_ENABLED } } // namespace class_sh_basic diff --git a/tests/test_class_sh_basic.py b/tests/test_class_sh_basic.py index 74a4e4075..f07253a5d 100644 --- a/tests/test_class_sh_basic.py +++ b/tests/test_class_sh_basic.py @@ -7,9 +7,6 @@ import pytest from pybind11_tests import class_sh_basic as m -if not m.defined_PYBIND11_SMART_HOLDER_ENABLED: - pytest.skip("smart_holder not available.", allow_module_level=True) - def test_atyp_constructors(): obj = m.atyp() diff --git a/tests/test_class_sh_disowning.cpp b/tests/test_class_sh_disowning.cpp index 81e17ac43..97c95287b 100644 --- a/tests/test_class_sh_disowning.cpp +++ b/tests/test_class_sh_disowning.cpp @@ -28,16 +28,7 @@ int overloaded(std::unique_ptr> at2, int i) { return at2->get() * 40 + } // namespace class_sh_disowning } // namespace pybind11_tests -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_disowning::Atype<1>) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_disowning::Atype<2>) - TEST_SUBMODULE(class_sh_disowning, m) { - m.attr("defined_PYBIND11_SMART_HOLDER_ENABLED") = -#ifndef PYBIND11_SMART_HOLDER_ENABLED - false; -#else - true; - using namespace pybind11_tests::class_sh_disowning; py::classh>(m, "Atype1").def(py::init()).def("get", &Atype<1>::get); @@ -49,5 +40,4 @@ TEST_SUBMODULE(class_sh_disowning, m) { m.def("overloaded", (int (*)(std::unique_ptr>, int)) &overloaded); m.def("overloaded", (int (*)(std::unique_ptr>, int)) &overloaded); -#endif // PYBIND11_SMART_HOLDER_ENABLED } diff --git a/tests/test_class_sh_disowning.py b/tests/test_class_sh_disowning.py index 95fd30c55..b9e648999 100644 --- a/tests/test_class_sh_disowning.py +++ b/tests/test_class_sh_disowning.py @@ -4,9 +4,6 @@ import pytest from pybind11_tests import class_sh_disowning as m -if not m.defined_PYBIND11_SMART_HOLDER_ENABLED: - pytest.skip("smart_holder not available.", allow_module_level=True) - def is_disowned(obj): try: diff --git a/tests/test_class_sh_disowning_mi.cpp b/tests/test_class_sh_disowning_mi.cpp index 662292758..8b9667253 100644 --- a/tests/test_class_sh_disowning_mi.cpp +++ b/tests/test_class_sh_disowning_mi.cpp @@ -48,21 +48,7 @@ int disown_base2(std::unique_ptr b2) { return b2->j * 2000 + 2; } } // namespace class_sh_disowning_mi } // namespace pybind11_tests -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_disowning_mi::B) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_disowning_mi::C0) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_disowning_mi::C1) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_disowning_mi::D) - -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_disowning_mi::Base1) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_disowning_mi::Base2) - TEST_SUBMODULE(class_sh_disowning_mi, m) { - m.attr("defined_PYBIND11_SMART_HOLDER_ENABLED") = -#ifndef PYBIND11_SMART_HOLDER_ENABLED - false; -#else - true; - using namespace pybind11_tests::class_sh_disowning_mi; py::classh(m, "B") @@ -98,5 +84,4 @@ TEST_SUBMODULE(class_sh_disowning_mi, m) { py::classh(m, "Base2").def(py::init()).def("bar", &Base2::bar); m.def("disown_base1", disown_base1); m.def("disown_base2", disown_base2); -#endif // PYBIND11_SMART_HOLDER_ENABLED } diff --git a/tests/test_class_sh_disowning_mi.py b/tests/test_class_sh_disowning_mi.py index 7b5261242..4a4beecce 100644 --- a/tests/test_class_sh_disowning_mi.py +++ b/tests/test_class_sh_disowning_mi.py @@ -5,9 +5,6 @@ import pytest import env # noqa: F401 from pybind11_tests import class_sh_disowning_mi as m -if not m.defined_PYBIND11_SMART_HOLDER_ENABLED: - pytest.skip("smart_holder not available.", allow_module_level=True) - def test_diamond_inheritance(): # Very similar to test_multiple_inheritance.py:test_diamond_inheritance. diff --git a/tests/test_class_sh_factory_constructors.cpp b/tests/test_class_sh_factory_constructors.cpp index f4c0c1d5c..3499eaea5 100644 --- a/tests/test_class_sh_factory_constructors.cpp +++ b/tests/test_class_sh_factory_constructors.cpp @@ -72,27 +72,7 @@ struct sddwaa : std::default_delete {}; } // namespace class_sh_factory_constructors } // namespace pybind11_tests -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_factory_constructors::atyp_valu) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_factory_constructors::atyp_rref) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_factory_constructors::atyp_cref) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_factory_constructors::atyp_mref) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_factory_constructors::atyp_cptr) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_factory_constructors::atyp_mptr) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_factory_constructors::atyp_shmp) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_factory_constructors::atyp_shcp) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_factory_constructors::atyp_uqmp) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_factory_constructors::atyp_uqcp) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_factory_constructors::atyp_udmp) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_factory_constructors::atyp_udcp) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_factory_constructors::with_alias) - TEST_SUBMODULE(class_sh_factory_constructors, m) { - m.attr("defined_PYBIND11_SMART_HOLDER_ENABLED") = -#ifndef PYBIND11_SMART_HOLDER_ENABLED - false; -#else - true; - using namespace pybind11_tests::class_sh_factory_constructors; py::classh(m, "atyp_valu") @@ -183,5 +163,4 @@ TEST_SUBMODULE(class_sh_factory_constructors, m) { [](int, int, int, int, int) { return std::make_shared(); // Invalid alias factory. })); -#endif // PYBIND11_SMART_HOLDER_ENABLED } diff --git a/tests/test_class_sh_factory_constructors.py b/tests/test_class_sh_factory_constructors.py index 149a33401..5d45db6fd 100644 --- a/tests/test_class_sh_factory_constructors.py +++ b/tests/test_class_sh_factory_constructors.py @@ -4,9 +4,6 @@ import pytest from pybind11_tests import class_sh_factory_constructors as m -if not m.defined_PYBIND11_SMART_HOLDER_ENABLED: - pytest.skip("smart_holder not available.", allow_module_level=True) - def test_atyp_factories(): assert m.atyp_valu().get_mtxt() == "Valu" diff --git a/tests/test_class_sh_inheritance.cpp b/tests/test_class_sh_inheritance.cpp index 86ecea9be..bb46fb92e 100644 --- a/tests/test_class_sh_inheritance.cpp +++ b/tests/test_class_sh_inheritance.cpp @@ -59,26 +59,7 @@ inline int pass_cptr_base2(base2 const *b) { return b->id() + 22; } inline int pass_cptr_drvd2(drvd2 const *d) { return d->id() + 23; } // clang-format on -} // namespace class_sh_inheritance -} // namespace pybind11_tests - -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_inheritance::base) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_inheritance::drvd) - -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_inheritance::base1) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_inheritance::base2) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_inheritance::drvd2) - -namespace pybind11_tests { -namespace class_sh_inheritance { - TEST_SUBMODULE(class_sh_inheritance, m) { - m.attr("defined_PYBIND11_SMART_HOLDER_ENABLED") = -#ifndef PYBIND11_SMART_HOLDER_ENABLED - false; -#else - true; - py::classh(m, "base"); py::classh(m, "drvd"); @@ -105,7 +86,6 @@ TEST_SUBMODULE(class_sh_inheritance, m) { m.def("pass_cptr_base1", pass_cptr_base1); m.def("pass_cptr_base2", pass_cptr_base2); m.def("pass_cptr_drvd2", pass_cptr_drvd2); -#endif // PYBIND11_SMART_HOLDER_ENABLED } } // namespace class_sh_inheritance diff --git a/tests/test_class_sh_inheritance.py b/tests/test_class_sh_inheritance.py index 4f8c0e698..cd9d6f47e 100644 --- a/tests/test_class_sh_inheritance.py +++ b/tests/test_class_sh_inheritance.py @@ -1,12 +1,7 @@ from __future__ import annotations -import pytest - from pybind11_tests import class_sh_inheritance as m -if not m.defined_PYBIND11_SMART_HOLDER_ENABLED: - pytest.skip("smart_holder not available.", allow_module_level=True) - def test_rtrn_mptr_drvd_pass_cptr_base(): d = m.rtrn_mptr_drvd() diff --git a/tests/test_class_sh_mi_thunks.cpp b/tests/test_class_sh_mi_thunks.cpp index 2630ab0dc..244ccbfac 100644 --- a/tests/test_class_sh_mi_thunks.cpp +++ b/tests/test_class_sh_mi_thunks.cpp @@ -35,17 +35,7 @@ struct Derived : Base1, Base0 { } // namespace test_class_sh_mi_thunks -PYBIND11_SMART_HOLDER_TYPE_CASTERS(test_class_sh_mi_thunks::Base0) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(test_class_sh_mi_thunks::Base1) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(test_class_sh_mi_thunks::Derived) - TEST_SUBMODULE(class_sh_mi_thunks, m) { - m.attr("defined_PYBIND11_SMART_HOLDER_ENABLED") = -#ifndef PYBIND11_SMART_HOLDER_ENABLED - false; -#else - true; - using namespace test_class_sh_mi_thunks; m.def("ptrdiff_drvd_base0", []() { @@ -103,5 +93,4 @@ TEST_SUBMODULE(class_sh_mi_thunks, m) { } return obj_der->vec.size(); }); -#endif // PYBIND11_SMART_HOLDER_ENABLED } diff --git a/tests/test_class_sh_mi_thunks.py b/tests/test_class_sh_mi_thunks.py index af3971bba..32bf47554 100644 --- a/tests/test_class_sh_mi_thunks.py +++ b/tests/test_class_sh_mi_thunks.py @@ -4,9 +4,6 @@ import pytest from pybind11_tests import class_sh_mi_thunks as m -if not m.defined_PYBIND11_SMART_HOLDER_ENABLED: - pytest.skip("smart_holder not available.", allow_module_level=True) - def test_ptrdiff_drvd_base0(): ptrdiff = m.ptrdiff_drvd_base0() diff --git a/tests/test_class_sh_property.cpp b/tests/test_class_sh_property.cpp index 22a1f6950..6476a9cad 100644 --- a/tests/test_class_sh_property.cpp +++ b/tests/test_class_sh_property.cpp @@ -46,24 +46,7 @@ struct WithConstCharPtrMember { } // namespace test_class_sh_property -PYBIND11_TYPE_CASTER_BASE_HOLDER(test_class_sh_property::ClassicField, - std::unique_ptr) -PYBIND11_TYPE_CASTER_BASE_HOLDER(test_class_sh_property::ClassicOuter, - std::unique_ptr) - -PYBIND11_SMART_HOLDER_TYPE_CASTERS(test_class_sh_property::Field) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(test_class_sh_property::Outer) - -PYBIND11_SMART_HOLDER_TYPE_CASTERS(test_class_sh_property::WithCharArrayMember) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(test_class_sh_property::WithConstCharPtrMember) - TEST_SUBMODULE(class_sh_property, m) { - m.attr("defined_PYBIND11_SMART_HOLDER_ENABLED") = -#ifndef PYBIND11_SMART_HOLDER_ENABLED - false; -#else - true; - using namespace test_class_sh_property; py::class_>(m, "ClassicField") @@ -109,5 +92,4 @@ TEST_SUBMODULE(class_sh_property, m) { py::classh(m, "WithConstCharPtrMember") .def(py::init<>()) .def_readonly("const_char_ptr_member", &WithConstCharPtrMember::const_char_ptr_member); -#endif // PYBIND11_SMART_HOLDER_ENABLED } diff --git a/tests/test_class_sh_property.py b/tests/test_class_sh_property.py index 9bd2fbfbf..0250a7f78 100644 --- a/tests/test_class_sh_property.py +++ b/tests/test_class_sh_property.py @@ -7,9 +7,6 @@ import pytest import env # noqa: F401 from pybind11_tests import class_sh_property as m -if not m.defined_PYBIND11_SMART_HOLDER_ENABLED: - pytest.skip("smart_holder not available.", allow_module_level=True) - @pytest.mark.skipif( "env.PYPY or env.GRAALPY", reason="gc after `del field` is apparently deferred" diff --git a/tests/test_class_sh_property_non_owning.cpp b/tests/test_class_sh_property_non_owning.cpp index 87b84334f..42f1f6fd3 100644 --- a/tests/test_class_sh_property_non_owning.cpp +++ b/tests/test_class_sh_property_non_owning.cpp @@ -46,17 +46,7 @@ public: using namespace test_class_sh_property_non_owning; -PYBIND11_SMART_HOLDER_TYPE_CASTERS(CoreField) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(DataField) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(DataFieldsHolder) - TEST_SUBMODULE(class_sh_property_non_owning, m) { - m.attr("defined_PYBIND11_SMART_HOLDER_ENABLED") = -#ifndef PYBIND11_SMART_HOLDER_ENABLED - false; -#else - true; - py::classh(m, "CoreField").def_readwrite("int_value", &CoreField::int_value); py::classh(m, "DataField") @@ -71,5 +61,4 @@ TEST_SUBMODULE(class_sh_property_non_owning, m) { py::classh(m, "DataFieldsHolder") .def(py::init()) .def("vec_at", &DataFieldsHolder::vec_at, py::return_value_policy::reference_internal); -#endif // PYBIND11_SMART_HOLDER_ENABLED } diff --git a/tests/test_class_sh_property_non_owning.py b/tests/test_class_sh_property_non_owning.py index b977e75b3..33a9d4503 100644 --- a/tests/test_class_sh_property_non_owning.py +++ b/tests/test_class_sh_property_non_owning.py @@ -4,9 +4,6 @@ import pytest from pybind11_tests import class_sh_property_non_owning as m -if not m.defined_PYBIND11_SMART_HOLDER_ENABLED: - pytest.skip("smart_holder not available.", allow_module_level=True) - @pytest.mark.parametrize("persistent_holder", [True, False]) @pytest.mark.parametrize( diff --git a/tests/test_class_sh_shared_ptr_copy_move.cpp b/tests/test_class_sh_shared_ptr_copy_move.cpp index 999832718..5eb0ef3ed 100644 --- a/tests/test_class_sh_shared_ptr_copy_move.cpp +++ b/tests/test_class_sh_shared_ptr_copy_move.cpp @@ -41,21 +41,8 @@ struct Outer { }; } // namespace -} // namespace pybind11_tests - -PYBIND11_TYPE_CASTER_BASE_HOLDER(pybind11_tests::FooShPtr, - std::shared_ptr) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::FooSmHld) - -namespace pybind11_tests { TEST_SUBMODULE(class_sh_shared_ptr_copy_move, m) { - m.attr("defined_PYBIND11_SMART_HOLDER_ENABLED") = -#ifndef PYBIND11_SMART_HOLDER_ENABLED - false; -#else - true; - namespace py = pybind11; py::class_>(m, "FooShPtr") @@ -63,30 +50,30 @@ TEST_SUBMODULE(class_sh_shared_ptr_copy_move, m) { py::classh(m, "FooSmHld").def("get_history", &FooSmHld::get_history); auto outer = py::class_(m, "Outer").def(py::init()); -# define MAKE_PROP(PropTyp) \ - MAKE_PROP_FOO(ShPtr, PropTyp) \ - MAKE_PROP_FOO(SmHld, PropTyp) +#define MAKE_PROP(PropTyp) \ + MAKE_PROP_FOO(ShPtr, PropTyp) \ + MAKE_PROP_FOO(SmHld, PropTyp) -# define MAKE_PROP_FOO(FooTyp, PropTyp) \ - .def_##PropTyp(#FooTyp "_" #PropTyp "_default", &Outer::FooTyp) \ - .def_##PropTyp( \ - #FooTyp "_" #PropTyp "_copy", &Outer::FooTyp, py::return_value_policy::copy) \ - .def_##PropTyp( \ - #FooTyp "_" #PropTyp "_move", &Outer::FooTyp, py::return_value_policy::move) +#define MAKE_PROP_FOO(FooTyp, PropTyp) \ + .def_##PropTyp(#FooTyp "_" #PropTyp "_default", &Outer::FooTyp) \ + .def_##PropTyp( \ + #FooTyp "_" #PropTyp "_copy", &Outer::FooTyp, py::return_value_policy::copy) \ + .def_##PropTyp( \ + #FooTyp "_" #PropTyp "_move", &Outer::FooTyp, py::return_value_policy::move) outer MAKE_PROP(readonly) MAKE_PROP(readwrite); -# undef MAKE_PROP_FOO +#undef MAKE_PROP_FOO -# define MAKE_PROP_FOO(FooTyp, PropTyp) \ - .def_##PropTyp(#FooTyp "_property_" #PropTyp "_default", &Outer::FooTyp) \ - .def_property_##PropTyp(#FooTyp "_property_" #PropTyp "_copy", \ - &Outer::get##FooTyp, \ - py::return_value_policy::copy) \ - .def_property_##PropTyp(#FooTyp "_property_" #PropTyp "_move", \ - &Outer::get##FooTyp, \ - py::return_value_policy::move) +#define MAKE_PROP_FOO(FooTyp, PropTyp) \ + .def_##PropTyp(#FooTyp "_property_" #PropTyp "_default", &Outer::FooTyp) \ + .def_property_##PropTyp(#FooTyp "_property_" #PropTyp "_copy", \ + &Outer::get##FooTyp, \ + py::return_value_policy::copy) \ + .def_property_##PropTyp(#FooTyp "_property_" #PropTyp "_move", \ + &Outer::get##FooTyp, \ + py::return_value_policy::move) outer MAKE_PROP(readonly); -# undef MAKE_PROP_FOO -# undef MAKE_PROP +#undef MAKE_PROP_FOO +#undef MAKE_PROP m.def("test_ShPtr_copy", []() { auto o = std::make_shared("copy"); @@ -113,7 +100,6 @@ TEST_SUBMODULE(class_sh_shared_ptr_copy_move, m) { l.append(std::move(o)); return l; }); -#endif // PYBIND11_SMART_HOLDER_ENABLED } } // namespace pybind11_tests diff --git a/tests/test_class_sh_shared_ptr_copy_move.py b/tests/test_class_sh_shared_ptr_copy_move.py index 70f5c76a0..067bb47d2 100644 --- a/tests/test_class_sh_shared_ptr_copy_move.py +++ b/tests/test_class_sh_shared_ptr_copy_move.py @@ -1,12 +1,7 @@ from __future__ import annotations -import pytest - from pybind11_tests import class_sh_shared_ptr_copy_move as m -if not m.defined_PYBIND11_SMART_HOLDER_ENABLED: - pytest.skip("smart_holder not available.", allow_module_level=True) - def test_shptr_copy(): txt = m.test_ShPtr_copy()[0].get_history() diff --git a/tests/test_class_sh_trampoline_basic.cpp b/tests/test_class_sh_trampoline_basic.cpp index 32bf23d2d..7ae3be5bf 100644 --- a/tests/test_class_sh_trampoline_basic.cpp +++ b/tests/test_class_sh_trampoline_basic.cpp @@ -34,7 +34,6 @@ struct AbaseAlias : Abase { } }; -#ifdef PYBIND11_SMART_HOLDER_ENABLED template <> struct AbaseAlias<1> : Abase<1>, py::trampoline_self_life_support { using Abase<1>::Abase; @@ -46,7 +45,6 @@ struct AbaseAlias<1> : Abase<1>, py::trampoline_self_life_support { other_val); } }; -#endif // PYBIND11_SMART_HOLDER_ENABLED template int AddInCppRawPtr(const Abase *obj, int other_val) { @@ -63,7 +61,6 @@ int AddInCppUniquePtr(std::unique_ptr> obj, int other_val) { return obj->Add(other_val) * 100 + 13; } -#ifdef PYBIND11_SMART_HOLDER_ENABLED template void wrap(py::module_ m, const char *py_class_name) { py::classh, AbaseAlias>(m, py_class_name) @@ -75,24 +72,13 @@ void wrap(py::module_ m, const char *py_class_name) { m.def("AddInCppSharedPtr", AddInCppSharedPtr, py::arg("obj"), py::arg("other_val")); m.def("AddInCppUniquePtr", AddInCppUniquePtr, py::arg("obj"), py::arg("other_val")); } -#endif } // namespace class_sh_trampoline_basic } // namespace pybind11_tests using namespace pybind11_tests::class_sh_trampoline_basic; -PYBIND11_SMART_HOLDER_TYPE_CASTERS(Abase<0>) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(Abase<1>) - TEST_SUBMODULE(class_sh_trampoline_basic, m) { - m.attr("defined_PYBIND11_SMART_HOLDER_ENABLED") = -#ifndef PYBIND11_SMART_HOLDER_ENABLED - false; -#else - true; - wrap<0>(m, "Abase0"); wrap<1>(m, "Abase1"); -#endif // PYBIND11_SMART_HOLDER_ENABLED } diff --git a/tests/test_class_sh_trampoline_basic.py b/tests/test_class_sh_trampoline_basic.py index 935a17275..eab82121f 100644 --- a/tests/test_class_sh_trampoline_basic.py +++ b/tests/test_class_sh_trampoline_basic.py @@ -4,9 +4,6 @@ import pytest from pybind11_tests import class_sh_trampoline_basic as m -if not m.defined_PYBIND11_SMART_HOLDER_ENABLED: - pytest.skip("smart_holder not available.", allow_module_level=True) - class PyDrvd0(m.Abase0): def __init__(self, val): diff --git a/tests/test_class_sh_trampoline_self_life_support.cpp b/tests/test_class_sh_trampoline_self_life_support.cpp index c342598e5..6c14e39c9 100644 --- a/tests/test_class_sh_trampoline_self_life_support.cpp +++ b/tests/test_class_sh_trampoline_self_life_support.cpp @@ -38,26 +38,16 @@ protected: Big5() : history{"DefaultConstructor"} {} }; -#ifdef PYBIND11_SMART_HOLDER_ENABLED struct Big5Trampoline : Big5, py::trampoline_self_life_support { using Big5::Big5; }; -#endif } // namespace class_sh_trampoline_self_life_support } // namespace pybind11_tests using namespace pybind11_tests::class_sh_trampoline_self_life_support; -PYBIND11_SMART_HOLDER_TYPE_CASTERS(Big5) - TEST_SUBMODULE(class_sh_trampoline_self_life_support, m) { - m.attr("defined_PYBIND11_SMART_HOLDER_ENABLED") = -#ifndef PYBIND11_SMART_HOLDER_ENABLED - false; -#else - true; - py::classh(m, "Big5") .def(py::init()) .def_readonly("history", &Big5::history); @@ -94,5 +84,4 @@ TEST_SUBMODULE(class_sh_trampoline_self_life_support, m) { py::object o1 = py::cast(std::move(obj)); return py::make_tuple(o1, o2); }); -#endif // PYBIND11_SMART_HOLDER_ENABLED } diff --git a/tests/test_class_sh_trampoline_self_life_support.py b/tests/test_class_sh_trampoline_self_life_support.py index 076f3007d..d4af2ab99 100644 --- a/tests/test_class_sh_trampoline_self_life_support.py +++ b/tests/test_class_sh_trampoline_self_life_support.py @@ -4,9 +4,6 @@ import pytest import pybind11_tests.class_sh_trampoline_self_life_support as m -if not m.defined_PYBIND11_SMART_HOLDER_ENABLED: - pytest.skip("smart_holder not available.", allow_module_level=True) - class PyBig5(m.Big5): pass diff --git a/tests/test_class_sh_trampoline_shared_from_this.cpp b/tests/test_class_sh_trampoline_shared_from_this.cpp index d09fe0041..9ccc21329 100644 --- a/tests/test_class_sh_trampoline_shared_from_this.cpp +++ b/tests/test_class_sh_trampoline_shared_from_this.cpp @@ -71,11 +71,9 @@ struct SftSharedPtrStash { } }; -#ifdef PYBIND11_SMART_HOLDER_ENABLED struct SftTrampoline : Sft, py::trampoline_self_life_support { using Sft::Sft; }; -#endif long use_count(const std::shared_ptr &obj) { return obj.use_count(); } @@ -111,16 +109,7 @@ std::shared_ptr pass_through_shd_ptr(const std::shared_ptr &obj) { ret using namespace pybind11_tests::class_sh_trampoline_shared_from_this; -PYBIND11_SMART_HOLDER_TYPE_CASTERS(Sft) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(SftSharedPtrStash) - TEST_SUBMODULE(class_sh_trampoline_shared_from_this, m) { - m.attr("defined_PYBIND11_SMART_HOLDER_ENABLED") = -#ifndef PYBIND11_SMART_HOLDER_ENABLED - false; -#else - true; - py::classh(m, "Sft") .def(py::init()) .def(py::init([](const std::string &history, int) { @@ -146,5 +135,4 @@ TEST_SUBMODULE(class_sh_trampoline_shared_from_this, m) { m.def("make_pure_cpp_sft_unq_ptr", make_pure_cpp_sft_unq_ptr); m.def("make_pure_cpp_sft_shd_ptr", make_pure_cpp_sft_shd_ptr); m.def("pass_through_shd_ptr", pass_through_shd_ptr); -#endif // PYBIND11_SMART_HOLDER_ENABLED } diff --git a/tests/test_class_sh_trampoline_shared_from_this.py b/tests/test_class_sh_trampoline_shared_from_this.py index 9b0d122b4..fbe31387a 100644 --- a/tests/test_class_sh_trampoline_shared_from_this.py +++ b/tests/test_class_sh_trampoline_shared_from_this.py @@ -8,9 +8,6 @@ import pytest import env import pybind11_tests.class_sh_trampoline_shared_from_this as m -if not m.defined_PYBIND11_SMART_HOLDER_ENABLED: - pytest.skip("smart_holder not available.", allow_module_level=True) - class PySft(m.Sft): pass diff --git a/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp b/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp index ced2ea9dd..ee381f2eb 100644 --- a/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp +++ b/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp @@ -57,18 +57,7 @@ struct SpGoAwayTester { using namespace pybind11_tests::class_sh_trampoline_shared_ptr_cpp_arg; -PYBIND11_SMART_HOLDER_TYPE_CASTERS(SpBase) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(SpBaseTester) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(SpGoAway) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(SpGoAwayTester) - TEST_SUBMODULE(class_sh_trampoline_shared_ptr_cpp_arg, m) { - m.attr("defined_PYBIND11_SMART_HOLDER_ENABLED") = -#ifndef PYBIND11_SMART_HOLDER_ENABLED - false; -#else - true; - // For testing whether a python subclass of a C++ object dies when the // last python reference is lost @@ -101,5 +90,4 @@ TEST_SUBMODULE(class_sh_trampoline_shared_ptr_cpp_arg, m) { py::classh(m, "SpGoAwayTester") .def(py::init<>()) .def_readwrite("obj", &SpGoAwayTester::m_obj); -#endif // PYBIND11_SMART_HOLDER_ENABLED } diff --git a/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.py b/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.py index 7a44a602d..a693621e3 100644 --- a/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.py +++ b/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.py @@ -5,9 +5,6 @@ import pytest import env # noqa: F401 import pybind11_tests.class_sh_trampoline_shared_ptr_cpp_arg as m -if not m.defined_PYBIND11_SMART_HOLDER_ENABLED: - pytest.skip("smart_holder not available.", allow_module_level=True) - @pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC") def test_shared_ptr_cpp_arg(): diff --git a/tests/test_class_sh_trampoline_unique_ptr.cpp b/tests/test_class_sh_trampoline_unique_ptr.cpp index 72c0ca5e0..1a5809420 100644 --- a/tests/test_class_sh_trampoline_unique_ptr.cpp +++ b/tests/test_class_sh_trampoline_unique_ptr.cpp @@ -34,12 +34,9 @@ private: } // namespace class_sh_trampoline_unique_ptr } // namespace pybind11_tests -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_trampoline_unique_ptr::Class) - namespace pybind11_tests { namespace class_sh_trampoline_unique_ptr { -#ifdef PYBIND11_SMART_HOLDER_ENABLED class PyClass : public Class, public py::trampoline_self_life_support { public: std::unique_ptr clone() const override { @@ -48,18 +45,11 @@ public: int foo() const override { PYBIND11_OVERRIDE_PURE(int, Class, foo); } }; -#endif } // namespace class_sh_trampoline_unique_ptr } // namespace pybind11_tests TEST_SUBMODULE(class_sh_trampoline_unique_ptr, m) { - m.attr("defined_PYBIND11_SMART_HOLDER_ENABLED") = -#ifndef PYBIND11_SMART_HOLDER_ENABLED - false; -#else - true; - using namespace pybind11_tests::class_sh_trampoline_unique_ptr; py::classh(m, "Class") @@ -71,5 +61,4 @@ TEST_SUBMODULE(class_sh_trampoline_unique_ptr, m) { m.def("clone", [](const Class &obj) { return obj.clone(); }); m.def("clone_and_foo", [](const Class &obj) { return obj.clone()->foo(); }); -#endif // PYBIND11_SMART_HOLDER_ENABLED } diff --git a/tests/test_class_sh_trampoline_unique_ptr.py b/tests/test_class_sh_trampoline_unique_ptr.py index 4044761fb..7799df6d6 100644 --- a/tests/test_class_sh_trampoline_unique_ptr.py +++ b/tests/test_class_sh_trampoline_unique_ptr.py @@ -1,12 +1,7 @@ from __future__ import annotations -import pytest - import pybind11_tests.class_sh_trampoline_unique_ptr as m -if not m.defined_PYBIND11_SMART_HOLDER_ENABLED: - pytest.skip("smart_holder not available.", allow_module_level=True) - class MyClass(m.Class): def foo(self): diff --git a/tests/test_class_sh_unique_ptr_custom_deleter.cpp b/tests/test_class_sh_unique_ptr_custom_deleter.cpp index 4bc4566bf..870779fdd 100644 --- a/tests/test_class_sh_unique_ptr_custom_deleter.cpp +++ b/tests/test_class_sh_unique_ptr_custom_deleter.cpp @@ -22,25 +22,10 @@ private: explicit Pet(const std::string &name) : name(name) {} }; -} // namespace class_sh_unique_ptr_custom_deleter -} // namespace pybind11_tests - -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_unique_ptr_custom_deleter::Pet) - -namespace pybind11_tests { -namespace class_sh_unique_ptr_custom_deleter { - TEST_SUBMODULE(class_sh_unique_ptr_custom_deleter, m) { - m.attr("defined_PYBIND11_SMART_HOLDER_ENABLED") = -#ifndef PYBIND11_SMART_HOLDER_ENABLED - false; -#else - true; - py::classh(m, "Pet").def_readwrite("name", &Pet::name); m.def("create", &Pet::New); -#endif // PYBIND11_SMART_HOLDER_ENABLED } } // namespace class_sh_unique_ptr_custom_deleter diff --git a/tests/test_class_sh_unique_ptr_custom_deleter.py b/tests/test_class_sh_unique_ptr_custom_deleter.py index 8658de8d1..34aa52068 100644 --- a/tests/test_class_sh_unique_ptr_custom_deleter.py +++ b/tests/test_class_sh_unique_ptr_custom_deleter.py @@ -1,12 +1,7 @@ from __future__ import annotations -import pytest - from pybind11_tests import class_sh_unique_ptr_custom_deleter as m -if not m.defined_PYBIND11_SMART_HOLDER_ENABLED: - pytest.skip("smart_holder not available.", allow_module_level=True) - def test_create(): pet = m.create("abc") diff --git a/tests/test_class_sh_unique_ptr_member.cpp b/tests/test_class_sh_unique_ptr_member.cpp index 90df0c62c..fc0a6a16e 100644 --- a/tests/test_class_sh_unique_ptr_member.cpp +++ b/tests/test_class_sh_unique_ptr_member.cpp @@ -36,21 +36,7 @@ private: std::unique_ptr ptr_; }; -} // namespace class_sh_unique_ptr_member -} // namespace pybind11_tests - -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_unique_ptr_member::pointee) - -namespace pybind11_tests { -namespace class_sh_unique_ptr_member { - TEST_SUBMODULE(class_sh_unique_ptr_member, m) { - m.attr("defined_PYBIND11_SMART_HOLDER_ENABLED") = -#ifndef PYBIND11_SMART_HOLDER_ENABLED - false; -#else - true; - py::classh(m, "pointee").def(py::init<>()).def("get_int", &pointee::get_int); m.def("make_unique_pointee", make_unique_pointee); @@ -60,7 +46,6 @@ TEST_SUBMODULE(class_sh_unique_ptr_member, m) { .def("is_owner", &ptr_owner::is_owner) .def("give_up_ownership_via_unique_ptr", &ptr_owner::give_up_ownership_via_unique_ptr) .def("give_up_ownership_via_shared_ptr", &ptr_owner::give_up_ownership_via_shared_ptr); -#endif // PYBIND11_SMART_HOLDER_ENABLED } } // namespace class_sh_unique_ptr_member diff --git a/tests/test_class_sh_unique_ptr_member.py b/tests/test_class_sh_unique_ptr_member.py index 25bcba976..a5d2ccd23 100644 --- a/tests/test_class_sh_unique_ptr_member.py +++ b/tests/test_class_sh_unique_ptr_member.py @@ -4,9 +4,6 @@ import pytest from pybind11_tests import class_sh_unique_ptr_member as m -if not m.defined_PYBIND11_SMART_HOLDER_ENABLED: - pytest.skip("smart_holder not available.", allow_module_level=True) - def test_make_unique_pointee(): obj = m.make_unique_pointee() diff --git a/tests/test_class_sh_virtual_py_cpp_mix.cpp b/tests/test_class_sh_virtual_py_cpp_mix.cpp index 28f7d8fd6..b39423eb4 100644 --- a/tests/test_class_sh_virtual_py_cpp_mix.cpp +++ b/tests/test_class_sh_virtual_py_cpp_mix.cpp @@ -31,8 +31,6 @@ int get_from_cpp_plainc_ptr(const Base *b) { return b->get() + 4000; } int get_from_cpp_unique_ptr(std::unique_ptr b) { return b->get() + 5000; } -#ifdef PYBIND11_SMART_HOLDER_ENABLED - struct BaseVirtualOverrider : Base, py::trampoline_self_life_support { using Base::Base; @@ -45,24 +43,12 @@ struct CppDerivedVirtualOverrider : CppDerived, py::trampoline_self_life_support int get() const override { PYBIND11_OVERRIDE(int, CppDerived, get); } }; -#endif - } // namespace class_sh_virtual_py_cpp_mix } // namespace pybind11_tests using namespace pybind11_tests::class_sh_virtual_py_cpp_mix; -PYBIND11_SMART_HOLDER_TYPE_CASTERS(Base) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(CppDerivedPlain) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(CppDerived) - TEST_SUBMODULE(class_sh_virtual_py_cpp_mix, m) { - m.attr("defined_PYBIND11_SMART_HOLDER_ENABLED") = -#ifndef PYBIND11_SMART_HOLDER_ENABLED - false; -#else - true; - py::classh(m, "Base").def(py::init<>()).def("get", &Base::get); py::classh(m, "CppDerivedPlain").def(py::init<>()); @@ -71,5 +57,4 @@ TEST_SUBMODULE(class_sh_virtual_py_cpp_mix, m) { m.def("get_from_cpp_plainc_ptr", get_from_cpp_plainc_ptr, py::arg("b")); m.def("get_from_cpp_unique_ptr", get_from_cpp_unique_ptr, py::arg("b")); -#endif // PYBIND11_SMART_HOLDER_ENABLED } diff --git a/tests/test_class_sh_virtual_py_cpp_mix.py b/tests/test_class_sh_virtual_py_cpp_mix.py index 937a15ab4..33133eb88 100644 --- a/tests/test_class_sh_virtual_py_cpp_mix.py +++ b/tests/test_class_sh_virtual_py_cpp_mix.py @@ -4,9 +4,6 @@ import pytest from pybind11_tests import class_sh_virtual_py_cpp_mix as m -if not m.defined_PYBIND11_SMART_HOLDER_ENABLED: - pytest.skip("smart_holder not available.", allow_module_level=True) - class PyBase(m.Base): # Avoiding name PyDerived, for more systematic naming. def __init__(self): diff --git a/ubench/holder_comparison.cpp b/ubench/holder_comparison.cpp index feed3a0b5..da7e744c6 100644 --- a/ubench/holder_comparison.cpp +++ b/ubench/holder_comparison.cpp @@ -22,8 +22,6 @@ void wrap_number_bucket(py::module m, const char *class_name) { .def("add", &WrappedType::add, py::arg("other")); } -#ifdef PYBIND11_SMART_HOLDER_ENABLED - template class padded_unique_ptr { std::unique_ptr ptr; @@ -37,21 +35,15 @@ public: static_assert(sizeof(padded_unique_ptr) == sizeof(py::smart_holder), "Unexpected sizeof mismatch."); -#endif - } // namespace hc -#ifdef PYBIND11_SMART_HOLDER_ENABLED PYBIND11_DECLARE_HOLDER_TYPE(T, hc::padded_unique_ptr); -#endif PYBIND11_MODULE(pybind11_ubench_holder_comparison, m) { using namespace hc; wrap_number_bucket>(m, "number_bucket_up"); wrap_number_bucket>(m, "number_bucket_sp"); -#ifdef PYBIND11_SMART_HOLDER_ENABLED m.def("sizeof_smart_holder", []() { return sizeof(py::smart_holder); }); wrap_number_bucket>(m, "number_bucket_pu"); wrap_number_bucket(m, "number_bucket_sh"); -#endif }