[pypy-svn] r79043 - in pypy/branch/mapdict-without-jit/pypy/objspace/std: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Fri Nov 12 15:31:41 CET 2010


Author: cfbolz
Date: Fri Nov 12 15:31:40 2010
New Revision: 79043

Modified:
   pypy/branch/mapdict-without-jit/pypy/objspace/std/mapdict.py
   pypy/branch/mapdict-without-jit/pypy/objspace/std/test/test_mapdict.py
Log:
Add a test and a fix for the case when the two uses of the cache disturb each
other. Can be improved, but probably rare.


Modified: pypy/branch/mapdict-without-jit/pypy/objspace/std/mapdict.py
==============================================================================
--- pypy/branch/mapdict-without-jit/pypy/objspace/std/mapdict.py	(original)
+++ pypy/branch/mapdict-without-jit/pypy/objspace/std/mapdict.py	Fri Nov 12 15:31:40 2010
@@ -428,6 +428,7 @@
         self.storage = make_sure_not_resized([None] * map.size_estimate())
 
     def _mapdict_read_storage(self, index):
+        assert index >= 0
         return self.storage[index]
     def _mapdict_write_storage(self, index, value):
         self.storage[index] = value
@@ -495,6 +496,7 @@
             return rerased.unerase_fixedsizelist(erased, W_Root)
 
         def _mapdict_read_storage(self, index):
+            assert index >= 0
             for i in rangenmin1:
                 if index == i:
                     erased = getattr(self, "_value%s" % i)
@@ -704,7 +706,7 @@
     # used if we_are_jitted().
     entry = pycode._mapdict_caches[nameindex]
     map = w_obj._get_mapdict_map()
-    if entry.is_valid_for_map(map):
+    if entry.is_valid_for_map(map) and entry.w_method is None:
         # everything matches, it's incredibly fast
         return w_obj._mapdict_read_storage(entry.index)
     return LOAD_ATTR_slowpath(pycode, w_obj, nameindex, map)

Modified: pypy/branch/mapdict-without-jit/pypy/objspace/std/test/test_mapdict.py
==============================================================================
--- pypy/branch/mapdict-without-jit/pypy/objspace/std/test/test_mapdict.py	(original)
+++ pypy/branch/mapdict-without-jit/pypy/objspace/std/test/test_mapdict.py	Fri Nov 12 15:31:40 2010
@@ -830,6 +830,34 @@
         res = self.check(h, 'cm')
         assert res == (0, 0, 0)
 
+    def test_mix_cache_bug(self):
+        # bit sucky
+        global C
+
+        class C(object):
+            def m(*args):
+                return args
+
+        exec """if 1:
+
+            def f():
+                c = C()
+                res = c.m(1)
+                assert res == (c, 1)
+                bm = c.m
+                res = bm(1)
+                assert res == (c, 1)
+                return 42
+
+        """
+        res = self.check(f, 'm')
+        assert res == (1, 1, 1)
+        res = self.check(f, 'm')
+        assert res == (0, 2, 1)
+        res = self.check(f, 'm')
+        assert res == (0, 2, 1)
+        res = self.check(f, 'm')
+        assert res == (0, 2, 1)
 
 class AppTestGlobalCaching(AppTestWithMapDict):
     def setup_class(cls):



More information about the Pypy-commit mailing list