[pypy-commit] pypy default: test and fix for cached empty list with deactivated strategies

l.diekmann noreply at buildbot.pypy.org
Sat Jan 28 14:01:00 CET 2012


Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: 
Changeset: r51906:2cb8ade3aef2
Date: 2012-01-27 17:42 +0100
http://bitbucket.org/pypy/pypy/changeset/2cb8ade3aef2/

Log:	test and fix for cached empty list with deactivated strategies

diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -110,7 +110,10 @@
         return list(items)
 
     def switch_to_object_strategy(self):
-        list_w = self.getitems()
+        if self.strategy is self.space.fromcache(EmptyListStrategy):
+            list_w = []
+        else:
+            list_w = self.getitems()
         self.strategy = self.space.fromcache(ObjectListStrategy)
         # XXX this is quite indirect
         self.init_from_list_w(list_w)
diff --git a/pypy/objspace/std/test/test_listobject.py b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -1251,6 +1251,20 @@
         l.reverse()
         assert l == [2,1,0]
 
+class AppTestWithoutStrategies(object):
+
+    def setup_class(cls):
+        cls.space = gettestobjspace(**{"objspace.std.withliststrategies" :
+                                       False})
+
+    def test_no_shared_empty_list(self):
+        l = []
+        copy = l[:]
+        copy.append({})
+        assert copy == [{}]
+
+        notshared = l[:]
+        assert notshared == []
 
 class AppTestListFastSubscr:
 


More information about the pypy-commit mailing list