Skip to content
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

Override dead bindings when registering a new binding. #75

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

codewarrior0
Copy link

This fixes the behavior observed in #74.

When a C++ object is deallocated, the BindingManager retains a binding that points from the C++ object to its Python wrapper. The binding is normally destroyed when the Python wrapper is freed. If a new C++ object is allocated at the same address (before the Python wrapper is freed), the new binding will not be registered.

This change ensures that the new binding will be registered even if the old Python wrapper has not been freed.

When the old Python wrapper is freed, it uses the Python wrapper's address to destroy the binding (not the C++ object's address), so it will not destroy the new binding.

(BindingManager would previously override old bindings. This was changed in commit 3b74744 without explaining why.)

Additionally, this change adds the method shiboken.getBinding(cppAddress) to the shiboken module to aid in debugging similar problems with the BindingManager.

This is needed to handle the case where the underlying C++ object is deleted, but its Python wrapper is still alive. If a new C++ object is allocated at the same address, it needs to override the old binding to prevent the situation where the old binding is reused. If the old binding is not replaced, a C++ object may be bound to a Python wrapper for different object type. (Or worse, a C++ object is bound to a Python object which no longer exists.)
…istered for a C++ object.

This allows you to assert that `shiboken.getBinding(shiboken.getCppPointer(obj)[0]) is obj`, which was not true in the issue I was investigating.
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.

None yet

1 participant