[pypy-svn] pypy collections-module: Missing a reset-item-to-None, otherwise the reference to the

arigo commits-noreply at bitbucket.org
Tue Feb 15 20:55:25 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: collections-module
Changeset: r41999:39f1b1be3f19
Date: 2011-02-15 20:43 +0100
http://bitbucket.org/pypy/pypy/changeset/39f1b1be3f19/

Log:	Missing a reset-item-to-None, otherwise the reference to the item
	stay around.

diff --git a/pypy/module/_collections/test/test_deque.py b/pypy/module/_collections/test/test_deque.py
--- a/pypy/module/_collections/test/test_deque.py
+++ b/pypy/module/_collections/test/test_deque.py
@@ -291,21 +291,18 @@
         for s in ('abcd', xrange(200)):
             assert list(reversed(deque(s))) == list(reversed(s))
 
-    def test_container_iterator(self):
-        # Bug #3680: tp_traverse was not implemented for deque iterator objects
-        class C(object):
-            pass
-        for i in range(2):
-            obj = C()
-            ref = weakref.ref(obj)
-            if i == 0:
-                container = deque([obj, 1])
-            else:
-                container = reversed(deque([obj, 1]))
-            obj.x = iter(container)
-            del obj, container
-            test_support.gc_collect()
-            self.assertTrue(ref() is None, "Cycle was not collected")
+    def test_free(self):
+        import gc
+        from _collections import deque
+        class X(object):
+            freed = False
+            def __del__(self):
+                X.freed = True
+        d = deque()
+        d.append(X())
+        d.pop()
+        gc.collect(); gc.collect(); gc.collect()
+        assert X.freed
 
 class XXXXXXXXXTestVariousIteratorArgs:
 

diff --git a/pypy/module/_collections/interp_deque.py b/pypy/module/_collections/interp_deque.py
--- a/pypy/module/_collections/interp_deque.py
+++ b/pypy/module/_collections/interp_deque.py
@@ -215,6 +215,7 @@
         self.len -= 1
         ri = self.rightindex
         w_obj = self.rightblock.data[ri]
+        self.rightblock.data[ri] = None
         ri -= 1
         if ri < 0:
             if self.len == 0:
@@ -239,6 +240,7 @@
         self.len -= 1
         li = self.leftindex
         w_obj = self.leftblock.data[li]
+        self.leftblock.data[li] = None
         li += 1
         if li >= BLOCKLEN:
             if self.len == 0:


More information about the Pypy-commit mailing list