[pypy-svn] r74177 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test
agaynor at codespeak.net
agaynor at codespeak.net
Wed Apr 28 16:04:21 CEST 2010
Author: agaynor
Date: Wed Apr 28 16:04:19 2010
New Revision: 74177
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/object.py
pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py
Log:
Implement PyObject_Hash.
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/object.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/object.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/object.py Wed Apr 28 16:04:19 2010
@@ -299,3 +299,10 @@
return rffi.cast(rffi.INT_real, fd)
+
+ at cpython_api([PyObject], lltype.Signed, error=-1)
+def PyObject_Hash(space, w_obj):
+ """
+ Compute and return the hash value of an object o. On failure, return -1.
+ This is the equivalent of the Python expression hash(o)."""
+ return space.int_w(space.hash(w_obj))
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py Wed Apr 28 16:04:19 2010
@@ -3101,16 +3101,6 @@
raise NotImplementedError
@cpython_api([PyObject], lltype.Signed, error=-1)
-def PyObject_Hash(space, o):
- """
-
-
-
- Compute and return the hash value of an object o. On failure, return -1.
- This is the equivalent of the Python expression hash(o)."""
- raise NotImplementedError
-
- at cpython_api([PyObject], lltype.Signed, error=-1)
def PyObject_HashNotImplemented(space, o):
"""Set a TypeError indicating that type(o) is not hashable and return -1.
This function receives special treatment when stored in a tp_hash slot,
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py Wed Apr 28 16:04:19 2010
@@ -157,3 +157,10 @@
return File""")
w_f = space.call_function(w_File)
assert api.PyObject_AsFileDescriptor(w_f) == 42
+
+ def test_hash(self, space, api):
+ assert api.PyObject_Hash(space.wrap(72)) == 72
+ assert api.PyObject_Hash(space.wrap(-1)) == -1
+ assert (api.PyObject_Hash(space.wrap([])) == -1 and
+ api.PyErr_Occurred() is space.w_TypeError)
+ api.PyErr_Clear()
More information about the Pypy-commit
mailing list