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

agaynor at codespeak.net agaynor at codespeak.net
Sun May 30 17:32:59 CEST 2010


Author: agaynor
Date: Sun May 30 17:32:57 2010
New Revision: 74921

Modified:
   pypy/trunk/pypy/module/cpyext/slotdefs.py
   pypy/trunk/pypy/module/cpyext/test/comparisons.c
   pypy/trunk/pypy/module/cpyext/test/test_typeobject.py
Log:
Implemented != support for cpyext (and refactored cmp op support a little)

Modified: pypy/trunk/pypy/module/cpyext/slotdefs.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/slotdefs.py	(original)
+++ pypy/trunk/pypy/module/cpyext/slotdefs.py	Sun May 30 17:32:57 2010
@@ -133,13 +133,18 @@
         raise OperationError(space.w_StopIteration, space.w_None)
     return w_res
 
-def richcmp_eq(space, w_self, w_args, func):
-    func_target = rffi.cast(richcmpfunc, func)
-    check_num_args(space, w_args, 1)
-    args_w = space.fixedview(w_args)
-    other_w = args_w[0]
-    return generic_cpy_call(space, func_target,
-        w_self, other_w, rffi.cast(rffi.INT_real, Py_EQ))
+def get_richcmp_func(OP_CONST):
+    def inner(space, w_self, w_args, func):
+        func_target = rffi.cast(richcmpfunc, func)
+        check_num_args(space, w_args, 1)
+        args_w = space.fixedview(w_args)
+        other_w = args_w[0]
+        return generic_cpy_call(space, func_target,
+            w_self, other_w, rffi.cast(rffi.INT_real, OP_CONST))
+    return inner
+
+richcmp_eq = get_richcmp_func(Py_EQ)
+richcmp_ne = get_richcmp_func(Py_NE)
 
 @cpython_api([PyTypeObjectPtr, PyObject, PyObject], PyObject, external=False)
 def slot_tp_new(space, type, w_args, w_kwds):

Modified: pypy/trunk/pypy/module/cpyext/test/comparisons.c
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/comparisons.c	(original)
+++ pypy/trunk/pypy/module/cpyext/test/comparisons.c	Sun May 30 17:32:57 2010
@@ -6,12 +6,17 @@
 
 
 static PyObject* cmp_richcmp(PyObject *self, PyObject *other, int opid) {
-    if (opid != Py_EQ || !PyInt_CheckExact(other)) {
+    if ((opid != Py_EQ && opid != Py_NE) || !PyInt_CheckExact(other)) {
         Py_INCREF(Py_NotImplemented);
         return Py_NotImplemented;
     }
     long val = PyLong_AsLong(other);
-    return PyBool_FromLong(val == 3);
+    if (opid == Py_EQ) {
+        return PyBool_FromLong(val == 3);
+    }
+    else if (opid == Py_NE) {
+        return PyBool_FromLong(val != 3);
+    }
 }
 
 

Modified: pypy/trunk/pypy/module/cpyext/test/test_typeobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_typeobject.py	(original)
+++ pypy/trunk/pypy/module/cpyext/test/test_typeobject.py	Sun May 30 17:32:57 2010
@@ -181,6 +181,7 @@
         module = self.import_module("comparisons")
         cmpr = module.CmpType()
         assert cmpr == 3
+        assert cmpr != 42
 
 
 class TestTypes(BaseApiTest):



More information about the Pypy-commit mailing list