@@ -58,20 +58,33 @@ struct Derived2 : Base12 {
5858 int bar () const { return 2 ; }
5959};
6060
61+ struct UnspecBase {
62+ virtual ~UnspecBase () = default ;
63+ virtual int Get () const { return 100 ; }
64+ };
65+
66+ inline int PassUnspecBase (const UnspecBase &sb) { return sb.Get () + 30 ; }
67+
68+ struct UnspecDerived : UnspecBase {
69+ int Get () const override { return 200 ; }
70+ };
71+
6172} // namespace class_sh_void_ptr_capsule
6273} // namespace pybind11_tests
6374
64- PYBIND11_SMART_HOLDER_TYPE_CASTERS (pybind11_tests::class_sh_void_ptr_capsule::Valid)
65- PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_void_ptr_capsule::TypeWithGetattr)
66- PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_void_ptr_capsule::Base1)
67- PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_void_ptr_capsule::Base2)
68- PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_void_ptr_capsule::Base12)
69- PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_void_ptr_capsule::Derived1)
70- PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_void_ptr_capsule::Derived2)
75+ using namespace pybind11_tests ::class_sh_void_ptr_capsule;
7176
72- TEST_SUBMODULE(class_sh_void_ptr_capsule, m) {
73- using namespace pybind11_tests ::class_sh_void_ptr_capsule;
77+ PYBIND11_SMART_HOLDER_TYPE_CASTERS (Valid)
78+ PYBIND11_SMART_HOLDER_TYPE_CASTERS(TypeWithGetattr)
79+ PYBIND11_SMART_HOLDER_TYPE_CASTERS(Base1)
80+ PYBIND11_SMART_HOLDER_TYPE_CASTERS(Base2)
81+ PYBIND11_SMART_HOLDER_TYPE_CASTERS(Base12)
82+ PYBIND11_SMART_HOLDER_TYPE_CASTERS(Derived1)
83+ PYBIND11_SMART_HOLDER_TYPE_CASTERS(Derived2)
84+ PYBIND11_SMART_HOLDER_TYPE_CASTERS(UnspecBase)
85+ PYBIND11_SMART_HOLDER_TYPE_CASTERS(UnspecDerived)
7486
87+ TEST_SUBMODULE(class_sh_void_ptr_capsule, m) {
7588 py::classh<Valid>(m, " Valid" );
7689
7790 m.def (" get_from_valid_capsule" , &get_from_valid_capsule);
@@ -102,4 +115,13 @@ TEST_SUBMODULE(class_sh_void_ptr_capsule, m) {
102115 py::classh<Derived1, Base12>(m, " Derived1" ).def (py::init<>()).def (" bar" , &Derived1::bar);
103116
104117 py::classh<Derived2, Base12>(m, " Derived2" ).def (py::init<>()).def (" bar" , &Derived2::bar);
118+
119+ py::classh<UnspecBase>(m, " UnspecBase" );
120+ m.def (" PassUnspecBase" , PassUnspecBase);
121+ py::classh<UnspecDerived>(m, " UnspecDerived" ) // UnspecBase NOT specified as base here.
122+ .def (py::init<>())
123+ .def (" as_pybind11_tests_class_sh_void_ptr_capsule_UnspecBase" , [](UnspecDerived *self) {
124+ return py::reinterpret_steal<py::object>(
125+ PyCapsule_New (static_cast <void *>(self), nullptr , nullptr ));
126+ });
105127}
0 commit comments