Author: Armin Rigo <[email protected]>
Branch:
Changeset: r58815:4cf40b5094b7
Date: 2012-11-09 18:07 +0100
http://bitbucket.org/pypy/pypy/changeset/4cf40b5094b7/
Log: Test from cffi/2f3f5a229adb and fix.
diff --git a/pypy/module/_cffi_backend/ctypefunc.py
b/pypy/module/_cffi_backend/ctypefunc.py
--- a/pypy/module/_cffi_backend/ctypefunc.py
+++ b/pypy/module/_cffi_backend/ctypefunc.py
@@ -305,6 +305,10 @@
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
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
@@ -937,6 +937,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