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.
diff --git a/tests/test_multiple_inheritance.py b/tests/test_multiple_inheritance.py
index 7121c81..434f477 100644
--- a/tests/test_multiple_inheritance.py
+++ b/tests/test_multiple_inheritance.py
@@ -331,3 +331,18 @@
e2 = m.i801e_b2()
assert type(e2) is m.I801B2
assert e2.b == 2
+
+
+def test_diamond_inheritance():
+ """Tests that diamond inheritance works as expected (issue #959)"""
+
+ # Issue #959: this shouldn't segfault:
+ d = m.D()
+
+ # Make sure all the various distinct pointers are all recognized as registered instances:
+ assert d is d.c0()
+ assert d is d.c1()
+ assert d is d.b()
+ assert d is d.c0().b()
+ assert d is d.c1().b()
+ assert d is d.c0().c1().b().c0().b()