diff options
author | Thomas Heller <theller@ctypes.org> | 2008-01-16 19:16:27 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2008-01-16 19:16:27 (GMT) |
commit | 902d30752fa79fa787114b3f2cde37513909bc57 (patch) | |
tree | 7c6489f100a485d80b171625f937bbed11fe64dd /Lib | |
parent | 5c8b2abf71497819636474eb211655772ad1f1d8 (diff) | |
download | cpython-902d30752fa79fa787114b3f2cde37513909bc57.zip cpython-902d30752fa79fa787114b3f2cde37513909bc57.tar.gz cpython-902d30752fa79fa787114b3f2cde37513909bc57.tar.bz2 |
Convert the internal ctypes array type cache to a WeakValueDict so
that array types do not live longer than needed.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/ctypes/test/test_arrays.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/ctypes/test/test_arrays.py b/Lib/ctypes/test/test_arrays.py index e635ae1..7ee16c1 100644 --- a/Lib/ctypes/test/test_arrays.py +++ b/Lib/ctypes/test/test_arrays.py @@ -116,5 +116,19 @@ class ArrayTestCase(unittest.TestCase): self.failUnlessEqual(sz[1:4:2], "o") self.failUnlessEqual(sz.value, "foo") + def test_cache(self): + # Array types are cached internally in the _ctypes extension, + # in a WeakValueDictionary. Make sure the array type is + # removed from the cache when the itemtype goes away. This + # test will not fail, but will show a leak in the testsuite. + + # Create a new type: + class my_int(c_int): + pass + # Create a new array type based on it: + t1 = my_int * 1 + t2 = my_int * 1 + self.failUnless(t1 is t2) + if __name__ == '__main__': unittest.main() |