Skip to content

Registered type fixes #960

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

Merged
merged 2 commits into from
Jul 29, 2017
Merged

Conversation

jagerman
Copy link
Member

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.

The PR also adds a new test to test_multiple_inheritance, so I first converted that to the new test style.

jagerman added 2 commits July 25, 2017 00:05
Significant rearrangement, but no new tests added.
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 pybind#959.
@garth-wells garth-wells mentioned this pull request Jul 25, 2017
6 tasks
@jagerman jagerman added this to the v2.2 milestone Jul 25, 2017
@jagerman jagerman merged commit 353615f into pybind:master Jul 29, 2017
jagerman added a commit to jagerman/pybind11 that referenced this pull request Jul 29, 2017
The fix for pybind#960 could result a type being registered multiple times if
its `__init__` is called multiple times.  This can happen perfectly
ordinarily when python-side multiple inheritance is involved: for
example, with a diamond inheritance pattern with each intermediate
classes invoking the parent constructor.

With the change in pybind#960, the multiple `__init__` calls meant
`register_instance` was called multiple times, but the deletion only
deleted it once.  Thus, if a future instance of the same type was
allocated at the same location, pybind would pick it up as a registered
type.

This fixes the issue by tracking whether a value pointer has been
registered to avoid both double-registering it.  (There's also a slight
optimization of not needing to do a registered_instances lookup when the
type is known not registered, but this is secondary).
jagerman added a commit to jagerman/pybind11 that referenced this pull request Jul 29, 2017
The fix for pybind#960 could result a type being registered multiple times if
its `__init__` is called multiple times.  This can happen perfectly
ordinarily when python-side multiple inheritance is involved: for
example, with a diamond inheritance pattern with each intermediate
classes invoking the parent constructor.

With the change in pybind#960, the multiple `__init__` calls meant
`register_instance` was called multiple times, but the deletion only
deleted it once.  Thus, if a future instance of the same type was
allocated at the same location, pybind would pick it up as a registered
type.

This fixes the issue by tracking whether a value pointer has been
registered to avoid both double-registering it.  (There's also a slight
optimization of not needing to do a registered_instances lookup when the
type is known not registered, but this is secondary).
@jagerman jagerman deleted the registered-type-fixes branch August 14, 2017 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Diamond inheritance -> segfault on OSX
1 participant