Handling rvalue function arguments
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
I'm trying to wrap a C++ function that accepts an rvalue argument (std::unique_ptr<T>&&) and consumes it. In the docs it is mentioned that unique_ptrs are not allowed as arguments, because the instance might still be used.
However, when passing the pointer as an rvalue reference, this should work anyway - the holder pointer still exists and re-accessing it in python should throw. That's the way it worked in boost::python at least. There, it was possible to release auto_ptrs. Accessing the python object subsequently, was just throwing:
Python argument types in
test_move_arg_bp.access(Item)
did not match C++ signature:
access(Item)
An example illustrating the pybind11 issue and a running boost::python example is available here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the advanced/smart_ptrs.html#std-unique-ptr documentation and the linked rvalue-argument comparison, then reproduce the pybind11 and boost::python examples. Trace how a std::unique_ptr&& argument is handled and verify that consuming it prevents subsequent access through the Python object.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100