[pypy-commit] cffi default: Test and fix.

arigo noreply at buildbot.pypy.org
Tue Jun 26 10:02:39 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r513:ad29c07c0119
Date: 2012-06-25 21:27 +0200
http://bitbucket.org/cffi/cffi/changeset/ad29c07c0119/

Log:	Test and fix.

diff --git a/c/_ffi_backend.c b/c/_ffi_backend.c
--- a/c/_ffi_backend.c
+++ b/c/_ffi_backend.c
@@ -764,6 +764,8 @@
             if (!CData_Check(init))
                 goto cannot_convert;
             ctinit = ((CDataObject *)init)->c_type;
+            if (!(ctinit->ct_flags & (CT_POINTER|CT_FUNCTIONPTR|CT_ARRAY)))
+                goto cannot_convert;
             if (ctinit->ct_itemdescr != ct->ct_itemdescr &&
                     !(ct->ct_itemdescr->ct_flags & CT_CAST_ANYTHING))
                 goto cannot_convert;
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -1023,3 +1023,10 @@
     assert str(a) == "hello"
     p = a + 2
     assert str(p) == "llo"
+
+def test_bug_convert_to_ptr():
+    BChar = new_primitive_type("char")
+    BCharP = new_pointer_type(BChar)
+    BDouble = new_primitive_type("double")
+    x = cast(BDouble, 42)
+    py.test.raises(TypeError, newp, new_pointer_type(BCharP), x)


More information about the pypy-commit mailing list