[pypy-svn] r74518 - in pypy/trunk/pypy/module/cpyext: . test

agaynor at codespeak.net agaynor at codespeak.net
Sun May 16 21:47:31 CEST 2010


Author: agaynor
Date: Sun May 16 21:47:29 2010
New Revision: 74518

Added:
   pypy/trunk/pypy/module/cpyext/test/test_cell.py
Modified:
   pypy/trunk/pypy/module/cpyext/api.py
Log:
Added PyCell_Type to cpyext, with tests.

Modified: pypy/trunk/pypy/module/cpyext/api.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/api.py	(original)
+++ pypy/trunk/pypy/module/cpyext/api.py	Sun May 16 21:47:29 2010
@@ -17,6 +17,7 @@
 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.gateway import ObjSpace, unwrap_spec
+from pypy.interpreter.nestedscope import Cell	
 from pypy.rlib.entrypoint import entrypoint
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.rlib.objectmodel import specialize
@@ -329,6 +330,7 @@
         "BaseObject": "space.w_object",
         'None': 'space.type(space.w_None)',
         'NotImplemented': 'space.type(space.w_NotImplemented)',
+        'Cell': 'space.gettypeobject(Cell.typedef)',
         }.items():
         GLOBALS['Py%s_Type#' % (cpyname, )] = ('PyTypeObject*', pypyexpr)
 
@@ -502,6 +504,7 @@
                 print str(e)
                 # we can't do much here, since we're in ctypes, swallow
             else:
+                print str(e)
                 pypy_debug_catch_fatal_exception()
         rffi.stackcounter.stacks_counter -= 1
         return retval

Added: pypy/trunk/pypy/module/cpyext/test/test_cell.py
==============================================================================
--- (empty file)
+++ pypy/trunk/pypy/module/cpyext/test/test_cell.py	Sun May 16 21:47:29 2010
@@ -0,0 +1,20 @@
+from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
+
+
+class AppTestCell(AppTestCpythonExtensionBase):
+    def test_cell_type(self):
+        module = self.import_extension('foo', [
+            ("cell_type", "METH_O",
+             """
+                 PyDict_SetItemString(args, "cell", &PyCell_Type);
+                 Py_RETURN_NONE;
+             """)])
+        d = {}
+        module.cell_type(d)
+        def f(o):
+            def g():
+                return o
+            return g
+        
+        cell_type = type(f(0).func_closure[0])
+        assert d["cell"] is cell_type



More information about the Pypy-commit mailing list