diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 82c5423de..6fe93e0ae 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1797,8 +1797,14 @@ struct property_cpp_function< #endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT +#ifdef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT +// BAKEIN_WIP: Add comment to explain: This is meant for stress-testing only. template using default_holder_type = pybindit::memory::smart_holder; +#else +template +using default_holder_type = std::unique_ptr; +#endif template class class_ : public detail::generic_type { @@ -1816,8 +1822,7 @@ public: using type = type_; using type_alias = detail::exactly_one_t; constexpr static bool has_alias = !std::is_void::value; - using holder_type - = detail::exactly_one_t; + using holder_type = detail::exactly_one_t, options...>; static_assert(detail::all_of...>::value, "Unknown/invalid class_ template parameters provided"); diff --git a/include/pybind11/smart_holder.h b/include/pybind11/smart_holder.h index d2aac88e8..8735ca95d 100644 --- a/include/pybind11/smart_holder.h +++ b/include/pybind11/smart_holder.h @@ -13,10 +13,12 @@ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +// Supports easier switching between py::class_ and py::class_: +// users can simply replace the `_` in `class_` with `h` or vice versa. template -class classh : public class_ { +class classh : public class_ { public: - using class_::class_; + using class_::class_; }; PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/tests/test_class.cpp b/tests/test_class.cpp index ba462fa85..2701632e1 100644 --- a/tests/test_class.cpp +++ b/tests/test_class.cpp @@ -614,8 +614,13 @@ CHECK_NOALIAS(8); CHECK_HOLDER(1, unique); CHECK_HOLDER(2, unique); CHECK_HOLDER(3, unique); +#ifdef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT CHECK_SMART_HOLDER(4); CHECK_SMART_HOLDER(5); +#else +CHECK_HOLDER(4, unique); +CHECK_HOLDER(5, unique); +#endif CHECK_HOLDER(6, shared); CHECK_HOLDER(7, shared); CHECK_HOLDER(8, shared);