[pypy-commit] pypy ffi-backend: Cannot use operator.ne()?

arigo noreply at buildbot.pypy.org
Fri Jul 6 16:47:59 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: ffi-backend
Changeset: r55943:021afa29b3fd
Date: 2012-07-06 16:42 +0200
http://bitbucket.org/pypy/pypy/changeset/021afa29b3fd/

Log:	Cannot use operator.ne()?

diff --git a/pypy/module/_cffi_backend/cdataobj.py b/pypy/module/_cffi_backend/cdataobj.py
--- a/pypy/module/_cffi_backend/cdataobj.py
+++ b/pypy/module/_cffi_backend/cdataobj.py
@@ -1,10 +1,9 @@
-import operator
 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.typedef import TypeDef, make_weakref_descr
 from pypy.rpython.lltypesystem import lltype, rffi
-from pypy.rlib.objectmodel import keepalive_until_here, specialize
+from pypy.rlib.objectmodel import keepalive_until_here
 from pypy.rlib import objectmodel, rgc
 
 from pypy.module._cffi_backend import misc
@@ -60,8 +59,7 @@
     def str(self):
         return self.ctype.str(self)
 
-    @specialize.arg(2)
-    def _cmp(self, w_other, cmp):
+    def _cmp(self, w_other, compare_for_ne):
         space = self.space
         cdata1 = self._cdata
         other = space.interpclass_w(w_other)
@@ -69,10 +67,11 @@
             cdata2 = other._cdata
         else:
             return space.w_NotImplemented
-        return space.newbool(cmp(cdata1, cdata2))
+        result = (cdata1 == cdata2) ^ compare_for_ne
+        return space.newbool(result)
 
-    def eq(self, w_other): return self._cmp(w_other, operator.eq)
-    def ne(self, w_other): return self._cmp(w_other, operator.ne)
+    def eq(self, w_other): return self._cmp(w_other, False)
+    def ne(self, w_other): return self._cmp(w_other, True)
 
     def hash(self):
         h = (objectmodel.compute_identity_hash(self.ctype) ^


More information about the pypy-commit mailing list