ifdef out classh if PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT is not defined.

This commit is contained in:
Ralf W. Grosse-Kunstleve 2024-07-19 10:31:41 -07:00
parent e4456197c4
commit 41433f632a
3 changed files with 15 additions and 3 deletions

View File

@ -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

View File

@ -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_<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>
@ -21,4 +23,6 @@ public:
using class_<type_, smart_holder, options...>::class_;
};
#endif
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -63,6 +63,7 @@ int AddInCppUniquePtr(std::unique_ptr<Abase<SerNo>> obj, int other_val) {
template <int SerNo>
void wrap(py::module_ m, const char *py_class_name) {
#ifdef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT
py::classh<Abase<SerNo>, AbaseAlias<SerNo>>(m, py_class_name)
.def(py::init<int>(), py::arg("val"))
.def("Get", &Abase<SerNo>::Get)
@ -71,6 +72,7 @@ void wrap(py::module_ m, const char *py_class_name) {
m.def("AddInCppRawPtr", AddInCppRawPtr<SerNo>, py::arg("obj"), py::arg("other_val"));
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