[pypy-svn] r74191 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test
afa at codespeak.net
afa at codespeak.net
Wed Apr 28 19:33:05 CEST 2010
Author: afa
Date: Wed Apr 28 19:33:03 2010
New Revision: 74191
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:
PyObject_Compare
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 19:33:03 2010
@@ -188,6 +188,16 @@
by reverse quotes."""
return space.repr(w_obj)
+ at cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
+def PyObject_Compare(space, w_o1, w_o2):
+ """
+ Compare the values of o1 and o2 using a routine provided by o1, if one
+ exists, otherwise with a routine provided by o2. Returns the result of the
+ comparison on success. On error, the value returned is undefined; use
+ PyErr_Occurred() to detect an error. This is equivalent to the Python
+ expression cmp(o1, o2)."""
+ return space.int_w(space.cmp(w_o1, w_o2))
+
@cpython_api([PyObject, PyObject, rffi.INT_real], PyObject)
def PyObject_RichCompare(space, w_o1, w_o2, opid_int):
"""Compare the values of o1 and o2 using the operation specified by opid,
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 19:33:03 2010
@@ -2968,16 +2968,6 @@
the Python statement result = cmp(o1, o2)."""
raise NotImplementedError
- at cpython_api([PyObject, PyObject], rffi.INT_real, error=None)
-def PyObject_Compare(space, o1, o2):
- """
- Compare the values of o1 and o2 using a routine provided by o1, if one
- exists, otherwise with a routine provided by o2. Returns the result of the
- comparison on success. On error, the value returned is undefined; use
- PyErr_Occurred() to detect an error. This is equivalent to the Python
- expression cmp(o1, o2)."""
- raise NotImplementedError
-
@cpython_api([PyObject], PyObject)
def PyObject_Bytes(space, o):
"""
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 19:33:03 2010
@@ -167,3 +167,8 @@
def test_type(self, space, api):
assert api.PyObject_Type(space.wrap(72)) is space.w_int
+
+ def test_compare(self, space, api):
+ assert api.PyObject_Compare(space.wrap(42), space.wrap(72)) == -1
+ assert api.PyObject_Compare(space.wrap(72), space.wrap(42)) == 1
+ assert api.PyObject_Compare(space.wrap("a"), space.wrap("a")) == 0
More information about the Pypy-commit
mailing list