diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2008-09-01 15:10:14 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2008-09-01 15:10:14 (GMT) |
commit | c6b09ebe58a968a85c725c3c01a1d6bca16fada0 (patch) | |
tree | 3ca5fc5f41464ed1e16bc780638891ddc99d5e16 /Lib | |
parent | d26782e8639df937fac1ef3f208986274138d5c1 (diff) | |
download | cpython-c6b09ebe58a968a85c725c3c01a1d6bca16fada0.zip cpython-c6b09ebe58a968a85c725c3c01a1d6bca16fada0.tar.gz cpython-c6b09ebe58a968a85c725c3c01a1d6bca16fada0.tar.bz2 |
#3712: The memoryview object had a reference leak and didn't support cyclic garbage collection.
Reviewed by Benjamin Peterson.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_memoryview.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_memoryview.py b/Lib/test/test_memoryview.py index dca48b1..0f6fc55 100644 --- a/Lib/test/test_memoryview.py +++ b/Lib/test/test_memoryview.py @@ -6,6 +6,8 @@ XXX We need more tests! Some tests are in test_bytes import unittest import test.support import sys +import gc +import weakref class CommonMemoryTests: @@ -157,6 +159,36 @@ class CommonMemoryTests: m = self.check_attributes_with_type(bytearray) self.assertEquals(m.readonly, False) + def test_getbuffer(self): + # Test PyObject_GetBuffer() on a memoryview object. + b = self.base_object + oldrefcount = sys.getrefcount(b) + m = self._view(b) + oldviewrefcount = sys.getrefcount(m) + s = str(m, "utf-8") + self._check_contents(b, s.encode("utf-8")) + self.assertEquals(sys.getrefcount(m), oldviewrefcount) + m = None + self.assertEquals(sys.getrefcount(b), oldrefcount) + + def test_gc(self): + class MyBytes(bytes): + pass + class MyObject: + pass + + # Create a reference cycle through a memoryview object + b = MyBytes(b'abc') + m = self._view(b) + o = MyObject() + b.m = m + b.o = o + wr = weakref.ref(o) + b = m = o = None + # The cycle must be broken + gc.collect() + self.assert_(wr() is None, wr()) + class MemoryviewTest(unittest.TestCase, CommonMemoryTests): |