[pypy-commit] pypy default: test, fix for Py_RichCompareBool(float('nan'), float('nan'))

mattip pypy.commits at gmail.com
Mon Aug 21 06:46:11 EDT 2017


Author: Matti Picus <matti.picus at gmail.com>
Branch: 
Changeset: r92197:3e2341208fe6
Date: 2017-08-21 13:44 +0300
http://bitbucket.org/pypy/pypy/changeset/3e2341208fe6/

Log:	test, fix for Py_RichCompareBool(float('nan'), float('nan'))

diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py
--- a/pypy/module/cpyext/object.py
+++ b/pypy/module/cpyext/object.py
@@ -305,7 +305,7 @@
     PyErr_BadInternalCall(space)
 
 @cpython_api([PyObject, PyObject, rffi.INT_real], rffi.INT_real, error=-1)
-def PyObject_RichCompareBool(space, ref1, ref2, opid_int):
+def PyObject_RichCompareBool(space, w_o1, w_o2, opid_int):
     """Compare the values of o1 and o2 using the operation specified by opid,
     which must be one of Py_LT, Py_LE, Py_EQ,
     Py_NE, Py_GT, or Py_GE, corresponding to <,
@@ -315,13 +315,13 @@
     opid."""
     # Quick result when objects are the same.
     # Guarantees that identity implies equality.
-    if ref1 is ref2:
+    if space.is_w(w_o1, w_o2):
         opid = rffi.cast(lltype.Signed, opid_int)
         if opid == Py_EQ:
             return 1
         if opid == Py_NE:
             return 0 
-    w_res = PyObject_RichCompare(space, ref1, ref2, opid_int)
+    w_res = PyObject_RichCompare(space, w_o1, w_o2, opid_int)
     return int(space.is_true(w_res))
 
 @cpython_api([PyObject], PyObject, result_is_ll=True)
diff --git a/pypy/module/cpyext/test/test_object.py b/pypy/module/cpyext/test/test_object.py
--- a/pypy/module/cpyext/test/test_object.py
+++ b/pypy/module/cpyext/test/test_object.py
@@ -408,7 +408,7 @@
         Py_buffer passed to it.
         """
         module = self.import_extension('foo', [
-                ("fillinfo", "METH_VARARGS",
+                ("fillinfo", "METH_NOARGS",
                  """
     Py_buffer buf;
     PyObject *str = PyString_FromString("hello, world.");
@@ -460,7 +460,7 @@
         object.
         """
         module = self.import_extension('foo', [
-                ("fillinfo", "METH_VARARGS",
+                ("fillinfo", "METH_NOARGS",
                  """
     Py_buffer buf;
     PyObject *str = PyString_FromString("hello, world.");
@@ -506,7 +506,7 @@
         PyBuffer_FillInfo fails if WRITABLE is passed but object is readonly.
         """
         module = self.import_extension('foo', [
-                ("fillinfo", "METH_VARARGS",
+                ("fillinfo", "METH_NOARGS",
                  """
     Py_buffer buf;
     PyObject *str = PyString_FromString("hello, world.");
@@ -533,7 +533,7 @@
         decremented by PyBuffer_Release.
         """
         module = self.import_extension('foo', [
-                ("release", "METH_VARARGS",
+                ("release", "METH_NOARGS",
                  """
     Py_buffer buf;
     buf.obj = PyString_FromString("release me!");
@@ -553,3 +553,19 @@
                  """)])
         assert module.release() is None
 
+
+class AppTestPyBuffer_Release(AppTestCpythonExtensionBase):
+    def test_richcomp_nan(self):
+        module = self.import_extension('foo', [
+               ("comp_eq", "METH_VARARGS",
+                """
+                PyObject *a = PyTuple_GetItem(args, 0);
+                PyObject *b = PyTuple_GetItem(args, 1);
+                int res = PyObject_RichCompareBool(a, b, Py_EQ);
+                return PyLong_FromLong(res);  
+                """),])
+        a = float('nan')
+        b = float('nan')
+        assert a is b
+        res = module.comp_eq(a, b)
+        assert res == 1


More information about the pypy-commit mailing list