[pypy-commit] pypy stm-gc: AddressStack.clear()

arigo noreply at buildbot.pypy.org
Wed Apr 18 18:07:40 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: stm-gc
Changeset: r54501:fe66c773ed6c
Date: 2012-04-18 16:28 +0200
http://bitbucket.org/pypy/pypy/changeset/fe66c773ed6c/

Log:	AddressStack.clear()

diff --git a/pypy/rpython/memory/support.py b/pypy/rpython/memory/support.py
--- a/pypy/rpython/memory/support.py
+++ b/pypy/rpython/memory/support.py
@@ -117,6 +117,15 @@
                 self.shrink()
             return result
 
+        def clear(self):
+            cur = self.chunk
+            while cur.next:
+                next = cur.next
+                unused_chunks.put(cur)
+                cur = next
+            self.chunk = cur
+            self.used_in_last_chunk = 0
+
         def delete(self):
             cur = self.chunk
             while cur:
diff --git a/pypy/rpython/memory/test/test_support.py b/pypy/rpython/memory/test/test_support.py
--- a/pypy/rpython/memory/test/test_support.py
+++ b/pypy/rpython/memory/test/test_support.py
@@ -94,6 +94,19 @@
             assert a == addrs[i]
         assert not ll.non_empty()
 
+    def test_clear(self):
+        AddressStack = get_address_stack(10)
+        ll = AddressStack()
+        for count in [0, 5, 15, 25]:
+            for i in range(count):
+                ll.append(llmemory.NULL)
+            ll.clear()
+            assert not ll.non_empty()
+            ll.append(llmemory.NULL)
+            assert ll.non_empty()
+            ll.pop()
+            assert not ll.non_empty()
+
 
 class TestAddressDeque:
     def test_big_access(self):


More information about the pypy-commit mailing list