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

afa at codespeak.net afa at codespeak.net
Sat May 22 00:52:15 CEST 2010


Author: afa
Date: Sat May 22 00:52:08 2010
New Revision: 74665

Modified:
   pypy/trunk/pypy/module/cpyext/api.py
   pypy/trunk/pypy/module/cpyext/test/test_cpyext.py
Log:
Expose PyModuleType, PyPropertyTyp


Modified: pypy/trunk/pypy/module/cpyext/api.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/api.py	(original)
+++ pypy/trunk/pypy/module/cpyext/api.py	Sat May 22 00:52:08 2010
@@ -18,6 +18,8 @@
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.gateway import ObjSpace, unwrap_spec
 from pypy.interpreter.nestedscope import Cell
+from pypy.interpreter.module import Module
+from pypy.module.__builtin__.descriptor import W_Property
 from pypy.rlib.entrypoint import entrypoint
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.rlib.objectmodel import specialize
@@ -323,6 +325,8 @@
         'None': 'space.type(space.w_None)',
         'NotImplemented': 'space.type(space.w_NotImplemented)',
         'Cell': 'space.gettypeobject(Cell.typedef)',
+        'Module': 'space.gettypeobject(Module.typedef)',
+        'Property': 'space.gettypeobject(W_Property.typedef)',
         }.items():
         GLOBALS['Py%s_Type#' % (cpyname, )] = ('PyTypeObject*', pypyexpr)
 

Modified: pypy/trunk/pypy/module/cpyext/test/test_cpyext.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_cpyext.py	(original)
+++ pypy/trunk/pypy/module/cpyext/test/test_cpyext.py	Sat May 22 00:52:08 2010
@@ -646,3 +646,21 @@
         h = mod.get_hash()
         assert h != 0
         assert h % 4 == 0 # it's the pointer value
+
+    def test_types(self):
+        """test the presence of random types"""
+
+        mod = self.import_extension('foo', [
+            ('get_names', 'METH_NOARGS',
+             '''
+             /* XXX in tests, the C type is not correct */
+             #define NAME(type) ((PyTypeObject*)&type)->tp_name
+             return Py_BuildValue("sss",
+                                  NAME(PyCell_Type),
+                                  NAME(PyModule_Type),
+                                  NAME(PyProperty_Type)
+                                  );
+             '''
+             ),
+            ])
+        assert mod.get_names() == ('cell', 'module', 'property')



More information about the Pypy-commit mailing list