Skip to content

[smart_holder] RuntimeError: Invalid return_value_policy for shared_ptr #3011

Description

@jakobandersen

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 using PYBIND11_OVERRIDE_PURE_NAME to implement the call back to the Python implementation it will call the override with the default return_value_policy, which seems to be automatic_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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions