Skip to content

Commit 36240b4

Browse files
committed
python: Reference parent Device object from Buffer
By having the Buffer objects reference their parent Device object, without having the opposite, we can have a proper dependency graph, and the objects will be freed in the correct order. Signed-off-by: Paul Cercueil <[email protected]>
1 parent befeb37 commit 36240b4

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

bindings/python/iio.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,9 +1018,10 @@ def __init__(self, device, samples_count, cyclic=False):
10181018
raise
10191019
self._length = samples_count * device.sample_size
10201020
self._samples_count = samples_count
1021-
self._ctx = device.ctx()
1022-
# Holds a reference to the corresponding IIO Context. This ensures that
1023-
# every iio.Buffer object is destroyed before its corresponding IIO Context.
1021+
1022+
# Hold a reference to the device, to ensure that every iio.Buffer object
1023+
# is destroyed before its corresponding IIO context.
1024+
self._dev = device
10241025

10251026
def __del__(self):
10261027
"""Destroy this buffer."""
@@ -1101,7 +1102,7 @@ def device(self):
11011102
Device for the buffer.
11021103
type: iio.Device
11031104
"""
1104-
return Device(self._ctx, _buffer_get_device(self._buffer))
1105+
return self._dev
11051106

11061107
@property
11071108
def poll_fd(self):

0 commit comments

Comments
 (0)