[pypy-commit] pypy default: update to cffi/2001880ed1c7
arigo
noreply at buildbot.pypy.org
Thu Jul 9 10:41:07 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r78502:177cb8be0682
Date: 2015-07-09 10:40 +0200
http://bitbucket.org/pypy/pypy/changeset/177cb8be0682/
Log: update to cffi/2001880ed1c7
diff --git a/pypy/module/_cffi_backend/ctypeobj.py b/pypy/module/_cffi_backend/ctypeobj.py
--- a/pypy/module/_cffi_backend/ctypeobj.py
+++ b/pypy/module/_cffi_backend/ctypeobj.py
@@ -90,6 +90,16 @@
def _convert_error(self, expected, w_got):
space = self.space
if isinstance(w_got, cdataobj.W_CData):
+ if self.name == w_got.ctype.name:
+ # in case we'd give the error message "initializer for
+ # ctype 'A' must be a pointer to same type, not cdata
+ # 'B'", but with A=B, then give instead a different error
+ # message to try to clear up the confusion
+ return oefmt(space.w_TypeError,
+ "initializer for ctype '%s' appears indeed to "
+ "be '%s', but the types are different (check "
+ "that you are not e.g. mixing up different ffi "
+ "instances)", self.name, w_got.ctype.name)
return oefmt(space.w_TypeError,
"initializer for ctype '%s' must be a %s, not cdata "
"'%s'", self.name, expected, w_got.ctype.name)
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -3402,6 +3402,29 @@
py.test.raises(RuntimeError, "p[42]")
py.test.raises(RuntimeError, "p[42] = -1")
+def test_mixup():
+ BStruct1 = new_struct_type("foo")
+ BStruct2 = new_struct_type("foo") # <= same name as BStruct1
+ BStruct3 = new_struct_type("bar")
+ BStruct1Ptr = new_pointer_type(BStruct1)
+ BStruct2Ptr = new_pointer_type(BStruct2)
+ BStruct3Ptr = new_pointer_type(BStruct3)
+ BStruct1PtrPtr = new_pointer_type(BStruct1Ptr)
+ BStruct2PtrPtr = new_pointer_type(BStruct2Ptr)
+ BStruct3PtrPtr = new_pointer_type(BStruct3Ptr)
+ pp1 = newp(BStruct1PtrPtr)
+ pp2 = newp(BStruct2PtrPtr)
+ pp3 = newp(BStruct3PtrPtr)
+ pp1[0] = pp1[0]
+ e = py.test.raises(TypeError, "pp3[0] = pp1[0]")
+ assert str(e.value).startswith("initializer for ctype 'bar *' must be a ")
+ assert str(e.value).endswith(", not cdata 'foo *'")
+ e = py.test.raises(TypeError, "pp2[0] = pp1[0]")
+ assert str(e.value) == ("initializer for ctype 'foo *' appears indeed to "
+ "be 'foo *', but the types are different (check "
+ "that you are not e.g. mixing up different ffi "
+ "instances)")
+
def test_version():
# this test is here mostly for PyPy
assert __version__ == "1.2.0"
More information about the pypy-commit
mailing list