Commits

Armin Rigo committed 4cf40b5

Test from cffi/2f3f5a229adb and fix.

Comments (0)

Files changed (2)

pypy/module/_cffi_backend/ctypefunc.py

             while isinstance(ct, ctypearray.W_CTypeArray):
                 flat *= ct.length
                 ct = ct.ctitem
+            if flat <= 0:
+                raise OperationError(space.w_NotImplementedError,
+                    space.wrap("cannot pass as argument or return value "
+                               "a struct with a zero-length array"))
             nflat += flat
 
         # allocate an array of (nflat + 1) ffi_types

pypy/module/_cffi_backend/test/_backend_test_c.py

     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