From: Simon Marchi Date: Wed, 20 Nov 2019 20:25:06 +0000 (-0500) Subject: bt2: make _ListenerHandle not hold a strong reference on the target object X-Git-Tag: v2.0.0~55 X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=d4024c865ab717d09e0055b41f72597baef23057;hp=d4024c865ab717d09e0055b41f72597baef23057;p=babeltrace.git 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 Reviewed-on: https://review.lttng.org/c/babeltrace/+/2426 Reviewed-by: Philippe Proulx ---