Replies: 1 comment
-
After reading the fine manual one more time, I found one workaround that will probably work for me using shared pointers: I changed the holder to a shared pointer: PYBIND11_EMBEDDED_MODULE(B, m) {
py::class_<B, std::shared_ptr<B>>(m, "B") And, changed the usage to defining a auto b_ptr = std::make_shared<B>();
b_ptr->a_list.resize(5);
auto b_py = py::cast(b_ptr);
// prints ...
// [65537, 65537, 65537, 65537, 65537]
py::print(b_py.attr("a_list")); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a problem where I am trying to wrap a legacy class in Python using pybind11. The special aspect of this legacy class (whose code I cannot change) is that it doesn't allow copy construction. See below for an minimal extracted example of what I am dealing with:
First, I tried to use Custom Type Casters directly to wrap
A
as described in the docs, but that also requires that the underlying class be copy constructible.As an alternative, I tried wrapping
B
by defining a class module that extractsobj
like below:Using the above example, the wrapping code works when
B
is used as a pointer, but doesn't work whenB
is used as a stack object. See below:I believe Case-B doesn't work because A doesn't allow copy construction. Is there a way I can make Case-B work (i.e., make wrapping work with
B
objects defined on the stack)?I am using pybind11 version 2.6.2.
Please let me know if I missing something basic. Appreciate your help.
Beta Was this translation helpful? Give feedback.
All reactions