Skip to content

Issue: object ref-count ignored when moving std::unique_ptr #2906

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

Closed
wants to merge 1 commit into from

Conversation

rhaschke
Copy link
Contributor

Inspecting the unit tests of #2904 in more detail, I noticed that the smart holder code is actually ignoring an object's ref-count, although there is this test:

holder().ensure_use_count_1(context);

Nevertheless, as shown in this example, the refcount of the object before moving it, is 3! Something weird is going on there. Moving should fail in this case, shouldn't it? @rwgk

Having that said, I actually want to have the possibility to move an object with a refcount > 1. Otherwise, I couldn't move a variable, but only "rvalues". There are extra checks in place to ensure that I don't access a disowned object again...

@rwgk
Copy link
Collaborator

rwgk commented Mar 17, 2021

holder().ensure_use_count_1(context);

Hi @rhaschke, this is the std::shared_ptr::use_count, which has basically nothing to do with the Python refcount, although conceptually both are very similar.

@rhaschke
Copy link
Contributor Author

Ah. Ok. Sorry for the noise.

@rhaschke rhaschke closed this Mar 17, 2021
@rhaschke rhaschke deleted the debug-smart-holder branch March 17, 2021 23:45
@EricCousineau-TRI EricCousineau-TRI added the smart holder See: https://github.com/pybind/pybind11/blob/smart_holder/README_smart_holder.rst label Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
smart holder See: https://github.com/pybind/pybind11/blob/smart_holder/README_smart_holder.rst
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants