mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-19 22:39:09 +00:00
Enable unique_ptr holder with mixed Deleters between base and derived types (#1353)
* Check default holder -Recognize "std::unique_ptr<T, D>" as a default holder even if "D" doesn't match between base and derived holders * Add test for unique_ptr<T, D> change
This commit is contained in:
committed by
Wenzel Jakob
parent
cea42467b0
commit
63c2a972fe
@@ -186,6 +186,32 @@ TEST_SUBMODULE(smart_ptr, m) {
|
||||
.def(py::init<int>())
|
||||
.def_readwrite("value", &MyObject4::value);
|
||||
|
||||
// test_unique_deleter
|
||||
// Object with std::unique_ptr<T, D> where D is not matching the base class
|
||||
// Object with a protected destructor
|
||||
class MyObject4a {
|
||||
public:
|
||||
MyObject4a(int i) {
|
||||
value = i;
|
||||
print_created(this);
|
||||
};
|
||||
int value;
|
||||
protected:
|
||||
virtual ~MyObject4a() { print_destroyed(this); }
|
||||
};
|
||||
py::class_<MyObject4a, std::unique_ptr<MyObject4a, py::nodelete>>(m, "MyObject4a")
|
||||
.def(py::init<int>())
|
||||
.def_readwrite("value", &MyObject4a::value);
|
||||
|
||||
// Object derived but with public destructor and no Deleter in default holder
|
||||
class MyObject4b : public MyObject4a {
|
||||
public:
|
||||
MyObject4b(int i) : MyObject4a(i) { print_created(this); }
|
||||
~MyObject4b() { print_destroyed(this); }
|
||||
};
|
||||
py::class_<MyObject4b, MyObject4a>(m, "MyObject4b")
|
||||
.def(py::init<int>());
|
||||
|
||||
// test_large_holder
|
||||
class MyObject5 { // managed by huge_unique_ptr
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user