[pypy-svn] r58618 - in pypy/dist/pypy/module/__builtin__: . test

xoraxax at codespeak.net xoraxax at codespeak.net
Mon Oct 6 11:22:01 CEST 2008


Author: xoraxax
Date: Mon Oct  6 11:22:00 2008
New Revision: 58618

Modified:
   pypy/dist/pypy/module/__builtin__/interp_classobj.py
   pypy/dist/pypy/module/__builtin__/test/test_classobj.py
Log:
(cfbolz, xoraxax) Use sharing dicts for oldstyle class instance dicts.

Modified: pypy/dist/pypy/module/__builtin__/interp_classobj.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/interp_classobj.py	(original)
+++ pypy/dist/pypy/module/__builtin__/interp_classobj.py	Mon Oct  6 11:22:00 2008
@@ -289,7 +289,7 @@
             space.w_TypeError,
             space.wrap("instance() first arg must be class"))
     if space.is_w(w_dict, space.w_None):
-        w_dict = space.newdict()
+        w_dict = None
     elif not space.is_true(space.isinstance(w_dict, space.w_dict)):
         raise OperationError(
             space.w_TypeError,
@@ -299,7 +299,12 @@
 class W_InstanceObject(Wrappable):
     def __init__(self, space, w_class, w_dict=None):
         if w_dict is None:
-            w_dict = space.newdict()
+            if space.config.objspace.std.withsharingdict:
+                from pypy.objspace.std import dictmultiobject
+                w_dict = dictmultiobject.W_DictMultiObject(space,
+                            sharing=True)
+            else:
+                w_dict = space.newdict()
         assert isinstance(w_class, W_ClassObject)
         self.w_class = w_class
         self.w_dict = w_dict

Modified: pypy/dist/pypy/module/__builtin__/test/test_classobj.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/test/test_classobj.py	(original)
+++ pypy/dist/pypy/module/__builtin__/test/test_classobj.py	Mon Oct  6 11:22:00 2008
@@ -1,3 +1,6 @@
+from pypy.conftest import gettestobjspace
+from pypy.interpreter import gateway
+
 
 class AppTestOldstyle(object):
 
@@ -755,3 +758,22 @@
             Z().__del__ = lambda self: None
         finally:
             warnings.simplefilter('default', RuntimeWarning)
+
+class AppTestOldStyleSharing(AppTestOldstyle):
+    def setup_class(cls):
+        cls.space = gettestobjspace(**{"objspace.std.withsharingdict": True})
+        def is_sharing(space, w_inst):
+            from pypy.objspace.std.dictmultiobject import SharedDictImplementation, W_DictMultiObject
+            w_d = w_inst.getdict()
+            return space.wrap(isinstance(w_d, W_DictMultiObject) and
+                              isinstance(w_d.implementation, SharedDictImplementation))
+        cls.w_is_sharing = cls.space.wrap(gateway.interp2app(is_sharing))
+
+
+    def test_real_sharing(self):
+        class A:
+            def __init__(self):
+                self.x = 42
+        A1, A2, A3 = A(), A(), A()
+        assert self.is_sharing(A3)
+        assert self.is_sharing(A2)



More information about the Pypy-commit mailing list