You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What version (or hash if on master) of pybind11 are you using?
2.10.2
Problem description
The docs state that passing arguments as reference and pointer should work, but actually, while pointers works well, references dont. They end up beeing copied, which is a blocker if the type is not copy constructible.
auto item = StandardItem("id");
INFO << item.id();
p->takeThisAndModifyP(&item);
INFO << item.id();
p->takeThisAndModifyR(item);
INFO << item.id();
Finally this prints:
10:47:43 [info:python] id
10:47:43 [info:python] takeThisAndModifyP
10:47:43 [warn:albert] [17ms] Failed loading 'find': return_value_policy = copy, but type albert::StandardItem is non-copyable!
Of course I exposed the item class. Left it out for readability. Obviously pybind does not like references. Is this a bug or a known limitation and I should rather look for a workaround?
Hello, I have a problem that i think it is related to the topic of this issue:
I want to have a two way communication to and from python and what I come out is using a helper class in C++ with its python interface that should do that.
So I tried to pass by reference to a python function loaded in the embedded interpreter, and what python sees its a copy of my C++ object, so calling methods in python that should modify it do not affect the C++ instatiated object.
mylib::SimpleIO mytest;
auto fn = py_module.attr(funcName);
//This will NOT modify the data in mytestfn(mytest, setValue).cast<py::tuple>();
But if i cast the pointer of the C++ object with py::cast(&myobject) i can pass it (the object, not the casted pointer) to the python function and the methods in python affect my C++ object
mylib::SimpleIO mytest;
auto fn = py_module.attr(funcName);
auto obj = py::cast(&mytest);
//This will modify the data in mytestfn(mytest, setValue).cast<py::tuple>();
I know I'm not clear with words: I have set up a small gist with the example of this. I'm using pybind v2.10.4, all the details are within the CMakeLists.txt in the gist
Required prerequisites
What version (or hash if on master) of pybind11 are you using?
2.10.2
Problem description
The docs state that passing arguments as reference and pointer should work, but actually, while pointers works well, references dont. They end up beeing copied, which is a blocker if the type is not copy constructible.
Then in a pyhton plugin I do:
In the app i do
Finally this prints:
Of course I exposed the item class. Left it out for readability. Obviously pybind does not like references. Is this a bug or a known limitation and I should rather look for a workaround?
Related:
Reproducible example code
No response
Is this a regression? Put the last known working version here if it is.
Not a regression
The text was updated successfully, but these errors were encountered: