mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-19 22:39:09 +00:00
Make init_holder do registration, and rename to init_instance
The instance registration for offset base types fails (under macOS, with a segfault) in the presense of virtual base types. The issue occurs when trying to `static_cast<Base *>(derived_ptr)` when `derived_ptr` has been allocated (via `operator new`) but not initialized. This commit fixes the issue by moving the addition to `registered_instances` into `init_holder` rather than immediately after value pointer allocation. This also renames it to `init_instance` since it does more than holder initialization now. (I also further renamed `init_holder_helper` to `init_holder` since `init_holder` isn't used anymore). Fixes #959.
This commit is contained in:
@@ -201,4 +201,20 @@ TEST_SUBMODULE(multiple_inheritance, m) {
|
||||
py::class_<VanillaDictMix1, Vanilla, WithDict>(m, "VanillaDictMix1").def(py::init<>());
|
||||
py::class_<VanillaDictMix2, WithDict, Vanilla>(m, "VanillaDictMix2").def(py::init<>());
|
||||
#endif
|
||||
|
||||
// test_diamond_inheritance
|
||||
// Issue #959: segfault when constructing diamond inheritance instance
|
||||
// All of these have int members so that there will be various unequal pointers involved.
|
||||
struct B { int b; virtual ~B() = default; };
|
||||
struct C0 : public virtual B { int c0; };
|
||||
struct C1 : public virtual B { int c1; };
|
||||
struct D : public C0, public C1 { int d; };
|
||||
py::class_<B>(m, "B")
|
||||
.def("b", [](B *self) { return self; });
|
||||
py::class_<C0, B>(m, "C0")
|
||||
.def("c0", [](C0 *self) { return self; });
|
||||
py::class_<C1, B>(m, "C1")
|
||||
.def("c1", [](C1 *self) { return self; });
|
||||
py::class_<D, C0, C1>(m, "D")
|
||||
.def(py::init<>());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user