-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30075 from rwgk/pywrapcc_merge_sh
git merge smart_holder (pybind/pybind11#4917)
- Loading branch information
Showing
7 changed files
with
127 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <pybind11/smart_holder.h> | ||
|
||
#include "pybind11_tests.h" | ||
|
||
#include <memory> | ||
|
||
namespace pybind11_tests { | ||
namespace class_sh_unique_ptr_custom_deleter { | ||
|
||
// Reduced from a PyCLIF use case in the wild by @wangxf123456. | ||
class Pet { | ||
public: | ||
using Ptr = std::unique_ptr<Pet, std::function<void(Pet *)>>; | ||
|
||
std::string name; | ||
|
||
static Ptr New(const std::string &name) { | ||
return Ptr(new Pet(name), std::default_delete<Pet>()); | ||
} | ||
|
||
private: | ||
explicit Pet(const std::string &name) : name(name) {} | ||
}; | ||
|
||
} // namespace class_sh_unique_ptr_custom_deleter | ||
} // namespace pybind11_tests | ||
|
||
PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_unique_ptr_custom_deleter::Pet) | ||
|
||
namespace pybind11_tests { | ||
namespace class_sh_unique_ptr_custom_deleter { | ||
|
||
TEST_SUBMODULE(class_sh_unique_ptr_custom_deleter, m) { | ||
py::classh<Pet>(m, "Pet").def_readwrite("name", &Pet::name); | ||
|
||
m.def("create", &Pet::New); | ||
} | ||
|
||
} // namespace class_sh_unique_ptr_custom_deleter | ||
} // namespace pybind11_tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from pybind11_tests import class_sh_unique_ptr_custom_deleter as m | ||
|
||
|
||
def test_create(): | ||
pet = m.create("abc") | ||
assert pet.name == "abc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters