[pypy-svn] r29906 - in pypy/dist/pypy: objspace/cpy/test translator/c translator/c/test

arigo at codespeak.net arigo at codespeak.net
Sun Jul 9 17:49:55 CEST 2006


Author: arigo
Date: Sun Jul  9 17:49:51 2006
New Revision: 29906

Modified:
   pypy/dist/pypy/objspace/cpy/test/test_typedef.py
   pypy/dist/pypy/translator/c/genc.py
   pypy/dist/pypy/translator/c/test/test_genc.py
Log:
(pedronis, arigo)

Bug fix and test for prebuilt exported type objects.


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 17:49:51 2006
@@ -274,3 +274,25 @@
                  annotatorpolicy = CPyAnnotatorPolicy(space))
     res = fn(expected_extra_mallocs=1)
     assert type(res).__name__ == 'MyType'
+
+def test_prebuilt_type():
+    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()
+
+    w_type = space.gettypefor(W_MyType)
+    def build():
+        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/translator/c/genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/genc.py	(original)
+++ pypy/dist/pypy/translator/c/genc.py	Sun Jul  9 17:49:51 2006
@@ -706,7 +706,7 @@
     print >> f, '/***  Table of global PyObjects                          ***/'
     print >> f
     print >> f, 'static globalobjectdef_t globalobjectdefs[] = {'
-    for node in database.globalcontainers():
+    for node in database.containerlist:
         if isinstance(node, (PyObjectNode, PyObjHeadNode)):
             for target in node.where_to_copy_me:
                 print >> f, '\t{%s, "%s"},' % (target, node.exported_name)

Modified: pypy/dist/pypy/translator/c/test/test_genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_genc.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_genc.py	Sun Jul  9 17:49:51 2006
@@ -50,11 +50,10 @@
             expected_extra_mallocs = kwds.pop('expected_extra_mallocs')
         else:
             expected_extra_mallocs = 0
-        try:
-            return compiled_fn(*args, **kwds)
-        finally:
-            mallocs, frees = module.malloc_counters()
-            assert mallocs - frees == expected_extra_mallocs
+        res = compiled_fn(*args, **kwds)
+        mallocs, frees = module.malloc_counters()
+        assert mallocs - frees == expected_extra_mallocs
+        return res
     return checking_fn
 
 def test_func_as_pyobject():



More information about the Pypy-commit mailing list