From d0003f5660362dd08ca48545b8b88bf8628abfdc Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Sat, 20 Jul 2024 17:53:37 -0700 Subject: [PATCH] Move `classh` into pybind11/pybind11.h and update test_classh_mock.cpp accordingly. --- include/pybind11/pybind11.h | 12 ++++++++++++ include/pybind11/smart_holder.h | 18 ++---------------- tests/test_classh_mock.cpp | 14 ++++++++------ 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 7c26f1d985..b7717f69b5 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -2308,6 +2308,18 @@ class class_ : public detail::generic_type { } }; +#ifdef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + +// 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_ { +public: + using class_::class_; +}; + +#endif + /// Binds an existing constructor taking arguments Args... template detail::initimpl::constructor init() { diff --git a/include/pybind11/smart_holder.h b/include/pybind11/smart_holder.h index 6ca9e7d3d5..5f568a5529 100644 --- a/include/pybind11/smart_holder.h +++ b/include/pybind11/smart_holder.h @@ -6,23 +6,9 @@ #include "pybind11.h" +// Legacy macros introduced with smart_holder_type_casters implementation in 2021. +// Deprecated. #define PYBIND11_TYPE_CASTER_BASE_HOLDER(...) #define PYBIND11_SMART_HOLDER_TYPE_CASTERS(...) #define PYBIND11_SH_AVL(...) // "Smart_Holder if AVaiLable" #define PYBIND11_SH_DEF(...) // "Smart_Holder if DEFault" - -PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) - -#ifdef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT - -// 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_ { -public: - using class_::class_; -}; - -#endif - -PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/tests/test_classh_mock.cpp b/tests/test_classh_mock.cpp index 38e765fb01..135320320f 100644 --- a/tests/test_classh_mock.cpp +++ b/tests/test_classh_mock.cpp @@ -1,18 +1,20 @@ #include "pybind11_tests.h" -// The main purpose of this test is to ensure the suggested BOILERPLATE code block below is -// correct. +// The main purpose of this test was to ensure that the suggested +// BOILERPLATE code block (NOW DEPRECATED!) block below is correct. // Copy this block of code into your project. // Replace FOOEXT with the name of your project. -// BOILERPLATE BEGIN +// BOILERPLATE BEGIN DEPRECATED DEPRECATED DEPRECATED DEPRECATED DEPRECATED #ifdef FOOEXT_USING_PYBIND11_SMART_HOLDER # include #else # include PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +# ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT template using classh = class_; +# endif PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) # ifndef PYBIND11_SH_AVL # define PYBIND11_SH_AVL(...) std::shared_ptr<__VA_ARGS__> // "Smart_Holder if AVaiLable" @@ -27,7 +29,7 @@ PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) # define PYBIND11_TYPE_CASTER_BASE_HOLDER(...) # endif #endif -// BOILERPLATE END +// BOILERPLATE END DEPRECATED DEPRECATED DEPRECATED DEPRECATED DEPRECATED namespace { struct FooUc {}; @@ -37,8 +39,8 @@ struct FooSc {}; struct FooSp {}; } // namespace -PYBIND11_SMART_HOLDER_TYPE_CASTERS(FooUp) -PYBIND11_SMART_HOLDER_TYPE_CASTERS(FooSp) +PYBIND11_SMART_HOLDER_TYPE_CASTERS(FooUp) // DEPRECATED +PYBIND11_SMART_HOLDER_TYPE_CASTERS(FooSp) // DEPRECATED PYBIND11_TYPE_CASTER_BASE_HOLDER(FooSa, std::shared_ptr)