[pypy-svn] r74001 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test

afa at codespeak.net afa at codespeak.net
Fri Apr 23 00:40:43 CEST 2010


Author: afa
Date: Fri Apr 23 00:40:41 2010
New Revision: 74001

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/pyobject.py
   pypy/branch/cpython-extension/pypy/module/cpyext/test/test_cpyext.py
Log:
_Py_HashPointer


Modified: pypy/branch/cpython-extension/pypy/module/cpyext/pyobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/pyobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/pyobject.py	Fri Apr 23 00:40:41 2010
@@ -3,7 +3,7 @@
 from pypy.interpreter.baseobjspace import W_Root, SpaceCache
 from pypy.rpython.lltypesystem import rffi, lltype
 from pypy.module.cpyext.api import cpython_api, bootstrap_function, \
-     PyObject, PyObjectP, ADDR,\
+     PyObject, PyObjectP, ADDR, CANNOT_FAIL, \
      Py_TPFLAGS_HEAPTYPE, PyTypeObjectPtr
 from pypy.module.cpyext.state import State
 from pypy.objspace.std.typeobject import W_TypeObject
@@ -315,4 +315,8 @@
     obj_ptr = rffi.cast(ADDR, obj)
     borrowees[obj_ptr] = None
 
+#___________________________________________________________
 
+ at cpython_api([rffi.VOIDP_real], lltype.Signed, error=CANNOT_FAIL)
+def _Py_HashPointer(space, ptr):
+    return rffi.cast(lltype.Signed, ptr)

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_cpyext.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_cpyext.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_cpyext.py	Fri Apr 23 00:40:41 2010
@@ -541,3 +541,15 @@
              ),
             ])
         raises(SystemError, mod.newexc, "name", Exception, {})
+
+    def test_hash_pointer(self):
+        mod = self.import_extension('foo', [
+            ('get_hash', 'METH_NOARGS',
+             '''
+             return PyInt_FromLong(_Py_HashPointer(Py_None));
+             '''
+             ),
+            ])
+        h = mod.get_hash()
+        assert h != 0
+        assert h % 4 == 0 # it's the pointer value



More information about the Pypy-commit mailing list