diff --git a/include/pybind11/detail/using_smart_holder.h b/include/pybind11/detail/using_smart_holder.h index 1762944d0..ef95ea7fc 100644 --- a/include/pybind11/detail/using_smart_holder.h +++ b/include/pybind11/detail/using_smart_holder.h @@ -4,11 +4,17 @@ #pragma once -#include "common.h" -#include "smart_holder_poc.h" +#include "internals.h" + +#ifdef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT + +# include "common.h" +# include "smart_holder_poc.h" PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) using pybindit::memory::smart_holder; PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) + +#endif diff --git a/include/pybind11/smart_holder.h b/include/pybind11/smart_holder.h index 8d776d970..6ca9e7d3d 100644 --- a/include/pybind11/smart_holder.h +++ b/include/pybind11/smart_holder.h @@ -1,4 +1,4 @@ -// Copyright (c) 2024 The Pybind Development Team. +// Copyright (c) 2021-2024 The Pybind Development Team. // All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -13,6 +13,8 @@ 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 @@ -21,4 +23,6 @@ public: using class_::class_; }; +#endif + PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/tests/test_class_sh_trampoline_basic.cpp b/tests/test_class_sh_trampoline_basic.cpp index 8627a8d6d..856f274c2 100644 --- a/tests/test_class_sh_trampoline_basic.cpp +++ b/tests/test_class_sh_trampoline_basic.cpp @@ -63,6 +63,7 @@ int AddInCppUniquePtr(std::unique_ptr> obj, int other_val) { template void wrap(py::module_ m, const char *py_class_name) { +#ifdef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT py::classh, AbaseAlias>(m, py_class_name) .def(py::init(), py::arg("val")) .def("Get", &Abase::Get) @@ -71,6 +72,7 @@ void wrap(py::module_ m, const char *py_class_name) { m.def("AddInCppRawPtr", AddInCppRawPtr, py::arg("obj"), py::arg("other_val")); 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