-
I'm converting a codebase from pybind11 to nanobind. There were some classes that used shared_ptr holder types, so I'm moving those to use intrusive pointers. I think I've done everything the docs say:
I'm running into some segfaults that I suspect might be related to this but I don't know for sure. I can try to make a proper repro if requested, but at a high level we're doing this:
Then we call One specific question that seems odd to me is how, if the move and copy assignment operators and constructors are deleted, does nanobind construct a Python object from an existing object? My best guess is this is something to do with RVO and out-pointers behind the scenes. Overall though, does this sound like this should work? Or is there something architecturally incorrect? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Nanobind supports shared pointers just fine, so you don't necessarily need to stop using them. There are mainly two advantages of intrusive pointers: a small performance increase, and leak-free reference counting when bound classes implement C++ <-> Python callbacks. It's not really clear what the issue could be based on your explanation. The intrusive pointers are in active use in various projects without problems. I suggest that you try to reduce the bug into something self-contained, which may also help to pinpoint the problem. |
Beta Was this translation helpful? Give feedback.
The problem here ended up being in
compile
, we were usingnb::rv_policy::take_ownership
(not entirely sure why we were using it before). We removed that and let the default kick in, and it works now.