Skip to content

Commit

Permalink
Move classh into pybind11/pybind11.h and update test_classh_mock.cp…
Browse files Browse the repository at this point in the history
…p accordingly.
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Jul 21, 2024
1 parent 9f9a698 commit d0003f5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
12 changes: 12 additions & 0 deletions include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -2308,6 +2308,18 @@ class class_ : public detail::generic_type {
}
};

#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>
class classh : public class_<type_, smart_holder, options...> {
public:
using class_<type_, smart_holder, options...>::class_;
};

#endif

/// Binds an existing constructor taking arguments Args...
template <typename... Args>
detail::initimpl::constructor<Args...> init() {
Expand Down
18 changes: 2 additions & 16 deletions include/pybind11/smart_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_<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>
class classh : public class_<type_, smart_holder, options...> {
public:
using class_<type_, smart_holder, options...>::class_;
};

#endif

PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
14 changes: 8 additions & 6 deletions tests/test_classh_mock.cpp
Original file line number Diff line number Diff line change
@@ -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 <pybind11/smart_holder.h>
#else
# include <pybind11/pybind11.h>
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
# ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT
template <typename type_, typename... options>
using classh = class_<type_, options...>;
# endif
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
# ifndef PYBIND11_SH_AVL
# define PYBIND11_SH_AVL(...) std::shared_ptr<__VA_ARGS__> // "Smart_Holder if AVaiLable"
Expand All @@ -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 {};
Expand All @@ -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<FooSa>)

Expand Down

0 comments on commit d0003f5

Please sign in to comment.