Brian Kearns avatar Brian Kearns committed 75a2ee7 Merge

merge heads

Comments (0)

Files changed (4)

pypy/module/_cffi_backend/cdataobj.py

             cdata1 = self._cdata
             other = space.interpclass_w(w_other)
             if isinstance(other, W_CData):
-                if requires_ordering:
-                    if (isinstance(self.ctype, W_CTypePrimitive) or
-                        isinstance(other.ctype, W_CTypePrimitive)):
-                        raise OperationError(space.w_TypeError,
-                            space.wrap("cannot do comparison on a "
-                                       "primitive cdata"))
                 cdata2 = other._cdata
-            elif (misc.is_zero(space, w_other) and
-                     not isinstance(self.ctype, W_CTypePrimitive)):
-                cdata2 = lltype.nullptr(rffi.CCHARP.TO)
             else:
                 return space.w_NotImplemented
 
             if requires_ordering:
+                if (isinstance(self.ctype, W_CTypePrimitive) or
+                    isinstance(other.ctype, W_CTypePrimitive)):
+                    raise OperationError(space.w_TypeError,
+                       space.wrap("cannot do comparison on a primitive cdata"))
                 cdata1 = rffi.cast(lltype.Unsigned, cdata1)
                 cdata2 = rffi.cast(lltype.Unsigned, cdata2)
             return space.newbool(op(cdata1, cdata2))

pypy/module/_cffi_backend/ctypeptr.py

         space = self.space
         ob = space.interpclass_w(w_ob)
         if not isinstance(ob, cdataobj.W_CData):
-            if misc.is_zero(space, w_ob):
-                NULL = lltype.nullptr(rffi.CCHARP.TO)
-                rffi.cast(rffi.CCHARPP, cdata)[0] = NULL
-                return
             raise self._convert_error("cdata pointer", w_ob)
         other = ob.ctype
         if not isinstance(other, W_CTypePtrBase):
 
     def _prepare_pointer_call_argument(self, w_init, cdata):
         space = self.space
-        if misc.is_zero(space, w_init):
-            # Convert 0 to NULL.  Note that passing 0 is not ambigous,
-            # despite the potential confusion: as a 'T*' argument, 0 means
-            # NULL, but as a 'T[]' argument it would mean "array of size 0"
-            # --- except that we specifically refuse to interpret numbers
-            # as the array size when passing arguments.
-            rffi.cast(rffi.CCHARPP, cdata)[0] = lltype.nullptr(rffi.CCHARP.TO)
-            return 3
-        elif (space.isinstance_w(w_init, space.w_list) or
+        if (space.isinstance_w(w_init, space.w_list) or
             space.isinstance_w(w_init, space.w_tuple)):
             length = space.int_w(space.len(w_init))
         elif space.isinstance_w(w_init, space.w_basestring):

pypy/module/_cffi_backend/misc.py

 neg_msg = "can't convert negative number to unsigned"
 ovf_msg = "long too big to convert"
 
-def is_zero(space, w_ob):
-    return ((space.isinstance_w(w_ob, space.w_int) or
-             space.isinstance_w(w_ob, space.w_long))
-            and not space.is_true(w_ob))
-
 # ____________________________________________________________
 
 class _NotStandardObject(Exception):

pypy/module/_cffi_backend/test/_backend_test_c.py

     assert (x != None) is True
     assert (x == ["hello"]) is False
     assert (x != ["hello"]) is True
-
-def test_cmp_pointer_with_0():
-    p = new_pointer_type(new_primitive_type("int"))
-    x = cast(p, 0)
-    assert (x == 0) is True
-    assert (x != 0) is False
-    assert (0 == x) is True
-    assert (0 != x) is False
-    y = cast(p, 42)
-    assert (y == 0) is False
-    assert (y != 0) is True
-    assert (0 == y) is False
-    assert (0 != y) is True
+    y = cast(p, 0)
+    assert (y == None) is False
 
 def test_invalid_indexing():
     p = new_primitive_type("int")
     assert s.a2 == 456
     assert s.a3 == 0
     assert s.p4 == cast(BVoidP, 0)
-    assert s.p4 == 0
+    assert s.p4 != 0
     #
     s = newp(BStructPtr, {'a2': 41122, 'a3': -123})
     assert s.a1 == 0
     p = newp(BIntPtr, 14141)
     s = newp(BStructPtr, [12, 34, 56, p])
     assert s.p4 == p
-    s.p4 = 0
-    assert s.p4 == 0
+    assert s.p4
     #
     s = newp(BStructPtr, [12, 34, 56, cast(BVoidP, 0)])
-    assert s.p4 == 0
-    #
-    s = newp(BStructPtr, [12, 34, 56, 0])
     assert s.p4 == cast(BVoidP, 0)
+    assert not s.p4
     #
     py.test.raises(TypeError, newp, BStructPtr, [12, 34, 56, None])
 
     f = cast(BFunc23, _testfunc(23))
     res = f(b"foo")
     assert res == 1000 * ord(b'f')
-    res = f(0)          # NULL
-    assert res == -42
-    res = f(long(0))    # NULL
+    res = f(cast(BVoidP, 0))        # NULL
     assert res == -42
     py.test.raises(TypeError, f, None)
+    py.test.raises(TypeError, f, 0)
     py.test.raises(TypeError, f, 0.0)
 
 def test_call_function_23_bis():
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.