[pypy-svn] r29902 - in pypy/dist/pypy: objspace/cpy objspace/cpy/test rpython

arigo at codespeak.net arigo at codespeak.net
Sun Jul 9 16:05:39 CEST 2006


Author: arigo
Date: Sun Jul  9 16:05:36 2006
New Revision: 29902

Modified:
   pypy/dist/pypy/objspace/cpy/test/test_typedef.py
   pypy/dist/pypy/objspace/cpy/typedef.py
   pypy/dist/pypy/rpython/rcpy.py
Log:
(pedronis, arigo)

Support for __new__ in CPyObjSpace-over-CPython mode.


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	Sun Jul  9 16:05:36 2006
@@ -252,3 +252,25 @@
     assert res2.__name__ == 'MyType2'
     res = fn(0)
     assert res.__name__ == 'MyType'
+
+def test_with_new():
+    def mytype_new(space, w_subtype, x):
+        return space.wrap(W_MyType(space, x))
+    mytype_new.unwrap_spec = [ObjSpace, W_Root, int]
+
+    W_MyType.typedef = TypeDef("MyType",
+                               __new__ = interp2app(mytype_new))
+    space = CPyObjSpace()
+
+    def build():
+        w_type = space.gettypefor(W_MyType)
+        return space.call_function(w_type, space.wrap(42))
+
+    w_obj = build()
+    w_name = space.getattr(space.type(w_obj), space.wrap('__name__'))
+    assert space.unwrap(w_name) == 'MyType'
+
+    fn = compile(build, [],
+                 annotatorpolicy = CPyAnnotatorPolicy(space))
+    res = fn(expected_extra_mallocs=1)
+    assert type(res).__name__ == 'MyType'

Modified: pypy/dist/pypy/objspace/cpy/typedef.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/typedef.py	(original)
+++ pypy/dist/pypy/objspace/cpy/typedef.py	Sun Jul  9 16:05:36 2006
@@ -39,7 +39,7 @@
         w_x = x.__cpy_wrapper__
         if w_x is None:
             w_type = cache.wraptypeintf(x.typedef, typeintf)
-            w_x = space.call_function(w_type)
+            w_x = W_Object(rpython_object.__new__(w_type.value))
             init_rpython_data(w_x, x)
         return w_x
 rpython2cpython.allow_someobjects = True

Modified: pypy/dist/pypy/rpython/rcpy.py
==============================================================================
--- pypy/dist/pypy/rpython/rcpy.py	(original)
+++ pypy/dist/pypy/rpython/rcpy.py	Sun Jul  9 16:05:36 2006
@@ -22,7 +22,7 @@
 
     def emulate(self, rootbase):
         "Build a type object that emulates 'self'."
-        d = {}
+        d = {'__slots__': []}
         for name, value in self.objects.items():
             assert lltype.typeOf(value) == PyObjPtr
             assert isinstance(value._obj, lltype._pyobject)



More information about the Pypy-commit mailing list