[smart_holder] Simplification: Enable smart_holder functionality unconditionally. (#5531)
* git merge --squash purge_internals_versions_4_5
* Remove PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT, set PYBIND11_INTERNALS_VERSION 7
* Remove all uses of PYBIND11_SMART_HOLDER_ENABLED under include/pybind11
* Remove obsolete PYBIND11_ACTUALLY_USING_SMART_HOLDER_AS_DEFAULT macro.
* Remove PYBIND11_SMART_HOLDER_ENABLED in ubench/holder_comparison.cpp
* Remove all uses of PYBIND11_SMART_HOLDER_ENABLED under tests/
* Remove `#define PYBIND11_SMART_HOLDER_ENABLED`
* Remove all uses of PYBIND11_SMART_HOLDER_TYPE_CASTERS under tests/
* Remove all uses of PYBIND11_TYPE_CASTER_BASE_HOLDER under tests/
* Add missing `#include <cstdint>`
Example error message (🐍 3.11 • ubuntu-latest • x64, GNU 13.3.0):
```
include/pybind11/detail/value_and_holder.h:56:52: error: ‘uint8_t’ is not a member of ‘std’; did you mean ‘wint_t’?
56 | inst->nonsimple.status[index] &= (std::uint8_t) ~instance::status_holder_constructed;
| ^~~~~~~
```
* Change PYBIND11_INTERNALS_VERSION to 106: It will be changed to 7 in a follow-on PR that actually changes the internals.diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index e3f2370..d8607ee 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -102,20 +102,6 @@
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 1b513f5..7267119 100644
--- a/include/pybind11/attr.h
+++ b/include/pybind11/attr.h
@@ -339,9 +339,7 @@
/// 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 9ab547b..09c262a 100644
--- a/include/pybind11/cast.h
+++ b/include/pybind11/cast.h
@@ -836,8 +836,6 @@
holder_type holder;
};
-#ifdef PYBIND11_SMART_HOLDER_ENABLED
-
template <typename, typename SFINAE = void>
struct copyable_holder_caster_shared_ptr_with_smart_holder_support_enabled : std::true_type {};
@@ -928,13 +926,13 @@
return;
}
throw cast_error("Unable to cast from non-held to held instance (T& to Holder<T>) "
-# 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<std::shared_ptr<type>>() + "''");
-# endif
+#endif
}
template <typename T = std::shared_ptr<type>,
@@ -968,8 +966,6 @@
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
template <typename T>
class type_caster<std::shared_ptr<T>> : public copyable_holder_caster<T, std::shared_ptr<T>> {};
@@ -990,8 +986,6 @@
static constexpr auto name = type_caster_base<type>::name;
};
-#ifdef PYBIND11_SMART_HOLDER_ENABLED
-
template <typename, typename SFINAE = void>
struct move_only_holder_caster_unique_ptr_with_smart_holder_support_enabled : std::true_type {};
@@ -1129,8 +1123,6 @@
std::shared_ptr<std::unique_ptr<type, deleter>> unique_ptr_storage;
};
-#endif // PYBIND11_SMART_HOLDER_ENABLED
-
template <typename type, typename deleter>
class type_caster<std::unique_ptr<type, deleter>>
: public move_only_holder_caster<type, std::unique_ptr<type, deleter>> {};
@@ -1169,10 +1161,8 @@
template <typename base, typename deleter>
struct is_holder_type<base, std::unique_ptr<base, deleter>> : std::true_type {};
-#ifdef PYBIND11_SMART_HOLDER_ENABLED
template <typename base>
struct is_holder_type<base, smart_holder> : 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 f119474..5e225f8 100644
--- a/include/pybind11/detail/common.h
+++ b/include/pybind11/detail/common.h
@@ -605,11 +605,8 @@
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 8fba2f8..ed95afe 100644
--- a/include/pybind11/detail/init.h
+++ b/include/pybind11/detail/init.h
@@ -198,8 +198,6 @@
v_h.value_ptr() = new Alias<Class>(std::move(result));
}
-#ifdef PYBIND11_SMART_HOLDER_ENABLED
-
template <typename T, typename D>
smart_holder init_smart_holder_from_unique_ptr(std::unique_ptr<T, D> &&unq_ptr,
bool void_cast_raw_ptr) {
@@ -268,8 +266,6 @@
v_h.type->init_instance(v_h.inst, &smhldr);
}
-#endif // PYBIND11_SMART_HOLDER_ENABLED
-
// Implementing class for py::init<...>()
template <typename... Args>
struct constructor {
diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h
index beba642..d8b7f69 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 @@
}
};
-#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 @@
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 @@
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 097d176..9618b21 100644
--- a/include/pybind11/detail/type_caster_base.h
+++ b/include/pybind11/detail/type_caster_base.h
@@ -511,8 +511,6 @@
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 @@
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 @@
// 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 @@
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 b2d2606..57f99b9 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 <type_traits>
-#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 <typename H>
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(PYBIND11_NAMESPACE)
diff --git a/include/pybind11/detail/value_and_holder.h b/include/pybind11/detail/value_and_holder.h
index ca37d70..64c55cc 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 <cstddef>
+#include <cstdint>
#include <typeinfo>
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h
index a09aafe..b4fdccf 100644
--- a/include/pybind11/pybind11.h
+++ b/include/pybind11/pybind11.h
@@ -1448,9 +1448,7 @@
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 @@
template <typename T, typename D, typename SFINAE = void>
struct property_cpp_function : detail::property_cpp_function_classic<T, D> {};
-#ifdef PYBIND11_SMART_HOLDER_ENABLED
-
PYBIND11_NAMESPACE_BEGIN(detail)
template <typename T, typename D, typename SFINAE = void>
@@ -1844,9 +1840,7 @@
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> {};
-#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 @@
// 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 <typename>
using default_holder_type = smart_holder;
#else
@@ -1913,7 +1906,6 @@
// A more fitting name would be uses_unique_ptr_holder.
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) {
record.holder_enum_v = detail::holder_enum_t::std_unique_ptr;
} else if (detail::is_instantiation<std::shared_ptr, holder_type>::value) {
@@ -1923,7 +1915,6 @@
} else {
record.holder_enum_v = detail::holder_enum_t::custom_holder;
}
-#endif
set_operator_new<type>(&record);
@@ -2265,8 +2256,6 @@
init_holder(inst, v_h, (const holder_type *) holder_ptr, v_h.value_ptr<type>());
}
-#ifdef PYBIND11_SMART_HOLDER_ENABLED
-
template <typename WrappedType>
static bool try_initialization_using_shared_from_this(holder_type *, WrappedType *, ...) {
return false;
@@ -2326,8 +2315,6 @@
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 @@
}
};
-#ifdef PYBIND11_SMART_HOLDER_ENABLED
-
// 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.
template <typename type_, typename... options>
@@ -2403,8 +2388,6 @@
using class_<type_, smart_holder, options...>::class_;
};
-#endif
-
/// Binds an existing constructor taking arguments Args...
template <typename... Args>
detail::initimpl::constructor<Args...> init() {
diff --git a/include/pybind11/trampoline_self_life_support.h b/include/pybind11/trampoline_self_life_support.h
index d988e75..484045b 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 @@
};
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
-
-#endif // PYBIND11_SMART_HOLDER_ENABLED
diff --git a/tests/test_class.cpp b/tests/test_class.cpp
index e4c0328..86c8d37 100644
--- a/tests/test_class.cpp
+++ b/tests/test_class.cpp
@@ -109,11 +109,7 @@
struct ToBeHeldByUniquePtr {};
py::class_<ToBeHeldByUniquePtr, std::unique_ptr<ToBeHeldByUniquePtr>>(m, "ToBeHeldByUniquePtr")
.def(py::init<>());
-#ifdef PYBIND11_SMART_HOLDER_ENABLED
m.def("pass_unique_ptr", [](std::unique_ptr<ToBeHeldByUniquePtr> &&) {});
-#else
- m.attr("pass_unique_ptr") = py::none();
-#endif
// test_inheritance
class Pet {
@@ -636,7 +632,7 @@
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 44a5582..b8102ec 100644
--- a/tests/test_class.py
+++ b/tests/test_class.py
@@ -51,8 +51,6 @@
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 1d23cd6..ee973c2 100644
--- a/tests/test_class_sh_basic.cpp
+++ b/tests/test_class_sh_basic.cpp
@@ -144,24 +144,7 @@
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<atyp>(m, "atyp").def(py::init<>()).def(py::init([](const std::string &mtxt) {
@@ -260,7 +243,6 @@
[]() { 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 74a4e40..f07253a 100644
--- a/tests/test_class_sh_basic.py
+++ b/tests/test_class_sh_basic.py
@@ -7,9 +7,6 @@
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 81e17ac..97c9528 100644
--- a/tests/test_class_sh_disowning.cpp
+++ b/tests/test_class_sh_disowning.cpp
@@ -28,16 +28,7 @@
} // 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<Atype<1>>(m, "Atype1").def(py::init<int>()).def("get", &Atype<1>::get);
@@ -49,5 +40,4 @@
m.def("overloaded", (int (*)(std::unique_ptr<Atype<1>>, int)) &overloaded);
m.def("overloaded", (int (*)(std::unique_ptr<Atype<2>>, int)) &overloaded);
-#endif // PYBIND11_SMART_HOLDER_ENABLED
}
diff --git a/tests/test_class_sh_disowning.py b/tests/test_class_sh_disowning.py
index 95fd30c..b9e6489 100644
--- a/tests/test_class_sh_disowning.py
+++ b/tests/test_class_sh_disowning.py
@@ -4,9 +4,6 @@
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 6622927..8b96672 100644
--- a/tests/test_class_sh_disowning_mi.cpp
+++ b/tests/test_class_sh_disowning_mi.cpp
@@ -48,21 +48,7 @@
} // 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<B>(m, "B")
@@ -98,5 +84,4 @@
py::classh<Base2>(m, "Base2").def(py::init<int>()).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 7b52612..4a4beec 100644
--- a/tests/test_class_sh_disowning_mi.py
+++ b/tests/test_class_sh_disowning_mi.py
@@ -5,9 +5,6 @@
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 f4c0c1d..3499eae 100644
--- a/tests/test_class_sh_factory_constructors.cpp
+++ b/tests/test_class_sh_factory_constructors.cpp
@@ -72,27 +72,7 @@
} // 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<atyp_valu>(m, "atyp_valu")
@@ -183,5 +163,4 @@
[](int, int, int, int, int) {
return std::make_shared<with_alias>(); // 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 149a334..5d45db6 100644
--- a/tests/test_class_sh_factory_constructors.py
+++ b/tests/test_class_sh_factory_constructors.py
@@ -4,9 +4,6 @@
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 86ecea9..bb46fb9 100644
--- a/tests/test_class_sh_inheritance.cpp
+++ b/tests/test_class_sh_inheritance.cpp
@@ -59,26 +59,7 @@
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<base>(m, "base");
py::classh<drvd, base>(m, "drvd");
@@ -105,7 +86,6 @@
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 4f8c0e6..cd9d6f4 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 2630ab0..244ccbf 100644
--- a/tests/test_class_sh_mi_thunks.cpp
+++ b/tests/test_class_sh_mi_thunks.cpp
@@ -35,17 +35,7 @@
} // 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 @@
}
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 af3971b..32bf475 100644
--- a/tests/test_class_sh_mi_thunks.py
+++ b/tests/test_class_sh_mi_thunks.py
@@ -4,9 +4,6 @@
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 22a1f69..6476a9c 100644
--- a/tests/test_class_sh_property.cpp
+++ b/tests/test_class_sh_property.cpp
@@ -46,24 +46,7 @@
} // namespace test_class_sh_property
-PYBIND11_TYPE_CASTER_BASE_HOLDER(test_class_sh_property::ClassicField,
- std::unique_ptr<test_class_sh_property::ClassicField>)
-PYBIND11_TYPE_CASTER_BASE_HOLDER(test_class_sh_property::ClassicOuter,
- std::unique_ptr<test_class_sh_property::ClassicOuter>)
-
-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_<ClassicField, std::unique_ptr<ClassicField>>(m, "ClassicField")
@@ -109,5 +92,4 @@
py::classh<WithConstCharPtrMember>(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 9bd2fbf..0250a7f 100644
--- a/tests/test_class_sh_property.py
+++ b/tests/test_class_sh_property.py
@@ -7,9 +7,6 @@
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 87b8433..42f1f6f 100644
--- a/tests/test_class_sh_property_non_owning.cpp
+++ b/tests/test_class_sh_property_non_owning.cpp
@@ -46,17 +46,7 @@
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<CoreField>(m, "CoreField").def_readwrite("int_value", &CoreField::int_value);
py::classh<DataField>(m, "DataField")
@@ -71,5 +61,4 @@
py::classh<DataFieldsHolder>(m, "DataFieldsHolder")
.def(py::init<std::size_t>())
.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 b977e75..33a9d45 100644
--- a/tests/test_class_sh_property_non_owning.py
+++ b/tests/test_class_sh_property_non_owning.py
@@ -4,9 +4,6 @@
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 9998327..5eb0ef3 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 @@
};
} // namespace
-} // namespace pybind11_tests
-
-PYBIND11_TYPE_CASTER_BASE_HOLDER(pybind11_tests::FooShPtr,
- std::shared_ptr<pybind11_tests::FooShPtr>)
-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_<FooShPtr, std::shared_ptr<FooShPtr>>(m, "FooShPtr")
@@ -63,30 +50,30 @@
py::classh<FooSmHld>(m, "FooSmHld").def("get_history", &FooSmHld::get_history);
auto outer = py::class_<Outer>(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<FooShPtr>("copy");
@@ -113,7 +100,6 @@
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 70f5c76..067bb47 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 32bf23d..7ae3be5 100644
--- a/tests/test_class_sh_trampoline_basic.cpp
+++ b/tests/test_class_sh_trampoline_basic.cpp
@@ -34,7 +34,6 @@
}
};
-#ifdef PYBIND11_SMART_HOLDER_ENABLED
template <>
struct AbaseAlias<1> : Abase<1>, py::trampoline_self_life_support {
using Abase<1>::Abase;
@@ -46,7 +45,6 @@
other_val);
}
};
-#endif // PYBIND11_SMART_HOLDER_ENABLED
template <int SerNo>
int AddInCppRawPtr(const Abase<SerNo> *obj, int other_val) {
@@ -63,7 +61,6 @@
return obj->Add(other_val) * 100 + 13;
}
-#ifdef PYBIND11_SMART_HOLDER_ENABLED
template <int SerNo>
void wrap(py::module_ m, const char *py_class_name) {
py::classh<Abase<SerNo>, AbaseAlias<SerNo>>(m, py_class_name)
@@ -75,24 +72,13 @@
m.def("AddInCppSharedPtr", AddInCppSharedPtr<SerNo>, py::arg("obj"), py::arg("other_val"));
m.def("AddInCppUniquePtr", AddInCppUniquePtr<SerNo>, 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 935a172..eab8212 100644
--- a/tests/test_class_sh_trampoline_basic.py
+++ b/tests/test_class_sh_trampoline_basic.py
@@ -4,9 +4,6 @@
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 c342598..6c14e39 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 @@
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<Big5, Big5Trampoline>(m, "Big5")
.def(py::init<std::string>())
.def_readonly("history", &Big5::history);
@@ -94,5 +84,4 @@
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 076f300..d4af2ab 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 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 d09fe00..9ccc213 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 @@
}
};
-#ifdef PYBIND11_SMART_HOLDER_ENABLED
struct SftTrampoline : Sft, py::trampoline_self_life_support {
using Sft::Sft;
};
-#endif
long use_count(const std::shared_ptr<Sft> &obj) { return obj.use_count(); }
@@ -111,16 +109,7 @@
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<Sft, SftTrampoline>(m, "Sft")
.def(py::init<const std::string &>())
.def(py::init([](const std::string &history, int) {
@@ -146,5 +135,4 @@
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 9b0d122..fbe3138 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 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 ced2ea9..ee381f2 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 @@
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 @@
py::classh<SpGoAwayTester>(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 7a44a60..a693621 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 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 72c0ca5..1a58094 100644
--- a/tests/test_class_sh_trampoline_unique_ptr.cpp
+++ b/tests/test_class_sh_trampoline_unique_ptr.cpp
@@ -34,12 +34,9 @@
} // 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<Class> clone() const override {
@@ -48,18 +45,11 @@
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<Class, PyClass>(m, "Class")
@@ -71,5 +61,4 @@
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 4044761..7799df6 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 4bc4566..870779f 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 @@
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<Pet>(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 8658de8..34aa520 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 90df0c6..fc0a6a1 100644
--- a/tests/test_class_sh_unique_ptr_member.cpp
+++ b/tests/test_class_sh_unique_ptr_member.cpp
@@ -36,21 +36,7 @@
std::unique_ptr<pointee> 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<pointee>(m, "pointee").def(py::init<>()).def("get_int", &pointee::get_int);
m.def("make_unique_pointee", make_unique_pointee);
@@ -60,7 +46,6 @@
.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 25bcba9..a5d2ccd 100644
--- a/tests/test_class_sh_unique_ptr_member.py
+++ b/tests/test_class_sh_unique_ptr_member.py
@@ -4,9 +4,6 @@
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 28f7d8f..b39423e 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_unique_ptr(std::unique_ptr<Base> 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 @@
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<Base, BaseVirtualOverrider>(m, "Base").def(py::init<>()).def("get", &Base::get);
py::classh<CppDerivedPlain, Base>(m, "CppDerivedPlain").def(py::init<>());
@@ -71,5 +57,4 @@
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 937a15a..33133eb 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 @@
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 feed3a0..da7e744 100644
--- a/ubench/holder_comparison.cpp
+++ b/ubench/holder_comparison.cpp
@@ -22,8 +22,6 @@
.def("add", &WrappedType::add, py::arg("other"));
}
-#ifdef PYBIND11_SMART_HOLDER_ENABLED
-
template <typename T>
class padded_unique_ptr {
std::unique_ptr<T> ptr;
@@ -37,21 +35,15 @@
static_assert(sizeof(padded_unique_ptr<nb_pu>) == sizeof(py::smart_holder),
"Unexpected sizeof mismatch.");
-#endif
-
} // namespace hc
-#ifdef PYBIND11_SMART_HOLDER_ENABLED
PYBIND11_DECLARE_HOLDER_TYPE(T, hc::padded_unique_ptr<T>);
-#endif
PYBIND11_MODULE(pybind11_ubench_holder_comparison, m) {
using namespace hc;
wrap_number_bucket<nb_up, std::unique_ptr<nb_up>>(m, "number_bucket_up");
wrap_number_bucket<nb_sp, std::shared_ptr<nb_sp>>(m, "number_bucket_sp");
-#ifdef PYBIND11_SMART_HOLDER_ENABLED
m.def("sizeof_smart_holder", []() { return sizeof(py::smart_holder); });
wrap_number_bucket<nb_pu, padded_unique_ptr<nb_pu>>(m, "number_bucket_pu");
wrap_number_bucket<nb_sh, py::smart_holder>(m, "number_bucket_sh");
-#endif
}