Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r1035:2f3f5a229adb
Date: 2012-11-09 18:04 +0100
http://bitbucket.org/cffi/cffi/changeset/2f3f5a229adb/

Log:    Cannot pass a struct with an array of length 0. We can't correctly
        build the ffi struct in this case.

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -3433,7 +3433,12 @@
                 flat *= ct->ct_length;
                 ct = ct->ct_itemdescr;
             }
-            assert(flat >= 0);
+            if (flat <= 0) {
+                PyErr_SetString(PyExc_NotImplementedError,
+                                "cannot pass as argument or return value "
+                                "a struct with a zero-length array");
+                return NULL;
+            }
             nflat += flat;
             cf = cf->cf_next;
         }
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -941,6 +941,16 @@
     for i in range(10):
         assert res.a[i] == p1.a[i] - p2.a[i]
 
+def test_cannot_pass_struct_with_array_of_length_0():
+    BInt = new_primitive_type("int")
+    BArray0 = new_array_type(new_pointer_type(BInt), 0)
+    BStruct = new_struct_type("foo")
+    complete_struct_or_union(BStruct, [('a', BArray0)])
+    py.test.raises(NotImplementedError, new_function_type,
+                   (BStruct,), BInt, False)
+    py.test.raises(NotImplementedError, new_function_type,
+                   (BInt,), BStruct, False)
+
 def test_call_function_9():
     BInt = new_primitive_type("int")
     BFunc9 = new_function_type((BInt,), BInt, True)    # vararg
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to