From 0a988f95bc16fcfdd9cd9c82f9307d6ad90c019b Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Thu, 18 Feb 2016 23:28:25 -0800 Subject: [PATCH] pybind: replace __del__ with __dealloc__ for rbd Cython extension types like these don't call __del__, but use __dealloc__ instead: http://docs.cython.org/src/userguide/special_methods.html#finalization-method-dealloc Signed-off-by: Josh Durgin --- src/pybind/rbd/rbd.pyx | 4 ++-- src/test/pybind/test_rbd.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pybind/rbd/rbd.pyx b/src/pybind/rbd/rbd.pyx index c7ae45aed7510..f25b3e10fce6d 100644 --- a/src/pybind/rbd/rbd.pyx +++ b/src/pybind/rbd/rbd.pyx @@ -661,7 +661,7 @@ cdef class Image(object): self.name,)) self.closed = True - def __del__(self): + def __dealloc__(self): self.close() def __repr__(self): @@ -1440,7 +1440,7 @@ cdef class SnapIterator(object): 'name' : decode_cstr(self.snaps[i].name), } - def __del__(self): + def __dealloc__(self): if self.snaps: rbd_snap_list_end(self.snaps) free(self.snaps) diff --git a/src/test/pybind/test_rbd.py b/src/test/pybind/test_rbd.py index 093a40dc8bc40..df98dee8c09c9 100644 --- a/src/test/pybind/test_rbd.py +++ b/src/test/pybind/test_rbd.py @@ -327,6 +327,9 @@ class TestImage(object): flags = self.image.flags() eq(0, flags) + def test_image_auto_close(self): + image = Image(ioctx, image_name) + def test_write(self): data = rand_data(256) self.image.write(data, 0) @@ -466,6 +469,11 @@ class TestImage(object): self.image.remove_snap('snap1') self.image.remove_snap('snap2') + def test_list_snaps_iterator_auto_close(self): + self.image.create_snap('snap1') + self.image.list_snaps() + self.image.remove_snap('snap1') + def test_remove_snap(self): eq([], list(self.image.list_snaps())) self.image.create_snap('snap1') -- 2.39.5