Skip to content

[BUG]: intrusive counter errors on reacquiring Python-side of object #1111

@tdavidovicNV

Description

@tdavidovicNV

Problem description

I have a piece of C++ code, where a ref-counted class (Outter) holds another ref-counted class (Inner) by nb::ref. The Inner class has a method get_name() that just returns a string. The Outter class has a method get_inner that returns an Inner&.

When I then do two consecutive calls to get_inner like so:

outter = Outter()
print(outter.get_inner().get_name())
print(outter.get_inner().get_name()) # hits abort here

it hits the abort in intrusive_counter::set_self_py.

If the get_inner() returns ref<Inner> instead of Inner&, things work fine.

My assumption is that the code that creates a Python object for Inner gets invoked twice, once for each get_inner() call. Instead it could first try to call self_py to check if the object exists, and avoid setting it the second time.

Reproducible example code

This is referenced in #1112

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions