pybind / pybind/pybind11

Handling rvalue function arguments

Open
#2,040 4 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.