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
Exposing different globals via std::unique_ptr<S, py::nodelete> > can lead to pybind11_object_dealloc(): Tried to deallocate unregistered instance! #2394
Comments
Update: The following code appears to work, but I'm not certain I'm holding this right. py::class_<S>(m, "S")
.def(
"__init__",
[](py::detail::value_and_holder& v_h, int index) {
v_h.value_ptr() = &sarray[index];
v_h.inst->owned = false;
v_h.set_holder_constructed(true);
},
py::detail::is_new_style_constructor())
.def_readonly("i", &S::i)
.def_readonly("name", &S::name); |
It also works for me, on linux with gcc 10 or clang 10. |
Actually, scratch that. It just happens at exit. I managed to reproduce eventually. EDIT: At least I've seen the error happen last night, but now I cannot repro... EDIT2: Here's how to repro.
|
Is this related to #2252, #1592, and #1568? Let me try if that proposed fix helps. Update: Good news! I could reproduce with @bstaletic's code, but not anymore with the fix from #2252. Let's now see if I can understand what goes wrong. |
See #2252 for further updates, @heiner & @bstaletic :-) |
Fixed in 2.6.0. Thanks to @YannickJadoul and @henryiii |
First of all, many thanks for this excellent library! <3
Issue description
I want to expose the values of global structs defined in a library I'm using. As I didn't get
py::return_value_policy::reference
to work withpy::init
ordef("__init__", ...)
, I'm trying with a holder type ofstd::unique_ptr<S, py::nodelete> >
. This appears to work at first, and in many situations, but breaks in a situation where different objects of this type override each other.Reproducible example code
Together with
On Ubuntu 18.04 with GCC 7.4.0, this fails with:
Interestingly, it works on MacOS 10.15.5 with Apple clang version 11.0.0 (clang-1100.0.33.12).
The text was updated successfully, but these errors were encountered: