Commits

Armin Rigo committed 021afa2

Cannot use operator.ne()?

Comments (0)

Files changed (1)

pypy/module/_cffi_backend/cdataobj.py

-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
     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)
             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) ^
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.