-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[smart_holder] RuntimeError: Invalid return_value_policy for shared_ptr #3011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
A simpler minimal case than above: class C {
C(int data);
public:
int data;
public:
static std::shared_ptr<C> make(int data) {
return std::shared_ptr<C>(new C(data));
}
};
void trigger() {
auto l = py::list();
auto c = C::make(42);
l.append(c); // throws RuntimeError: Invalid return_value_policy for shared_ptr.
} I'm not sure if this intersects the same code as the original example. |
As noted in #3012, the original issue seems fixed in the smart_holder branch, but the second issue is still present. |
Hi @jakobandersen, echoing @rhaschke 's request: #3012 (comment) That would help us working on the issue together. BTW: I will respond to PRs much faster, I just don't have the free bandwidth to pay much attention to the pybind11 github issues. |
Sure, I started working in #3039, at least for adding tests for the cases I ran into and see if a simple change works out. |
Fixed via #3039. |
While trying to convert from Boost.Python I ran into the lifetime issue raised, e.g., in #2839, so I am using the smart_holder branch.
A minimal test case can be found at https://github.com/jakobandersen/pyTest/tree/pybind, with the central part at https://github.com/jakobandersen/pyTest/blob/pybind/libpytest.cpp#L42.
Essentially I have a custom function class which can be derived in Python. The problem is occurs when the function takes a
std::shared_ptr
as argument and is called from C++. When usingPYBIND11_OVERRIDE_PURE_NAME
to implement the call back to the Python implementation it will call the override with the defaultreturn_value_policy
, which seems to beautomatic_reference
.This gives the exception
RuntimeError: Invalid return_value_policy for shared_ptr.
.Expanding the macro and giving
automatic
as policy makes it work as intended (as done in https://github.com/jakobandersen/pyTest/blob/pybind/libpytest.cpp#L58).Am I missing something in the setup? Is this manual hax to make it work correct?
The text was updated successfully, but these errors were encountered: