bt2: make _ListenerHandle not hold a strong reference on the target object
The bt2._ListenerHandle object currently holds a strong reference to the
Python object on which the listener was added. This allows validating
that a handle passed to the remove_destruction_listener method of an
object mathces that object.
However, keeping that strong reference also prevents the destruction of
that target object. So, adding a destruction listener and keeping the
handle around actually prevents the destruction from happening, making
that destruction listener useless.
Change it so the _ListenerHandle only keeps the address of the target
object. This is enough to do the check described above. We must
however invalidate the _ListenerHandle when the target object is
destroyed, because another object could be later created at the same
address. To achieve this, the handle object is bound to the destruction
callback, so that we can invalidate it in
_trace_destruction_listener_from_native /
_trace_class_destruction_listener_from_native.
The "del" statements in the tests were necessary before, otherwise the
handles would keep the trace class / trace alive, and the destruction
listeners would not get called. I removed them, so it now tests that
keeping a listener handle doesn't keep the target object alive.
Change-Id: I668cf29b5a6046a89d4eff73d322cb0cd83e5109
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2426
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
This page took 0.026091 seconds and 4 git commands to generate.