[pypy-svn] r29526 - in pypy/dist/pypy/objspace/cpy: . test

arigo at codespeak.net arigo at codespeak.net
Fri Jun 30 10:55:53 CEST 2006


Author: arigo
Date: Fri Jun 30 10:55:52 2006
New Revision: 29526

Modified:
   pypy/dist/pypy/objspace/cpy/objspace.py
   pypy/dist/pypy/objspace/cpy/test/test_typedef.py
   pypy/dist/pypy/objspace/cpy/typedef.py
Log:
Oups oups oups.  Wrong specialization caused troubles in programs
with more than one TypeDef, or other similar things.  This is a
tentative fix.


Modified: pypy/dist/pypy/objspace/cpy/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/objspace.py	(original)
+++ pypy/dist/pypy/objspace/cpy/objspace.py	Fri Jun 30 10:55:52 2006
@@ -6,6 +6,7 @@
 from pypy.interpreter.function import Function
 from pypy.interpreter.typedef import GetSetProperty
 from pypy.rpython.rarithmetic import r_uint
+from pypy.rpython.objectmodel import we_are_translated
 
 
 class CPyObjSpace(baseobjspace.ObjSpace):
@@ -41,14 +42,15 @@
 
     def wrap(self, x):
         if isinstance(x, baseobjspace.Wrappable):
-            x = x.__spacebind__(self)
-            # special cases
-            if isinstance(x, Function):
-                from pypy.objspace.cpy.function import FunctionCache
-                return self.fromcache(FunctionCache).getorbuild(x)
-            if isinstance(x, GetSetProperty):
-                from pypy.objspace.cpy.property import PropertyCache
-                return self.fromcache(PropertyCache).getorbuild(x)
+            # special cases, only when bootstrapping
+            if not we_are_translated():
+                x = x.__spacebind__(self)
+                if isinstance(x, Function):
+                    from pypy.objspace.cpy.function import FunctionCache
+                    return self.fromcache(FunctionCache).getorbuild(x)
+                if isinstance(x, GetSetProperty):
+                    from pypy.objspace.cpy.property import PropertyCache
+                    return self.fromcache(PropertyCache).getorbuild(x)
             # normal case
             from pypy.objspace.cpy.typedef import rpython2cpython
             return rpython2cpython(self, x)
@@ -66,7 +68,7 @@
         # in the format string, but it's that someone is calling space.wrap()
         # on a strange object.
         raise TypeError("wrap(%r)" % (x,))
-    wrap._annspecialcase_ = "specialize:wrap"
+    wrap._annspecialcase_ = "specialize:argtype(1)"
 
     def unwrap(self, w_obj):
         assert isinstance(w_obj, W_Object)

Modified: pypy/dist/pypy/objspace/cpy/test/test_typedef.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/test/test_typedef.py	(original)
+++ pypy/dist/pypy/objspace/cpy/test/test_typedef.py	Fri Jun 30 10:55:52 2006
@@ -54,7 +54,6 @@
 
 
 def test_get_blackboxes():
-    py.test.skip("a bug with specialize:wrap?")
     W_MyType.typedef = TypeDef("MyType")
 
     class W_MyType2(Wrappable):
@@ -72,10 +71,10 @@
     fn = compile(make_mytype, [int],
                  annotatorpolicy = CPyAnnotatorPolicy(space))
 
-    res = fn(1, expected_extra_mallocs=1)
+    res2 = fn(1, expected_extra_mallocs=1)
+    assert type(res2).__name__ == 'MyType2'
+    res = fn(0, expected_extra_mallocs=2)
     assert type(res).__name__ == 'MyType'
-    res = fn(0, expected_extra_mallocs=1)
-    assert type(res).__name__ == 'MyType2'
 
 
 def test_blackbox():

Modified: pypy/dist/pypy/objspace/cpy/typedef.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/typedef.py	(original)
+++ pypy/dist/pypy/objspace/cpy/typedef.py	Fri Jun 30 10:55:52 2006
@@ -6,6 +6,8 @@
 from pypy.objspace.cpy.capi import *
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.baseobjspace import Wrappable, SpaceCache
+from pypy.interpreter.function import Function
+from pypy.interpreter.typedef import GetSetProperty
 from pypy.rpython.objectmodel import we_are_translated
 from pypy.rpython.rcpy import CPyTypeInterface, cpy_export, cpy_import
 from pypy.rpython.rcpy import cpy_typeobject
@@ -41,6 +43,7 @@
             init_rpython_data(w_x, x)
         return w_x
 rpython2cpython.allow_someobjects = True
+rpython2cpython._annspecialcase_ = "specialize:argtype(1)"
 
 def cpython2rpython_raw(space, w_obj):
     "NOT_RPYTHON."
@@ -83,6 +86,9 @@
         self.wrappedtypes = {}
 
     def build(cache, typedef):
+        if typedef in (Function.typedef, GetSetProperty.typedef):
+            raise ValueError("cannot wrap at run-time an interpreter object "
+                             "of type %r" % (typedef.name,))
         space = cache.space
         objects = {}
         for name, value in typedef.rawdict.items():



More information about the Pypy-commit mailing list